示例#1
0
        /// <summary>
        /// Gets the mappings for the specified entity and worksheet
        /// </summary>
        /// <returns></returns>
        public Message GetEntityMappings()
        {
            Message         responseMsg   = null;
            ImportUtilities importUtility = new ImportUtilities();
            SPDataAccess    spDataAccess  = new SPDataAccess();
            MappedColumns   mappedColumns = new MappedColumns();

            WorksheetUtilities worksheetUtilities = new WorksheetUtilities(spDataAccess);

            MappingData mappingData = this.ValidateRequest(spDataAccess, false);

            // get the columns from the supplied worksheet
            mappedColumns.WSColumns = worksheetUtilities.GetWorksheetColumns(mappingData);

            // checks to see if the columns pulled from sheet map to
            // a predefined template e.g. Bulk Import or Goals Export
            mappedColumns.TemplateType = ImportUtilities.GetImportTemplateType(mappedColumns.WSColumns);

            // get the entity columns with the default values for choice columns
            mappedColumns.ColumnDefinitions = importUtility.GetEntityColumnDefaultValues(spDataAccess, mappingData.ListName);

            responseMsg = ctx.CreateJsonResponse <MappedColumns>(mappedColumns);

            return(responseMsg);
        }
示例#2
0
        /// <summary>
        /// Tries to add a ColumnMap for the given field name.
        /// Throws and exception if field cannot be found.
        /// </summary>
        private void TryAddColumnMapForField(string fieldName)
        {
            // Set strategy to filter for public or private fields
            ConventionMapStrategy strategy = new ConventionMapStrategy(false);

            // Find the field that matches the given field name
            strategy.ColumnPredicate = mi => mi.Name == fieldName;
            ColumnMap columnMap = strategy.MapColumns(typeof(TEntity)).FirstOrDefault();

            if (columnMap == null)
            {
                throw new DataMappingException(string.Format("Could not find the field '{0}' in '{1}'.",
                                                             fieldName,
                                                             typeof(TEntity).Name));
            }
            MappedColumns.Add(columnMap);
        }
示例#3
0
        private string GenerateSqlMapping()
        {
            var tSourceType = typeof(T);
            var columnList  = new List <string>();

            Properties = tSourceType.GetProperties();

            MappedColumns = Properties.Where(property => property.CustomAttributes.Any(customAttribute =>
                                                                                       customAttribute.AttributeType == typeof(ColumnAttribute))).ToDictionary(a => a.Name,
                                                                                                                                                               a => a.CustomAttributes.FirstOrDefault(b => b.AttributeType == typeof(ColumnAttribute)));

            KeyProperties = Properties.Where(property => property.CustomAttributes.Any(customAttribute =>
                                                                                       customAttribute.AttributeType == typeof(KeyAttribute))).ToArray();

            IdentityProperty = Properties.SingleOrDefault(property => property.CustomAttributes.Any(customAttribute =>
                                                                                                    customAttribute.AttributeType == typeof(IdentityAttribute))) ?? KeyProperties.FirstOrDefault();

            foreach (var property in GetProperties(Properties))
            {
                var propertyName = property;

                if (MappedColumns.ContainsKey(propertyName))
                {
                    var constructorArguments = MappedColumns[propertyName].ConstructorArguments;

                    if (constructorArguments.Any())
                    {
                        propertyName = constructorArguments.SingleOrDefault().Value.ToString();
                    }
                }

                columnList.Add(propertyName);
            }

            Columns = columnList;

            return(GetSchemaTable(tSourceType));
        }
示例#4
0
 bool IMappedType.ColumnHasBeenMapped(string columnName)
 {
     return(MappedColumns.ContainsKey(columnName));
 }
示例#5
0
        public bool HasChanges(Relationship value, out string description)
        {
            StringBuilder sb = new StringBuilder();

            // Note: IsUnique is dependant on Column changes, so we don't check it here.
            if (base.HasChanges(value))
            {
                sb.Append("Value,");
            }
            if (this.ForeignCardinality != null && value.ForeignCardinality != null && ForeignCardinality != value.ForeignCardinality)
            {
                sb.Append("ForeignCardinality,");
            }
            if (this.ForeignKey != null && value.ForeignCardinality != null && ForeignKey.Name != value.ForeignKey.Name)
            {
                sb.Append("ForeignKeyName,");
            }
            if (this.ForeignTable != null && value.ForeignTable != null && ForeignTable.Name != value.ForeignTable.Name)
            {
                sb.Append("ForeignTableName,");
            }
            if (this.PrimaryCardinality != null && value.PrimaryCardinality != null && PrimaryCardinality != value.PrimaryCardinality)
            {
                sb.Append("PrimaryCardinality,");
            }
            if (this.PrimaryKey != null && value.PrimaryCardinality != null && PrimaryKey.Name != value.PrimaryKey.Name)
            {
                sb.Append("PrimaryKeyName,");
            }
            if (this.PrimaryTable != null && value.PrimaryTable != null && PrimaryTable.Name != value.PrimaryTable.Name)
            {
                sb.Append("PrimaryTableName,");
            }
            if (this.Name != value.Name)
            {
                sb.Append("Name,");
            }
            if (this.Schema != value.Schema)
            {
                sb.Append("Schema,");
            }

            List <MappedColumn> myMappedColumns    = MappedColumns.ToList();
            List <MappedColumn> theirMappedColumns = value.MappedColumns.ToList();

            if (myMappedColumns.Count() != theirMappedColumns.Count())
            {
                sb.Append("CountOfColumns,");
            }

            for (int i = 0; i < myMappedColumns.Count; i++)
            {
                MappedColumn matchingColumn = theirMappedColumns.SingleOrDefault(c => c.Source.Name == myMappedColumns[i].Source.Name && c.Target.Name == myMappedColumns[i].Target.Name);

                if (matchingColumn == null)                // ||
                //myMappedColumns[i].Name != matchingColumn.Name)
                {
                    sb.Append(string.Format("MappedColumns[{0}]:[{1}],", myMappedColumns[i].Source.Name, myMappedColumns[i].Target.Name));
                }
            }
            if (sb.Length > 0)
            {
                description = sb.ToString().TrimEnd(',');
                return(true);
            }
            description = "";
            return(false);
        }