/// <summary>
        /// Gets key columns values.
        /// </summary>
        /// <param name="parameters">Import parameters.</param>
        /// <param name="importEntity">Import entity.</param>
        /// <param name="keyColumns">Key columns.</param>
        /// <returns>Key columns values.</returns>
        private List <ColumnExpression> GetKeyColumnsValues(ImportParameters parameters, ImportEntity importEntity,
                                                            IEnumerable <ImportColumn> keyColumns)
        {
            var columnsExpressions = new List <ColumnExpression>();

            foreach (var column in keyColumns)
            {
                var columnValue = importEntity.FindColumnValue(column);
                if (columnValue == null)
                {
                    continue;
                }
                foreach (var destination in column.Destinations)
                {
                    if (!destination.SchemaUId.Equals(parameters.RootSchemaUId) || !destination.IsKey)
                    {
                        continue;
                    }
                    var valueForSave = ColumnsProcessor.FindValueForSave(destination, columnValue);
                    if (valueForSave == null)
                    {
                        continue;
                    }
                    columnsExpressions.Add(new ColumnExpression {
                        ColumnValueName  = destination.ColumnName,
                        ComparisonType   = FilterComparisonType.Equal,
                        ColumnValue      = valueForSave,
                        DataValueTypeUId = Guid.Parse(destination.Properties[_typeUIdPropertyName].ToString())
                    });
                }
            }
            return(columnsExpressions);
        }
Esempio n. 2
0
 /// <inheritdoc cref="BaseFileImportStage"/>
 protected override FileImportStagesEnum?InternalProcess(ImportParameters parameters)
 {
     ColumnsProcessor.ProcessError += ImportLogger.HandleError;
     ColumnsProcessor.Process(parameters);
     ColumnsProcessor.ProcessError -= ImportLogger.HandleError;
     return(FileImportStagesEnum.ProcessEntitiesFileImportStage);
 }
