コード例 #1
0
        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);
        }
コード例 #2
0
        public Stream TransformToFile(Mapping.Mapping mapping, object data)
        {
            var output = new MemoryStream();

            new XDocument(new XElement(mapping.ParentName, mapping.PropertyMappings)).Save(output);
            return(output);
        }
コード例 #3
0
 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));
 }
コード例 #4
0
 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));
 }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: Context.cs プロジェクト: llenroc/Zahar
        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
                };
            }
        }
コード例 #7
0
ファイル: EraMapper.cs プロジェクト: npenin/uss
        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",
                    });
                }
            }
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
ファイル: TypeFinderVisitor.cs プロジェクト: npenin/uss
 public TypeFinderVisitor(Model.Model model, Mapping.Mapping mapping)
 {
     this.model = model;
     this.mapping = mapping;
 }
コード例 #11
0
        //IDictionary<AliasedExpression, TableAlias> registeredAliasedExpression = new Dictionary<AliasedExpression, TableAlias>();

        public ReferenceToColumnMutator(Mapping.Mapping mapping)
        {
            AliasesMapping = new Dictionary<TableAlias, TableAlias>();
            this.mapping = mapping;
        }
コード例 #12
0
ファイル: EntityToTableMutator.cs プロジェクト: npenin/uss
 public EntityToTableMutator(Mapping.Mapping mapping, IDriver driver)
 {
     this.mapping = mapping;
     this.driver = driver;
 }
コード例 #13
0
 public override Stream TransformToFile(Mapping.Mapping mapping, IList <Dictionary <string, object> > data, IDictionary <string, object> parameters)
 {
     throw new NotImplementedException();
 }
コード例 #14
0
 internal Soccer()      //  <-- instead of 'public'
 {
     Mappings = new Mapping.Mapping();
 }
コード例 #15
0
 public virtual Dictionary <string, object> TransformFromFile(Mapping.Mapping mapping, Stream file)
 {
     throw new NotImplementedException();
 }
コード例 #16
0
ファイル: DateOperations.cs プロジェクト: npenin/uss
 public DateOperations(Mapping.Mapping mapping)
 {
     this.mapping = mapping;
 }
コード例 #17
0
 public virtual IList <T> TransformFromFile <T>(Mapping.Mapping mapping, Stream file)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
 public virtual Stream TransformToFile(Mapping.Mapping mapping, IList <Dictionary <string, object> > data)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
 public AttributeToColumnMutator(Mapping.Mapping mapping)
 {
     this.mapping = mapping;
 }