public void SetConnectionMeteringData(byte[] data, ServiceCollectionHelper serviceHelper)
 {
     this.m_data = new RPCConnectionMetering.MeteringData();
     if (data == null || data.Length == 0 || serviceHelper == null)
     {
         this.m_log.LogError("Unable to retrieve Connection Metering data");
         return;
     }
     try
     {
         RPCMeterConfig rpcmeterConfig = RPCMeterConfigParser.ParseConfig(Encoding.ASCII.GetString(data));
         if (rpcmeterConfig == null || !rpcmeterConfig.IsInitialized)
         {
             this.m_data = null;
             throw new Exception("Unable to parse metering config protocol buffer.");
         }
         this.UpdateConfigStats(rpcmeterConfig);
         if (rpcmeterConfig.HasStartupPeriod)
         {
             this.m_data.StartupPeriodDuration = rpcmeterConfig.StartupPeriod;
             this.m_data.StartupPeriodEnd      = (float)BattleNet.GetRealTimeSinceStartup() + rpcmeterConfig.StartupPeriod;
             this.m_log.LogDebug("StartupPeriod={0}", new object[]
             {
                 rpcmeterConfig.StartupPeriod
             });
             this.m_log.LogDebug("StartupPeriodEnd={0}", new object[]
             {
                 this.m_data.StartupPeriodEnd
             });
         }
         this.InitializeInternalState(rpcmeterConfig, serviceHelper);
     }
     catch (Exception ex)
     {
         this.m_data = null;
         this.m_log.LogError("EXCEPTION = {0} {1}", new object[]
         {
             ex.Message,
             ex.StackTrace
         });
     }
     if (this.m_data == null)
     {
         this.m_log.LogError("Unable to parse Connection Metering data");
     }
 }
Пример #2
0
        protected DatabaseTests()
        {
            var databaseIdentifier = Guid.NewGuid();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddDbContext <ApplicationDbContext>(options =>
                                                                  options.UseInMemoryDatabase(databaseIdentifier.ToString()));

            serviceCollection.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            ServiceCollectionHelper.RegisterServices(serviceCollection);

            var mockBankHolidayFetcher = new Mock <IBankHolidayFetcher>(MockBehavior.Strict);

            mockBankHolidayFetcher
            .Setup(f => f.Fetch())
            .Returns(() => Task.FromResult(this.bankHolidayDates));

            serviceCollection.Replace(
                new ServiceDescriptor(
                    typeof(IBankHolidayFetcher),
                    s => mockBankHolidayFetcher.Object,
                    ServiceLifetime.Scoped));

            var mockClock = new Mock <IClock>(MockBehavior.Strict);

            mockClock
            .Setup(c => c.GetCurrentInstant())
            .Returns(() => this.currentInstant);

            serviceCollection.Replace(
                new ServiceDescriptor(
                    typeof(IClock),
                    s => mockClock.Object,
                    ServiceLifetime.Singleton));

            this.serviceProvider = serviceCollection.BuildServiceProvider();

            this.Seed = new DatabaseSeeder(this.serviceProvider);
        }
Пример #3
0
 public void SetConnectionMeteringData(byte[] data, ServiceCollectionHelper serviceHelper)
 {
     this.m_data = new MeteringData();
     if (((data == null) || (data.Length == 0)) || (serviceHelper == null))
     {
         this.m_log.LogError("Unable to retrieve Connection Metering data");
     }
     else
     {
         try
         {
             RPCMeterConfig config = RPCMeterConfigParser.ParseConfig(Encoding.ASCII.GetString(data));
             if ((config == null) || !config.IsInitialized)
             {
                 this.m_data = null;
                 throw new Exception("Unable to parse metering config protocol buffer.");
             }
             this.UpdateConfigStats(config);
             if (config.HasStartupPeriod)
             {
                 this.m_data.StartupPeriodDuration = config.StartupPeriod;
                 this.m_data.StartupPeriodEnd      = UnityEngine.Time.realtimeSinceStartup + config.StartupPeriod;
                 object[] args = new object[] { config.StartupPeriod };
                 this.m_log.LogDebug("StartupPeriod={0}", args);
                 object[] objArray2 = new object[] { this.m_data.StartupPeriodEnd };
                 this.m_log.LogDebug("StartupPeriodEnd={0}", objArray2);
             }
             this.InitializeInternalState(config, serviceHelper);
         }
         catch (Exception exception)
         {
             this.m_data = null;
             object[] objArray3 = new object[] { exception.Message, exception.StackTrace };
             this.m_log.LogError("EXCEPTION = {0} {1}", objArray3);
         }
         if (this.m_data == null)
         {
             this.m_log.LogError("Unable to parse Connection Metering data");
         }
     }
 }
