/// <summary> /// Creates the deep copy instance of this instance /// </summary> public MapperSettings DeepClone() { MapperSettings clonnedMapper = new MapperSettings(); //Allowed pools foreach (KeyValuePair<string, List<AllowedPool>> keyValuePair in PoolsMap) { List<AllowedPool> clonnedAllowedPoolsList = new List<AllowedPool>(keyValuePair.Value.Count); foreach (AllowedPool allowedPool in keyValuePair.Value) { AllowedPool clonnedAllowedPool = new AllowedPool { _reservoirInstanceIdx = allowedPool._reservoirInstanceIdx, _poolIdx = allowedPool._poolIdx }; clonnedAllowedPoolsList.Add(clonnedAllowedPool); } clonnedMapper.PoolsMap.Add(keyValuePair.Key, clonnedAllowedPoolsList); } //Allowed input fields foreach (KeyValuePair<string, List<int>> keyValuePair in RoutedInputFieldsMap) { List<int> clonnedAllowedRoutedInputFieldsIdxs = new List<int>(keyValuePair.Value.Count); foreach (int allowedRoutedInputFieldIdx in keyValuePair.Value) { clonnedAllowedRoutedInputFieldsIdxs.Add(allowedRoutedInputFieldIdx); } clonnedMapper.RoutedInputFieldsMap.Add(keyValuePair.Key, clonnedAllowedRoutedInputFieldsIdxs); } return clonnedMapper; }
public frmPerformance(MapperSettings settings) { InitializeComponent(); this.settings = settings; chkCache.Checked = settings.Performance.CacheResources; cmbRendering.SelectedIndex = (settings.Performance.FastRendering ? 0 : 1); }
public IExcelMapper Build(IWorkbook workbook, MapperSettings settings) { if (workbook == null) { throw new ArgumentNullException(nameof(workbook)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } IConverterProvider converterProvider = GetDefaultConvertersProvider(); IPropertyNameConvention propertyNameConvention = GetDefaultPropertyNamingConventions(); if (settings.Convention.AnyValue()) { propertyNameConvention = settings.Convention; } if (settings.ConverterProvider.AnyValue()) { converterProvider = settings.ConverterProvider; } var propertiesExtractor = new TypeInfoProvider(); var propertyInfoExtractor = new PropertyInfoExtractor(); var propertiesMapFactory = new ExcelPropertyMapFactory(propertiesExtractor, propertyInfoExtractor, propertyNameConvention, _loggerFactory.CreateLogger <ExcelPropertyMapFactory>()); var typeConverter = new CellValueConverter(converterProvider); var modelFactory = new ModelBuilder(propertyInfoExtractor); return(new ExcelMapper(workbook, propertiesMapFactory, typeConverter, modelFactory, _loggerFactory.CreateLogger <ExcelMapper>())); }
public static void SaveSettings(MapperSettings settings) { logger.Info("Serializing settings."); string json = JsonConvert.SerializeObject(settings, Formatting.Indented); logger.Info("Saving settings to {0}.", SettingsPath); File.WriteAllText(SettingsPath, json); }
//Constructors /// <summary> /// Creates an uninitialized instance. /// </summary> public StateMachineSettings() { //Default settings RandomizerSeek = 0; NeuralPreprocessorConfig = new NeuralPreprocessorSettings(); ReadoutLayerConfig = new ReadoutLayerSettings(); MapperConfig = null; return; }
public IMapper CreateMapper() { var config = new MapperConfiguration(cfg => { cfg.AddMaps(new string[] { "MartianRobot.Application" }); MapperSettings.GetMapperSettings(cfg); }); return(config.CreateMapper()); }
public void ConfigureAMapWithCSharpBuiltInType() { var mapperSettings = new MapperSettings((config) => { config.CreateMap <string, PersonDto>(); }); Assert.That(() => MapperBuilder.Instance.ApplySettings(mapperSettings).Build(), Throws.TypeOf <RegisterBuiltInTypesException>().With.Message .EqualTo("C# built-in types or value types can't be mapped!")); }
//Constructors /// <summary> /// Creates an initialized instance /// </summary> /// <param name="neuralPreprocessorCfg">Configuration of the neural preprocessor</param> /// <param name="readoutLayerCfg">Configuration of the readout layer</param> /// <param name="mapperCfg">Configuration of mapper of predictors to readout units</param> /// <param name="randomizerSeek">Specifies random number generator's initial seek</param> public StateMachineSettings(NeuralPreprocessorSettings neuralPreprocessorCfg, ReadoutLayerSettings readoutLayerCfg, MapperSettings mapperCfg = null, int randomizerSeek = DefaultRandomizerSeek) { NeuralPreprocessorCfg = neuralPreprocessorCfg == null ? null : (NeuralPreprocessorSettings)neuralPreprocessorCfg.DeepClone(); ReadoutLayerCfg = (ReadoutLayerSettings)readoutLayerCfg.DeepClone(); MapperCfg = mapperCfg == null ? null : (MapperSettings)mapperCfg.DeepClone(); RandomizerSeek = randomizerSeek; Check(); return; }
public void ConfigureTwoMappingsForTheSameType() { var mapperSettings = new MapperSettings((config) => { config.CreateMap <Person, PersonDto>(); config.CreateMap <Person, PersonDtoCaseInsensitive>(); }); Assert.That(() => MapperBuilder.Instance.ApplySettings(mapperSettings).Build(), Throws.TypeOf <DuplicateRegisteredTypeException>().With.Message .EqualTo("Duplicate types could not be registered as source!")); }
/// <summary> /// The deep copy constructor /// </summary> /// <param name="source">Source instance</param> public StateMachineSettings(StateMachineSettings source) { //Copy RandomizerSeek = source.RandomizerSeek; NeuralPreprocessorConfig = source.NeuralPreprocessorConfig.DeepClone(); ReadoutLayerConfig = new ReadoutLayerSettings(source.ReadoutLayerConfig); MapperConfig = null; if (source.MapperConfig != null) { MapperConfig = source.MapperConfig.DeepClone(); } return; }
public void BeforeEach() { var mapperSettings = new MapperSettings((config) => { config.CreateMap <ContactDto, Contact>(); config.CreateMap <PersonDto, Person>(); config.CreateMap <PersonDtoCaseInsensitive, Person>(); config.CreateMap <PhoneDto, Phone>(); //config.CreateCollectionMap<List<PersonDto>, List<Person>>(); }); Mapper = MapperBuilder.Instance.ApplySettings(mapperSettings).Build(); }
public IExcelMapper Build(string path, MapperSettings settings) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } var workbook = _workbookLoader.Load(path); return(Build(workbook, settings)); }
//bool addedData = false; public frmPaths(MapperSettings settings) { InitializeComponent(); this.settings = settings; txtBasePath.Text = settings.Paths.BaseDir; txtCritterProtos.Text = settings.Paths.CritterProtos; txtItemProtos.Text = settings.Paths.ItemProtos; txtFOOBJ.Text = settings.Paths.FOOBJ; txtCritterTypes.Text = settings.Paths.CritterTypes; txtMapsDir.Text = settings.Paths.MapsDir; if (settings.Paths.DataFiles == null) settings.Paths.DataFiles = new List<string>(); foreach (var file in settings.Paths.DataFiles) lstDataFiles.Items.Add(file); foreach (var dir in settings.Paths.DataDirs) lstDataDirs.Items.Add(dir); }
//Methods /// <summary> /// See the base. /// </summary> public override bool Equals(object obj) { if (obj == null) { return(false); } MapperSettings cmpSettings = obj as MapperSettings; if (Map.Count != cmpSettings.Map.Count) { return(false); } foreach (string key in Map.Keys) { List <PoolRef> myAllowedPools = Map[key]; List <PoolRef> cmpAllowedPools = null; try { cmpAllowedPools = cmpSettings.Map[key]; } catch { return(false); } if (myAllowedPools.Count != cmpAllowedPools.Count) { return(false); } foreach (PoolRef ap in myAllowedPools) { for (int i = 0; i < cmpAllowedPools.Count; i++) { if (cmpAllowedPools[i]._reservoirInstanceIdx == ap._reservoirInstanceIdx && cmpAllowedPools[i]._poolIdx == ap._poolIdx) { break; } else if (i == cmpAllowedPools.Count - 1) { return(false); } } } } return(true); }
/// <summary> /// Creates the deep copy instance of this instance /// </summary> public MapperSettings DeepClone() { MapperSettings clonnedMapper = new MapperSettings(); foreach (KeyValuePair <string, List <PoolRef> > keyValuePair in Map) { List <PoolRef> clonnedList = new List <PoolRef>(keyValuePair.Value.Count); foreach (PoolRef ap in keyValuePair.Value) { PoolRef clonnedAP = new PoolRef { _reservoirInstanceIdx = ap._reservoirInstanceIdx, _poolIdx = ap._poolIdx }; clonnedList.Add(clonnedAP); } clonnedMapper.Map.Add(keyValuePair.Key, clonnedList); } return(clonnedMapper); }
private void LoadResources() { SettingsManager.Init(); mapperSettings = SettingsManager.LoadSettings(); if (mapperSettings.UI.Overlay == null) { mapperSettings.UI.Overlay = new OverlaySettings(); mapperSettings.UI.Overlay.CritterFormat = "PID=%PID% [%P_ScriptName%@%P_FuncName%]\nBag=%P_ST_BAG_ID%"; mapperSettings.UI.Overlay.SceneryFormat = "PID=%PID%"; } frmPaths = new frmPaths(mapperSettings); if (mapperSettings == null) { mapperSettings = new MapperSettings(); frmPaths.ShowDialog(); mapperSettings.View.Tiles = mapperSettings.View.Roofs = mapperSettings.View.Critters = mapperSettings.View.Items = mapperSettings.View.Scenery = mapperSettings.View.Walls = true; mapperSettings.Performance.CacheResources = true; mapperSettings.Performance.FastRendering = true; } menuViewTiles.Checked = mapperSettings.View.Tiles; menuViewRoofs.Checked = mapperSettings.View.Roofs; menuViewCritters.Checked = mapperSettings.View.Critters; menuViewItems.Checked = mapperSettings.View.Items; menuViewScenery.Checked = mapperSettings.View.Scenery; menuViewSceneryWalls.Checked = mapperSettings.View.Walls; resourceLoader.RunWorkerAsync(); }
//bool addedData = false; public frmPaths(MapperSettings settings) { InitializeComponent(); this.settings = settings; txtBasePath.Text = settings.Paths.BaseDir; txtCritterProtos.Text = settings.Paths.CritterProtos; txtItemProtos.Text = settings.Paths.ItemProtos; txtFOOBJ.Text = settings.Paths.FOOBJ; txtCritterTypes.Text = settings.Paths.CritterTypes; txtMapsDir.Text = settings.Paths.MapsDir; if (settings.Paths.DataFiles == null) { settings.Paths.DataFiles = new List <string>(); } foreach (var file in settings.Paths.DataFiles) { lstDataFiles.Items.Add(file); } foreach (var dir in settings.Paths.DataDirs) { lstDataDirs.Items.Add(dir); } }
public frmOverlay(MapperSettings mapperSettings) { InitializeComponent(); txtCritter.Text = mapperSettings.UI.Overlay.CritterFormat; txtScenery.Text = mapperSettings.UI.Overlay.SceneryFormat; }
public static void AddSkeMapper(this IServiceCollection services, MapperSettings mapperSettings) { services.AddSingleton((sp) => MapperBuilder.Instance.ApplySettings(mapperSettings).Build()); }
/// <summary> /// Creates the instance and initializes it from given xml element. /// This is the preferred way to instantiate State Machine settings. /// </summary> /// <param name="elem"> /// Xml data containing State Machine settings. /// Content of xml element is always validated against the xml schema. /// </param> public StateMachineSettings(XElement elem) { //Validation ElemValidator validator = new ElemValidator(); Assembly assemblyRCNet = Assembly.GetExecutingAssembly(); validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.StateMachineSettings.xsd"); validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd"); XElement stateMachineSettingsElem = validator.Validate(elem, "rootElem"); //Parsing //Randomizer seek RandomizerSeek = int.Parse(stateMachineSettingsElem.Attribute("randomizerSeek").Value); //Neural preprocessor NeuralPreprocessorConfig = new NeuralPreprocessorSettings(stateMachineSettingsElem.Descendants("neuralPreprocessor").First()); //Readout layer ReadoutLayerConfig = new ReadoutLayerSettings(stateMachineSettingsElem.Descendants("readoutLayer").First()); //Mapper XElement mapperSettingsElem = stateMachineSettingsElem.Descendants("mapper").FirstOrDefault(); if(mapperSettingsElem != null) { //Create mapper object MapperCfg = new MapperSettings(); //Loop through mappings foreach(XElement mapElem in mapperSettingsElem.Descendants("map")) { //Readout unit name string readoutUnitName = mapElem.Attribute("readoutUnitName").Value; int readoutUnitIdx = -1; for (int i = 0; i < ReadoutLayerConfig.ReadoutUnitCfgCollection.Count; i++) { if(ReadoutLayerConfig.ReadoutUnitCfgCollection[i].Name == readoutUnitName) { readoutUnitIdx = i; break; } else if(i == ReadoutLayerConfig.ReadoutUnitCfgCollection.Count - 1) { throw new Exception($"Name {readoutUnitName} not found among readout units."); } } //Allowed pools List<MapperSettings.AllowedPool> allowedPools = new List<MapperSettings.AllowedPool>(); XElement allowedPoolsElem = mapElem.Descendants("allowedPools").FirstOrDefault(); if (allowedPoolsElem != null) { foreach (XElement allowedPoolElem in allowedPoolsElem.Descendants("pool")) { //Reservoir instance name string reservoirInstanceName = allowedPoolElem.Attribute("reservoirInstanceName").Value; int reservoirInstanceIdx = -1; for (int i = 0; i < NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection.Count; i++) { if (NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection[i].InstanceName == reservoirInstanceName) { reservoirInstanceIdx = i; break; } else if (i == NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection.Count - 1) { throw new Exception($"Name {reservoirInstanceName} not found among resevoir instances."); } } //Pool name string reservoirCfgName = NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection[reservoirInstanceIdx].Settings.SettingsName; ReservoirSettings reservoirSettings = NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection[reservoirInstanceIdx].Settings; string poolName = allowedPoolElem.Attribute("poolName").Value; int poolIdx = -1; for (int i = 0; i < reservoirSettings.PoolSettingsCollection.Count; i++) { if (reservoirSettings.PoolSettingsCollection[i].Name == poolName) { poolIdx = i; break; } else if (i == reservoirSettings.PoolSettingsCollection.Count - 1) { throw new Exception($"Name {poolName} not found among resevoir's pools."); } } allowedPools.Add(new MapperSettings.AllowedPool { _reservoirInstanceIdx = reservoirInstanceIdx, _poolIdx = poolIdx }); } MapperCfg.PoolsMap.Add(readoutUnitName, allowedPools); } //Allowed routed input fields List<int> allowedRoutedFieldsIdxs = new List<int>(); XElement allowedInputFieldsElem = mapElem.Descendants("allowedInputFields").FirstOrDefault(); List<string> routedInputFieldNames = NeuralPreprocessorConfig.InputConfig.RoutedFieldNameCollection(); if (allowedInputFieldsElem != null) { foreach (XElement allowedInputFieldElem in allowedInputFieldsElem.Descendants("field")) { //Input field name string inputFieldName = allowedInputFieldElem.Attribute("name").Value; int routedFieldIdx = routedInputFieldNames.IndexOf(inputFieldName); if (routedFieldIdx == -1) { throw new Exception($"Name {inputFieldName} not found among input fields allowed to be routed to readout."); } allowedRoutedFieldsIdxs.Add(routedFieldIdx); } MapperCfg.RoutedInputFieldsMap.Add(readoutUnitName, allowedRoutedFieldsIdxs); } } } return; }
/// <summary> /// Constructor to initialize /// </summary> /// <param name="next"></param> /// <param name="options"></param> public MappingMiddleware(RequestDelegate next, IOptions <MapperSettings> options) { _next = next; _mapper = options.Value; }
//Methods /// <summary> /// See the base. /// </summary> public override bool Equals(object obj) { if (obj == null) return false; MapperSettings cmpSettings = obj as MapperSettings; //Pools map if (PoolsMap.Count != cmpSettings.PoolsMap.Count) { return false; } foreach(string key in PoolsMap.Keys) { List<AllowedPool> myAllowedPools = PoolsMap[key]; List<AllowedPool> cmpAllowedPools = null; try { cmpAllowedPools = cmpSettings.PoolsMap[key]; } catch { return false; } if(myAllowedPools.Count != cmpAllowedPools.Count) { return false; } foreach(AllowedPool allowedPool in myAllowedPools) { for(int i = 0; i < cmpAllowedPools.Count; i++) { if(cmpAllowedPools[i]._reservoirInstanceIdx == allowedPool._reservoirInstanceIdx && cmpAllowedPools[i]._poolIdx == allowedPool._poolIdx) { break; } else if(i == cmpAllowedPools.Count - 1) { return false; } } } } //Input fields map if (RoutedInputFieldsMap.Count != cmpSettings.RoutedInputFieldsMap.Count) { return false; } foreach (string key in RoutedInputFieldsMap.Keys) { List<int> myAllowedRoutedInputFieldsIdxs = RoutedInputFieldsMap[key]; List<int> cmpAllowedRoutedInputFieldsIdxs = null; try { cmpAllowedRoutedInputFieldsIdxs = cmpSettings.RoutedInputFieldsMap[key]; } catch { return false; } if (myAllowedRoutedInputFieldsIdxs.Count != cmpAllowedRoutedInputFieldsIdxs.Count) { return false; } foreach (int allowedInputField in myAllowedRoutedInputFieldsIdxs) { for (int i = 0; i < cmpAllowedRoutedInputFieldsIdxs.Count; i++) { if (cmpAllowedRoutedInputFieldsIdxs[i] == allowedInputField) { break; } else if (i == cmpAllowedRoutedInputFieldsIdxs.Count - 1) { return false; } } } } return true; }