private static void SetProviderStrengthsAndWeaknesses(Feedback providerFeedback, IEnumerable <EmployerFeedbackSourceDto> feedbackForProvider) { var distinctAttributeList = feedbackForProvider.SelectMany(fp => fp.ProviderAttributes).GroupBy(pa => pa.Name).Select(group => group.Key); foreach (var providerAttributeName in distinctAttributeList) { var strengthAttribute = new ProviderAttribute { Name = providerAttributeName }; var weaknessAttribute = new ProviderAttribute { Name = providerAttributeName }; var matchingAttributeFeedback = feedbackForProvider .Select(a => a.ProviderAttributes.SingleOrDefault(p => p.Name == providerAttributeName)) .Where(pf => pf != default(ProviderAttributeSourceDto)); strengthAttribute.Count = matchingAttributeFeedback.Count(x => x.Value > 0); if (strengthAttribute.Count > 0) { providerFeedback.Strengths.Add(strengthAttribute); } weaknessAttribute.Count = matchingAttributeFeedback.Count(x => x.Value < 0); if (weaknessAttribute.Count > 0) { providerFeedback.Weaknesses.Add(weaknessAttribute); } } }
public void GetNames_should_include_default_type_name() { ProviderAttribute pa = new ProviderAttribute(typeof(StreamContext)); Assert.Equal(new[] { typeof(StreamContext).GetQualifiedName() }, pa.GetNames(typeof(StreamContext))); }
public void Then_Maps_All_Fields(int ukprn, ProviderAttribute source) { var actual = new ProviderRegistrationFeedbackAttributeImport().Map(ukprn, source); actual.Ukprn.Should().Be(ukprn); actual.AttributeName.Should().Be(source.Name); actual.Strength.Should().Be(source.Strengths); actual.Weakness.Should().Be(source.Weaknesses); }
public ProviderRegistrationFeedbackAttributeImport Map(int ukprn, ProviderAttribute source) { return(new ProviderRegistrationFeedbackAttributeImport { Ukprn = ukprn, AttributeName = source.Name, Strength = source.Strengths, Weakness = source.Weaknesses }); }
private void CreateProvider(MemberInfo memberInfo, ProviderAttribute providerAttribute, MethodBase method) { if (memberInfo.IsDefined(typeof(ProvidesSetAttribute))) { this.CreateSetProvider( method, providerAttribute, memberInfo.IsDefined(typeof(SingletonAttribute))); } else { this.CreateInstanceProvider(method, providerAttribute, memberInfo.IsDefined(typeof(SingletonAttribute))); } }
public void GetNames_should_be_distinct_by_ignoring_case() { ProviderAttribute pa = new ProviderAttribute(typeof(StreamContext)) { Name = "streamContext b b" }; var ns = typeof(StreamContext).GetQualifiedName().Namespace; Assert.SetEqual(new[] { ns + "streamContext", ns + "b", }, pa.GetNames(typeof(StreamContext)), QualifiedNameComparer.IgnoreCaseLocalName); }
private void CreateInstanceProvider(MethodBase method, ProviderAttribute providerAttribute, bool isSingleton) { InjectionProvider provider = isSingleton ? new SingletonInjectionProvider(method) : new InjectionProvider(method); if (providerAttribute.Name != null) { this.namedProviderMap.Add(providerAttribute.Name, provider); } if (providerAttribute.ProvidesType != null) { this.providerMap.Add(providerAttribute.ProvidesType, provider); } }
public void GetNames_should_generate_names_with_generated_ns() { ProviderAttribute pa = new ProviderAttribute(typeof(StreamContext)) { Name = "a\t\t\r\nb,c d" }; var ns = typeof(StreamContext).GetQualifiedName().Namespace; Assert.Equal(new[] { ns + "a", ns + "b", ns + "c", ns + "d", ns + "StreamContext", }, pa.GetNames(typeof(StreamContext))); }
public static void Initialize() { LoadSectionSystemData(); //Ensure table exists if (systemData.Tables.IndexOf(DbProviderFactoriesTable) > -1) { ////remove existing provider factory //if (systemData.Tables[systemData.Tables.IndexOf("DbProviderFactories")].Rows.Find("System.Data.SQLite") != null) //{ // systemData.Tables[systemData.Tables.IndexOf("DbProviderFactories")].Rows.Remove( // systemData.Tables[systemData.Tables.IndexOf("DbProviderFactories")].Rows.Find("System.Data.SQLite") // ); //} // Remove existing provider factories systemData.Tables[systemData.Tables.IndexOf("DbProviderFactories")].Rows.Clear(); } else { systemData.Tables.Add(DbProviderFactoriesTable); } List <DataProviderType> dbTypes = ((DataProviderType[])Enum.GetValues(typeof(DataProviderType))).ToList(); foreach (DataProviderType dbType in dbTypes) { ProviderAttribute pi = dbType.GetAttribute <ProviderAttribute>(); if (pi == null) { continue; } systemData.RegisterDbProvider(pi.Invariant, pi.Description, pi.Name, pi.FactoryType, null); } ////Add provider factory with our assembly in it. //systemData.Tables[systemData.Tables.IndexOf("DbProviderFactories")].Rows.Add("SQLite Data Provider" // , ".NET Framework Data Provider for SQLite" // , "System.Data.SQLite" // , "System.Data.SQLite.SQLiteFactory, System.Data.SQLite" //); }
private void CreateSetProvider(MethodBase method, ProviderAttribute providesSetAttribute, bool isSingleton) { InjectionProvider mappedProvider; SetInjectionProvider setProvider = null; if (providesSetAttribute.Name != null) { if (this.namedProviderMap.TryGetValue(providesSetAttribute.Name, out mappedProvider)) { setProvider = mappedProvider as SetInjectionProvider; } else { setProvider = new SetInjectionProvider(); this.namedProviderMap.Add(providesSetAttribute.Name, setProvider); } } if (providesSetAttribute.ProvidesType != null) { if (this.providerMap.TryGetValue(providesSetAttribute.ProvidesType, out mappedProvider)) { setProvider = mappedProvider as SetInjectionProvider; } else { setProvider = new SetInjectionProvider(); this.providerMap.Add(providesSetAttribute.ProvidesType, setProvider); } } if (setProvider != null) { InjectionProvider provider = isSingleton ? new SingletonInjectionProvider(method) : new InjectionProvider(method); setProvider.AddProvider(provider); } }
// Token: 0x0600001F RID: 31 RVA: 0x00002A58 File Offset: 0x00000C58 private static bool TryAddProviderType(Type type, CreateProviderDelegate createProvider) { try { foreach (object obj in type.GetCustomAttributes(typeof(ProviderAttribute), false)) { ProviderAttribute attributes = obj as ProviderAttribute; ProviderInfo providerInfo = new ProviderInfo(type, attributes, createProvider); ProvidersTable.providersList.Add(providerInfo); XmlSchema xmlSchema = ProvidersTable.LoadSchemaFromResource(type.Assembly, providerInfo.Attributes.RequestSchemaFile); if (!ProvidersTable.RequestSchemaSet.Contains(xmlSchema.TargetNamespace)) { ExTraceGlobals.FrameworkTracer.TraceDebug <string, string>(0L, "[ProvidersTable::TryAddProviderType] 'adding request schema to ProvidersTable' TargetNamespace=\"{0}\";SourceUri=\"{1}\"", xmlSchema.TargetNamespace, xmlSchema.SourceUri); ProvidersTable.RequestSchemaSet.Add(xmlSchema); return(true); } } } catch (FormatException ex) { ExTraceGlobals.FrameworkTracer.TraceError <string, string>(0L, "[ProvidersTable::TryAddProviderType] Message=\"{0}\";StackTrace=\"{1}\"", ex.Message, ex.StackTrace); Common.EventLog.LogEvent(AutodiscoverEventLogConstants.Tuple_WarnCoreProviderAttributeException, Common.PeriodicKey, new object[] { type.FullName, ex.Message }); } catch (ArgumentNullException ex2) { ExTraceGlobals.FrameworkTracer.TraceError <string, string>(0L, "[ProvidersTable::TryAddProviderType] Message=\"{0}\";StackTrace=\"{1}\"", ex2.Message, ex2.StackTrace); Common.EventLog.LogEvent(AutodiscoverEventLogConstants.Tuple_WarnCoreProviderAttributeException, Common.PeriodicKey, new object[] { type.FullName, ex2.Message }); } return(false); }
public void LoadModule(Type module) { PropertyInfo[] properties = module.GetProperties(); foreach (PropertyInfo property in properties) { ProviderAttribute providerAttribute = property.GetCustomAttribute <ProviderAttribute>(); if (providerAttribute != null) { ConstructorInfo constructor = this.GetConstructor(property.PropertyType); this.CreateProvider(property, providerAttribute, constructor); } } MethodInfo[] methods = module.GetMethods(BindingFlags.Public | BindingFlags.Static); foreach (MethodInfo method in methods) { ProviderAttribute providerAttribute = method.GetCustomAttribute <ProviderAttribute>(); if (providerAttribute != null) { this.CreateProvider(method, providerAttribute, method); } } }
public static DbProviderFactory GetDbProviderFactory(DataProviderType providerType, bool useAtrributeInfo) { DbProviderFactory providerFactory; ProviderAttribute attrib = providerType.GetAttribute <ProviderAttribute>(); string factoryTypeName = attrib?.FactoryType; string assemblyName = attrib?.Invariant; if (useAtrributeInfo) { if (string.IsNullOrEmpty(factoryTypeName) && string.IsNullOrEmpty(assemblyName)) { throw new NotSupportedException($"Unsuported provider factory for {factoryTypeName} and {assemblyName}"); } providerFactory = GetDbProviderFactory(factoryTypeName, assemblyName); if (providerFactory == null) { throw new NotSupportedException($"Unsuported provider factory for {factoryTypeName} and {assemblyName}"); } } else { switch (providerType) { case DataProviderType.Access: providerFactory = OleDbFactory.Instance; break; case DataProviderType.MySql: providerFactory = MySqlClientFactory.Instance; break; case DataProviderType.Oracle: providerFactory = OracleClientFactory.Instance; break; case DataProviderType.PostgreSql: providerFactory = NpgsqlFactory.Instance; break; case DataProviderType.SqLite: providerFactory = SQLiteFactory.Instance; break; case DataProviderType.SqlServer: providerFactory = SqlClientFactory.Instance; break; default: throw new NotSupportedException($"Unsuported provider type {providerType.ToString()}"); } } return(providerFactory); // if (providerType == DataProviderType.SqlServer) // return SqlClientFactory.Instance; // this library has a ref to SqlClient so this works // if (providerType == DataProviderType.SqLite) // { //#if NETFULL // return GetDbProviderFactory("System.Data.SQLite.SQLiteFactory", "System.Data.SQLite"); //#else // return GetDbProviderFactory("Microsoft.Data.Sqlite.SqliteFactory", "Microsoft.Data.Sqlite"); //#endif // } // if (providerType == DataProviderType.MySql) // return GetDbProviderFactory("MySql.Data.MySqlClient.MySqlClientFactory", "MySql.Data"); // if (providerType == DataProviderType.PostgreSql) // return GetDbProviderFactory("Npgsql.NpgsqlFactory", "Npgsql"); //#if NETFULL // if (type == DataAccessProviderTypes.OleDb) // return System.Data.OleDb.OleDbFactory.Instance; // if (type == DataAccessProviderTypes.SqlServerCompact) // return DbProviderFactories.GetFactory("System.Data.SqlServerCe.4.0"); //#endif // throw new NotSupportedException($"Unsuported provider factory for type {providerType.ToString()}"); }
internal ProviderInfo(Type systemType, ProviderAttribute attributes, CreateProviderDelegate createProvider) { this.systemType = systemType; this.attributes = attributes; this.createProvider = createProvider; }