public override Stream TransformToFile(Mapping.Mapping mapping, IList <Dictionary <string, object> > data) { var output = new MemoryStream(); new XDocument(new XElement(mapping.ParentName, data.Select(d => WriteObject(d, mapping.ObjectName, mapping.PropertyMappings)))).Save(output); return(output); }
public Stream TransformToFile(Mapping.Mapping mapping, object data) { var output = new MemoryStream(); new XDocument(new XElement(mapping.ParentName, mapping.PropertyMappings)).Save(output); return(output); }
public IList <T> TransformFromFile <T>(string format, Mapping.Mapping mapping, Stream file) { if (!Transformers.ContainsKey(format)) { throw new NotSupportedException("This format is not supported"); } return(Transformers[format].TransformFromFile <T>(mapping, file)); }
public Stream TransformToFile(string format, Mapping.Mapping mapping, IList <Dictionary <string, object> > data, IDictionary <string, object> parameters) { if (!Transformers.ContainsKey(format)) { throw new NotSupportedException("This format is not supported"); } return(Transformers[format].TransformToFile(mapping, data, parameters)); }
public override Dictionary <string, object> TransformFromFile(Mapping.Mapping mapping, Stream file) { var workbook = ExcelManager.OpenWorkbook(file); var objects = mapping.PropertyMappings.Where(m => m.PropertyMappings != null && m.PropertyMappings.Any()).ToList(); var listOffsets = new List <KeyValuePair <int, int> >(); var result = objects.ToDictionary(obj => obj.PropertyName, obj => ReadObjectToDictionary(obj.PropertyMappings, workbook, listOffsets)); var properties = mapping.PropertyMappings.Where(m => m.PropertyMappings == null || !m.PropertyMappings.Any()); foreach (var property in properties) { result.Add(property.PropertyName, GetRange(workbook, property, GetRowOffset(listOffsets, property, workbook)).Value); } return(result); }
public Context(Mapping.Mapping mapping) { if (ReferenceEquals(mapping, null)) { throw new ArgumentNullException(nameof(mapping)); } var procedures = mapping.Procedures ?? new Mapping.Procedure[0]; foreach (var selector in procedures) { m_spSelectorInfos[selector.FullName] = new SpSelectorInfo { IgnoreQueryResult = selector.IgnoreQueryResult }; } }
public void Map(Model.Model model, params IMapperOption[] options) { Mapping.Mapping mapping = new Mapping.Mapping(); mapping.Model = model; foreach (Model.Entity e in model) { Mapping.Entity entityMapping = new Mapping.Entity(); entityMapping.TableName = "Entity"; entityMapping.Add(new Mapping.Attribute("Id") { IsPrimaryKey = true, Generator = SqlMapper.Mapping.Generator.Native, DbType = System.Data.DbType.UInt32 }); entityMapping.Constraint = "Type=='" + e.Type + "'"; foreach (Model.Attribute attribute in e.Attributes.Values) { entityMapping.Add(new Mapping.Attribute(attribute.Name) { TableName = "Attribute", ColumnName = "Name", DbType = driver.GetDbType(attribute.Type) }); } foreach (Model.Reference reference in e.References.Values) { Mapping.Reference referenceMapping = new Mapping.Reference(); referenceMapping.Rules.Add(new Rule() { ParentTableName = "Entity", ParentFieldNames = "Id", ChildTableName = "Relation", ChildFieldNames = "FK_ParentID,Name='" + reference.Name + "'", }); referenceMapping.Rules.Add(new Rule() { ParentTableName = "Relation", ParentFieldNames = "FK_ChildID,Name='" + reference.Name + "'", ChildTableName = "Entity", ChildFieldNames = "Id", }); } } }
public override Stream TransformToFile(Mapping.Mapping mapping, IList <Dictionary <string, object> > data, IDictionary <string, object> parameters) { if (data.Count != 1) { throw new NotSupportedException(); } var workbook = parameters.ContainsKey("template") ? ExcelManager.OpenWorkbook((Stream)parameters["template"]) : ExcelManager.OpenWorkbook(Path.GetTempFileName()); var buildHeaderRow = parameters.ContainsKey("buildHeaderRow") && (bool)parameters["buildHeaderRow"]; var refs = (Dictionary <string, ImportReferencedataList>)(parameters.ContainsKey("referenceData") ? parameters["referenceData"] : null); if (buildHeaderRow) { WriteHeaderRow(workbook, mapping.PropertyMappings.Where(p => p.IsHeaderMapping).ToList()); } if (refs != null && refs.Count > 0) { WriteRefDataSheets(refs, workbook); } WriteObject(workbook, data[0], mapping.PropertyMappings, 0, mapping.SubstituteYesForTrue, refs: refs); //clean up unfilled cells for (var i = 1; i <= workbook.Worksheets.Count; i++) { var worksheet = workbook.Worksheets[i]; var cells = worksheet.FindWithValue("###"); foreach (var cell in cells) { worksheet.Cells[cell.Key].Value = ""; } worksheet.UsedRange?.AutoFitColumns(); } var path = Path.GetTempFileName(); workbook.SaveAs(path); return(new FileStream(path, FileMode.Open)); }
/// <summary> /// Currently we're only assuming a basic list of columns that will be mapped to object properties on one worksheet /// </summary> /// <typeparam name="T"></typeparam> /// <param name="mapping"></param> /// <param name="file"></param> /// <returns></returns> public override IList <T> TransformFromFile <T>(Mapping.Mapping mapping, Stream file) { var workbook = ExcelManager.OpenWorkbook(file); var properties = mapping.PropertyMappings.Where(m => m.PropertyMappings == null || !m.PropertyMappings.Any()); var results = new List <T>(); //For the moment the first column needs to be filled var tempMapping = mapping.PropertyMappings.FirstOrDefault(); var firstColString = tempMapping.SheetName + "!A" + tempMapping.RowNumber; var rowOffset = 0; var firstColValue = GetRange(workbook, new PropertyMapping { MappingInfo = firstColString }).Value; while (firstColValue != null && !string.IsNullOrEmpty(firstColValue.ToString())) { results.Add(ReadObject <T>(mapping.PropertyMappings, workbook, rowOffset)); rowOffset++; firstColValue = GetRange(workbook, new PropertyMapping { MappingInfo = firstColString }, rowOffset).Value; } return(results); }
public TypeFinderVisitor(Model.Model model, Mapping.Mapping mapping) { this.model = model; this.mapping = mapping; }
//IDictionary<AliasedExpression, TableAlias> registeredAliasedExpression = new Dictionary<AliasedExpression, TableAlias>(); public ReferenceToColumnMutator(Mapping.Mapping mapping) { AliasesMapping = new Dictionary<TableAlias, TableAlias>(); this.mapping = mapping; }
public EntityToTableMutator(Mapping.Mapping mapping, IDriver driver) { this.mapping = mapping; this.driver = driver; }
public override Stream TransformToFile(Mapping.Mapping mapping, IList <Dictionary <string, object> > data, IDictionary <string, object> parameters) { throw new NotImplementedException(); }
internal Soccer() // <-- instead of 'public' { Mappings = new Mapping.Mapping(); }
public virtual Dictionary <string, object> TransformFromFile(Mapping.Mapping mapping, Stream file) { throw new NotImplementedException(); }
public DateOperations(Mapping.Mapping mapping) { this.mapping = mapping; }
public virtual IList <T> TransformFromFile <T>(Mapping.Mapping mapping, Stream file) { throw new NotImplementedException(); }
public virtual Stream TransformToFile(Mapping.Mapping mapping, IList <Dictionary <string, object> > data) { throw new NotImplementedException(); }
public AttributeToColumnMutator(Mapping.Mapping mapping) { this.mapping = mapping; }