Пример #4
0
        private static ServiceProvider BuildServiceProvider(string connectionString)
        {
            var services = new ServiceCollection();

            var configuration = GetConfiguration();

            services.AddLogging(configure => configure
                                .AddConsole()
                                .AddConfiguration(configuration.GetSection("Logging")));

            var databaseConnectionString =
                connectionString ??
                Environment.GetEnvironmentVariable("ParkingRotaConnectionString") ??
                configuration.GetConnectionString("DefaultConnection");

            services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(databaseConnectionString));

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            ServiceCollectionHelper.RegisterServices(services);

            return(services.BuildServiceProvider());
        }
Пример #5
0
 public DatabaseFixture()
 {
     Configuration   = ConfigurationHelper.GetConfiguration();
     ServiceProvider = ServiceCollectionHelper.BuildServiceProvider(ConfigureServices);
 }
Пример #6
0
 public ConsumerFixture()
 {
     Configuration   = ConfigurationHelper.GetConfiguration();
     ServiceProvider = ServiceCollectionHelper.BuildServiceProvider(ConfigureServices);
     Harness         = ServiceProvider.GetRequiredService <InMemoryTestHarness>();
 }
        private void InitializeInternalState(RPCMeterConfig config, ServiceCollectionHelper serviceHelper)
        {
            List <string> list        = new List <string>();
            List <string> list2       = new List <string>();
            int           methodCount = config.MethodCount;

            for (int i = 0; i < methodCount; i++)
            {
                RPCMethodConfig rpcmethodConfig             = config.Method[i];
                RPCConnectionMetering.StaticData staticData = new RPCConnectionMetering.StaticData();
                staticData.FromProtocol(rpcmethodConfig);
                if (!rpcmethodConfig.HasServiceName)
                {
                    if (this.m_data.GlobalDefault == null)
                    {
                        this.m_data.GlobalDefault = staticData;
                        this.m_log.LogDebug("Adding global default {0}", new object[]
                        {
                            staticData
                        });
                    }
                    else
                    {
                        this.m_log.LogWarning("Static data has two defaults, ignoring additional ones.");
                    }
                }
                else
                {
                    string            serviceName           = rpcmethodConfig.ServiceName;
                    ServiceDescriptor importedServiceByName = serviceHelper.GetImportedServiceByName(serviceName);
                    if (importedServiceByName == null)
                    {
                        if (!list2.Contains(serviceName))
                        {
                            this.m_log.LogDebug("Ignoring not imported service {0}", new object[]
                            {
                                serviceName
                            });
                            list2.Add(serviceName);
                        }
                    }
                    else
                    {
                        staticData.ServiceId = importedServiceByName.Id;
                        if (rpcmethodConfig.HasMethodName)
                        {
                            string           methodName             = rpcmethodConfig.MethodName;
                            string           text                   = string.Format("{0}.{1}", serviceName, methodName);
                            MethodDescriptor methodDescriptorByName = importedServiceByName.GetMethodDescriptorByName(text);
                            if (methodDescriptorByName == null)
                            {
                                this.m_log.LogDebug("Configuration specifies an unused method {0}, ignoring.", new object[]
                                {
                                    methodName
                                });
                                goto IL_231;
                            }
                            if (this.m_data.MethodDefaults.ContainsKey(text))
                            {
                                this.m_log.LogWarning("Default for method {0} already exists, ignoring extras.", new object[]
                                {
                                    text
                                });
                                goto IL_231;
                            }
                            staticData.MethodId = methodDescriptorByName.Id;
                            this.m_data.MethodDefaults[text] = staticData;
                            this.m_log.LogDebug("Adding Method default {0}", new object[]
                            {
                                staticData
                            });
                        }
                        else
                        {
                            if (this.m_data.ServiceDefaults.ContainsKey(serviceName))
                            {
                                this.m_log.LogWarning("Default for service {0} already exists, ignoring extras.", new object[]
                                {
                                    serviceName
                                });
                                goto IL_231;
                            }
                            this.m_data.ServiceDefaults[serviceName] = staticData;
                            this.m_log.LogDebug("Adding Service default {0}", new object[]
                            {
                                staticData
                            });
                        }
                        list.Add(serviceName);
                    }
                }
                IL_231 :;
            }
            foreach (KeyValuePair <uint, ServiceDescriptor> keyValuePair in serviceHelper.ImportedServices)
            {
                if (!list.Contains(keyValuePair.Value.Name) && this.m_data.GlobalDefault == null)
                {
                    this.m_log.LogDebug("Configuration for service {0} was not found and will not be metered.", new object[]
                    {
                        keyValuePair.Value.Name
                    });
                }
            }
        }
        private void InitializeInternalState(RPCMeterConfig config, ServiceCollectionHelper serviceHelper)
        {
            string        serviceName;
            string        str;
            List <string> strs        = new List <string>();
            List <string> strs1       = new List <string>();
            int           methodCount = config.MethodCount;

            for (int i = 0; i < methodCount; i++)
            {
                RPCMethodConfig item = config.Method[i];
                RPCConnectionMetering.StaticData staticDatum = new RPCConnectionMetering.StaticData();
                staticDatum.FromProtocol(item);
                if (item.HasServiceName)
                {
                    serviceName = item.ServiceName;
                    ServiceDescriptor importedServiceByName = serviceHelper.GetImportedServiceByName(serviceName);
                    if (importedServiceByName != null)
                    {
                        staticDatum.ServiceId = importedServiceByName.Id;
                        if (!item.HasMethodName)
                        {
                            if (this.m_data.ServiceDefaults.ContainsKey(serviceName))
                            {
                                goto Label1;
                            }
                            this.m_data.ServiceDefaults[serviceName] = staticDatum;
                            this.m_log.LogDebug("Adding Service default {0}", new object[] { staticDatum });
                        }
                        else
                        {
                            string methodName = item.MethodName;
                            str = string.Format("{0}.{1}", serviceName, methodName);
                            MethodDescriptor methodDescriptorByName = importedServiceByName.GetMethodDescriptorByName(str);
                            if (methodDescriptorByName != null)
                            {
                                if (this.m_data.MethodDefaults.ContainsKey(str))
                                {
                                    goto Label2;
                                }
                                staticDatum.MethodId            = methodDescriptorByName.Id;
                                this.m_data.MethodDefaults[str] = staticDatum;
                                this.m_log.LogDebug("Adding Method default {0}", new object[] { staticDatum });
                            }
                            else
                            {
                                this.m_log.LogDebug("Configuration specifies an unused method {0}, ignoring.", new object[] { methodName });
                                goto Label0;
                            }
                        }
                        strs.Add(serviceName);
                    }
                    else if (!strs1.Contains(serviceName))
                    {
                        this.m_log.LogDebug("Ignoring not imported service {0}", new object[] { serviceName });
                        strs1.Add(serviceName);
                    }
                }
                else if (this.m_data.GlobalDefault != null)
                {
                    this.m_log.LogWarning("Static data has two defaults, ignoring additional ones.");
                }
                else
                {
                    this.m_data.GlobalDefault = staticDatum;
                    this.m_log.LogDebug("Adding global default {0}", new object[] { staticDatum });
                }
Label0:
            }
            foreach (KeyValuePair <uint, ServiceDescriptor> importedService in serviceHelper.ImportedServices)
            {
                if (strs.Contains(importedService.Value.Name) || this.m_data.GlobalDefault != null)
                {
                    continue;
                }
                this.m_log.LogDebug("Configuration for service {0} was not found and will not be metered.", new object[] { importedService.Value.Name });
            }
            return;

Label1:
            BattleNetLogSource mLog = this.m_log;

            mLog.LogWarning("Default for service {0} already exists, ignoring extras.", new object[] { serviceName });
            goto Label0;
Label2:
            BattleNetLogSource battleNetLogSource = this.m_log;

            battleNetLogSource.LogWarning("Default for method {0} already exists, ignoring extras.", new object[] { str });
            goto Label0;
        }
