public void TestConnectorSerialization()
        {
            var obj = new DestinationFieldList
                          {
                              Id = Guid.NewGuid(),
                          };
            obj.Fields.Add(new DestinationField(null));
            obj.Fields.Add(new DestinationField(null) { Subfields = { new DestinationField(null) } });

            var tw = new StringWriter();
            using (var xw = XmlWriter.Create(tw))
            {
                xw.WriteStartElement("Node");
                obj.Serialize(xw);
                xw.WriteEndElement();
            }

            var sr = new StringReader(tw.ToString());
            using (var wr = XmlReader.Create(sr))
            {
                wr.ReadToFollowing("Node");
                var result = new DestinationFieldList();
                result.Deserialize(wr);

                Assert.AreEqual(obj.Id, result.Id);
                Assert.AreEqual(obj.Fields.Count, result.Fields.Count);
            }
        }
        /// <summary>
        /// Adds the version fields.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="destination">The destination.</param>
        private static void AddVersionFields(ProcessEdit process, DestinationFieldList destination)
        {
            if (process.ProcessOptionChoose != ProcessOption.VersionEnabled)
                return;

            var dataType = DestinationNodeFactory.GetDataType(typeof(string));
            var df = new DestinationField(destination)
            {
                Name = "Version",
                SystemName = Constants.Version,
                DataType = dataType,
                SetName = SourceFieldSetNames.Item,
                ConnectorIn = { DataType = dataType, Name = Constants.Version, IsNullable = false },
                SubfieldsRetriever = new VersionSubfieldsRetriever(process),
                IsKeyVisible = true,
                IsKeyEnabled = false
            };

            destination.Fields.Add(df);
        }
        public void TestDestinationFieldList_GetConnectors()
        {
            var obj = new DestinationFieldList();
            obj.Fields.Add(new DestinationField(null));
            obj.Fields.Add(new DestinationField(null) { Subfields = { new DestinationField(null) } });

            Assert.AreEqual(3, obj.GetConnectors().Count());
        }
        /// <summary>
        /// Adds the identifier fields.
        /// </summary>
        /// <param name="destination">The destination.</param>
        private static void AddIdFields(DestinationFieldList destination)
        {
            var dataType = DestinationNodeFactory.GetDataType(typeof(int));

            var df = new DestinationField(destination)
                         {
                             Name = "Id",
                             SystemName = Constants.IdColumnName,
                             DataType = dataType,
                             SetName = SourceFieldSetNames.Item,
                             ConnectorIn = { DataType = dataType, Name = "Id", IsNullable = false },
                             IsKeyEnabled = true,
                             IsKeyVisible = true
                         };

            destination.Fields.Add(df);
        }
        /// <summary>
        /// Adds the state fields.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="destination">The destination.</param>
        private static void AddStateFields(ProcessEdit process, DestinationFieldList destination)
        {
            if (!process.IsStateEnabled)
                return;

            var dataType = DestinationNodeFactory.GetDataType(typeof(string));
            var df = new DestinationField(destination)
            {
                Name = "Current State",
                SystemName = Constants.CurrentStateColumnName,
                DataType = dataType,
                SetName = SourceFieldSetNames.Item,
                ConnectorIn = { DataType = dataType, Name = "Current State", IsNullable = false },
                IsKeyVisible = true,
                IsKeyEnabled = false
            };

            destination.Fields.Add(df);
        }
        private DestinationFieldList CreateDestinationItem(Guid resultTypeGuid)
        {
            var result = new DestinationFieldList { ExpressionName = "Method Result", UniqueName = MethodResultItemName, Left = 210, Top = 10 };
            var resultField = new MethodResultField(resultTypeGuid);
            if (CanBeDestinationField(resultField))
                result.Fields.Add(CreateDestinationField(resultField, result));

            return result;
        }
        /// <summary>
        /// Loads the expression items.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="syncProcess">The synchronize process.</param>
        private void LoadExpressionItems(ProcessEdit process, ESyncProcessEdit syncProcess)
        {
            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();

            var source = new SourceFieldList { ExpressionName = "Source", Top = 10, Left = 10 };

            foreach (var providerField in syncProcess.Endpoints.Source.ProviderFields)
            {
                var sourceField = CreateSourceField(providerField, source);

                if (sourceField != null)
                    source.Fields.Add(sourceField);
            }

            newExpressions.Add(source);

            var destination = new DestinationFieldList { ExpressionName = process.Name, Top = 10, Left = 600 };

            AddIdFields(destination);
            AddStateFields(process, destination);
            AddVersionFields(process, destination);

            foreach (var field in process.GetAllFields().Where(CanBeDestinationField))
            {
                var destinationField = CreateDestinationField(field, destination);

                if (destinationField != null)
                    destination.Fields.Add(destinationField);
            }

            newExpressions.Add(destination);

            if (!string.IsNullOrWhiteSpace(syncProcess.Map.Designer))
            {
                try
                {
                    var expressionsContainer = ExpressionsSerializer.Deserialize(syncProcess.Map.Designer);
                    ExpressionNodeFactory.RestoreConnections(expressionsContainer.Expressions);
                    expressions.AddRange(expressionsContainer.Expressions);
                }
                catch
                {
                    // Do nothing, new expressions will be used.
                }
            }

            UpdateStateList(process);

            UpdateStoredExpressions(expressions, newExpressions, syncContext);

            syncContext.OperationCompleted();
        }
        private DestinationFieldList CreateDestinationItem(ProcessInfo process, string uniqueName, string name)
        {
            var destination = new DestinationFieldList { ExpressionName = name, UniqueName = uniqueName };

            AddStateFields(process, destination);
            AddVersionFields(process, destination);
            AddLastModifiedOnField(destination);

            foreach (var field in process.GetAllFields().Where(x => x.SystemName != Constants.IdColumnName && CanBeDestinationField(x)))
            {
                var destinationField = CreateDestinationField(field, process.SystemName, destination);

                destination.Fields.Add(destinationField);
            }

            return destination;
        }
        private async void LoadExpressionItems(ProcessEdit sourceProcess, ExternalDataConfigurationEdit externalDataConfiguration, ProcessExternalDataEdit model)
        {
            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();

            var source = new SourceFieldList
                {
                    ExpressionName = string.Format("{0} (source)", sourceProcess.Name),
                    UniqueName = SourceItemName,
                    Top = 10,
                    Left = 10
                };

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

            var modifiedSource = new SourceFieldList
            {
                ExpressionName = string.Format("External Data: {0}", externalDataConfiguration.Name),
                UniqueName = SourceToModifyItemName,
                Top = 310,
                Left = 10
            };

            // add data variable
            foreach (var field in externalDataConfiguration.DataVariableList)
            {
                var sourceField = CreateSourceFieldFromDataVariable(field, modifiedSource);
                sourceField.ObjectName = ModifiedItemObjectName;
                modifiedSource.Fields.Add(sourceField);
            }

            newExpressions.Add(modifiedSource);
          
            SourceFieldList systemParameters;

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

            if (systemParameters != null)
            {
                systemParameters.Left = 350;
                systemParameters.Top = 10;
                newExpressions.Add(systemParameters);
            }

            var destination = new DestinationFieldList
            {
                ExpressionName = sourceProcess.Name,
                UniqueName = DestinationItemName,
                Top = 10,
                Left = 500
            };

            foreach (var field in sourceProcess.GetAllFields().Where(CanBeDestinationField))
            {
                var destinationField = CreateDestinationField(field, destination);
                destination.Fields.Add(destinationField);
            }

            newExpressions.Add(destination);


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

            UpdateStoredExpressions(expressions, newExpressions, syncContext);
            syncContext.OperationCompleted();
        }
        /// <summary>
        /// Creates the LastModifiedOn system field.
        /// </summary>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <returns>
        /// The LastModifiedOn system field.
        /// </returns>
        protected override DestinationField CreateLastModifiedOnField(DestinationFieldList destination)
        {
            var field = base.CreateLastModifiedOnField(destination);
            field.IsKeyVisible = true;
            field.IsKey = false;
            field.IsKeyEnabled = false;
            field.ConnectorIn.Validator = CreateConnectionValidator(field);

            return field;
        }
        /// <summary>
        /// Creates the destination item.
        /// </summary>
        /// <param name="resultType">Type of the result.</param>
        /// <returns>DestinationFieldList.</returns>
        private DestinationFieldList CreateDestinationItem(Type resultType)
        {
            var result = new DestinationFieldList { ExpressionName = "Expression Result", Top = 200, Left = 600, UniqueName = DestinationItemName };
            var nodeType = GetNodeDataType(resultType);

            result.Fields.Add(
                new DestinationField(result)
                    {
                        Name = "Result",
                        SystemName = "Result",
                        InnerName = "Result",
                        DataType = nodeType,
                        ConnectorIn = { Name = "Result", DataType = nodeType }
                    });

            return result;
        }
        /// <summary>
        /// Creates version-related system fields.
        /// </summary>
        /// <param name="destination">
        /// The destination field list.
        /// </param>
        /// <returns>
        /// The collection of version-related system fields.
        /// </returns>
        protected override IEnumerable<DestinationField> CreateVersionFields(DestinationFieldList destination)
        {
            foreach (var field in base.CreateVersionFields(destination))
            {
                field.IsKeyVisible = true;
                field.IsKey = false;
                field.IsKeyEnabled = false;
                field.ConnectorIn.Validator = CreateConnectionValidator(field);

                yield return field;
            }
        }
        /// <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;
        }
        public void GetResultFields_Returns_ConnectedDestinationFields()
        {
            // Arrange.
            var expressionService = CreateExpressionService();

            var expressions = new List<IExpressionObjectBase>();
            var source = new ConstantExpression();
            expressions.Add(source);

            var destination = new DestinationFieldList();
            expressions.Add(destination);

            // This field is connected.
            var destinationField1 = new DestinationField(destination) { SystemName = "Field1" };
            destination.Fields.Add(destinationField1);
            expressions.Add(CreateConnection(source.ConnectorOut, destinationField1.ConnectorIn));

            // This field is not connected, but has subfields that are connected.
            var destinationField2 = new DestinationField(destination) { SystemName = "Field2" };
            destination.Fields.Add(destinationField2);

            var subfield1 = new DestinationField(destination) { SystemName = "Subfield1" };
            destinationField2.Subfields.Add(subfield1);
            expressions.Add(CreateConnection(source.ConnectorOut, subfield1.ConnectorIn));

            var subfield2 = new DestinationField(destination) { SystemName = "Subfield2" };
            destinationField2.Subfields.Add(subfield2);

            // This field is not connected and doesn't have any subfields that are connected.
            var destinationField3 = new DestinationField(destination) { SystemName = "Field3" };
            destination.Fields.Add(destinationField3);

            var subfield3 = new DestinationField(destination) { SystemName = "Subfield3" };
            destinationField3.Subfields.Add(subfield3);

            var xml = _expressionsSerializer.Serialize(new ExpressionContainer(expressions));

            // Act.
            var resultFields = expressionService.GetResultFields(xml).ToList();

            // Assert.
            Assert.AreEqual(2, resultFields.Count);

            Assert.AreEqual("Field1", resultFields[0].SystemName);

            Assert.AreEqual("Field2", resultFields[1].SystemName);
            Assert.AreEqual(1, resultFields[1].Subfields.Count);
            Assert.AreEqual("Subfield1", resultFields[1].Subfields[0].SystemName);
        }
 public void DeserilizationShouldExitIfXmlReaderIsOnEmptyElement()
 {
     var sr = new StringReader(string.Empty);
     using (var rd = XmlReader.Create(sr))
     {
         var result = new DestinationFieldList();
         Mock.Arrange(() => rd.IsEmptyElement).Returns(true);
         Mock.Arrange(() => rd.GetAttribute(Arg.AnyString)).Returns("0");
         Mock.Arrange(() => rd.GetAttribute("id")).Returns(Guid.Empty.ToString());
         result.Deserialize(rd);
         Mock.Assert(() => rd.Read(), Occurs.Never());
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DestinationFieldsExpressionNode"/> class.
        /// </summary>
        /// <param name="diagramViewModel">The diagram view model.</param>
        /// <param name="expressionObject">The expression object.</param>
        /// <exception cref="System.ArgumentNullException">expressionObject</exception>
        public DestinationFieldsExpressionNode(IDiagramViewModel diagramViewModel, DestinationFieldList expressionObject)
            : base(expressionObject)
        {
            if (expressionObject == null) throw new ArgumentNullException("expressionObject");

            _diagramViewModel = diagramViewModel;
            _connectorsIn.CollectionChanged += ConnectorsInCollectionChanged;

            IsValidFunc = n => true;
            UpdateAction = n => { };

            foreach (var node in expressionObject.Fields)
            {
                var connector = new ExpressionConnectorViewModel(new ExpressionConnector(ConnectorType.In, node), diagramViewModel);
                ConnectorsIn.Add(connector);
                ExpandSubconnectors(connector, false, true);
                //ConnectorsIn.Add(new ExpressionConnectorViewModel(new ExpressionConnector(ConnectorType.In, node), diagramViewModel));
            }
        }
        /// <summary>
        /// Edits the expression.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="process">The process.</param>
        /// <param name="expressionDesignerString">The expression designer string.</param>
        /// <param name="parameterType">Type of the parameter.</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, ProcessEdit process, string expressionDesignerString, SystemParameterType parameterType, Action saveAction, Action cancelAction, Action removeAction)
        {
            this.saveAction = saveAction;
            this.cancelAction = cancelAction;
            this.removeAction = removeAction;
            
            var source = new SourceFieldList {ExpressionName = process.Name, Top = 10, Left = 10};

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


            foreach (var field in process.GetAllFields())
            {
                if (field.FieldType.ColumnType == ColumnTypes.Reference)
                {
                    var crossRefStep = (CrossRefRequiredStepEdit)field.StepList.FirstOrDefault(x => x is CrossRefRequiredStepEdit);
                    if (crossRefStep != null)
                    {
                        if (crossRefStep.AllowMultiple)
                        {
                            source.Fields.Add(BuildSourceFieldForList(source, field, new CrSubfieldsRetriever(field.Id)));
                        }
                        else
                        {
                            source.Fields.Add(new SourceField(source)
                            {
                                DataType = NodeDataType.CrossReference,
                                Name = field.Name,
                                ConnectorOut =
                                    {
                                        DataType = NodeDataType.CrossReference,
                                        Name = field.Name
                                    },
                                SetName = SourceFieldSetNames.Item,
                                InnerName = field.SystemName,
                                SystemName = string.Format("{0}Member", field.SystemName),
                                SubfieldsRetriever = new CrSubfieldsRetriever(field.Id)
                            });
                        }
                    }
                }
                else
                {
                    if (field.FieldType.ColumnType == ColumnTypes.ReverseReference || field.FieldType.ColumnType == ColumnTypes.ReverseMultiReference)
                    {
                        var crossRefStep = (ReverseCrossRefRequiredStepEdit)field.StepList.FirstOrDefault(x => x is ReverseCrossRefRequiredStepEdit);
                        if (crossRefStep != null)
                        {
                            if (crossRefStep.DisplayMultiple)
                            {
                                source.Fields.Add(BuildSourceFieldForList(source, field, new ReverseCrSubfieldsRetriever(field.Id)));
                            }
                            else
                            {
                                source.Fields.Add(new SourceField(source)
                                {
                                    DataType = NodeDataType.ReverseCrossReference,
                                    Name = field.Name,
                                    ConnectorOut =
                                    {
                                        DataType = NodeDataType.ReverseCrossReference,
                                        Name = field.Name
                                    },
                                    SetName = SourceFieldSetNames.Item,
                                    InnerName = field.SystemName,
                                    SystemName = string.Format("{0}Member", field.SystemName),
                                    SubfieldsRetriever = new ReverseCrSubfieldsRetriever(field.Id)
                                });
                            }
                        }
                    }
                    else if (field.FieldType.ColumnType == ColumnTypes.Checklist)
                    {
                        source.Fields.Add(BuildSourceFieldForList(source, field, new ChecklistSubFieldsRetriever(field.Id)));
                    }
                    else if (field.FieldType.ColumnType == ColumnTypes.DisplayList)
                    {
                        source.Fields.Add(BuildSourceFieldForList(source, field, new DisplayListSubFieldsRetriever(field.Id)));
                    }
                    else if (field.FieldType.ColumnType == ColumnTypes.Result)
                    {
                        source.Fields.Add(new SourceField(source)
                        {
                            DataType = NodeDataType.Result,
                            Name = field.Name,
                            ConnectorOut =
                            {
                                DataType = NodeDataType.Result,
                                Name = field.Name
                            },
                            SetName = SourceFieldSetNames.Item,
                            InnerName = field.SystemName,
                            SystemName = field.SystemName
                        });
                    }
                    else
                    {
                        //var fieldType = GetType(field.FieldType);
                        var dataType = SourceNodeFactory.GetDataType(GetType(field.FieldType));
                        var sf = new SourceField(source)
                                     {
                                         DataType = dataType,
                                         Name = field.Name,
                                         ConnectorOut = { DataType = dataType, Name = field.Name },
                                         SetName = SourceFieldSetNames.Item,
                                         InnerName = field.SystemName,
                                         SystemName = field.SystemName
                                     };
                        source.Fields.Add(sf);
                    }
                }
            }

            var expressions = new List<IExpressionObjectBase>();

            var isNew = true;

            ExpressionContainer expressionsContainer;
            try
            {
                expressionsContainer = Serializer.Deserialize(expressionDesignerString);
            }
            catch
            {
                expressionsContainer = null;
            }

            if (!string.IsNullOrWhiteSpace(expressionDesignerString) && expressionsContainer != null)
            {
                isNew = false;
                expressions.AddRange(expressionsContainer.Expressions);
            }
            else
            {
                expressions.Add(source);
                var destination = new DestinationFieldList
                                      {
                                          Top = 200,
                                          Left = 600,
                                          ExpressionName = "Expression Result"
                                      };
                destination.Fields.Add(new DestinationField(destination)
                                           {
                                               Name = "Result",
                                               SystemName = "Result",
                                               InnerName = "Result",
                                               DataType = GetNodeType(parameterType),
                                               ConnectorIn = { Name = "Result", DataType = GetNodeType(parameterType) }
                                           });
                expressions.Add(destination);
            }

            if (expressionsContainer != null)
            {
                var sourceFieldList =
                   (from fl in expressions
                    where fl is SourceFieldList
                    select fl).Cast<SourceFieldList>().FirstOrDefault();

                if (sourceFieldList != null)
                {
                    var fieldList = sourceFieldList.Fields.Cast<IExpressionField>().ToList();
                    UpdateStoredFields(fieldList, source.Fields, (sf) => FinalizeUpdate(sourceFieldList, fieldList, source, expressions, parentWindow)); // Here we load all subtypes async that's why we need reload window after all subtypes are loaded
                }
            }

            if (!isNew)
            {
                return;
            }

            var userInfoSource = SourceNodeFactory.CreateUserInformationItem(CurrentUserInformationItemName);
            userInfoSource.Left = 175;
            userInfoSource.Top = 10;

            expressions.Add(userInfoSource);

            this.expressionDesigner.Diagram.Items.Clear();
            ExpressionTranslator.TranslateToDiagram(expressions, this.expressionDesigner.Diagram);

            WindowManager.Value.ShowChildWindow(parentWindow, this);
        }
Esempio n. 18
0
        /// <summary>
        /// To the expression node.
        /// </summary>
        /// <param name="destination">The destination.</param>
        /// <returns>DestinationNode.</returns>
        private DestinationNode ToExpressionNode(DestinationFieldList destination)
        {
            var destinationNode = new DestinationNode();

            foreach (var field in destination.Fields)
            {
                AddDestinationNode(field, destinationNode);
            }

            return destinationNode;
        }