Example #1
0
        public virtual void UpdateEntityCollection(EntityCollection entityCollection, EntitySchema entitySchema)
        {
            string GetDebugInfo(Entity source)
            {
                var info = new System.Text.StringBuilder();

                try {
                    info.Append(source.SchemaName);
                    info.Append($" ({source.Schema.PrimaryColumn.Name}: [{source.PrimaryColumnValue}])");
                } catch (Exception) {
                }
                return(info.ToString());
            }

            foreach (Entity entity in entityCollection)
            {
                try {
                    foreach (KeyValuePair <string, object> columnValue in RecordColumnValues.Values)
                    {
                        EntitySchemaColumn column = entitySchema.GetSchemaColumnByMetaPath(columnValue.Key);
                        object             value  = columnValue.Value;
                        if (ProcessUserTaskUtilities.GetIsEmptyLookupOrDateTimeValue(value, column.DataValueType))
                        {
                            value = null;
                        }
                        entity.SetColumnValue(column, value);
                    }
                    entity.UseAdminRights = false;
                    entity.Save(false);
                } catch (Exception e) {
                    string debugInfo = GetDebugInfo(entity);
                    Log.Error("An error occurred during process element {this} when updating an entity {debugInfo}", e);
                }
            }
        }
Example #2
0
        public Dictionary <string, Guid> GetColumnReferenceSchemaUIds(Dictionary <string, List <string> > columnMetaSchema)
        {
            var response = new Dictionary <string, Guid>();

            EntitySchemaManager entitySchemaManager = UserConnection.EntitySchemaManager;

            foreach (KeyValuePair <string, List <string> > keyValuePair in columnMetaSchema)
            {
                string        entitySchemaName = keyValuePair.Key;
                EntitySchema  entitySchema     = entitySchemaManager.GetInstanceByName(entitySchemaName);
                List <string> metaPaths        = keyValuePair.Value;
                foreach (string metaPath in metaPaths)
                {
                    EntitySchemaColumn columnPath = entitySchema.GetSchemaColumnByMetaPath(metaPath);
                    response[metaPath] = columnPath.ReferenceSchemaUId;
                }
            }
            return(response);
        }
Example #3
0
 public virtual void UpdateEntityCollection(EntityCollection entityCollection, EntitySchema entitySchema)
 {
     foreach (var entity in entityCollection)
     {
         try {
             foreach (KeyValuePair <string, object> columnValue in RecordColumnValues.Values)
             {
                 EntitySchemaColumn column = entitySchema.GetSchemaColumnByMetaPath(columnValue.Key);
                 object             value  = columnValue.Value;
                 if (ProcessUserTaskUtilities.GetIsEmptyLookupOrDateTimeValue(value, column.DataValueType))
                 {
                     value = null;
                 }
                 entity.SetColumnValue(column, value);
             }
             entity.UseAdminRights = false;
             entity.Save(false);
         } catch (Exception e) {
             Log.Error(e);
         }
     }
 }
Example #4
0
        protected override bool InternalExecute(ProcessExecutingContext context)
        {
            if (EntityCollection == null || EntityCollection.Schema == null)
            {
                return(true);
            }
            EntitySchema entitySchema = EntityCollection.Schema;
            EntitySchema samplingEntitySchema;
            var          selectedConstColumnValues    = new Dictionary <EntitySchemaColumn, object>();
            var          selectedFuncColumnValues     = new Dictionary <EntitySchemaColumn, Func <Entity, object> >();
            var          selectedSamplingColumnValues = new Dictionary <EntitySchemaColumn, EntitySchemaColumn>();

            if (SamplingEntityCollection != null)
            {
                samplingEntitySchema = SamplingEntityCollection.Schema;
            }
            else
            {
                samplingEntitySchema = null;
            }
            if (IsSelectedSamplingAddMode)
            {
                if (samplingEntitySchema == null)
                {
                    return(true);
                }
                else
                {
                    foreach (KeyValuePair <string, string> selectedColumnValue in RecordDefValues.FetchMetaPathes)
                    {
                        EntitySchemaColumn entitySchemaColumn         = entitySchema.GetSchemaColumnByMetaPath(selectedColumnValue.Key);
                        EntitySchemaColumn samplingEntitySchemaColumn = samplingEntitySchema
                                                                        .GetSchemaColumnByMetaPath(selectedColumnValue.Value);
                        selectedSamplingColumnValues.Add(entitySchemaColumn, samplingEntitySchemaColumn);
                    }
                }
            }
            foreach (KeyValuePair <string, object> selectedColumnValue in RecordDefValues.Values)
            {
                EntitySchemaColumn entitySchemaColumn = entitySchema.GetSchemaColumnByMetaPath(selectedColumnValue.Key);
                var func = selectedColumnValue.Value as Func <Entity, object>;
                if (func != null)
                {
                    selectedFuncColumnValues.Add(entitySchemaColumn, func);
                }
                else
                {
                    selectedConstColumnValues.Add(entitySchemaColumn, selectedColumnValue.Value);
                }
            }
            if (IsSelectedSamplingAddMode)
            {
                IQueryable <Entity> samplingEntityQuery = CreateQuery();
                foreach (Entity samplingEntity in samplingEntityQuery)
                {
                    Entity newEntity = entitySchema.CreateEntity(UserConnection);
                    //newEntity.SetDefColumnValues();

                    //CopyColumnValues(samplingEntity, newEntity);
                    SetColumnValues(newEntity, selectedConstColumnValues);
                    SetSamplingFuncColumnValues(newEntity, samplingEntity, selectedFuncColumnValues);
                    SetSamplingColumnValues(newEntity, samplingEntity, selectedSamplingColumnValues);
                    EntityCollection.Add(newEntity);
                }
            }
            else
            {
                Entity newEntity = entitySchema.CreateEntity(UserConnection);
                //newEntity.SetDefColumnValues();
                SetColumnValues(newEntity, selectedConstColumnValues);
                EntityCollection.Add(newEntity);
            }
            return(true);
        }