private IEnumerable <KeyValuePair <TemplateKey, ProviderField> > ExtractFromTypes(Assembly a) { if (!AssemblyInfo.GetAssemblyInfo(a).ScanForTemplates) { yield break; } foreach (TypeInfo type in a.GetTypesHelper()) { if (type.IsDefined(typeof(TemplatesAttribute))) { foreach (FieldInfo field in type.GetFields()) { if (!field.IsStatic) { continue; } if (typeof(ITemplate).IsAssignableFrom(field.FieldType)) { var fieldResult = new ProviderField(field); yield return(new KeyValuePair <TemplateKey, ProviderField>(fieldResult.Key, fieldResult)); } } } } }
private void AddSourceFile(string file) { var assemblyInfo = AssemblyInfo.GetAssemblyInfo(file); if (assemblyInfo != null) { AssemblyInfo existingInfo; if (assemblies.TryGetValue(assemblyInfo.Name, out existingInfo)) { var fileName = Path.GetFileName(assemblyInfo.Path); var existingFileName = Path.GetFileName(existingInfo.Path); if (fileName.Equals(existingFileName)) { Log.LogError($"Duplicate entries for {assemblyInfo.Name} : {assemblyInfo.Path} & {existingInfo.Path}"); } else { // tolerate mismatched filenames, eg: foo.dll and foo.ni.dll Log.LogMessage($"Duplicate entries for {assemblyInfo.Name}, but different filenames : preferring {existingInfo.Path} over {assemblyInfo.Path}."); } } else { assemblies[assemblyInfo.Name] = assemblyInfo; } } }
public void GetXmlNamespace_should_get_xmlns_from_clrnamespaces() { AssemblyInfo ai = AssemblyInfo.GetAssemblyInfo(typeof(TypeReference).GetTypeInfo().Assembly); Assert.Equal(NamespaceUri.Parse(Xmlns.Core2008), ai.GetXmlNamespace("Carbonfrost.Commons.Core")); Assert.Equal(NamespaceUri.Parse(Xmlns.Core2008), ai.GetXmlNamespace("Carbonfrost.Commons.Core.Runtime")); }
public void LookupPrefix_should_account_for_XmlnsPrefixAttribute() { var ai = AssemblyInfo.GetAssemblyInfo(typeof(TypeReference).GetTypeInfo().Assembly); var xr = ai.XmlNamespaceResolver; var all = xr.LookupNamespace("core"); Assert.Equal(Xmlns.Core2008, all); }
static IEnumerable <Type> GetRootProviderTypes(Assembly a) { IProviderRegistration registration = AssemblyInfo.GetAssemblyInfo(a).GetProviderRegistration(); ProviderRegistrationContext context = new ProviderRegistrationContext(a); registration.RegisterRootProviderTypes(context); return(context.EnumerateRoots()); }
private static IEnumerable <ProviderValueSource> ExtractFromTypes(Assembly a) { IProviderRegistration registration = AssemblyInfo.GetAssemblyInfo(a).GetProviderRegistration(); ProviderRegistrationContext context = new ProviderRegistrationContext(a); registration.RegisterProviderTypes(context); return(context.EnumerateValueSources()); }
public void XmlNamespaces_should_get_known_namespaces() { Assembly a = typeof(TypeReference).GetTypeInfo().Assembly; var info = AssemblyInfo.GetAssemblyInfo(a); Assert.Equal(new [] { NamespaceUri.Parse(Xmlns.Core2008) }, info.XmlNamespaces.ToArray()); }
public void LookupPrefix_should_return_reflected_ns_name() { var ai = AssemblyInfo.GetAssemblyInfo(typeof(TypeReference).GetTypeInfo().Assembly); var xr = (AssemblyInfoXmlNamespaceResolver)ai.XmlNamespaceResolver; var all = xr.LookupPrefix(Xmlns.Core2008); Assert.Equal("runtime", all); }
public void GetXmlNamespaces_should_get_clr_namespaces_from_xmlns() { AssemblyInfo ai = AssemblyInfo.GetAssemblyInfo(typeof(TypeReference).GetTypeInfo().Assembly); var all = ai.GetClrNamespaces(NamespaceUri.Parse(Xmlns.Core2008)); Assert.Contains("Carbonfrost.Commons.Core", all); Assert.Contains("Carbonfrost.Commons.Core.Runtime", all); Assert.DoesNotContain("Carbonfrost.Commons.ComponentModel.Annotations", all); }
private void UploadSplitAssembly(AssemblyInfo assemblyInfo, PluginRegistrationHelper pluginRegistrationHelper, Type type) { var temp = new FileInfo(ProjectFilePath); var splitAssembly = AssemblyInfo.GetAssemblyInfo(assemblyInfo.AssemblyDirectory.Replace(temp.DirectoryName, temp.DirectoryName + type.Name) + "\\" + type.Name + ".dll"); var pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(null, splitAssembly, SolutionName, RegistrationType); WriteVerbose($"UpsertPluginAssembly {pluginAssemblyId} completed"); pluginRegistrationHelper.UpsertPluginTypeAndSteps(pluginAssemblyId, type, SolutionName, RegistrationType); }
public static IEnumerable <string> FilterNamespaces( this Assembly assembly, string namespacePattern) { if (assembly == null) { throw new ArgumentNullException(nameof(assembly)); } return(AssemblyInfo.GetAssemblyInfo(assembly).GetNamespaces(namespacePattern)); }
public void BuildDate_should_derive_from_metadata() { var a = AssemblyInfo.GetAssemblyInfo(typeof(AssemblyInfoTests).GetTypeInfo().Assembly); var attr = typeof(AssemblyInfoTests).GetTypeInfo().Assembly.GetCustomAttributes(typeof(AssemblyMetadataAttribute)) .Cast <AssemblyMetadataAttribute>() .First(n => n.Key == "[share:BuildDate]"); var expected = DateTimeOffset.Parse(attr.Value); Assert.Equal(expected, a.BuildDate); }
public void GetNamespacesInScope_should_contain_all_xmlns() { var ai = AssemblyInfo.GetAssemblyInfo(typeof(TypeReference).GetTypeInfo().Assembly); var xr = (AssemblyInfoXmlNamespaceResolver)ai.XmlNamespaceResolver; var all = xr.GetNamespacesInScope(XmlNamespaceScope.Local); Assert.Equal(2, all.Count); Assert.Contains("runtime", all.Keys); Assert.Contains("core", all.Keys); Assert.Equal(Xmlns.Core2008, all["runtime"]); }
public void GetNamespacesInScope_should_contain_all_inherited_xmlns() { var ai = AssemblyInfo.GetAssemblyInfo(typeof(ServiceProviderTests).GetTypeInfo().Assembly); Assert.True(ai.Scannable); var all = ai.XmlNamespaceResolver.GetNamespacesInScope(XmlNamespaceScope.All); Assert.Equal(3, all.Count); Assert.Contains("test-sr", all.Keys); Assert.Contains("runtime", all.Keys); Assert.Contains("core", all.Keys); }
private Guid UploadSplitAssembly(AssemblyInfo assemblyDetails, string assemblyName, string version, string content, PluginRegistrationHelper pluginRegistrationHelper, Assembly pluginAssembly, Type type) { var temp = new FileInfo(ProjectFilePath); var splitAssembly = AssemblyInfo.GetAssemblyInfo(assemblyDetails.AssemblyDirectory.Replace(temp.DirectoryName, temp.DirectoryName + type.Name) + "\\" + type.Name + ".dll"); assemblyName = splitAssembly.AssemblyName; version = splitAssembly.Version; content = splitAssembly.Content; var pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyName, version, content, SolutionName, IsWorkflowActivityAssembly, RegistrationType); base.WriteVerbose(string.Format("UpsertPluginAssembly {0} completed", pluginAssemblyId)); return(pluginAssemblyId); }
public EnvResponse GetEnvironment() { var assemblyInfo = AssemblyInfo.GetAssemblyInfo(); var ret = new EnvResponse { AppName = assemblyInfo.Title, MachineName = Environment.MachineName, Version = assemblyInfo.Version }; return(ret); }
public void Namespaces_should_get_known_namespaces() { Assembly a = typeof(TypeReference).GetTypeInfo().Assembly; var info = AssemblyInfo.GetAssemblyInfo(a); // Notice that default ns isn't included // Exclude System (and coverlet when coverage is running) Assert.SetEqual(new [] { "Carbonfrost.Commons.Core.Resources", "Carbonfrost.Commons.Core", "Carbonfrost.Commons.Core.Runtime", }, info.Namespaces.Except(new[] { "System", "Coverlet.Core.Instrumentation.Tracker" })); }
private string GetCanonicalTypeName() { var type = Resolve(); var assembly = AssemblyInfo.GetAssemblyInfo(type.GetTypeInfo().Assembly); string prefix = assembly.GetXmlNamespacePrefix( ToQualifiedName().Namespace ); if (string.IsNullOrEmpty(prefix)) { return(type.Name); } return(string.Concat(prefix, ':', type.Name)); }
static string FindPrefix(Type dt) { string prefix = HxlCompilerContext.Current.Prefix; if (prefix == null) { prefix = AssemblyInfo.GetAssemblyInfo(dt.GetTypeInfo().Assembly) .GetXmlNamespacePrefix(dt.GetQualifiedName().Namespace); } if (prefix != null) { prefix = prefix + ":"; } return(prefix); }
public static QualifiedName GetQualifiedName(this Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var tt = type.GetTypeInfo(); if (tt.IsGenericParameter || (tt.IsGenericType && !tt.IsGenericTypeDefinition)) { throw RuntimeFailure.QualifiedNameCannotBeGeneratedFromConstructed("type"); } AssemblyInfo ai = AssemblyInfo.GetAssemblyInfo(tt.Assembly); NamespaceUri xmlns = ai.GetXmlNamespace(tt.Namespace); return(xmlns + QualName(type)); }
public MainWindow() { try { InitializeComponent(); AssemblyInfo = AssemblyInfo.GetAssemblyInfo(Assembly.GetExecutingAssembly(), Author, ProgramDate); GetHostfilePhase(); cbx_phase.ItemsSource = PhaseList; cbx_phase.SelectedIndex = GetHostfileIndex(); var viewModel = new ViewModel(); DataContext = viewModel; Phase = HostfilePhase; viewModel.Phase = Phase; viewModel.Phase = cbx_phase.Text; Loaded += delegate { var thread = new Thread(() => { while (true) { viewModel.Phase = Phase; } ; }) { IsBackground = true }; thread.Start(); }; Title = $"{AssemblyInfo.Product} - {AssemblyInfo.Version} - {ClassInfraPhases.PhaseOperations.InfraHost()}"; myStatusBar.InitStatusbar(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error); Application.Current.Shutdown(); } }
public override Type Resolve() { string cleanName = _qn.LocalName.Replace('.', '+').Replace('-', '`'); foreach (var a in App.Assemblies) { AssemblyInfo ai = AssemblyInfo.GetAssemblyInfo(a); foreach (string clrns in ai.GetClrNamespaces(_qn.Namespace)) { Type result = a.GetType(CombinedTypeName(clrns, cleanName)); if (result != null) { return(result); } } } return(null); }
static IAdapterFactory FromAssemblyInternal(Assembly assembly) { if (!AssemblyInfo.GetAssemblyInfo(assembly).ScanForAdapters) { return(Null); } // This will contain all factories that are declared. If any factory has an explicit role, then // all adapters in that role must be made available from it (otherwise, the optimization is pointless since we // have to fall back to a full scan). var all = (AdapterFactoryAttribute[])assembly.GetCustomAttributes(typeof(AdapterFactoryAttribute)); var except = new HashSet <string>(StringComparer.OrdinalIgnoreCase); var genericFactories = new List <IAdapterFactory>(); // [assembly: AdapterFactory(typeof(H))] var roleFactories = new List <IAdapterFactory>(); // [assembly: StreamingSourceFactory(typeof(H))] if (all.Length == 0) { return(ReflectedAdapterFactory.Create(assembly, Array.Empty <string>())); } foreach (var t in all) { var inst = (IAdapterFactory)Activator.CreateInstance(t.AdapterFactoryType); if (t.Role == null) { genericFactories.Add(inst); } else { except.Add(t.Role); // Don't consider role because it has a factory roleFactories.Add(inst); } } // If no generic factories were defined, then fallback available if (genericFactories.Count == 0) { genericFactories.Add(ReflectedAdapterFactory.Create(assembly, except)); } // Consider role factories before generic ones return(Compose(roleFactories.Concat(genericFactories))); }
private void AddSourceFile(string file) { var assemblyInfo = AssemblyInfo.GetAssemblyInfo(file); if (assemblyInfo == null) { otherFiles.Add(Path.GetFileName(file)); } else { AssemblyInfo existingInfo; if (assemblies.TryGetValue(assemblyInfo.Name, out existingInfo)) { Log.LogError($"Duplicate entries for {assemblyInfo.Name} : {assemblyInfo.Path} & {existingInfo.Path}"); } else { assemblies[assemblyInfo.Name] = assemblyInfo; } } }
protected override void ProcessRecord() { base.ProcessRecord(); base.WriteVerbose("Plugin Registration intiated"); if (UseSplitAssembly) { if (!File.Exists(ProjectFilePath)) { throw new Exception("Project File Path is required if you want to split assembly."); } if (RegistrationType.Equals("delsert", StringComparison.InvariantCultureIgnoreCase)) { throw new Exception("Registration type 'Remove Plugin Types and Steps which are not in mapping and Upsert' will not work when 'Split Assembly' is enabled."); } if (!File.Exists(MappingJsonPath)) { throw new Exception("Mapping Json Path is required if you want to split assembly."); } } var assemblyDetails = AssemblyInfo.GetAssemblyInfo(AssemblyPath); string assemblyName = assemblyDetails.AssemblyName; string version = assemblyDetails.Version; string content = assemblyDetails.Content; base.WriteVerbose(string.Format("Assembly Name: {0}", assemblyName)); base.WriteVerbose(string.Format("Assembly Version: {0}", version)); using (var context = new CIContext(OrganizationService)) { PluginRegistrationHelper pluginRegistrationHelper = new PluginRegistrationHelper(OrganizationService, context, this); base.WriteVerbose("PluginRegistrationHelper intiated"); Assembly pluginAssembly = null; Guid pluginAssemblyId = Guid.Empty; if (File.Exists(MappingJsonPath)) { base.WriteVerbose("Reading mapping json file"); string json = File.ReadAllText(MappingJsonPath); pluginAssembly = JsonConvert.DeserializeObject <Assembly>(json); base.WriteVerbose("Deserialized mapping json file"); } else { pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyName, version, content, SolutionName, IsWorkflowActivityAssembly, RegistrationType); base.WriteVerbose(string.Format("UpsertPluginAssembly {0} completed", pluginAssemblyId)); } if (pluginAssembly != null) { // var assemblyTypes = IsWorkflowActivityAssembly ? pluginAssembly.WorkflowTypes : pluginAssembly.PluginTypes; if (pluginAssembly.PluginTypes == null) { base.WriteVerbose("No mapping found for types."); } else { if (RegistrationType.Equals("delsert", StringComparison.InvariantCultureIgnoreCase)) { pluginRegistrationHelper.RemoveComponentsNotInMapping(assemblyName, pluginAssembly); RegistrationType = "upsert"; } if (!UseSplitAssembly) { pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyName, version, content, SolutionName, IsWorkflowActivityAssembly, RegistrationType); base.WriteVerbose(string.Format("UpsertPluginAssembly {0} completed", pluginAssemblyId)); } foreach (var type in pluginAssembly.PluginTypes) { if (UseSplitAssembly) { pluginAssemblyId = UploadSplitAssembly(assemblyDetails, assemblyName, version, content, pluginRegistrationHelper, pluginAssembly, type); } var pluginTypeId = pluginRegistrationHelper.UpsertPluginType(pluginAssemblyId, type, SolutionName, RegistrationType, IsWorkflowActivityAssembly, assemblyName); base.WriteVerbose(string.Format("UpsertPluginType {0} completed", pluginTypeId)); if (!IsWorkflowActivityAssembly) { foreach (var step in type.Steps) { var sdkMessageProcessingStepId = pluginRegistrationHelper.UpsertSdkMessageProcessingStep(pluginTypeId, step, SolutionName, RegistrationType); base.WriteVerbose(string.Format("UpsertSdkMessageProcessingStep {0} completed", sdkMessageProcessingStepId)); foreach (var image in step.Images) { var sdkMessageProcessingStepImageId = pluginRegistrationHelper.UpsertSdkMessageProcessingStepImage(sdkMessageProcessingStepId, image, SolutionName, RegistrationType); base.WriteVerbose(string.Format("UpsertSdkMessageProcessingStepImage {0} completed", sdkMessageProcessingStepImageId)); } } } } } } } base.WriteVerbose("Plugin Registration completed"); }
protected override void ProcessRecord() { base.ProcessRecord(); WriteVerbose("Plugin Registration intiated"); if (UseSplitAssembly) { if (!File.Exists(ProjectFilePath)) { throw new Exception("Project File Path is required if you want to split assembly."); } if (RegistrationType == RegistrationTypeEnum.Delsert) { throw new Exception("Registration type 'Remove Plugin Types and Steps which are not in mapping and Upsert' will not work when 'Split Assembly' is enabled."); } if (!File.Exists(MappingFile)) { throw new Exception("Mapping Json Path is required if you want to split assembly."); } } var assemblyInfo = AssemblyInfo.GetAssemblyInfo(AssemblyPath); WriteVerbose($"Assembly Name: {assemblyInfo.AssemblyName}"); WriteVerbose($"Assembly Version: {assemblyInfo.Version}"); using (var context = new CIContext(OrganizationService)) { var pluginRegistrationHelper = new PluginRegistrationHelper(OrganizationService, context, WriteVerbose, WriteWarning); WriteVerbose("PluginRegistrationHelper intiated"); Assembly pluginAssembly = null; Guid pluginAssemblyId = Guid.Empty; if (File.Exists(MappingFile)) { pluginAssembly = ReadMappingFile(); pluginAssemblyId = pluginAssembly.Id ?? Guid.Empty; } else { pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyInfo, SolutionName, RegistrationType); WriteVerbose($"UpsertPluginAssembly {pluginAssemblyId} completed"); WriteVerbose("Plugin Registration completed"); return; } if (pluginAssembly == null) { WriteVerbose("Plugin Registration completed"); return; } if (pluginAssembly.PluginTypes == null) { WriteVerbose("No mapping found for types."); WriteVerbose("Plugin Registration completed"); return; } if (RegistrationType == RegistrationTypeEnum.Delsert) { WriteVerbose($"RemoveComponentsNotInMapping {assemblyInfo.AssemblyName} started"); pluginRegistrationHelper.RemoveComponentsNotInMapping(pluginAssembly); WriteVerbose($"RemoveComponentsNotInMapping {assemblyInfo.AssemblyName} completed"); RegistrationType = RegistrationTypeEnum.Upsert; } if (UseSplitAssembly) { foreach (var type in pluginAssembly.PluginTypes) { UploadSplitAssembly(assemblyInfo, pluginRegistrationHelper, type); } } else { WriteVerbose($"UpsertPluginAssembly {pluginAssemblyId} started"); pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyInfo, SolutionName, RegistrationType); WriteVerbose($"UpsertPluginAssembly {pluginAssemblyId} completed"); foreach (var type in pluginAssembly.PluginTypes) { pluginRegistrationHelper.UpsertPluginTypeAndSteps(pluginAssemblyId, type, SolutionName, RegistrationType); } } } WriteVerbose("Plugin Registration completed"); }
public void Properties_should_contain_expected_properties(string name) { var a = AssemblyInfo.GetAssemblyInfo(typeof(AssemblyInfoTests).GetTypeInfo().Assembly); Assert.True(a.Metadata.HasProperty(name)); }
internal static string GetDefaultPrefix(NamespaceUri ns, Assembly assembly) { return(AssemblyInfo.GetAssemblyInfo(assembly) .GetXmlNamespacePrefix(ns)); }