/// <inheritdoc />
        protected override bool InternalExecute(ProcessExecutingContext context)
        {
            bool isRedo = (Status == ProcessStatus.Error && CurrentActivityId == Guid.Empty &&
                           !ProcessUserTaskUtilities.GetIsActivityCreated(UserConnection, UId));
            bool isRunning = !CurrentActivityId.Equals(Guid.Empty) && !IsActivityCompleted;

            if (!isRunning || isRedo)
            {
                var            editMode = (RecordEditMode)Enum.ToObject(typeof(RecordEditMode), EditMode);
                bool           isActivityEntitySchema = GetIsActivityEntitySchema();
                Entity         activity      = null;
                IProcessEngine processEngine = UserConnection.ProcessEngine;
                if (isActivityEntitySchema)
                {
                    if (editMode == RecordEditMode.New)
                    {
                        activity = CreateActivity();
                        RecordId = CurrentActivityId;
                    }
                    else
                    {
                        CurrentActivityId = RecordId;
                    }
                }
                else
                {
                    Entity           accompaningActivity  = CreateAccompaningActivity();
                    CoreEntitySchema activityEntitySchema = GetActivityEntitySchema();
                    Guid             resultColumnUId      = activityEntitySchema.Columns.GetByName("Status").UId;
                    processEngine.AddProcessListener(accompaningActivity, UId,
                                                     GetConditionData(resultColumnUId, accompaningActivity));
                    if (editMode == RecordEditMode.New)
                    {
                        RecordId = Guid.NewGuid();
                    }
                }
                string serializedFilters = IsMatchConditions && DataSourceFilters.IsNotNullOrEmpty()
                                        ? ConvertToProcessDataSourceFilters(ObjectSchemaId, DataSourceFilters)
                                        : null;
                if (activity == null)
                {
                    if (editMode != RecordEditMode.New)
                    {
                        processEngine.AddProcessListener(RecordId, ObjectSchemaId, UId, serializedFilters);
                    }
                    else
                    {
                        processEngine.AddProcessListener(RecordId, ObjectSchemaId, UId, null, null,
                                                         EntityChangeType.Inserted);
                    }
                }
                else
                {
                    processEngine.AddProcessListener(activity, UId, serializedFilters);
                }
            }
            InteractWithUser(context, isRunning, ShowExecutionPage);
            return(false);
        }
        /// <inheritdoc />
        public override bool CompleteExecuting(params object[] parameters)
        {
            bool isActivityEntitySchema = GetIsActivityEntitySchema();
            Guid activityStatusId       = isActivityEntitySchema
                                ? Guid.Empty
                                : ProcessUserTaskUtilities.GetActivityStatus(UserConnection, CurrentActivityId);
            IProcessEngine processEngine = UserConnection.ProcessEngine;

            if (GetIsMatchedConditions())
            {
                if (!isActivityEntitySchema && activityStatusId != ActivityConsts.CanceledStatusUId)
                {
                    activityStatusId = ActivityConsts.CompletedStatusUId;
                }
                processEngine.RemoveActivityProcessListener(CurrentActivityId, UId, activityStatusId);
                if (!GetIsActivityEntitySchema())
                {
                    var editMode = (RecordEditMode)Enum.ToObject(typeof(RecordEditMode), EditMode);
                    EntityChangeType entityChangeType = editMode == RecordEditMode.New
                                                ? EntityChangeType.Inserted
                                                : EntityChangeType.Updated;
                    processEngine.RemoveProcessListener(RecordId, ObjectSchemaId, UId, entityChangeType);
                }
                if (GenerateDecisionsFromColumn)
                {
                    ResultParameter = GetResultParameter();
                }
                return(base.CompleteExecuting(parameters));
            }
            if ((RecordEditMode)Enum.ToObject(typeof(RecordEditMode), EditMode) == RecordEditMode.New)
            {
                string serializedFilters = IsMatchConditions && DataSourceFilters.IsNotNullOrEmpty()
                                        ? ConvertToProcessDataSourceFilters(ObjectSchemaId, DataSourceFilters)
                                        : null;
                processEngine.AddProcessListener(RecordId, ObjectSchemaId, UId, serializedFilters);
                EditMode = (int)RecordEditMode.Existing;
            }
            if (activityStatusId == ActivityConsts.NewStatusUId)
            {
                ProcessUserTaskUtilities.SetActivityStatus(UserConnection, CurrentActivityId,
                                                           ActivityConsts.InProgressUId);
            }
            return(false);
        }
        public virtual EntityCollection GetFilterResultEntityCollection(out Dictionary <string, string> entityColumnMap)
        {
            entityColumnMap = null;
            if (FilterEntitySchemaId.Equals(Guid.Empty))
            {
                return(null);
            }
            var entitySchema = GetEntitySchema(FilterEntitySchemaId);

            if (entitySchema == null)
            {
                return(null);
            }
            var entitySchemaQuery = new EntitySchemaQuery(entitySchema);

            entitySchemaQuery.UseAdminRights = false;
            if (RecordDefValues.FetchMetaPathes == null || RecordDefValues.FetchMetaPathes.Count == 0)
            {
                entitySchemaQuery.PrimaryQueryColumn.IsAlwaysSelect = true;
            }
            else
            {
                entityColumnMap = new Dictionary <string, string>();
                foreach (var columnValue in RecordDefValues.FetchMetaPathes)
                {
                    string columnPath  = entitySchema.GetSchemaColumnPathByMetaPath(columnValue.Value);
                    var    queryColumn = entitySchemaQuery.AddColumn(columnPath);
                    entityColumnMap[columnValue.Value] = queryColumn.Name;
                }
            }
            if (!FilterEntitySchemaId.Equals(Guid.Empty) && DataSourceFilters.IsNotNullOrEmpty())
            {
                ProcessUserTaskUtilities.SpecifyESQFilters(UserConnection, this, entitySchema, entitySchemaQuery,
                                                           DataSourceFilters);
            }
            return(entitySchemaQuery.GetEntityCollection(UserConnection));
        }