public AmbientSubscription(string subscriptionId, bool disableArmsAuxiliaryMitigation = false) { if (subscriptionId == null) { throw new ArgumentNullException(nameof(subscriptionId)); } if (string.IsNullOrWhiteSpace(subscriptionId)) { throw new ArgumentException("subscriptionId cannot be empty", nameof(subscriptionId)); } if (Ambient.Value != null) { throw new InvalidOperationException("There is already an ambient subscription in effect - nesting ambient subscriptions is not supported, you must close the previous subscription before trying to switch to a new one"); } if (AmbientResourceGroup.Current != null) { throw new InvalidOperationException("There is an ambient resource group in effect - nesting an ambient subscription inside an ambient resource group is not supported"); } SubscriptionId = subscriptionId; lock (ProviderCache) { AzureNextGenProvider = ProviderCache.TryGetValue(subscriptionId, out var provider) ? provider : ProviderCache[subscriptionId] = GetProvider(subscriptionId, disableArmsAuxiliaryMitigation); } Ambient.Value = this; }
public static IProvider GetProvider(string providerName) { if (!ProviderCache.ContainsKey(providerName)) { throw new Exception("Unknown Provider. (See Provider Configuration)"); } ProviderSetting setting = ProviderCache[providerName]; if (setting.ProviderType == null) { Type type = Type.GetType(setting.ProviderTypeName); if (type == null) { throw new Exception(string.Format("Unknown Type {0}", setting.ProviderTypeName)); } setting.ProviderType = type; } IProvider provider = CreateIProviderInstance(setting.ProviderType); string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[setting.ConnectionString].ConnectionString; if (!string.IsNullOrEmpty(connectionString)) { provider.ConnectionString = connectionString; } if (typeof(ProviderBase).IsAssignableFrom(provider.GetType())) { (provider as ProviderBase).SetProviderName(providerName); } return(provider); }
private static void InitConfiguration() { var section = System.Configuration.ConfigurationManager.GetSection("AnitoProviderConfiguration"); if (section == null) { throw new Exception("Default Anito Provider Configuration Section doesn't exist (AnitoProviderConfiguration)"); } m_configuration = section as ProviderConfiguration; foreach (ProviderConfigurationElement element in m_configuration.Providers) { ProviderSetting setting = new ProviderSetting(); setting.Name = element.Name; setting.ConnectionString = element.ConnectionString; setting.ProviderTypeName = element.Type; ProviderCache.Add(element.Name, setting); TypeSchemaSource source = new TypeSchemaSource(); foreach (SchemaSourceElement schemaElement in element.SchemaSourceCollection) { XmlReader reader = new XmlTextReader(schemaElement.SourceFile); (source as IXmlSerializable).ReadXml(reader); reader.Close(); } CacheManager.SchemaCache.Add(element.Name, source); } }
public static ScoreService ProvideScore() { return(ProviderCache.GetOrInstanciate <ScoreService>(() => new ScoreService( InfrastructureProvider.ProvideScore(), InfrastructureProvider.ProvideMaxScore(), ProvideLeaderBoardScore()))); }
private TestSuite BuildSingleAssembly(TestPackage package) { TestAssemblyBuilder builder = new TestAssemblyBuilder(); builders.Clear(); builders.Add(builder); TestSuite suite = (TestSuite)builder.Build( package.FullName, package.TestName, package.GetSetting("AutoNamespaceSuites", true)); ProviderCache.Clear(); return(suite); }
/// <summary> /// Build a suite based on a TestPackage /// </summary> /// <param name="package">The TestPackage</param> /// <returns>A TestSuite</returns> public TestSuite Build(TestPackage package) { bool autoNamespaceSuites = package.GetSetting("AutoNamespaceSuites", true); bool mergeAssemblies = package.GetSetting("MergeAssemblies", false); TestExecutionContext.CurrentContext.TestCaseTimeout = package.GetSetting("DefaultTimeout", 0); if (package.IsSingleAssembly) { return(BuildSingleAssembly(package)); } string targetAssemblyName = null; if (package.TestName != null && package.Assemblies.Contains(package.TestName)) { targetAssemblyName = package.TestName; package.TestName = null; } TestSuite rootSuite = new ProjectRootSuite(package.FullName); NamespaceTreeBuilder namespaceTree = new NamespaceTreeBuilder(rootSuite); builders.Clear(); foreach (string assemblyName in package.Assemblies) { if (targetAssemblyName == null || targetAssemblyName == assemblyName) { TestAssemblyBuilder builder = new TestAssemblyBuilder(); builders.Add(builder); Test testAssembly = builder.Build(assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies); if (testAssembly != null) { if (!mergeAssemblies) { rootSuite.Add(testAssembly); } else if (autoNamespaceSuites) { namespaceTree.Add(testAssembly.Tests); rootSuite = namespaceTree.RootSuite; } else { foreach (Test test in testAssembly.Tests) { rootSuite.Add(test); } } } } } ProviderCache.Clear(); if (rootSuite.Tests.Count == 0) { return(null); } return(rootSuite); }
/// <summary> /// /// </summary> /// <param name="locationAreaIdentifier"></param> /// <param name="currentProvider"></param> /// <returns></returns> private async Task <ILocationDataProvider> ResolveLocationDataAsync( Guid locationAreaIdentifier, CancellationToken cancellationToken = default(CancellationToken)) { ILocationDataProvider locationData = null; ProviderCache providerLookup = m_providerLookup; if (providerLookup == null) { providerLookup = new ProviderCache(); // Create and seed the cache with the local url String location = await LocalDataProvider.LocationForCurrentConnectionAsync( ServiceInterfaces.LocationService2, LocationServiceConstants.SelfReferenceIdentifier, cancellationToken).ConfigureAwait(false); if (location != null) { providerLookup.GetOrAdd(location, LocalDataProvider); } ProviderCache actualProvider = Interlocked.CompareExchange(ref m_providerLookup, providerLookup, null); // Did we lose the race? Pick the winner if (actualProvider != null) { providerLookup = actualProvider; } } if (!providerLookup.TryGetValue(locationAreaIdentifier, out locationData)) { // First, check our current provider (see if a direct pointer is registered) String location = await LocalDataProvider.LocationForCurrentConnectionAsync( ServiceInterfaces.LocationService2, locationAreaIdentifier, cancellationToken).ConfigureAwait(false); // Next, check and see if we have a root pointer if (location == null && locationAreaIdentifier != LocationServiceConstants.ApplicationIdentifier && locationAreaIdentifier != LocationServiceConstants.RootIdentifier) // Don't infinitely recurse { ILocationDataProvider rootProvider = await ResolveLocationDataAsync( LocationServiceConstants.RootIdentifier, cancellationToken).ConfigureAwait(false); if (rootProvider != null && !Object.ReferenceEquals(rootProvider, LocalDataProvider)) { location = await rootProvider.LocationForCurrentConnectionAsync( ServiceInterfaces.LocationService2, locationAreaIdentifier, cancellationToken).ConfigureAwait(false); } } if (location != null) { // The caller could be asking for a serviceIdentifier which resolves to a URL // for which we already have a cached provider. // This is typical when serviceIdentifier is a ResourceArea guid. if (!providerLookup.TryGetValue(location, out locationData)) { locationData = await CreateDataProviderAsync(location, cancellationToken).ConfigureAwait(false); locationData = providerLookup.GetOrAdd(location, locationData); } providerLookup[locationAreaIdentifier] = locationData; } } return(locationData); }
public static EconomyRepository ProvideEconomy() { return(ProviderCache.GetOrInstanciate <EconomyRepository>(() => new PlayerPrefsEconomyRepository())); }
public static IPlayerLevelProgression ProvidePlayerLevelProgression() { return(ProviderCache.GetOrInstanciate <IPlayerLevelProgression>(() => new InMemoryPlayerLevelProgression())); }
public static IExperienceRepository ProvideExperience() { return(ProviderCache.GetOrInstanciate <IExperienceRepository>(() => new PlayerPrefsExperienceRepository())); }
public static MaxScoreRepository ProvideMaxScore() { return(ProviderCache.GetOrInstanciate <MaxScoreRepository>(() => new LocalMaxScoreRepository())); }
public static IScoreRepository ProvideScore() { return(ProviderCache.GetOrInstanciate <IScoreRepository>(() => new InMemoryScoreRepository())); }
public static EconomyService ProvideEconomy() { return(ProviderCache.GetOrInstanciate <EconomyService>(() => new EconomyService(InfrastructureProvider.ProvideEconomy()))); }
public static LeaderBoardScoreService ProvideLeaderBoardScore() { return(ProviderCache.GetOrInstanciate <LeaderBoardScoreService>(() => new LeaderBoardScoreService(LeaderboardManager.leaderboard_highscores))); }
public static ExperienceService ProvideExperience() { return(ProviderCache.GetOrInstanciate <ExperienceService>(() => new ExperienceService( InfrastructureProvider.ProvidePlayerLevelProgression(), InfrastructureProvider.ProvideExperience()))); }
public static AdsService ProvideAdsService() { return(ProviderCache.GetOrInstanciate <AdsService>(() => new AdsService(new UnityAdsProvider()))); }