Esempio n. 1
0
 public void Reset()
 {
     Cache.Empty();
     UserConfigurations.Reset();
     ConstructionFactory.Reset();
     ObjectMapperFactory.Reset();
 }
 private static void ClassInitialize_Api()
 {
     _testContext.Properties.Add(
         "apiDataRows",
         new Dictionary <BillPaymentsClient, ApiPresets>
     {
         {
             BillPaymentsClientFactory.Create(Config.MerchantSecretKey),
             new ApiPresets
             {
                 Bills   = new List <BillResponse>(),
                 Refunds = new List <RefundResponse>()
             }
         },
         {
             BillPaymentsClientFactory.Create(
                 Config.MerchantSecretKey,
                 null,
                 ObjectMapperFactory.Create <NewtonsoftMapper>()
                 ),
             new ApiPresets
             {
                 Bills   = new List <BillResponse>(),
                 Refunds = new List <RefundResponse>()
             }
         }
     }
         );
 }
Esempio n. 3
0
        public void Load()
        {
            var objectMapper = ObjectMapperFactory.CreateInstance();

            try
            {
                _settings = objectMapper.ReadValue <Settings>(_fileName);
                UpdateEffectPatternManager();

                //try loading the ELS configuration files, if something goes wrong, disable the els option
                if (_settings.ColorSettings.ElsEnabled)
                {
                    _settings.ColorSettings.ElsEnabled = _elsSettingsManager.Load();
                }

                _rage.DisplayPluginNotification("configuration loaded");
                _rage.LogTrivial(Settings.ToString());

                //initialize/reinitialize the effect devices and color manager
                _effectsManager.Initialize();
                _colorManager.Initialize(_settings);
            }
            catch (FileNotFoundException)
            {
                _rage.DisplayPluginNotification("configuration file not found, using defaults instead");
                LoadDefaults();
            }
            catch (Exception e)
            {
                _rage.LogTrivial(e.Message + Environment.NewLine + e.StackTrace);
                _rage.DisplayPluginNotification("configuration file is not valid, using defaults instead");
                LoadDefaults();
            }
        }
Esempio n. 4
0
 public void Dispose()
 {
     _isDisposed = true;
     Cache.Empty();
     UserConfigurations.Reset();
     ConstructionFactory.Reset();
     ObjectMapperFactory.Reset();
 }
Esempio n. 5
0
 public MapperContext()
 {
     Cache  = new CacheSet();
     Naming = new NamingSettings(Cache);
     QualifiedMemberFactory = new QualifiedMemberFactory(this);
     RootMembersSource      = new RootMembersSource(QualifiedMemberFactory);
     ObjectMapperFactory    = new ObjectMapperFactory(Cache);
     UserConfigurations     = new UserConfigurationSet(this);
     ConstructionFactory    = new ComplexTypeConstructionFactory(Cache);
     ValueConverters        = new ConverterSet(UserConfigurations);
     RuleSets = MappingRuleSetCollection.Default;
 }
Esempio n. 6
0
 public MapperContext(NamingSettings namingSettings = null)
 {
     Cache               = new CacheSet();
     DataSources         = new DataSourceFinder();
     NamingSettings      = namingSettings ?? new NamingSettings();
     RootMembersSource   = new RootMembersSource(new RootQualifiedMemberFactory(this));
     ObjectMapperFactory = new ObjectMapperFactory(this);
     ObjectFlattener     = new ObjectFlattener();
     DerivedTypes        = new DerivedTypesCache();
     UserConfigurations  = new UserConfigurationSet();
     ValueConverters     = new ConverterSet();
     RuleSets            = new MappingRuleSetCollection();
 }
Esempio n. 7
0
        public void ShouldLoadElsFile()
        {
            var elsSettings = new ElsSettings
            {
                LightingSettings = new LightingSettings
                {
                    Extra01 = new ExtraSettings
                    {
                        IsElsControlled = true,
                        AllowEnvLight   = true,
                        Color           = Color.Blue
                    },
                    Extra02 = new ExtraSettings
                    {
                        IsElsControlled = true,
                        AllowEnvLight   = true,
                        Color           = Color.Blue
                    },
                    Extra03 = new ExtraSettings
                    {
                        IsElsControlled = true,
                        AllowEnvLight   = true,
                        Color           = Color.Blue
                    },
                    Extra04 = new ExtraSettings
                    {
                        IsElsControlled = true,
                        AllowEnvLight   = true,
                        Color           = Color.Red
                    },
                    Extra05 = new ExtraSettings
                    {
                        IsElsControlled = true,
                        AllowEnvLight   = true,
                        Color           = Color.Red
                    },
                    Extra06 = new ExtraSettings
                    {
                        IsElsControlled = true,
                        AllowEnvLight   = true,
                        Color           = Color.Red
                    }
                }
            };
            var objectMapper = ObjectMapperFactory.CreateInstance();

            var result = objectMapper.ReadValue <ElsSettings>(FILE);

            Assert.NotNull(result);
            Assert.Equal(elsSettings, result);
        }
