private IEnumerable<RevitProductInfo> GetProducts(int verion)
{
var revitKey =
Registry.LocalMachine.OpenSubKey(RevitRegistryKeyName, false);
if (revitKey == null)
yield break;
var revitVersionNumberKey =
revitKey.OpenSubKey(verion.ToString(), false);
if (revitVersionNumberKey == null)
yield break;
var revitVersionNumberKeyPattern = @"^REVIT-\d{2}:\d{4}$";
var regex = new Regex(revitVersionNumberKeyPattern);
foreach (var keyName in revitVersionNumberKey.GetSubKeyNames())
{
if (regex.IsMatch(keyName))
{
var revitVersionKey =
revitVersionNumberKey.OpenSubKey(keyName, false);
RevitProductInfo revitProductInfo =
RevitProductInfo.Create(verion);
revitProductInfo.Language =
revitVersionKey.GetValue("Language", string.Empty).ToString();
revitProductInfo.Location =
revitVersionKey.GetValue("InstallationLocation", string.Empty).ToString();
revitProductInfo.ProductName =
revitVersionKey.GetValue("ProductName", string.Empty).ToString();
revitProductInfo.Version =
revitVersionKey.GetValue("Version", string.Empty).ToString();
yield return revitProductInfo;
}
}
}
public abstract class RevitProductInfo : ProductInfo
{
public static RevitProductInfo Create(int version)
{
switch (version)
{
case 2012:
return new Revit2012ProductInfo();
case 2013:
return new Revit2013ProductInfo();
case 2014:
return new Revit2014ProductInfo();
default:
throw new NotSupportedException
(string.Format("Revit {0} is not supported", version));
}
}
public override string ProgramPath
{
get { return Path.Combine(Location, "Program", "Revit.exe"); }
}
}
public class Revit2012ProductInfo : RevitProductInfo
{
}
public class Revit2013ProductInfo : RevitProductInfo
{
}
public class Revit2014ProductInfo : RevitProductInfo
{
public override string ProgramPath
{
get { return Path.Combine(Location, "Revit.exe"); }
}
}