Exemplo n.º 1
0
        /// <summary>
        /// Gets the calculated field dependencies.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="expression">The expression.</param>
        /// <returns>ICollection{ExpressionDependency}.</returns>
        /// <exception cref="Cebos.Veyron.Library.Process.Publisher.Definitions.ExpressionDependencies.InvalidExpressionException">Calculated field expression is invalid.</exception>
        public ICollection<ExpressionDependency> GetCalculatedFieldDependencies(IProcessEdit process, string expression)
        {
            var dependencies = new List<ExpressionDependency>();

            if (string.IsNullOrEmpty(expression))
                return dependencies;

            try
            {
                var container = ExpressionsSerializer.Deserialize(expression);
                ExpressionNodeFactory.RestoreConnections(container.Expressions);

                var sourceFieldList = container.Expressions.OfType<SourceFieldList>().FirstOrDefault();

                if (sourceFieldList == null)
                    return dependencies;

                foreach (var field in sourceFieldList.Fields)
                    AddDependencies(dependencies, process, field);

                return dependencies;
            }
            catch (Exception ex)
            {
                throw new InvalidExpressionException("Calculated field expression is invalid.", ex);
            }
        }
        /// <summary>
        /// Opens an expression designer window and initializes the designer with the specified expression.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="process">The source process.</param>
        /// <param name="resultType">The result type.</param>
        /// <param name="expression">The expression.</param>
        /// <param name="saveAction">The save action.</param>
        /// <param name="cancelAction">The cancel action.</param>
        /// <param name="removeAction">The remove action.</param>
        protected void EditExpression(
            ITopLevelWindow parentWindow,
            IProcessEdit process,
            Type resultType,
            string expression,
            Action saveAction,
            Action cancelAction,
            Action removeAction)
        {
            SaveAction = saveAction;
            CancelAction = cancelAction;
            RemoveAction = removeAction;

            ExpressionDesigner.Value.LoadFromExpressionObjects(new List<IExpressionObjectBase>());

            WindowManager.Value.ShowStatus(new Status { IsBusy = true });

            var expressions = new List<IExpressionObjectBase>();
            var newExpressions = new List<IExpressionObjectBase>();

            var syncContext = new NotifyClientAction(
                () =>
                    {
                        ExpressionDesigner.Value.LoadFromExpressionObjects(expressions);
                        WindowManager.Value.ShowStatus(new Status());
                    });

            syncContext.OperationStarted();

            newExpressions.Add(CreateSourceItem(process));
            newExpressions.Add(CreateUserInformationItem(CurrentUserInformationItemName, 10, 400));
            newExpressions.Add(CreateDestinationItem(resultType));

            if (!string.IsNullOrWhiteSpace(expression))
            {
                try
                {
                    var expressionsContainer = Serializer.Deserialize(expression);
                    expressions.AddRange(expressionsContainer.Expressions);
                }
                catch
                {
                    // Do nothing, new expressions will be used.
                }
            }

            UpdateStateList(process);

            UpdateStoredExpressions(expressions, newExpressions, syncContext);

            syncContext.OperationCompleted();
            WindowManager.Value.ShowChildWindow(parentWindow, this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Bases the sections.
        /// </summary>
        /// <param name="baseProcess">The base process.</param>
        /// <param name="sections">The sections.</param>
        private void BaseSections(IProcessEdit baseProcess, List<SectionEdit> sections)
        {
            if (baseProcess == null)
                return;

            foreach (var processSection in baseProcess.SectionList)
            {
                if (sections.Count(s => (s.Guid == processSection.Guid)) == 0)
                    sections.Add(processSection);
            }
            
            BaseSections(baseProcess.BaseProcess, sections);

        }
        /// <summary>
        /// Opens the data trigger field mapping designer window.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="sourceProcess">The process.</param>
        /// <param name="trigger">The trigger.</param>
        /// <param name="saveAction">The save action.</param>
        /// <param name="cancelAction">The cancel action.</param>
        /// <param name="removeAction">The remove action.</param>
        public async void EditExpression(
            ITopLevelWindow parentWindow,
            IProcessEdit sourceProcess,
            ProcessDataTriggerEdit trigger,
            Action saveAction,
            Action cancelAction,
            Action removeAction)
        {
            SaveAction = saveAction;
            CancelAction = cancelAction;
            RemoveAction = removeAction;

            KeyFieldsEnabled = false;
            ProcessEdit = sourceProcess;

            ExpressionDesigner.LoadFromExpressionObjects(new List<IExpressionObjectBase>());

            if (string.IsNullOrEmpty(trigger.ProcessToModifySystemName))
            {
                PopupFactory.NotifyFailure("Process to modify not found. Please select a process and try again.");
                CancelCommand.Execute(null);
                return;
            }

            ProcessInfo destinationProcess;
            try
            {
                WindowManager.Value.ShowStatus(new Status { IsBusy = true });
                try
                {
                    destinationProcess = await ProcessInfo.GetProcessAsync(trigger.ProcessToModifySystemName);
                }
                finally
                {
                    WindowManager.Value.ShowStatus(new Status());
                }
            }
            catch (Exception ex)
            {
                PopupFactory.NotifyFailure(ex);
                CancelCommand.Execute(null);
                return;
            }

            LoadExpressionItems(sourceProcess, destinationProcess, trigger);

            _itemHashes = ExpressionDesigner.Diagram.Items.Select(x => x.GetHashCode()).ToList();
            WindowManager.Value.ShowChildWindow(parentWindow, this);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds the rule to scheduler.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="rule">The rule.</param>
        public void AddRuleToScheduler(IProcessEdit process, ProcessActionRuleEdit rule)
        {
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                const string sql = @"DELETE FROM [dbo].[ScheduledActions] WHERE [RuleGuid] = @ruleGuid;";

                using (var command = new SqlCommand(sql, cn))
                {
                    command.Parameters.AddWithValue("@ruleGuid", rule.Guid);

                    command.ExecuteNonQuery();
                }
                
            }

            if (string.IsNullOrEmpty(rule.Expression) || !CheckRule(rule.Expression, process))
                return;


            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                const string sql = @"
INSERT INTO [dbo].[ScheduledActions]
(
     [ProcessSystemName]
    ,[RuleGuid]
)
VALUES
(
     @processSystemName
    ,@ruleGuid
);";

                using (var command = new SqlCommand(sql, cn))
                {
                    command.Parameters.AddWithValue("@processSystemName", process.SystemName);
                    command.Parameters.AddWithValue("@ruleGuid", rule.Guid);

                    command.ExecuteNonQuery();
                }
            }
        }
        /// <summary>
        /// Creates the source item.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <returns> The List of Source Field. </returns>
        private SourceFieldList CreateSourceItem(IProcessEdit process)
        {
            var result = new SourceFieldList { ExpressionName = process.Name, UniqueName = SourceItemName, Top = 10, Left = 10 };

            AddIdFields(process, result, SourceItemObjectName, SourceFieldSetNames.Item);
            AddProcessIdFields(process, result, SourceItemObjectName, SourceFieldSetNames.Item);
            AddStateFields(process, result, SourceItemObjectName, SourceFieldSetNames.Item);
            AddVersionFields(process, result, SourceItemObjectName, SourceFieldSetNames.Item);
            AddLastModifiedOnField(process, result, SourceItemObjectName, SourceFieldSetNames.Item);

            foreach (var field in process.GetAllFields().Where(CanBeSourceField))
            {
                var sourceField = CreateSourceField(field, result);
                sourceField.ObjectName = SourceItemObjectName;
                result.Fields.Add(sourceField);
            }

            return result;
        }
        private SourceFieldList CreateSourceItem(IProcessEdit process, string uniqueName, string name, string objectName)
        {
            var source = new SourceFieldList { ExpressionName = name, UniqueName = uniqueName };

            AddIdFields(process, source, objectName);
            AddStateFields(process, source, objectName);
            AddVersionFields(process, source, objectName);
            AddLastModifiedOnField(source, objectName);

            foreach (var field in process.GetAllFields().Where(CanBeSourceField))
            {
                var sourceField = CreateSourceField(field, source);
                sourceField.ObjectName = objectName;
                source.Fields.Add(sourceField);
            }

            return source;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates the process definition.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <returns>ProcessDefinition.</returns>
        private ProcessDefinition CreateProcessDefinition(IProcessEdit process)
        {
            var processDefinition = new ProcessDefinition { SystemName = process.SystemName };

            if (process.BaseProcess != null)
                processDefinition.BaseProcess = CreateProcessDefinition(process.BaseProcess);

            return processDefinition;            
        }
        /// <summary>
        /// Adds the state fields.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="source">The source.</param>
        private static void AddStateFields(IProcessEdit process, SourceFieldList source)
        {
            const string CurrentStateName = "Current State";
            const string CurrentStateSystemName = "CurrentStateName";

            if (!process.IsStateEnabled)
                return;

            var dataType = SourceNodeFactory.GetDataType(typeof (string));

            var sf = new SourceField(source)
                         {
                             DataType = dataType,
                             Name = CurrentStateName,
                             ConnectorOut = {DataType = dataType, Name = CurrentStateName},
                             SetName = SourceFieldSetNames.Item,
                             InnerName = CurrentStateSystemName,
                             SystemName = CurrentStateSystemName
                         };

            source.Fields.Add(sf);
        }
        /// <summary>
        /// Creates the source item.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="expressionName">Name of the expression.</param>
        /// <param name="uniqueName">Name of the unique.</param>
        /// <param name="objectName">Name of the object.</param>
        /// <param name="left">The left position.</param>
        /// <param name="top">The top position.</param>
        /// <returns>List of Source Fields.</returns>  
        private static SourceFieldList CreateSourceItem(
            IProcessEdit process,
            string expressionName,
            string uniqueName,
            string objectName,
            int left,
            int top)
        {
            var result = new SourceFieldList
                {
                    ExpressionName = expressionName,
                    Top = top,
                    Left = left,
                    UniqueName = uniqueName
                };

            AddIdFields(process, result, objectName);
            AddStateFields(process, result, objectName);
            AddVersionFields(process, result, objectName);
            AddLastModifiedOnField(result, objectName);

            foreach (var field in process.GetAllFields())
            {
                var sourceField = CreateSourceField(new ProcessFieldEditWrapper(field), result);
                sourceField.ObjectName = objectName;
                result.Fields.Add(sourceField);
            }

            return result;
        }
Exemplo n.º 11
0
            public ProcessEditFilterSource(IProcessEdit process)
            {
                _process = process;

                AddProcessEventHandlers();
            }
Exemplo n.º 12
0
        internal static void FillSectionIdProperties(IProcessEdit procAfterSave)
        {
            foreach (var sectionEdit in procAfterSave.SectionList.Where(x => !x.IsBase))
            {
                var sectionId = sectionEdit.Id;

                foreach (var fieldEdit in sectionEdit.FieldList)
                {
                    fieldEdit.SectionId = sectionId;
                }
            }
        }
Exemplo n.º 13
0
        internal static void FillViewDocuments(IProcessEdit process)
        {
            foreach (var viewEdit in process.ViewList.Where(x => x.ViewType == ProcessViewType.APQP))
            {
                var leftSection = viewEdit.SectionList.FirstOrDefault(x => x.Name == "Left");
                if (leftSection == null)
                    continue;

                var documentStep = leftSection.StepList.OfType<DocumentListStepEdit>().FirstOrDefault();
                if (documentStep == null)
                    continue;

                var documentList = documentStep.DocumentsList;
                if (documentList == null)
                    continue;

                foreach (var sectionEdit in viewEdit.SectionList)
                {
                    var docListStep = sectionEdit.StepList.OfType<FieldListDocumentStepEdit>().FirstOrDefault();
                    if (docListStep == null)
                        continue;

                    foreach (var document in docListStep.DocumentFieldsList)
                    {
                        var firstOrDefault = documentList.FirstOrDefault(x => x.Name == document.DocumentNameForExport);
                        if (firstOrDefault != null)
                        {
                            document.DocumentGuid = firstOrDefault.Guid;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Creates the destination item.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <returns> The DestinationFieldList. </returns>
        private DestinationFieldList CreateDestinationItem(IProcessEdit process)
        {
            var result = new DestinationFieldList { ExpressionName = process.Name, UniqueName = DestinationItemName, Top = 10, Left = 600 };

            AddIdField(result);
            AddStateFields(process, result);
            AddVersionFields(process, result);
            AddLastModifiedOnField(process, result);

            foreach (var field in process.GetAllFields().Where(CanBeDestinationField))
                result.Fields.Add(CreateDestinationField(field, result));

            return result;
        }
        /// <summary>
        /// Initializes the expression designer and opens the expression designer window.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="process">The parent process.</param>
        /// <param name="method">The service method.</param>
        /// <param name="serviceTypes">The collection of known service types.</param>
        /// <param name="saveAction">The save action.</param>
        /// <param name="cancelAction">The cancel action.</param>
        /// <param name="removeAction">The remove action.</param>
        public void EditExpression(
            ITopLevelWindow parentWindow,
            IProcessEdit process,
            ServiceMethodEdit method,
            IEnumerable<ServiceExposedTypeEdit> serviceTypes,
            Action saveAction,
            Action cancelAction,
            Action removeAction)
        {
            SaveAction = saveAction;
            CancelAction = cancelAction;
            RemoveAction = removeAction;
            _knownTypes = serviceTypes.ToArray();

            ExpressionDesigner.Value.LoadFromExpressionObjects(new List<IExpressionObjectBase>());

            WindowManager.Value.ShowStatus(new Status { IsBusy = true });

            var expressions = new List<IExpressionObjectBase>();
            var newExpressions = new List<IExpressionObjectBase>();

            var syncContext = new NotifyClientAction(
                () =>
                {
                    ExpressionDesigner.Value.LoadFromExpressionObjects(expressions);
                    WindowManager.Value.ShowStatus(new Status());
                });

            syncContext.OperationStarted();

            newExpressions.Add(CreateSourceItem(method.InputParameters));
            newExpressions.Add(CreateDestinationItem(process));

            if (!string.IsNullOrWhiteSpace(method.EndpointMapping))
            {
                try
                {
                    var expressionsContainer = Serializer.Deserialize(method.EndpointMapping);
                    expressions.AddRange(expressionsContainer.Expressions);
                }
                catch
                {
                    // Do nothing, new expressions will be used.
                }
            }

            UpdateStateList(process);

            UpdateStoredExpressions(expressions, newExpressions, syncContext);

            syncContext.OperationCompleted();
            WindowManager.Value.ShowChildWindow(parentWindow, this);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the list of process fields that are compatible with the specified UDP type.
        /// </summary>
        /// <param name="process">
        /// The process.
        /// </param>
        /// <param name="memberType">
        /// The UDP type.
        /// </param>
        /// <returns>
        /// The list of process fields.
        /// </returns>
        public static IList<ProcessField> GetProcessFields(IProcessEdit process, Type memberType)
        {
            if (process == null)
                throw new ArgumentNullException("process");

            var fields = new List<ProcessField>();

            if (memberType == typeof(int) || memberType == typeof(int?) || memberType == typeof(IInfoClass))
            {
                fields.Add(new ProcessField("Id", Constants.IdColumnName));

                if (process.ProcessOptionChoose == ProcessOption.VersionEnabled)
                    fields.Add(new ProcessField("Version Master Id", Constants.VersionMasterId));
            }

            if (memberType == typeof(string))
            {
                if (process.ProcessOptionChoose == ProcessOption.VersionEnabled)
                {
                    fields.Add(new ProcessField(Constants.VersionNumberName, Constants.VersionNumber));
                }
            }

            if (memberType == typeof(DateTime))
            {
                if (process.ProcessOptionChoose == ProcessOption.VersionEnabled)
                {
                    fields.Add(new ProcessField("Version Date", Constants.VersionDate));
                }
            }

            fields.AddRange(
                from field in process.GetAllFields()
                where !Constants.CurrentStateColumnName.Equals(field.SystemName)
                where TypesCompatible(field.FieldType.ColumnType, memberType)
                select new ProcessField(field.Name, field.SystemName));

            return fields;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Gets the process definition.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <returns>The ReferenceProcessDefinition.</returns>
        public ReferenceProcessDefinition GetProcessDefinition(IProcessEdit process)
        {
            var processDefinition = new ReferenceProcessDefinition { Name = process.Name, SystemName = process.SystemName };

            if (process.BaseProcess != null)
                processDefinition.BaseProcess = GetProcessDefinition(process.BaseProcess);

            return processDefinition;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Checks the rule.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="process">The process.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool CheckRule(string expression, IProcessEdit process)
        {
            if (expression.Contains("DateTime.Now"))
                return true;

            var fields = ExpressionServiceBase.GetExpressionSourceFields(expression, true);

            foreach(var field in fields)
            {
                //TODO ELMTSUP-552 - if we get all ExpressionSourceFields (not root only) and CR process has a field with the same SystemName,
                // FirstOrDefault() may return the same field which will lead to circular recursion.
                //Not sure if we need to check CR fields here, if we do, we'd have to rely on field.Guid, not SystemName
                var expr = process.GetAllFields().Where(x => x.SystemName == field).Select(x =>
                                                                                               {
                                                                                                   var expressionsStepEdit =
                                                                                                       (ExpressionsStepEdit)x.StepList.FirstOrDefault(y => y.GetType() == typeof (ExpressionsStepEdit));

                                                                                                   return expressionsStepEdit != null ? expressionsStepEdit.CalculatedExpression : null;
                                                                                               }).FirstOrDefault();

                //This will also stop circular recursion
                //if (!string.IsNullOrEmpty(expr) && !expression.Equals(expr))

                if (!string.IsNullOrEmpty(expr))
                    return CheckRule(expr, process);
            }

            return false;
        }
Exemplo n.º 19
0
        internal static void FillViewDocuments(IProcessEdit procAfterSave, IProcessEdit procEdit)
        {
            foreach (var viewEdit in procAfterSave.ViewList.Where(x => x.ViewType == ProcessViewType.APQP))
            {
                DocumentList documentList = null;

                var processViewSectionEdit = viewEdit.SectionList.FirstOrDefault(x => x.Name == "Left");
                if (processViewSectionEdit != null)
                {
                    var documentStep = processViewSectionEdit.StepList.FirstOrDefault(x => x.GetType() == typeof(DocumentListStepEdit)) as DocumentListStepEdit;

                    if (documentStep != null)
                    {
                        documentList = documentStep.DocumentsList;
                    }
                }

                if (documentList == null)
                {
                    continue;
                }

                foreach (var sectionEdit in procEdit.ViewList.FirstOrDefault(x => x.Name == viewEdit.Name).SectionList.Where(x => x.StepList.Any(y => y.GetType() == typeof(FieldListDocumentStepEdit))))
                {
                    var newSectionEdit = viewEdit.SectionList.FirstOrDefault(x => x.Name == sectionEdit.Name);

                    var docListStep = sectionEdit.StepList.FirstOrDefault(x => x.GetType() == typeof(FieldListDocumentStepEdit)) as FieldListDocumentStepEdit;

                    if (docListStep == null || newSectionEdit == null)
                    {
                        continue;
                    }

                    var newDocListStep = newSectionEdit.StepList.FirstOrDefault(x => x.GetType() == typeof(FieldListDocumentStepEdit)) as FieldListDocumentStepEdit;
                    if (newDocListStep == null)
                    {
                        continue;
                    }

                    newDocListStep.DocumentFieldsList.Clear();

                    foreach (var document in docListStep.DocumentFieldsList)
                    {
                        var firstOrDefault = documentList.FirstOrDefault(x => x.Name == document.DocumentNameForExport);
                        if (firstOrDefault != null)
                        {
                            document.DocumentGuid = firstOrDefault.Guid;
                        }

                        newDocListStep.DocumentFieldsList.Add(document);
                    }
                }
            }
        }
 /// <summary>
 /// Opens an expression designer window and initializes the designer with the specified expression.
 /// </summary>
 /// <param name="parentWindow">The parent window.</param>
 /// <param name="process">The source process.</param>
 /// <param name="expression">The expression.</param>
 /// <param name="saveAction">The save action.</param>
 /// <param name="cancelAction">The cancel action.</param>
 /// <param name="removeAction">The remove action.</param>
 public void EditExpression(ITopLevelWindow parentWindow, IProcessEdit process, string expression, Action saveAction, Action cancelAction, Action removeAction)
 {
     EditExpression(parentWindow, process, typeof(string), expression, saveAction, cancelAction, removeAction);
 }
Exemplo n.º 21
0
        internal static void CorrectReportFileNameProperties(IProcessEdit procAfterSave)
        {
            foreach (var sectionEdit in procAfterSave.SectionList.Where(x => x.FieldList.Any(y => y.FieldType.Name == "File")))
            {
                foreach (var fieldEdit in sectionEdit.FieldList.Where(x => x.FieldType.Name == "File"))
                {
                    var step = fieldEdit.StepList.FirstOrDefault(x => x.StepId == 40) as FileFieldStepEdit;

                    if (step == null)
                    {
                        continue;
                    }

                    var processReportEdit = procAfterSave.ReportList.FirstOrDefault(x => x.FileName.Substring(0, x.FileName.Length - 12) + ".trdx" == step.ReportName);
                    if (processReportEdit != null)
                    {
                        step.ReportName = processReportEdit.FileName;
                    }

                    var processWatermarkPortraitReportEdit = procAfterSave.ReportList.FirstOrDefault(x => x.FileName.Substring(0, x.FileName.Length - 12) + ".trdx" == step.WatermarkPortraitReportName);
                    if (processWatermarkPortraitReportEdit != null)
                    {
                        step.WatermarkPortraitReportName = processWatermarkPortraitReportEdit.FileName;
                    }

                    var processWatermarkLandscapeReportEdit = procAfterSave.ReportList.FirstOrDefault(x => x.FileName.Substring(0, x.FileName.Length - 12) + ".trdx" == step.WatermarkLandscapeReportName);
                    if (processWatermarkLandscapeReportEdit != null)
                    {
                        step.WatermarkLandscapeReportName = processWatermarkLandscapeReportEdit.FileName;
                    }

                    var processCoverPagePortraitReportEdit = procAfterSave.ReportList.FirstOrDefault(x => x.FileName.Substring(0, x.FileName.Length - 12) + ".trdx" == step.CoverPagePortraitReportName);
                    if (processCoverPagePortraitReportEdit != null)
                    {
                        step.CoverPagePortraitReportName = processCoverPagePortraitReportEdit.FileName;
                    }

                    var processCoverPageLandscapeReportEdit = procAfterSave.ReportList.FirstOrDefault(x => x.FileName.Substring(0, x.FileName.Length - 12) + ".trdx" == step.CoverPageLandscapeReportName);
                    if (processCoverPageLandscapeReportEdit != null)
                    {
                        step.CoverPageLandscapeReportName = processCoverPageLandscapeReportEdit.FileName;
                    }

                    var processAppendixLandscapeReportEdit = procAfterSave.ReportList.FirstOrDefault(x => x.FileName.Substring(0, x.FileName.Length - 12) + ".trdx" == step.AppendixLandscapeReportName);
                    if (processAppendixLandscapeReportEdit != null)
                    {
                        step.AppendixLandscapeReportName = processAppendixLandscapeReportEdit.FileName;
                    }

                    var processAppendixPortraitReportEdit = procAfterSave.ReportList.FirstOrDefault(x => x.FileName.Substring(0, x.FileName.Length - 12) + ".trdx" == step.AppendixPortraitReportName);
                    if (processAppendixPortraitReportEdit != null)
                    {
                        step.AppendixPortraitReportName = processAppendixPortraitReportEdit.FileName;
                    }
                }
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilterValueEditorProcessStatesRetriever"/> class.
 /// </summary>
 /// <param name="process">The process.</param>
 public FilterValueEditorProcessStatesRetriever(IProcessEdit process)
 {
     Process = process;
 }
        /// <summary>
        /// Initiates expression editing.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="process">The process containing rule.</param>
        /// <param name="rule">The rule containing expression.</param>
        /// <param name="saveAction">The save action.</param>
        /// <param name="cancelAction">The cancel action.</param>
        /// <param name="removeAction">The remove action.</param>
        public async void EditExpression(
            ITopLevelWindow parentWindow,
            IProcessEdit process,
            ProcessActionRuleEdit rule,
            Action saveAction,
            Action cancelAction,
            Action removeAction)
        {
            WindowManager.Value.ShowStatus(new Status { IsBusy = true });

            SaveAction = saveAction;
            CancelAction = cancelAction;
            RemoveAction = removeAction;

            ProcessEdit = process;

            ExpressionDesigner.LoadFromExpressionObjects(new List<IExpressionObjectBase>());

            var expressions = new List<IExpressionObjectBase>();
            var newExpressions = new List<IExpressionObjectBase>();

            var syncContext = new NotifyClientAction(
                () =>
                {
                    ExpressionDesigner.LoadFromExpressionObjects(expressions);
                    WindowManager.Value.ShowStatus(new Status());

                    _itemHashes = ExpressionDesigner.Diagram.Items.Select(x => x.GetHashCode()).ToList();
                });

            syncContext.OperationStarted();

            var oldSourceName = string.Format("Old {0}", process.SystemName);
            var sourceName = process.SystemName;

            newExpressions.Add(CreateSourceItem(process, oldSourceName, OldSourceItemName, OldItemObjectName, 10, 10));
            newExpressions.Add(CreateSourceItem(process, sourceName, NewSourceItemName, NewItemObjectName, 10, 300));
            newExpressions.Add(CreateUserInfoSourceItem());
            newExpressions.Add(CreateDestinationItem());

            SourceFieldList systemParameters;

            try
            {
                systemParameters = await CreateSystemParametersItemAsync(SystemParametersItemName);
            }
            catch (Exception)
            {
                systemParameters = null;
            }

            if (systemParameters != null)
                newExpressions.Add(systemParameters);

            if (!string.IsNullOrWhiteSpace(rule.Expression))
            {
                try
                {
                    var expressionsContainer = Serializer.Deserialize(rule.Expression);
                    expressions.AddRange(expressionsContainer.Expressions);
                }
                catch
                {
                    // Do nothing, new expressions will be used.
                }
            }
            
            UpdateStateList(process);

            UpdateStoredExpressions(expressions, newExpressions, syncContext);
            syncContext.OperationCompleted();

            WindowManager.Value.ShowChildWindow(parentWindow, this);
        }
        /// <summary>
        /// Opens the data trigger field mapping designer window.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="process">The process.</param>
        /// <param name="trigger">The trigger.</param>
        /// <param name="fieldMapping">The field mapping.</param>
        /// <param name="saveAction">The save action.</param>
        /// <param name="cancelAction">The cancel action.</param>
        /// <param name="removeAction">The remove action.</param>
        public void EditExpression(
            ITopLevelWindow parentWindow,
            IProcessEdit process,
            ProcessDataTriggerEdit trigger,
            DataTriggerFieldMappingEdit fieldMapping,
            Action saveAction,
            Action cancelAction,
            Action removeAction)
        {
            SaveAction = saveAction;
            CancelAction = cancelAction;
            RemoveAction = removeAction;

            ProcessEdit = process;
            KeyFieldsEnabled = fieldMapping.ModificationType != DataTriggerModificationType.Link
                               && fieldMapping.ModificationType != DataTriggerModificationType.Unlink;

            ExpressionDesigner.LoadFromExpressionObjects(new List<IExpressionObjectBase>());

            var criteria = new DataTriggerListFieldsMappingCriteria
                               {
                                   ModifiedProcessSystemName = trigger.ProcessToModifySystemName,
                                   DestinationFieldSystemName = fieldMapping.DestinationFieldSystemName
                               };

            var processFields = process.GetAllFields().ToArray();

            if (fieldMapping.ModificationType == DataTriggerModificationType.Link || fieldMapping.ModificationType == DataTriggerModificationType.Unlink)
            {
                if (string.IsNullOrEmpty(fieldMapping.SourceDataProcessName))
                {
                    PopupFactory.NotifyFailure("Source field is invalid. Please select a valid source field and try again.");
                    CancelCommand.Execute(null);
                    return;
                }

                criteria.SourceDataProcessName = fieldMapping.SourceDataProcessName;
            }
            else
            {
                foreach (var dataSource in fieldMapping.DataSources)
                {
                    var sourceField = processFields.FirstOrDefault(f => f.SystemName == dataSource.SourceFieldSystemName);

                    if (sourceField == null)
                    {
                        PopupFactory.NotifyFailure("Source field not found. Please select a valid source field and try again.");
                        CancelCommand.Execute(null);
                        return;
                    }

                    var requiredStep = (CrossRefRequiredStepEdit)sourceField.StepList.FirstOrDefault(s => s is CrossRefRequiredStepEdit);

                    if (requiredStep == null || !requiredStep.CrossRefProcessId.HasValue)
                    {
                        PopupFactory.NotifyFailure("Source field is invalid. Please select a valid source field and try again.");
                        CancelCommand.Execute(null);
                        return;
                    }

                    criteria.DataSourcesCriteria.Add(
                        new DataTriggerFieldMappingDataSourceCriteria
                        {
                            SourceName = dataSource.Name,
                            PublishedProcessId = requiredStep.CrossRefProcessId.Value,
                            SourceFieldName = sourceField.Name,
                            PropertyPath = dataSource.GetPropertyPath()
                        });
                }
            }

            WindowManager.Value.ShowStatus(new Status { IsBusy = true });

            DataTriggerMappingDataRetriever.GetDataTriggerMappingDataRetriever(
                criteria,
                result =>
                    {
                        WindowManager.Value.ShowStatus(new Status());
                        if (result.Error != null)
                        {
                            PopupFactory.NotifyFailure(result.Error);
                            CancelCommand.Execute(null);
                            return;
                        }

                        LoadExpressionItems(
                            process,
                            result.Object.DataSources,
                            result.Object.SourceDataProcess,
                            result.Object.DestinationListField,
                            result.Object.DestinationProcess,
                            fieldMapping);

                        _itemHashes = ExpressionDesigner.Diagram.Items.Select(x => x.GetHashCode()).ToList();

                        WindowManager.Value.ShowChildWindow(parentWindow, this);
                    });
        }
        private void UpdateStateList(IProcessEdit process)
        {
            ExpressionDesigner.Diagram.StateList.Clear();

            if (process.IsStateEnabled)
            {
                ExpressionDesigner.Diagram.StateList.AddRange(
                    process.StateList.OrderBy(s => s.Name, StringComparer.CurrentCulture).Select(s => StateInfo.NewState(s.Guid, s.Name)));
            }
        }
        /// <summary>
        /// Loads the expression items.
        /// </summary>
        /// <param name="sourceProcess">The source process.</param>
        /// <param name="destinationProcess">The destination process.</param>
        /// <param name="trigger">The trigger.</param>
        private async void LoadExpressionItems(
            IProcessEdit sourceProcess,
            ProcessInfo destinationProcess,
            ProcessDataTriggerEdit trigger)
        {
            WindowManager.Value.ShowStatus(new Status { IsBusy = true });

            var expressions = new List<IExpressionObjectBase>();
            var newExpressions = new List<IExpressionObjectBase>();

            var syncContext = new NotifyClientAction(
                () =>
                    {
                        ExpressionDesigner.LoadFromExpressionObjects(expressions);
                        IsSaveable = IsTestable();
                        WindowManager.Value.ShowStatus(new Status());
                    });

            syncContext.OperationStarted();

            newExpressions.Add(
                CreateSourceItem(
                    sourceProcess,
                    DataTriggerMappingExpressionNames.SourceItem,
                    string.Format("{0} (source)", sourceProcess.Name),
                    SourceItemObjectName));

            if (trigger.ModificationType != DataTriggerModificationType.Self)
                newExpressions.Add(
                    CreateSourceItem(
                        destinationProcess,
                        DataTriggerMappingExpressionNames.SourceToModifyItem,
                        string.Format("{0} (old)", destinationProcess.Name),
                        ModifiedItemObjectName));

            newExpressions.Add(CreateUserInfoSourceItem(DataTriggerMappingExpressionNames.UserInfo));

            try
            {
                var systemParameters = await CreateSystemParametersItemAsync(DataTriggerMappingExpressionNames.SystemParameters);
                if (systemParameters != null)
                {
                    newExpressions.Add(systemParameters);
                }
            }
            catch (DataPortalException)
            {
            }

            newExpressions.Add(CreateDestinationItem(destinationProcess, DataTriggerMappingExpressionNames.DestinationItem, destinationProcess.Name));

            UpdatePositions(newExpressions);

            if (!string.IsNullOrWhiteSpace(trigger.ModificationMapping))
            {
                try
                {
                    var expressionsContainer = Serializer.Deserialize(trigger.ModificationMapping);
                    expressions.AddRange(expressionsContainer.Expressions);
                }
                catch
                {
                    // Do nothing, new expressions will be used.
                }
            }

            UpdateStateList(sourceProcess);

            UpdateStoredExpressions(expressions, newExpressions, syncContext);
            syncContext.OperationCompleted();
        }
        /// <summary>
        /// Adds the identifier fields.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="source">The source.</param>
        private static void AddIdFields(IProcessEdit process, SourceFieldList source)
        {
            const string IdName = "Id";
            const string BaseIdName = "Base Id";

            var dataType = SourceNodeFactory.GetDataType(typeof(int));
            var sf = new SourceField(source)
            {
                DataType = dataType,
                Name = IdName,
                ConnectorOut = { DataType = dataType, Name = IdName },
                SetName = SourceFieldSetNames.Item,
                InnerName = Constants.IdColumnName,
                SystemName = Constants.IdColumnName,
                ObjectName = "context"
            };
            source.Fields.Add(sf);

            if (process.BaseProcess != null)
            {
                sf = new SourceField(source)
                {
                    DataType = dataType,
                    Name = BaseIdName,
                    ConnectorOut = {DataType = dataType, Name = BaseIdName},
                    SetName = SourceFieldSetNames.Item,
                    InnerName = Constants.BaseIdColumnName,
                    SystemName = Constants.BaseIdColumnName,
                };
                source.Fields.Add(sf);
            }
        }
        /// <summary>
        /// Loads the expression items.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="dataSources">The data sources.</param>
        /// <param name="sourceDataProcess">The source data process.</param>
        /// <param name="destinationListField">The destination list field.</param>
        /// <param name="destinationProcess">The destination process.</param>
        /// <param name="fieldMapping">The field mapping.</param>
        private async void LoadExpressionItems(
            IProcessEdit process,
            IEnumerable<DataTriggerMappingDataSourceRetriever> dataSources,
            ProcessInfo sourceDataProcess,
            FieldInfo destinationListField,
            ProcessInfo destinationProcess,
            DataTriggerFieldMappingEdit fieldMapping)
        {
            WindowManager.Value.ShowStatus(new Status { IsBusy = true });

            var expressions = new List<IExpressionObjectBase>();
            var newExpressions = new List<IExpressionObjectBase>();

            var syncContext = new NotifyClientAction(
                () =>
                    {
                        ExpressionDesigner.LoadFromExpressionObjects(expressions);
                        WindowManager.Value.ShowStatus(new Status());
                    });

            syncContext.OperationStarted();

            if (fieldMapping.ModificationType == DataTriggerModificationType.Link || fieldMapping.ModificationType == DataTriggerModificationType.Unlink)
            {
                var objectName = string.Format("sourceData.GetSourceItem(\"{0}\")", DataTriggerFieldMappingExpressionNames.SourceDataProcess);

                newExpressions.Add(CreateSourceItem(sourceDataProcess, DataTriggerFieldMappingExpressionNames.SourceDataProcess, sourceDataProcess.Name, objectName));
            }
            else
            {
                foreach (var dataSource in dataSources)
                {
                    var name = string.Format(CultureInfo.InvariantCulture, "{0} (source)", dataSource.SourceFieldName);
                    var objectName = string.Format("sourceData.GetSourceItem(\"{0}\")", dataSource.SourceName);
                    newExpressions.Add(CreateSourceItem(dataSource.SourceProcess, dataSource.SourceName, name, objectName));
                }

                newExpressions.Add(
                    CreateSourceItem(
                        destinationProcess,
                        DataTriggerFieldMappingExpressionNames.ModifiedItem,
                        string.Format("{0} (old)", destinationListField.Name),
                        ModifiedItemObjectName));
            }

            newExpressions.Add(CreateUserInfoSourceItem(DataTriggerFieldMappingExpressionNames.UserInfo));

            try
            {
                var systemParameters = await CreateSystemParametersItemAsync(DataTriggerFieldMappingExpressionNames.SystemParameters);
                if (systemParameters != null)
                {
                    newExpressions.Add(systemParameters);
                }
            }
            catch (DataPortalException)
            {
            }

            newExpressions.Add(CreateDestinationItem(destinationProcess, DataTriggerFieldMappingExpressionNames.DestinationItem, destinationListField.Name));

            UpdatePositions(newExpressions);

            if (!string.IsNullOrWhiteSpace(fieldMapping.Expression))
            {
                try
                {
                    var expressionsContainer = Serializer.Deserialize(fieldMapping.Expression);
                    expressions.AddRange(expressionsContainer.Expressions);
                }
                catch
                {
                    // Do nothing, new expressions will be used.
                }
            }

            UpdateStateList(process);

            UpdateStoredExpressions(expressions, newExpressions, syncContext);
            syncContext.OperationCompleted();
        }
        /// <summary>
        /// Adds the version fields.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="source">The source.</param>
        private static void AddVersionFields(IProcessEdit process, SourceFieldList source)
        {
            const string VersionDateName = "Version Date";

            if (process.ProcessOptionChoose != ProcessOption.VersionEnabled)
                return;

            var dataType = SourceNodeFactory.GetDataType(typeof (string));

            var sf = new SourceField(source)
                         {
                             DataType = dataType,
                             Name = Constants.VersionNumberName,
                             ConnectorOut = { DataType = dataType, Name = Constants.VersionNumberName },
                             SetName = SourceFieldSetNames.Item,
                             InnerName = Constants.VersionNumber,
                             SystemName = Constants.VersionNumber
                         };

            source.Fields.Add(sf);

            dataType = SourceNodeFactory.GetDataType(typeof (DateTime));

            sf = new SourceField(source)
                     {
                         DataType = dataType,
                         Name = VersionDateName,
                         ConnectorOut = {DataType = dataType, Name = VersionDateName},
                         SetName = SourceFieldSetNames.Item,
                         InnerName = Constants.VersionDate,
                         SystemName = Constants.VersionDate
                     };

            source.Fields.Add(sf);

            dataType = SourceNodeFactory.GetDataType(typeof(int));

            sf = new SourceField(source)
            {
                DataType = dataType,
                Name = Constants.VersionMasterId,
                ConnectorOut = { DataType = dataType, Name = Constants.VersionMasterId },
                SetName = SourceFieldSetNames.Item,
                InnerName = Constants.VersionMasterId,
                SystemName = Constants.VersionMasterId,
            };

            source.Fields.Add(sf);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Creates the dependencies.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="fullPath">The full path.</param>
        /// <returns>IEnumerable{ExpressionDependency}.</returns>
        /// <exception cref="System.ArgumentException">Invalid field path.;fullPath</exception>
        /// <exception cref="System.InvalidOperationException"></exception>
        private IEnumerable<ExpressionDependency> CreateDependencies(IProcessEdit process, string fullPath)
        {
            if (string.IsNullOrWhiteSpace(fullPath))
                throw new ArgumentException("Invalid field path.", "fullPath");

            var tokens = fullPath.Split(new[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
            var dependentProcess = CreateProcessDefinition(process);

            if (IsSystemField(tokens[0]))
            {
                if (tokens.Length > 1)
                {
                    var join = CreateJoinFromSystemField(dependentProcess, tokens[0]);

                    foreach (var dependency in CreateDependencies(join.ReferencedProcess, tokens[1]))
                    {
                        dependency.DependentProcess = dependentProcess;
                        dependency.JoinFields.Insert(0, join);

                        yield return dependency;
                    }

                    yield break;
                }

                foreach (var dependency in CreateDependenciesFromSystemField(dependentProcess, tokens[0]))
                {
                    dependency.DependentProcess = dependentProcess;

                    yield return dependency;
                }

                yield break;
            }

            var field = process.GetAllFields().FirstOrDefault(f => f.SystemName == tokens[0]);
            if (field == null)
                throw new InvalidOperationException(
                    string.Format(CultureInfo.InvariantCulture, "Could not find field \"{0}\" in process \"{1}\".", tokens[0], process.SystemName));

            if (field.ColumnType == ColumnTypes.DisplayList)
            {
                // Since we can't determine which items should recalculate expressions when a DL item changes
                // and recalculating expressions for all items is too slow, we'll skip DL dependencies.

                yield break;
            }

            if (tokens.Length > 1 && IsJoinField(field))
            {
                var join = CreateJoin(dependentProcess, field);

                foreach (var dependency in CreateDependencies(join.ReferencedProcess, tokens[1]))
                {
                    dependency.DependentProcess = dependentProcess;
                    dependency.JoinFields.Insert(0, join);

                    yield return dependency;
                }

                yield break;
            }
            
            foreach (var dependency in CreateDependencies(dependentProcess, field))
            {
                dependency.DependentProcess = dependentProcess;

                yield return dependency;
            }
        }