Esempio n. 8
0
 public static BillPaymentsClient Create(
     string secretKey,
     IClient client             = null,
     IObjectMapper objectMapper = null,
     IFingerprint fingerprint   = null
     )
 {
     return(new BillPaymentsClient(
                secretKey,
                new RequestMappingIntercessor(
                    client ?? ClientFactory.Create(),
                    objectMapper ?? ObjectMapperFactory.Create()
                    ),
                fingerprint ?? FingerprintFactory.Create()
                ));
 }
        public static IServiceCollection AddMapper(this IServiceCollection services)
        {
            AutoMapper.IConfigurationProvider configuration = new MapperConfiguration(config =>
            {
                config.AddProfile <ApplicationServiceProfile>();
            });

            services.AddSingleton(configuration);

            services.AddScoped <IMapper, Mapper>();

            var mapperService = services.BuildServiceProvider().GetService <IMapper>();

            ObjectMapperFactory.SetObjectMapper(new AutoMapAdapter(mapperService));

            return(services);
        }
Esempio n. 10
0
        internal static void AddMapper(this IServiceCollection services, IObjectMapper objectMapper)
        {
            if (objectMapper is null)
            {
                objectMapper.AddAutoMapperConfiguration(services, confg => {});

                services.AddScoped <IMapper, Mapper>();

                var mapperService = services.BuildServiceProvider().GetService <IMapper>();

                ObjectMapperFactory.SetObjectMapper(new AutoMapAdapter(mapperService));

                return;
            }

            ObjectMapperFactory.SetObjectMapper(objectMapper);
        }
Esempio n. 11
0
        public bool Load()
        {
            _rage.LogTrivialDebug("loading ELS configuration files...");
            var objectMapper = ObjectMapperFactory.CreateInstance();

            _elsVehicleSettings.Clear();
            _elsSettings.Clear();

            try
            {
                foreach (var file in Directory.GetFiles(ElsDirectory, "*.xml"))
                {
                    _rage.LogTrivialDebug("loading els configuration file " + file);
                    var settings = LoadElsFile(file, objectMapper);

                    _rage.LogTrivialDebug("storing els configuration for vehicle " + settings.Key);
                    _elsSettings.Add(settings.Key, settings.Value);
                }

                foreach (var file in Directory.GetFiles(DefaultDirectory, "*.xml"))
                {
                    _rage.LogTrivialDebug("loading els default configuration file " + file);
                    var settings = LoadElsFile(file, objectMapper);
                    var name     = settings.Key;

                    _rage.LogTrivialDebug("storing els default configuration for vehicle " + name);
                    _elsVehicleSettings.Add(_elsSettings.ContainsKey(name)
                        ? new ElsVehicleSettings(name, _elsSettings[name], settings.Value)
                        : new ElsVehicleSettings(name, settings.Value));
                }

                _rage.LogTrivial("ELS configuration files loaded");
                return(true);
            }
            catch (Exception e)
            {
                _rage.LogTrivial(e.Message + Environment.NewLine + e.StackTrace);
                _rage.DisplayPluginNotification("an error occurred while loading the ELS configuration");
            }

            return(false);
        }
Esempio n. 12
0
 public Children(IChildren children, bool flag = true)
 {
     Name               = "Test";
     FatherName         = "TestFather";
     childrenCollection = new ChildrenCollection()
     {
         DefaultValue = -1, FullName = "Children Name 1", Enabled = false
     };
     if (children != null)
     {
         if (flag)
         {
             /////////////////////////////////////////////////////////////////////
             ////            Using Generic Mapper Configuration                ///
             /////////////////////////////////////////////////////////////////////
             var mapper = ObjectMapperFactory.CreateMapper <IChildren, IChildren>();
             mapper.Map(children, this);
         }
         else
         {
             /////////////////////////////////////////////////////////////////////
             ////       Using Profile Registration Mapper Configuration        ///
             /////////////////////////////////////////////////////////////////////
             var config = new MapperConfiguration(
                 cfg =>
             {
                 cfg.CreateMap <Children, Children>()
                 .PreserveReferences();
                 cfg.CreateMap <ChildrenCollection, ChildrenCollection>()
                 .PreserveReferences();
                 cfg.CreateMap <ChildrenElements, ChildrenElements>()
                 .PreserveReferences();
             });
             config.AssertConfigurationIsValid();
             var mapper = new Mapper(config);
             mapper.Map(children, this);
         }
     }
 }
Esempio n. 13
0
 private static void ClassInitialize_Fake()
 {
     _testContext.Properties.Add(
         "fakeDataRows",
         new Dictionary <BillPaymentsClient, FakeApiPresets>(
             new[]
     {
         new FakeClient(ObjectMapperFactory.Create()),
         new FakeClient(ObjectMapperFactory.Create <NewtonsoftMapper>())
     }
             .Select(fakeClient => new KeyValuePair <BillPaymentsClient, FakeApiPresets>(
                         BillPaymentsClientFactory.Create(Config.MerchantSecretKey, fakeClient,
                                                          fakeClient.ObjectMapper),
                         new FakeApiPresets
     {
         Client  = fakeClient,
         Bills   = new List <BillResponse>(),
         Refunds = new List <RefundResponse>()
     }
                         ))
             )
         );
 }
Esempio n. 14
0
 public ReadValue()
 {
     _objectMapper = ObjectMapperFactory.CreateInstance();
 }