首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LicenseManager与FlexLM的结合使用

LicenseManager与FlexLM的结合使用
EN

Stack Overflow用户
提问于 2016-08-02 17:06:57
回答 1查看 1.1K关注 0票数 0

我正在为第三方应用程序开发一个插件,它需要使用System.LicenseProvider。

许可文件本身是FlexLM生成的。

所以我有:

代码语言:javascript
复制
[LicenseProvider(typeof(LicFileLicenseProvider))]
public class MyLicensedModule
{
    protected System.ComponentModel.License thisLicense;
    protected ModuleFlexFeature thisfeature;

    public bool LicenseCheck()
    {
        bool isLicensed = LicenseManager.IsLicensed(typeof(ModuleFlexFeature)); //returns TRUE
        if(thisFeature==null) thisFeature = new ModuleFlexFeature();
        thisLicense = LicenseManager.Validate(typeof(ModuleFlexFeature),thisFeature);
        //no thrown exception
        return (thisLicense != null); //thisLicense is always null
    }

    public void Dispose()
    {
        if (thisLicense!=null)
        {
            thisLicense.Dispose();
            thisLicense = null;
        }
    }
}

(+其他不相关的方法),使用:

代码语言:javascript
复制
internal class ModuleFlexFeature
{
    public ModuleFlexFeature() { }
    public string FeatureName { get { return "myFlexLMFeature"; } }
    public float FeatureVersion { get { return 2016.0f; } }
}

使用Flexera的LMTOOLS,我可以获得许可服务器状态(我运行在7507@mypcname上,使用了myFlexLMFeature的1种许可证中的0)。

然后,我可以在第三方应用程序使用的额外服务器中添加7507@mypcname,但是:

  • isLicensed返回true (预期)
  • LicenseManager.Validate()不会抛出异常(预期)
  • thisLicense为null (不期望)

我试着用

代码语言:javascript
复制
LicenseManager.IsValid(typeof(ModuleFlexFeature),new ModuleFlexFeature(), out thisLicense);

但两者都有相似的结果(代码似乎有效,但thisLicense为null)

我做错什么了吗?LicenseManager与FlexLM兼容吗?或者,在运行我的插件的第三方应用程序(不知何故没有正确连接到许可服务器)上有错误吗?怎么检查?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-08-09 19:59:06

好吧,经过进一步的调查:

您不能使用LicFileProvider读取FlexLMFiles

您必须创建自己的LicenseProvider并实现getLicense。要做到这一点,您必须知道文件在哪里/可能在哪里,并使用lmutil。因此,首先,您需要检查许可是否可用。

this previous question的启发,我能够获得以下代码来检查许可证是否有效(并检测当使用多个lm服务器时,使用哪一个服务器):

代码语言:javascript
复制
//get the potential file candidates
string file = Environment.GetEnvironmentVariable("LM_LICENSE_FILE");
List<string> candidates = new List<string>(file.Split(';'));
foreach (string filecan in candidates)
{
    //read the lm stats for this
    string args = "lmstat -f " + MyFeatureName + " -c " + file;
    ProcessStartInfo info = new ProcessStartInfo(@"lmutil.exe", args);
    Process lmutil = Process.Start(info);
    string output = lmutil.StandardOutput.ReadToEnd();

    //now get the line
    string matchPattern = @"Users of (\w+):.*Total of (\d+) license.*Total of (\d+) license";
    MatchCollection matches = Regex.Matches(output, matchPattern);
    foreach(Match m in matches)
    {
        //are only returned: m.Succes = true and m.Groups[1].Value = MyFeatureName
        int value;
        int total = Int32.TryParse(m.Groups[2].Value, out value) ? value : 0;
        int used = Int32.TryParse(m.Groups[3].Value, out value) ? value : 0;
        if (total - used > 0) return true;
    }
}
return false;

这个很好..。但是这会使而不是生成一个许可证(这只能检查我是否能够合理地希望获得一个许可)。

我已经调查过了,但它似乎也没有产生任何标记。你有什么想法吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38726575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档