Пример #9
0
    private void InitializeInternalState(RPCMeterConfig config, ServiceCollectionHelper serviceHelper)
    {
        List <string> list        = new List <string>();
        List <string> list2       = new List <string>();
        int           methodCount = config.MethodCount;

        for (int i = 0; i < methodCount; i++)
        {
            RPCMethodConfig method = config.Method[i];
            StaticData      data   = new StaticData();
            data.FromProtocol(method);
            if (!method.HasServiceName)
            {
                if (this.m_data.GlobalDefault == null)
                {
                    this.m_data.GlobalDefault = data;
                    object[] args = new object[] { data };
                    this.m_log.LogDebug("Adding global default {0}", args);
                }
                else
                {
                    this.m_log.LogWarning("Static data has two defaults, ignoring additional ones.");
                }
            }
            else
            {
                string            serviceName           = method.ServiceName;
                ServiceDescriptor importedServiceByName = serviceHelper.GetImportedServiceByName(serviceName);
                if (importedServiceByName == null)
                {
                    if (!list2.Contains(serviceName))
                    {
                        object[] objArray2 = new object[] { serviceName };
                        this.m_log.LogDebug("Ignoring not imported service {0}", objArray2);
                        list2.Add(serviceName);
                    }
                }
                else
                {
                    data.ServiceId = importedServiceByName.Id;
                    if (method.HasMethodName)
                    {
                        string           methodName             = method.MethodName;
                        string           name                   = string.Format("{0}.{1}", serviceName, methodName);
                        MethodDescriptor methodDescriptorByName = importedServiceByName.GetMethodDescriptorByName(name);
                        if (methodDescriptorByName == null)
                        {
                            object[] objArray3 = new object[] { methodName };
                            this.m_log.LogDebug("Configuration specifies an unused method {0}, ignoring.", objArray3);
                            goto Label_0231;
                        }
                        if (this.m_data.MethodDefaults.ContainsKey(name))
                        {
                            object[] objArray4 = new object[] { name };
                            this.m_log.LogWarning("Default for method {0} already exists, ignoring extras.", objArray4);
                            goto Label_0231;
                        }
                        data.MethodId = methodDescriptorByName.Id;
                        this.m_data.MethodDefaults[name] = data;
                        object[] objArray5 = new object[] { data };
                        this.m_log.LogDebug("Adding Method default {0}", objArray5);
                    }
                    else
                    {
                        if (this.m_data.ServiceDefaults.ContainsKey(serviceName))
                        {
                            object[] objArray6 = new object[] { serviceName };
                            this.m_log.LogWarning("Default for service {0} already exists, ignoring extras.", objArray6);
                            goto Label_0231;
                        }
                        this.m_data.ServiceDefaults[serviceName] = data;
                        object[] objArray7 = new object[] { data };
                        this.m_log.LogDebug("Adding Service default {0}", objArray7);
                    }
                    list.Add(serviceName);
                    Label_0231 :;
                }
            }
        }
        foreach (KeyValuePair <uint, ServiceDescriptor> pair in serviceHelper.ImportedServices)
        {
            if (!list.Contains(pair.Value.Name) && (this.m_data.GlobalDefault == null))
            {
                object[] objArray8 = new object[] { pair.Value.Name };
                this.m_log.LogDebug("Configuration for service {0} was not found and will not be metered.", objArray8);
            }
        }
    }