我正在为第三方应用程序开发一个插件,它需要使用System.LicenseProvider。
许可文件本身是FlexLM生成的。
所以我有:
[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;
}
}
}(+其他不相关的方法),使用:
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,但是:
我试着用
LicenseManager.IsValid(typeof(ModuleFlexFeature),new ModuleFlexFeature(), out thisLicense);但两者都有相似的结果(代码似乎有效,但thisLicense为null)
我做错什么了吗?LicenseManager与FlexLM兼容吗?或者,在运行我的插件的第三方应用程序(不知何故没有正确连接到许可服务器)上有错误吗?怎么检查?
谢谢
发布于 2016-08-09 19:59:06
好吧,经过进一步的调查:
您不能使用LicFileProvider读取FlexLMFiles
您必须创建自己的LicenseProvider并实现getLicense。要做到这一点,您必须知道文件在哪里/可能在哪里,并使用lmutil。因此,首先,您需要检查许可是否可用。
受this previous question的启发,我能够获得以下代码来检查许可证是否有效(并检测当使用多个lm服务器时,使用哪一个服务器):
//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;这个很好..。但是这会使而不是生成一个许可证(这只能检查我是否能够合理地希望获得一个许可)。
我已经调查过了,但它似乎也没有产生任何标记。你有什么想法吗?
https://stackoverflow.com/questions/38726575
复制相似问题