public void CanCorrectlyImportXlsFiles() { var excelFileInfo = new ExcelFileInfo(new FileInfo(@"Excel\Resources\People.xls")); var mapping = new MappingRules <Person, int>(); mapping.AddMapping(0, p => p.Name); mapping.AddMapping(1, p => p.FriendsCount); mapping.AddMapping(2, p => p.DateOfBirth); mapping.AddMapping(3, p => p.Sex, value => Enum.Parse(typeof(Gender), value as string)); var dataLoader = new ExcelDataLoader <Person>(excelFileInfo, mapping); var result = dataLoader.LoadData(); Assert.IsNotNull(result); Assert.AreEqual(4, result.Count()); }
public async Task CanCorrectlyImportCsvFilesAsync() { var csvFileInfo = new CsvFileInfo(new FileInfo(@"CSV\Resources\People.csv"), true); var mapping = new MappingRules <Person, int>(); mapping.AddMapping(0, p => p.Name); mapping.AddMapping(1, p => p.FriendsCount); mapping.AddMapping(2, p => p.DateOfBirth); mapping.AddMapping(3, p => p.Sex, value => Enum.Parse(typeof(Gender), value as string)); var dataLoader = new CsvDataLoader <Person>(csvFileInfo, mapping); var result = (await dataLoader.LoadDataAsync()).ToArray(); Assert.IsNotNull(result); Assert.IsTrue(result.Any()); }
public void CanCorrectlyImportCsvFilesWithoutHeaders() { var csvFileInfo = new CsvFileInfo(new FileInfo(@"CSV\Resources\People_NoHeaders.csv"), hasHeaders: false); var mapping = new MappingRules <Person, int>(); mapping.AddMapping(0, p => p.Name); mapping.AddMapping(1, p => p.FriendsCount); mapping.AddMapping(2, p => p.DateOfBirth); mapping.AddMapping(3, p => p.Sex, value => Enum.Parse(typeof(Gender), value as string)); var dataLoader = new CsvDataLoader <Person>(csvFileInfo, mapping); var result = dataLoader.LoadData().ToArray(); Assert.IsNotNull(result); Assert.IsTrue(result.Any()); }
public bool Initialize(string configFile) { initialized = false; if (System.IO.File.Exists(configFile)) { XmlSerializer ruleSerializer = new XmlSerializer(typeof(MappingRules)); System.IO.FileStream readFileStream = new System.IO.FileStream(configFile, FileMode.Open, FileAccess.Read, FileShare.Read); mappingRules = (MappingRules)ruleSerializer.Deserialize(readFileStream); readFileStream.Close(); configurationFile = configFile; initialized = true; } return initialized; }
public static IStringManipulationRule GetInstance(MappingRules mappingRuleType) { switch (mappingRuleType) { case MappingRules.SimpleReplacement: return(s_simpleTextReplacementRule); case MappingRules.Ignore: return(s_ignoreTextRule); case MappingRules.FormatStringComposition: return(s_formatStringCompositionRule); case MappingRules.FormatStringDecomposition: return(s_formatStringDecompositionRule); default: Debug.Assert(false, "Unknown DisplayNameMapping.MappingRule type"); TraceManager.TraceError("Unknown DisplayNameMapping.MappingRule type"); return(null); } }
private bool GetIsMultischema() { return(!string.IsNullOrEmpty(DefaultSchema) || MappingRules.Any(rule => !string.IsNullOrEmpty(rule.Schema)) || GetIsMultidatabase()); }
private bool GetIsMultidatabase() { return(!string.IsNullOrEmpty(DefaultDatabase) || MappingRules.Any(rule => !string.IsNullOrEmpty(rule.Database))); }
public Interceptor(MappingRules <T> rules, InterfaceWrapper <T> parent, T instance) { _rules = rules; _parent = parent; _instance = instance; }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object" /> class. /// </summary> public InterfaceWrapper(T instance, MappingRules <T> rules) { Target = typeof(T).IsInterface ? Generator.CreateInterfaceProxyWithTarget(instance, new Interceptor(rules, this, instance)) : Generator.CreateClassProxyWithTarget(instance, new Interceptor(rules, this, instance)); }
public static BatchingConfig Load(XmlReader reader) { BatchingConfig result = new BatchingConfig(); reader.GoToElement(); reader.ReadStartElement(); if (!reader.IsEmptyElement) { while (reader.GoToSibling()) { switch (reader.LocalName) { case "Application": if (!reader.IsEmptyElement) { reader.ReadStartElement(); while (reader.GoToSibling()) { switch (reader.LocalName) { case "Id": result.ApplicationId = new Guid(reader.ReadElementContentAsString()); break; case "Name": result.ApplicationName = reader.ReadElementContentAsString(); break; case "Version": result.ApplicationVersion = reader.ReadElementContentAsString(); break; case "Enabled": result.LoggingEnabled = reader.ReadElementContentAsBoolean(); break; default: reader.Skip(); break; } } reader.ReadEndElement(); } else { reader.Skip(); } break; case "Queue": if (!reader.IsEmptyElement) { reader.ReadStartElement(); while (reader.GoToSibling()) { switch (reader.LocalName) { case "maxLength": result.MaxQueueLength = reader.ReadElementContentAsInt(); break; case "maxBatchLength": result.MaxBatchLength = reader.ReadElementContentAsInt(); break; case "maxSendErrors": result.MaxSendErrors = reader.ReadElementContentAsInt(); break; case "maxSendErrorsThrottled": result.MaxSendErrorsThrottled = reader.ReadElementContentAsInt(); break; case "pollingIntervalSeconds": result.QueuePollingInterval = TimeSpan.FromSeconds(reader.ReadElementContentAsInt()); break; case "pollingIntervalThrottledSeconds": result.QueuePollingIntervalThrottled = TimeSpan.FromSeconds(reader.ReadElementContentAsInt()); break; case "maxRetries": result.MaxRetries = reader.ReadElementContentAsInt(); break; default: reader.Skip(); break; } } reader.ReadEndElement(); } else { reader.Skip(); } break; case "Session": if (!reader.IsEmptyElement) { reader.ReadStartElement(); while (reader.GoToSibling()) { switch (reader.LocalName) { case "maxSessionLogs": result.MaxSessionLogs = reader.ReadElementContentAsInt(); break; default: reader.Skip(); break; } } reader.ReadEndElement(); } else { reader.Skip(); } break; case "MappingRules": if (!reader.IsEmptyElement) { result.MappingRules = MappingRules.Load(reader); } else { reader.Skip(); } break; default: reader.Skip(); break; } } reader.ReadEndElement(); } else { reader.Skip(); } return(result); }
public DynamicWrapper(object root, MappingRules <T> businessRules) { _wrappedObject = root ?? throw new ArgumentNullException(nameof(root)); _root = root; _businessRules = businessRules; }
internal DynamicWrapper(object root, object obj, MappingRules <T> businessRules) { _root = root; _wrappedObject = obj ?? throw new ArgumentNullException(nameof(obj)); _businessRules = businessRules; }