Esempio n. 3
0
 private void InitEntityForSave(ImportParameters parameters, ImportEntity importEntity)
 {
     importEntity.InitPrimaryEntity(UserConnection, parameters);
     foreach (var column in parameters.Columns)
     {
         var columnValue = importEntity.FindColumnValue(column);
         if (columnValue == null)
         {
             continue;
         }
         foreach (var destination in column.Destinations)
         {
             var entity          = importEntity.GetEntityForSave(UserConnection, destination);
             var columnValueName = destination.ColumnValueName;
             var valueForSave    = ColumnsProcessor.FindValueForSave(destination, columnValue);
             if (valueForSave == null)
             {
                 continue;
             }
             if (entity.StoringState != StoringObjectState.New)
             {
                 var entityValue = entity.GetColumnValue(columnValueName);
                 if (valueForSave.Equals(entityValue) || destination.IsKey)
                 {
                     continue;
                 }
             }
             if (entity.Schema.Columns.GetByName(destination.ColumnName).DataValueType is TextDataValueType)
             {
                 valueForSave = valueForSave.ToString().Trim();
             }
             entity.SetColumnValue(columnValueName, valueForSave);
         }
     }
 }
        /// <summary>
        /// Gets schemas key columns values.
        /// </summary>
        /// <param name="parameters">Import parameters.</param>
        /// <param name="importEntity">Import entity.</param>
        /// <returns>Schemas key columns values.</returns>
        private SchemasKeyColumnsValues GetSchemasKeyColumnsValues(
            ImportParameters parameters, ImportEntity importEntity)
        {
            var schemasKeyColumnsValues = new SchemasKeyColumnsValues();

            foreach (ImportColumn column in parameters.Columns)
            {
                ImportColumnValue columnValue = importEntity.FindColumnValue(column);
                if (columnValue == null)
                {
                    continue;
                }
                foreach (ImportColumnDestination destination in column.Destinations)
                {
                    Guid schemaUId = destination.SchemaUId;
                    if (schemaUId.Equals(parameters.RootSchemaUId))
                    {
                        continue;
                    }
                    object valueForSave = ColumnsProcessor.FindValueForSave(destination, columnValue);
                    if (valueForSave == null)
                    {
                        continue;
                    }
                    EntitySchema             schema = UserConnection.EntitySchemaManager.GetInstanceByUId(schemaUId);
                    EntitiesKeyColumnsValues entitiesKeyColumnsValues;
                    if (!schemasKeyColumnsValues.TryGetValue(schema, out entitiesKeyColumnsValues))
                    {
                        entitiesKeyColumnsValues = new EntitiesKeyColumnsValues();
                        schemasKeyColumnsValues.Add(schema, entitiesKeyColumnsValues);
                    }
                    int              destinationIndex     = destination.GetIndex();
                    object           attributeColumnValue = destination.FindAttributeColumnValue();
                    string           destinationKey       = string.Concat(destinationIndex, attributeColumnValue);
                    KeyColumnsValues keyColumnsValues;
                    if (!entitiesKeyColumnsValues.TryGetValue(destinationKey, out keyColumnsValues))
                    {
                        keyColumnsValues = new KeyColumnsValues();
                        entitiesKeyColumnsValues.Add(destinationKey, keyColumnsValues);
                    }
                    keyColumnsValues.Add(destination.ColumnName, valueForSave);
                    string attributeColumnName = GetDestinationAttributeColumnName(destination, schema);
                    if (!keyColumnsValues.ContainsKey(attributeColumnName))
                    {
                        keyColumnsValues.Add(attributeColumnName, attributeColumnValue);
                    }
                    EntitySchemaColumn connectionColumn     = importEntity.GetReferenceColumn(schema);
                    string             connectionColumnName = connectionColumn.Name;
                    if (!keyColumnsValues.ContainsKey(connectionColumnName))
                    {
                        Guid primaryColumnValue = importEntity.PrimaryEntity.PrimaryColumnValue;
                        keyColumnsValues.Add(connectionColumnName, primaryColumnValue);
                    }
                }
            }
            return(schemasKeyColumnsValues);
        }
        private KeyValuePair <string, object> GetFilterItemParameter(ImportColumnDestination destination, ImportColumnValue importColumnValue, EntitySchema entitySchema)
        {
            object value = null;

            if (importColumnValue != null)
            {
                value = ColumnsProcessor.FindValueForSave(destination, importColumnValue);
            }
            if (value == null)
            {
                var columns = entitySchema.Columns;
                value = columns.GetByName(destination.ColumnName).DataValueType.DefValue;
            }
            return(new KeyValuePair <string, object>(destination.ColumnName, value));
        }
        private void SetBufferedImportEntityInsertColumnValues(ImportEntity importEntity, Insert insertQuery,
                                                               IEnumerable <ImportColumn> keyColumns)
        {
            var schemaColumns = _schema.Columns;

            foreach (var c in keyColumns.Select((c, i) => (Column: c, Index: i + 1)))
            {
                var column      = c.Column;
                var index       = c.Index;
                var columnName  = $"Column{index}";
                var destination = column.Destinations.FirstOrDefault();
                if (destination == null)
                {
                    throw new ArgumentNullOrEmptyException(nameof(destination));
                }
                var dataValueType = schemaColumns.GetByName(destination.ColumnName).DataValueType;
                var columnValue   = importEntity.FindColumnValue(column);
                var valueForSave  = columnValue == null
                                                ? dataValueType.DefValue
                                                : ColumnsProcessor.FindValueForSave(destination, columnValue);
                insertQuery.Set(columnName, Column.Parameter(valueForSave, dataValueType));
            }
        }
        /// <summary>
        /// Gets schemas key columns values.
        /// </summary>
        /// <param name="parameters">Import parameters.</param>
        /// <param name="importEntity">Import entity.</param>
        /// <returns>Schemas key columns values.</returns>
        private Dictionary <EntitySchema, Dictionary <ImportColumnDestination, object> > GetSchemasKeyDestinations(
            ImportParameters parameters, ImportEntity importEntity)
        {
            var schemasKeyDestinations = new Dictionary <EntitySchema, Dictionary <ImportColumnDestination, object> >();

            foreach (ImportColumn column in parameters.Columns)
            {
                ImportColumnValue columnValue = importEntity.FindColumnValue(column);
                if (columnValue == null)
                {
                    continue;
                }
                foreach (ImportColumnDestination destination in column.Destinations)
                {
                    Guid schemaUId = destination.SchemaUId;
                    if (schemaUId.Equals(parameters.RootSchemaUId))
                    {
                        continue;
                    }
                    object valueForSave = ColumnsProcessor.FindValueForSave(destination, columnValue);
                    if (valueForSave == null)
                    {
                        continue;
                    }
                    EntitySchema schema = UserConnection.EntitySchemaManager.GetInstanceByUId(schemaUId);
                    Dictionary <ImportColumnDestination, object> keyDestinations;
                    if (!schemasKeyDestinations.TryGetValue(schema, out keyDestinations))
                    {
                        keyDestinations = new Dictionary <ImportColumnDestination, object>();
                        schemasKeyDestinations.Add(schema, keyDestinations);
                    }
                    keyDestinations.Add(destination, valueForSave);
                }
            }
            return(schemasKeyDestinations);
        }
Esempio n. 8
0
 /// <summary>
 /// Processes column values.
 /// </summary>
 /// <param name="parameters">File import parameters.</param>
 protected virtual void ProcessColumnValues(ImportParameters parameters)
 {
     InitColumnsProcessor(parameters);
     ColumnsProcessor.Process();
 }