/// <summary> /// Enumerates assemblies from the global assembly cache. /// </summary> /// <param name="onAssemblyEnumerated">Action to call when each assembly is enumerated.</param> /// <returns> /// The time taken to enumerate all assemblies. /// </returns> public TimeSpan EnumerateAssemblies(Action <AssemblyDescription> onAssemblyEnumerated) { // Start a stopwatch. var stopwatch = new Stopwatch(); stopwatch.Start(); // Create an assembly cache enumerator. var assemblyCacheEnum = new AssemblyCacheEnumerator(null); // Enumerate the assemblies. var assemblyName = assemblyCacheEnum.GetNextAssembly(); while (assemblyName != null) { // Create the assembly description. var desc = new AssemblyDescription(assemblyName); // Create an assembly view model. onAssemblyEnumerated(desc); assemblyName = assemblyCacheEnum.GetNextAssembly(); } // Stop the stopwatch. stopwatch.Stop(); // Return the elapsed time. return(stopwatch.Elapsed); }
private static void GetSubKeys(RegistryKey SubKey, string b, string name) { foreach (string sub in SubKey.GetSubKeyNames()) { // MessageBox.Show(sub); // RegistryKey local = Registry.Users; RegistryKey local = SubKey.OpenSubKey(sub); if (local.GetValue(null) != null) { var v = local.GetValue(null); if (sub.ToString() == b) { AssemblyDescription asd = null; string c = local.Name.ToString(); //RegistryKey r = local.OpenSubKey(local.GetValue(null).ToString()); //if(v.ToString().EndsWith(".dll") == true) asd = new GACManagerApi.AssemblyDescription(v.ToString(), "", true); asd.Name = name; C.Add(asd); } } GetSubKeys(local, b, name); // By recalling itself it makes sure it get all the subkey names } }
static async public Task <ArrayList> EnumerateAssemblies() { ArrayList L = new ArrayList(); // Start a stopwatch. //var stopwatch = new Stopwatch(); //stopwatch.Start(); // Create an assembly cache enumerator. var assemblyCacheEnum = new AssemblyCacheEnumerator(null); // Enumerate the assemblies. var assemblyName = assemblyCacheEnum.GetNextAssembly(); while (assemblyName != null) { // Create the assembly description. var desc = new AssemblyDescription(assemblyName); // Create an assembly view model. //onAssemblyEnumerated(desc); assemblyName = assemblyCacheEnum.GetNextAssembly(); L.Add(desc); } // Stop the stopwatch. //stopwatch.Stop(); // Return the elapsed time. //return stopwatch.Elapsed; return(L); }
public void ReflectionProperties() { // Get the first assembly in the global assembly cache. var someAssembly = new AssemblyDescription(new AssemblyCacheEnumerator().GetNextAssembly()); // Show the Runtime Version. System.Diagnostics.Trace.WriteLine(someAssembly.ReflectionProperties.RuntimeVersion); }
static List <IFileListing> GetDllListing(IFileListing src) { var completeList = new List <IFileListing>(); var fileSystemParent = new DllListing { Name = "File System", IsDirectory = true }; var gacItem = new DllListing { Name = "GAC", IsDirectory = true }; if (src == null) { var drives = DriveInfo.GetDrives().Where(info => info.DriveType != DriveType.CDRom && info.DriveType != DriveType.Removable); try { var listing = drives.Select(BuildDllListing); fileSystemParent.Children = listing.ToList(); } catch (Exception e) { Dev2Logger.Error(e.Message, GlobalConstants.WarewolfError); } var enumAssembly = new AssemblyCacheEnumerator(); var assemblyName = enumAssembly.GetNextAssembly(); var gacList = new List <IFileListing>(); while (assemblyName != null) { // Create the assembly description. try { var displayName = new AssemblyDescription(assemblyName).DisplayName; var name = GlobalConstants.GACPrefix + displayName; gacList.Add(new DllListing { Name = displayName, FullName = name, IsDirectory = false }); } catch (Exception e) { Dev2Logger.Error(e.Message, GlobalConstants.WarewolfError); } // Create an assembly view model. assemblyName = enumAssembly.GetNextAssembly(); } gacItem.Children = gacList; completeList.Add(fileSystemParent); completeList.Add(gacItem); } else { if (src.IsDirectory) { completeList = GetChildrenForDllListing(new DirectoryInfo(src.FullName)); } } return(completeList); }
public AboutBox() { InitializeComponent(); this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion); this.labelCopyright.Text = AssemblyCopyright; this.labelCompanyName.Text = AssemblyCompany; this.textBoxDescription.Text = AssemblyDescription.Replace("NL", Environment.NewLine); this.labelLink.Text = "http://blogs.msdn.com/b/nadeemis/archive/2012/08/24/sharepoint-2013-search-rest-api.aspx"; }
public AboutBasecampSync() { InitializeComponent(); this.Text = String.Format("About {0}", AssemblyTitle); this.labelProductName.Text = AssemblyProduct; this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion); this.labelCopyright.Text = AssemblyCopyright; this.textBoxDescription.Lines = AssemblyDescription.Split('|'); }
public void FusionProperties() { // Get the first assembly in the global assembly cache. var someAssembly = new AssemblyDescription(new AssemblyCacheEnumerator().GetNextAssembly()); // Show the install references. foreach (var installReference in someAssembly.FusionProperties.InstallReferences) { System.Diagnostics.Trace.WriteLine(installReference.Description); } }
private AssemblyDescription GetAssemblyDescription(string fullName, string path) { // maybe we already have one like that (interning) if (assemblyFromAssemblyPath.ContainsKey(path)) { return(assemblyFromAssemblyPath[path]); } var description = new AssemblyDescription(fullName, path); assemblyFromAssemblyPath.Add(path, description); return(description); }
public static XmlElement GetFrameworkXmlDoc(string assembly, string data, string prefix = "") { if (asmd == null) { return(null); } if (asmd.ContainsKey(assembly) == false) { return(null); } AssemblyDescription d = asmd[assembly]; XmlElement xml = d.GetDocument(data, prefix); return(xml); }
public static Type FindTypeFromAssemblies(string name) { Type T = null; foreach (string s in asmd.Keys) { AssemblyDescription d = asmd[s]; T = d.GetTypeForName(name); if (T != null) { return(T); } } return(T); }
public void EnumerateAssemblies() { // Create an assembly enumerator. var assemblyEnumerator = new AssemblyCacheEnumerator(); // Get the first assembly. var assemblyName = assemblyEnumerator.GetNextAssembly(); // Start to loop through the assemblies. while (assemblyName != null) { // The 'assemblyName' object is a COM interface, if we create an // AssemblyDescription from it, we will have access to more information. var assemblyDescription = new AssemblyDescription(assemblyName); // Show the display name. System.Diagnostics.Trace.WriteLine("Display Name: " + assemblyDescription.DisplayName); // Move to the next assembly. assemblyName = assemblyEnumerator.GetNextAssembly(); } }
private void FindFrameworks() { if (frameworks == null || frameworks.Count < 0) { L = new ArrayList(); var ac = new AssemblyCacheEnumerator(); int i = 0; while (i < 2000) { GACManagerApi.Fusion.IAssemblyName name = ac.GetNextAssembly(); if (name == null) { break; } // Get the first assembly in the global assembly cache. var someAssembly = new AssemblyDescription(name); if (someAssembly == null) { break; } if (someAssembly.Name == null) { break; } // Show the Runtime Version. System.Diagnostics.Trace.WriteLine(someAssembly.ReflectionProperties.RuntimeVersion); //richTextBox1.AppendText("\n\n\n" + someAssembly.ReflectionProperties.RuntimeVersion); //richTextBox1.AppendText("\n\n\n" + someAssembly.ReflectionProperties.ToString()); int p = L.IndexOf(someAssembly.ReflectionProperties.RuntimeVersion); if (p < 0) { L.Add(someAssembly.ReflectionProperties.RuntimeVersion); } i++; } } else { L = new ArrayList(); foreach (DirectoryInfo d in frameworks) { L.Add(d.Name); } } ToolStripComboBox c = toolStripComboBox1; c.DropDownStyle = ComboBoxStyle.DropDownList; c.Items.Clear(); foreach (string s in L) { c.Items.Add(s); } if (c.Items.Count > 0) { c.SelectedIndex = c.Items.Count - 1; } }
private TypeName(string s, ref int index) { try { var startIndex = index; var nameStartIndex = startIndex; var nameEndIndex = (int?)null; var assemblyDescriptionStartIndex = (int?)null; var assemblyDescriptionEndIndex = (int?)null; var hasGroupingBracket = false; var state = State.Name; for (; index < s.Length; ++index) { var currentCharacter = s[index]; var nextCharacter = index + 1 < s.Length ? s[index + 1] : (char?)null; if (state == State.Name) { if (currentCharacter == '[') { if (index == startIndex) { // Skip type grouping bracket hasGroupingBracket = true; nameStartIndex++; } else if (nextCharacter == ']' || nextCharacter == ',') { // Square bracket delimits an array state = State.Array; } else { // Square bracket delimits the generic argument list nameEndIndex = index; state = State.Generics; } } else if (currentCharacter == ']') { if (hasGroupingBracket) { // We finished the current grouping, break out break; } } else if (currentCharacter == ',') { // We're entering assembly description state = State.Assembly; assemblyDescriptionStartIndex = index + 1; if (nameEndIndex == null) { nameEndIndex = index; } } } else if (state == State.Array) { if (currentCharacter == ']') { state = State.Name; } } else if (state == State.Generics) { if (currentCharacter == ']') { state = State.Name; } else if (currentCharacter == ',' || currentCharacter == ' ') { // Generic delimiters } else { GenericParameters.Add(new TypeName(s, ref index)); } } else if (state == State.Assembly) { if (currentCharacter == ']') { if (hasGroupingBracket) { // We finished the current grouping, break out assemblyDescriptionEndIndex = index; break; } } } } if (nameEndIndex == null) { nameEndIndex = s.Length; } if (assemblyDescriptionEndIndex == null) { assemblyDescriptionEndIndex = s.Length; } Name = s.Substring(nameStartIndex, nameEndIndex.Value - nameStartIndex); if (Name.Contains('+')) { var nestedNames = Name.Split('+'); foreach (var nestedName in nestedNames) { nestedName.PartsAround('`', out var name, out var genericarity); names.Add(name); if (genericarity != null) { genericarities.Add(int.Parse(genericarity)); } else { genericarities.Add(0); } } } else { Name.PartsAround('`', out var name, out var genericarity); names.Add(name); if (genericarity != null) { genericarities.Add(int.Parse(genericarity)); } else { genericarities.Add(0); } } if (assemblyDescriptionStartIndex != null) { AssemblyDescription = s.Substring(assemblyDescriptionStartIndex.Value, assemblyDescriptionEndIndex.Value - assemblyDescriptionStartIndex.Value); var parts = AssemblyDescription.Split(',') .Select(x => x.Trim()) .ToList(); AssemblyVersion = LookForPairThenRemove(parts, "Version"); AssemblyCulture = LookForPairThenRemove(parts, "Culture"); AssemblyPublicKeyToken = LookForPairThenRemove(parts, "PublicKeyToken"); if (parts.Count > 0) { AssemblyName = parts[0]; } } } catch (Exception ex) { throw new FormatException($"Failed to parse type name: {s}", ex); } }
private static AssemblyDescription GetGacAssemblyPath(String moduleName) { ////String embedResourcePath = "DXApplication"; ////String embedResourceCategoryPath = "Path"; String dllModuleName = moduleName; // Create an assembly cache enumerator. var assemblyCacheEnum = new AssemblyCacheEnumerator(null); // Enumerate the assemblies. var assemblyName = assemblyCacheEnum.GetNextAssembly(); while (assemblyName != null) { // Create the assembly description. var desc = new AssemblyDescription(assemblyName); if (desc.Name.Equals(dllModuleName)) { // We'll need a display name of the assembly to uninstall. ////var displayName = @"Apex, Version=1.4.0.0, Culture=neutral, PublicKeyToken=98d06957926c086d, processorArchitecture=MSIL"; var displayName = desc.DisplayName; // When we try to uninstall an assembly, an uninstall disposition will be // set to indicate the success of the operation. var uninstallDisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown; // Install the assembly, without an install reference. try { IAssemblyCache ac = AssemblyCache.GetIAssemblyCache(displayName, null); if (ac != null) { return(desc); } } catch (Exception exception) { // We've failed to uninstall the assembly. throw new InvalidOperationException("Failed to uninstall the assembly.", exception); } finally { ////////assemblyName = null; } ////////// Did we succeed? ////////if (uninstallDisposition == IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED) ////////{ //////// // Hooray! //////// if (false) //////// { //////// assemblyName = null; //////// } //////// else //////// { //////// // Create an assembly cache enumerator. //////// assemblyCacheEnum = new AssemblyCacheEnumerator(null); //////// // Enumerate the assemblies. //////// assemblyName = assemblyCacheEnum.GetNextAssembly(); //////// } ////////} } else { assemblyName = assemblyCacheEnum.GetNextAssembly(); } } return(null); }
public bool TryInitialize(ScopeNode scopeNode, AssemblyDescription resourceAssembly, ViewAssemblyDescription viewAssemblyDescription) { return(true); }
private void ParseAssemblyRules(IEnumerable<Rule> assemblyRules) { foreach (var a in assemblyRules) { var assm = new AssemblyDescription { PrimaryFile = a.Parameter.FixFilepathSlashes() }; if (ValidVal(a.Prop("name"))) { assm.SetPropertyAndRuleProp("Name", a.Prop("name")); } //get all the includes var includes = from p in a.Properties where p.Name == "include" select p; foreach (var i in includes) { assm.AddInclude(i); } var excludes = from p in a.Properties where p.Name == "exclude" select p; foreach (var e in excludes) { assm.AddExclude(e); } _package.SharedLibs = _package.SharedLibs ?? new SharedLib(); _package.SharedLibs.Assemblies.Add(assm); if (ValidVal(a.Prop("global"))) { assm.SetPropertyAndRuleProp("GlobalEntry", a.Prop("global")); } } }
private static void UnregisterDll(String moduleName, Boolean log = false) { ////String embedResourcePath = "DXApplication"; ////String embedResourceCategoryPath = "Path"; String dllModuleName = moduleName; // Create an assembly cache enumerator. var assemblyCacheEnum = new AssemblyCacheEnumerator(null); // Enumerate the assemblies. var assemblyName = assemblyCacheEnum.GetNextAssembly(); while (assemblyName != null) { // Create the assembly description. var desc = new AssemblyDescription(assemblyName); if (desc.Name.Equals(dllModuleName)) { // We'll need a display name of the assembly to uninstall. ////var displayName = @"Apex, Version=1.4.0.0, Culture=neutral, PublicKeyToken=98d06957926c086d, processorArchitecture=MSIL"; var displayName = desc.DisplayName; // When we try to uninstall an assembly, an uninstall disposition will be // set to indicate the success of the operation. var uninstallDisposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown; // Install the assembly, without an install reference. try { AssemblyCache.UninstallAssembly(displayName, null, out uninstallDisposition); // Depending on the result, show the appropriate message. string message = string.Empty; switch (uninstallDisposition) { case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown: message = "Failed to uninstall assembly."; break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED: message = "The assembly was uninstalled successfully!"; break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_STILL_IN_USE: message = "Cannot uninstall this assembly - it is in use."; break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED: message = "Cannot uninstall this assembly - it has already been uninstalled."; break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_DELETE_PENDING: message = "Cannot uninstall this assembly - it has has a delete pending."; break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_HAS_INSTALL_REFERENCES: message = "Cannot uninstall this assembly - it was installed as part of another product."; break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_REFERENCE_NOT_FOUND: message = "Cannot uninstall this assembly - cannot find the assembly."; break; default: break; } if (log) { } } catch (Exception exception) { // We've failed to uninstall the assembly. throw new InvalidOperationException("Failed to uninstall the assembly.", exception); } finally { ////////assemblyName = null; } // Did we succeed? if (uninstallDisposition == IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED) { // Hooray! if (false) { assemblyName = null; } else { // Create an assembly cache enumerator. assemblyCacheEnum = new AssemblyCacheEnumerator(null); // Enumerate the assemblies. assemblyName = assemblyCacheEnum.GetNextAssembly(); } } } else { assemblyName = assemblyCacheEnum.GetNextAssembly(); } } }
private AssemblyDescription GetAssemblyDescription(string fullName, string path) { // maybe we already have one like that (interning) if(assemblyFromAssemblyPath.ContainsKey(path)) { return assemblyFromAssemblyPath[path]; } var description = new AssemblyDescription(fullName, path); assemblyFromAssemblyPath.Add(path, description); return description; }
public static List <DotnetLibrary> GetGACLibraries() { var gacList = new List <DotnetLibrary>(); try { var assemblyEnumerator = new AssemblyCacheEnumerator(); var assemblyName = assemblyEnumerator.GetNextAssembly(); while (assemblyName != null) { var assemblyDescription = new AssemblyDescription(assemblyName); string name = assemblyDescription.Name; bool probablyMicrosoftPackage = (name.StartsWith("Microsoft", StringComparison.Ordinal) || name.StartsWith("System", StringComparison.Ordinal)); if (!probablyMicrosoftPackage) { var gacLib = new DotnetLibrary { Culture = assemblyDescription.Culture, ProcessorArchitecture = assemblyDescription.ProcessorArchitecture, Name = name, Version = assemblyDescription.Version, Filepath = assemblyDescription.Path, }; FileInfo fi = new FileInfo(gacLib.Filepath); if (fi.Exists) { gacLib.Filename = fi.Name; FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(gacLib.Filepath); bool isDllFile = fvi.FileVersion != null; bool isMicrosoftCopyright = fvi.LegalCopyright != null && fvi.LegalCopyright.Contains("Microsoft Corporation"); if (isDllFile && !isMicrosoftCopyright) { gacLib.FileDescription = fvi.FileDescription; gacLib.Version = fvi.FileVersion; gacLib.ProductName = fvi.ProductName; gacLib.ProductVersion = fvi.ProductVersion; gacLib.Copyright = fvi.LegalCopyright; gacLib.Language = fvi.Language; gacLib.SHA1Hash = GetFileSHA1(gacLib.Filepath); gacLib.Md5Hash = GetFileMD5(gacLib.Filepath); try { gacLib.Issue = LibraryIssueChecker.GetIssue(gacLib); } catch { gacLib.Issue = null; } gacList.Add(gacLib); } } } assemblyName = assemblyEnumerator.GetNextAssembly(); } } catch (Exception ex) { Trace.TraceWarning("Could not load DLL list from the GAC. Error: {0}", ex.ToString()); Console.Error.WriteLine("Could not load DLL list from the GAC."); return(new List <DotnetLibrary>()); } return(gacList); }
public ResourceRouteHandler(Assembly assembly) { //Contract.Requires( assembly != null ); _themedAssemblies[""] = _root = new AssemblyDescription(assembly); }