Ejemplo n.º 1
0
        private static async Task <Activity[]> Activities(string directory)
        {
            var files       = new Files().Find(directory).ToArray();
            var entryParser = new ActivityParser();

            foreach (var fileTask in new FileReader().ReadAll(files))
            {
                entryParser.AddXml(await fileTask);
            }
            return(entryParser.TopLevelActivities().ToArray());
        }
Ejemplo n.º 2
0
        public static void ReadActivityFiles(string directory)
        {
            if (!Directory.Exists(directory))
            {
                throw new ApplicationException($"The supplied directory: {directory}, does not exist");
            }

            foreach (var file in Directory.EnumerateFiles(directory))
            {
                FileStream fstream    = new FileStream(file, FileMode.Open);
                FitDecoder fitDecoder = new FitDecoder(fstream, Dynastream.Fit.File.Activity);

                // Decode the FIT file
                try
                {
                    Console.WriteLine("Decoding...");
                    fitDecoder.Decode();
                }
                catch (FileTypeException ex)
                {
                    Console.WriteLine("DecodeDemo caught FileTypeException: " + ex.Message);
                    return;
                }
                catch (FitException ex)
                {
                    Console.WriteLine("DecodeDemo caught FitException: " + ex.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("DecodeDemo caught Exception: " + ex.Message);
                }
                finally
                {
                    fstream.Close();
                }

                var timezoneOffset = fitDecoder.Messages.Activity.TimezoneOffset();
                Console.WriteLine($"The timezone offset for this activity file is {timezoneOffset?.TotalHours ?? 0} hours.");

                // Create the Activity Parser and group the messages into individual sessions.
                ActivityParser activityParser = new ActivityParser(fitDecoder.Messages);
                var            sessions       = activityParser.ParseSessions();
                ExportToCsv(sessions);
            }
        }
        public void LoadsNestedActivities()
        {
            var parser = new ActivityParser();

            parser.AddXml(Xml1);
            parser.AddXml(Xml2);
            parser.AddXml(Xml3);
            parser.AddXml(Xml4);
            var actual = parser.TopLevelActivities().ToList();

            Assert.Collection(actual, a =>
            {
                Assert.Equal("|85239d86-498cf83c8feb6846.", a.Id);
                Assert.Collection(a.Children, c =>
                {
                    Assert.Equal("|85239d86-498cf83c8feb6846.1.", c.Id);
                    Assert.Equal(a, c.Parent);
                });
            });
        }
Ejemplo n.º 4
0
        public void Eval(DynamicActivity flowchartProcess, IDSFDataObject dsfDataObject, int update)
        {
            var resource = new ActivityParser().Parse(flowchartProcess);

            EvalInner(dsfDataObject, resource, update);
        }
Ejemplo n.º 5
0
        public void Eval(DynamicActivity flowchartProcess, Guid resourceID, IDSFDataObject dsfDataObject)
        {
            IDev2Activity resource = new ActivityParser().Parse(flowchartProcess);

            resource.Execute(dsfDataObject);
        }
Ejemplo n.º 6
0
        private IDev2Activity FindActivity(IDev2Activity resource)
        {
            var allNodes = new ActivityParser().ParseToLinkedFlatList(resource);

            return(allNodes.FirstOrDefault(p => p.UniqueID == _resumeActivityId.ToString()));
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("FIT Decode Example Application");

            if (args.Length != 1)
            {
                Console.WriteLine("Usage: decode.exe <filename>");
                return;
            }

            try
            {
                // Attempt to open the input file
                FileStream fileStream = new FileStream(args[0], FileMode.Open);
                Console.WriteLine($"Opening {args[0]}");

                // Create our FIT Decoder
                FitDecoder fitDecoder = new FitDecoder(fileStream, Dynastream.Fit.File.Activity);

                // Decode the FIT file
                try
                {
                    Console.WriteLine("Decoding...");
                    fitDecoder.Decode();
                }
                catch (FileTypeException ex)
                {
                    Console.WriteLine("DecodeDemo caught FileTypeException: " + ex.Message);
                    return;
                }
                catch (FitException ex)
                {
                    Console.WriteLine("DecodeDemo caught FitException: " + ex.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("DecodeDemo caught Exception: " + ex.Message);
                }
                finally
                {
                    fileStream.Close();
                }

                // Check the time zone offset in the Activity message.
                var timezoneOffset = fitDecoder.Messages.Activity.TimezoneOffset();
                Console.WriteLine($"The timezone offset for this activity file is {timezoneOffset?.TotalHours ?? 0} hours.");

                // Create the Activity Parser and group the messages into individual sessions.
                ActivityParser activityParser = new ActivityParser(fitDecoder.Messages);
                var            sessions       = activityParser.ParseSessions();

                // Export a CSV file for each Activity Session
                foreach (SessionMessages session in sessions)
                {
                    if (session.Records.Count > 0)
                    {
                        var recordsCSV = Export.RecordsToCSV(session);

                        var recordsPath = Path.Combine(Path.GetDirectoryName(args[0]), $"{Path.GetFileNameWithoutExtension(args[0])}_{session.Session.GetStartTime().GetDateTime().ToString("yyyyMMddHHmmss")}_{session.Session.GetSport()}_Records.csv");

                        using (StreamWriter outputFile = new StreamWriter(recordsPath))
                        {
                            outputFile.WriteLine(recordsCSV);
                        }

                        Console.WriteLine($"The file {recordsPath} has been saved.");
                    }

                    if (session.Session.GetSport() == Sport.Swimming && session.Session.GetSubSport() == SubSport.LapSwimming && session.Lengths.Count > 0)
                    {
                        var lengthsCSV = Export.LengthsToCSV(session);

                        var lengthsPath = Path.Combine(Path.GetDirectoryName(args[0]), $"{Path.GetFileNameWithoutExtension(args[0])}_{session.Session.GetStartTime().GetDateTime().ToString("yyyyMMddHHmmss")}_{session.Session.GetSport()}_Lengths.csv");

                        using (StreamWriter outputFile = new StreamWriter(lengthsPath))
                        {
                            outputFile.WriteLine(lengthsCSV);
                        }

                        Console.WriteLine($"The file {lengthsPath} has been saved.");
                    }
                }

                // How are the sensor batteries?
                var deviceInfos = activityParser.DevicesWhereBatteryStatusIsLow();
                foreach (DeviceInfoMesg info in deviceInfos)
                {
                    Console.WriteLine($"Device Type {info.GetAntplusDeviceType()} has a low battery.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception {ex}");
            }
        }
Ejemplo n.º 8
0
 public ActivitySourceTest()
 {
     _parser = new ActivityParser();
 }
        public void GetDifferences_WhenToolModifiedOnBithSides_ShouldNullOnRemoteChart()
        {
            var activityParser = new ActivityParser();
            var shellView      = new Mock <IShellViewModel>();
            var serverMock     = new Mock <IServer>();

            shellView.Setup(model => model.ActiveServer).Returns(serverMock.Object);
            CustomContainer.Register(shellView.Object);
            CustomContainer.Register <IActivityParser>(activityParser);

            var assignId = Guid.NewGuid().ToString();
            var chart    = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfMultiAssignActivity
                    {
                        FieldsCollection = new List <ActivityDTO>
                        {
                            new ActivityDTO("field1", "field1", 1),
                            new ActivityDTO("field2", "field2", 4),
                            new ActivityDTO("field3", "field3", 3),
                            new ActivityDTO("field3", "field3", 2),
                        },
                        UniqueID = assignId
                    }
                }
            };

            var otherChart = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfMultiAssignActivity
                    {
                        FieldsCollection = new List <ActivityDTO>
                        {
                            new ActivityDTO("field1", "field1", 1),
                            new ActivityDTO("field2", "field2", 2),
                            new ActivityDTO("field2", "fff", 4),
                            new ActivityDTO("field3", "field3", 3),
                        },
                        UniqueID = assignId
                    }
                }
            };

            var current = ParserTestHelper.CreateContextualResourceModel(otherChart);
            var diff    = ParserTestHelper.CreateContextualResourceModel(chart);

            var psd = new ServiceDifferenceParser();

            var(currentTree, diffTree) = psd.GetDifferences(current, diff);

            var currConflicts = currentTree;
            var diffConflicts = diffTree;

            var count = currConflicts.Count + diffConflicts.Count;

            Assert.AreEqual(2, count);

            Assert.IsFalse(diffTree.Any(d => d.IsInConflict));
            Assert.AreEqual(assignId, diffTree[0].UniqueId);

            Assert.IsFalse(currentTree.Any(d => d.IsInConflict));
            Assert.AreEqual(assignId, currentTree[0].UniqueId);

            //First Node chart
            var tupleDifference = diffTree[0];
            var tupleCurrent    = currentTree[0];

            Assert.IsNotNull(tupleDifference);
            Assert.IsNotNull(tupleCurrent);

            var devActivityDiff = tupleDifference.Activity;
            var devActivityCurr = tupleCurrent.Activity;

            Assert.IsNotNull(devActivityDiff);
            Assert.IsNotNull(devActivityCurr);
            Assert.AreEqual(assignId, devActivityCurr.UniqueID);
            Assert.AreEqual(assignId, devActivityDiff.UniqueID);
        }
        public void FlowDecision_GetDifferences_WhenMainDecisionModified_DecisionToolHasConflict()
        {
            var activityParser = new ActivityParser();
            var shellView      = new Mock <IShellViewModel>();
            var serverMock     = new Mock <IServer>();

            shellView.Setup(model => model.ActiveServer).Returns(serverMock.Object);
            CustomContainer.Register(shellView.Object);
            CustomContainer.Register <IActivityParser>(activityParser);
            var deicisionId = Guid.NewGuid().ToString();
            var bb          = new DsfFlowDecisionActivity {
                UniqueID = deicisionId
            };
            var jsonSerializer    = new Dev2JsonSerializer();
            var dev2DecisionStack = new Dev2DecisionStack
            {
                TheStack = new List <Dev2Decision>
                {
                    new Dev2Decision
                    {
                        Cols1 = new List <DataStorage.WarewolfAtom>
                        {
                            DataStorage.WarewolfAtom.NewDataString("a")
                        }
                    },
                    new Dev2Decision
                    {
                        Cols1 = new List <DataStorage.WarewolfAtom>
                        {
                            DataStorage.WarewolfAtom.NewDataString("a")
                        }
                    }
                },
                DisplayText  = "a",
                FalseArmText = "ErrorArm",
                TrueArmText  = "true Arm",
                Version      = "2",
                Mode         = Dev2DecisionMode.AND
            };

            bb.ExpressionText = jsonSerializer.Serialize(dev2DecisionStack);

            var bb2 = new DsfFlowDecisionActivity {
                UniqueID = deicisionId
            };
            var dev2DecisionStack2 = new Dev2DecisionStack
            {
                TheStack = new List <Dev2Decision>
                {
                    new Dev2Decision
                    {
                        Cols1 = new List <DataStorage.WarewolfAtom>
                        {
                            DataStorage.WarewolfAtom.NewDataString("a")
                        }
                    },
                    new Dev2Decision
                    {
                        Cols1 = new List <DataStorage.WarewolfAtom>
                        {
                            DataStorage.WarewolfAtom.NewDataString("a")
                        }
                    }
                },
                DisplayText  = "changed",
                FalseArmText = "false",
                TrueArmText  = "true",
                Version      = "2",
                Mode         = Dev2DecisionMode.AND
            };

            bb2.ExpressionText = jsonSerializer.Serialize(dev2DecisionStack2);

            var assignId     = Guid.NewGuid().ToString();
            var calcActivity = new DsfCalculateActivity {
                UniqueID = assignId
            };
            var chart = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = calcActivity,
                    Next   = new FlowDecision
                    {
                        DisplayName = "DisplayName",
                        True        = new FlowStep {
                            Action = calcActivity
                        },
                        Condition = bb
                    }
                }
            };

            var otherChart = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = calcActivity,
                    Next   = new FlowDecision
                    {
                        DisplayName = "DisplayName",
                        True        = new FlowStep {
                            Action = calcActivity
                        },
                        Condition = bb2
                    }
                }
            };

            var current = ParserTestHelper.CreateContextualResourceModel(otherChart);
            var diff    = ParserTestHelper.CreateContextualResourceModel(chart);

            var psd = new ServiceDifferenceParser();

            var(currentTree, diffTree) = psd.GetDifferences(current, diff);

            var currConflicts = currentTree;
            var diffConflicts = diffTree;

            var count = currConflicts.Count + diffConflicts.Count;

            Assert.AreEqual(4, count);
            Assert.IsFalse(diffTree.First().IsInConflict);
            Assert.IsFalse(currentTree.First().IsInConflict);
            Assert.IsFalse(diffTree.Last().IsInConflict);
            Assert.IsFalse(currentTree.Last().IsInConflict);
            Assert.AreEqual(assignId, diffTree[0].UniqueId);
            Assert.AreEqual(assignId, currentTree[0].UniqueId);

            //First Node chart
            var tupleDifference = diffTree[0];
            var tupleCurrent    = currentTree[0];

            Assert.IsNotNull(tupleDifference);
            Assert.IsNotNull(tupleCurrent);

            var devActivityDiff = tupleDifference.Activity;
            var devActivityCurr = tupleCurrent.Activity;

            Assert.IsNotNull(devActivityDiff);
            Assert.IsNotNull(devActivityCurr);
            Assert.AreEqual(assignId, devActivityCurr.UniqueID);
            Assert.AreEqual(assignId, devActivityDiff.UniqueID);

            //Decision Node chart
            var tupleDifference1 = diffTree[1];
            var tupleCurrent1    = currentTree[1];

            Assert.IsNotNull(tupleDifference1);
            Assert.IsNotNull(tupleCurrent1);

            var devActivityDiff1 = tupleDifference1.Activity;
            var devActivityCurr1 = tupleCurrent1.Activity;

            Assert.IsNotNull(devActivityDiff1);
            Assert.IsNotNull(devActivityCurr1);
            Assert.IsFalse(devActivityDiff1.Equals(devActivityCurr1));
        }
        public void GetDifferences_WhenDecisionAddedOnLocal_ShouldNullOnRemoteChart()
        {
            var activityParser = new ActivityParser();
            var shellView      = new Mock <IShellViewModel>();
            var serverMock     = new Mock <IServer>();

            shellView.Setup(model => model.ActiveServer).Returns(serverMock.Object);
            CustomContainer.Register(shellView.Object);
            CustomContainer.Register <IActivityParser>(activityParser);

            var randomActivityUniqueId = Guid.NewGuid().ToString();
            var calculateUniqueId      = Guid.NewGuid().ToString();
            var chart = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfRandomActivity
                    {
                        UniqueID = randomActivityUniqueId,
                    },
                    Next =
                        new FlowStep
                    {
                        Action = new DsfCalculateActivity {
                            UniqueID = calculateUniqueId
                        }
                    }
                }
            };
            var dev2DecisionStack = new Dev2DecisionStack
            {
                TheStack     = new List <Dev2Decision>(),
                TrueArmText  = "a",
                FalseArmText = "a",
                DisplayText  = "a",
                Mode         = Dev2DecisionMode.AND
            };
            var serializer = new Dev2JsonSerializer();
            var serialize  = serializer.Serialize(dev2DecisionStack);
            var otherChart = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfRandomActivity
                    {
                        UniqueID = randomActivityUniqueId,
                    },
                    Next =
                        new FlowStep
                    {
                        Action = new DsfCalculateActivity {
                            UniqueID = calculateUniqueId
                        },
                        Next = new FlowDecision
                        {
                            True = new FlowStep
                            {
                                Action = new DsfMultiAssignActivity()
                            },
                            False = new FlowStep
                            {
                                Action = new DsfActivity()
                            },
                            Condition = new DsfFlowDecisionActivity
                            {
                                ExpressionText = serialize
                            }
                        }
                    }
                }
            };

            var current = ParserTestHelper.CreateContextualResourceModel(otherChart);
            var diff    = ParserTestHelper.CreateContextualResourceModel(chart);

            var psd = new ServiceDifferenceParser();

            var(currentTree, diffTree) = psd.GetDifferences(current, diff);

            var currConflicts = currentTree;
            var diffConflicts = diffTree;

            var count = currConflicts.Count + diffConflicts.Count;

            Assert.AreEqual(7, count);

            Assert.IsFalse(diffTree.Any(d => d.IsInConflict));
            Assert.AreEqual(calculateUniqueId, diffTree[1].UniqueId);
            Assert.AreEqual(randomActivityUniqueId, diffTree[0].UniqueId);

            Assert.IsFalse(currentTree.Any(d => d.IsInConflict));
            Assert.AreEqual(calculateUniqueId, currentTree[1].UniqueId);
            Assert.AreEqual(randomActivityUniqueId, currentTree[0].UniqueId);

            //First Node chart
            var tupleDifference = diffTree[0];
            var tupleCurrent    = currentTree[0];

            Assert.IsNotNull(tupleDifference);
            Assert.IsNotNull(tupleCurrent);

            var devActivityDiff = tupleDifference.Activity;
            var devActivityCurr = tupleCurrent.Activity;

            Assert.IsNotNull(devActivityDiff);
            Assert.IsNotNull(devActivityCurr);
            Assert.AreEqual(randomActivityUniqueId, devActivityCurr.UniqueID);
            Assert.AreEqual(randomActivityUniqueId, devActivityDiff.UniqueID);

            //Second chart
            var tupleDifference1 = diffTree[1];
            var tupleCurrent1    = currentTree[1];

            Assert.IsNotNull(tupleDifference1);
            Assert.IsNotNull(tupleCurrent1);

            var devActivityDiff1 = tupleDifference1.Activity;
            var devActivityCurr1 = tupleCurrent1.Activity;

            Assert.IsNotNull(devActivityDiff1);
            Assert.IsNotNull(devActivityCurr1);
            Assert.AreEqual(calculateUniqueId, devActivityDiff1.UniqueID);
            Assert.AreEqual(calculateUniqueId, devActivityCurr1.UniqueID);
        }
        public void GetDifferences_WhenFlatToolAddedOnLocal_ShouldNullOnRemoteChart()
        {
            var activityParser = new ActivityParser();
            var shellView      = new Mock <IShellViewModel>();
            var serverMock     = new Mock <IServer>();

            shellView.Setup(model => model.ActiveServer).Returns(serverMock.Object);
            CustomContainer.Register(shellView.Object);
            CustomContainer.Register <IActivityParser>(activityParser);

            var randomActivityUniqueId = Guid.NewGuid().ToString();
            var calculateUniqueId      = Guid.NewGuid().ToString();
            var chart = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfRandomActivity
                    {
                        UniqueID = randomActivityUniqueId,
                    },
                    Next =
                        new FlowStep
                    {
                        Action = new DsfCalculateActivity {
                            UniqueID = calculateUniqueId
                        }
                    }
                }
            };
            var baseConvertId = Guid.NewGuid().ToString();
            var otherChart    = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfRandomActivity
                    {
                        UniqueID = randomActivityUniqueId
                    },
                    Next =
                        new FlowStep
                    {
                        Action = new DsfBaseConvertActivity {
                            UniqueID = baseConvertId
                        }
                        ,
                        Next = new FlowStep
                        {
                            Action = new DsfCalculateActivity {
                                UniqueID = calculateUniqueId
                            }
                        }
                    }
                }
            };

            var current = ParserTestHelper.CreateContextualResourceModel(otherChart);
            var diff    = ParserTestHelper.CreateContextualResourceModel(chart);

            var psd = new ServiceDifferenceParser();

            var(currentTree, diffTree) = psd.GetDifferences(current, diff);

            var currConflicts = currentTree;
            var diffConflicts = diffTree;

            var count = currConflicts.Count + diffConflicts.Count;

            Assert.AreEqual(5, count);

            Assert.IsFalse(diffTree.Any(d => d.IsInConflict));
            Assert.AreEqual(calculateUniqueId, diffTree[1].UniqueId);
            Assert.AreEqual(randomActivityUniqueId, diffTree[0].UniqueId);

            Assert.IsFalse(currentTree.Any(d => d.IsInConflict));
            Assert.AreEqual(baseConvertId, currentTree[1].UniqueId);
            Assert.AreEqual(randomActivityUniqueId, currentTree[0].UniqueId);

            //First Node chart
            var tupleDifference = diffTree[0];
            var tupleCurrent    = currentTree[0];

            Assert.IsNotNull(tupleDifference);
            Assert.IsNotNull(tupleCurrent);

            var devActivityDiff = tupleDifference.Activity;
            var devActivityCurr = tupleCurrent.Activity;

            Assert.IsNotNull(devActivityDiff);
            Assert.IsNotNull(devActivityCurr);
            Assert.AreEqual(randomActivityUniqueId, devActivityCurr.UniqueID);
            Assert.AreEqual(randomActivityUniqueId, devActivityDiff.UniqueID);

            //Second chart
            var tupleDifference1 = diffTree[1];
            var tupleCurrent1    = currentTree[1];

            Assert.IsNotNull(tupleDifference1);
            Assert.IsNotNull(tupleCurrent1);

            var devActivityDiff1 = tupleDifference1.Activity;
            var devActivityCurr1 = tupleCurrent1.Activity;

            Assert.IsNotNull(devActivityDiff1);
            Assert.IsNotNull(devActivityCurr1);
            Assert.AreEqual(calculateUniqueId, devActivityDiff1.UniqueID);
            Assert.AreEqual(baseConvertId, devActivityCurr1.UniqueID);
        }
        public void FlowSwitch_GetDifferences_WhenCasesTheSame_SwitchHasNoConflict()
        {
            var activityParser = new ActivityParser();
            var shellView      = new Mock <IShellViewModel>();
            var serverMock     = new Mock <IServer>();

            shellView.Setup(model => model.ActiveServer).Returns(serverMock.Object);
            CustomContainer.Register(shellView.Object);
            CustomContainer.Register <IActivityParser>(activityParser);
            var switchActivity = new DsfFlowSwitchActivity("MyName", new Mock <IDebugDispatcher>().Object, It.IsAny <bool>())
            {
                UniqueID = Guid.NewGuid().ToString(),
            };
            var dev2DecisionStack = new Dev2DecisionStack
            {
                TheStack = new List <Dev2Decision>
                {
                    new Dev2Decision
                    {
                        Cols1 = new List <DataStorage.WarewolfAtom>
                        {
                            DataStorage.WarewolfAtom.NewDataString("a")
                        }
                    },
                    new Dev2Decision
                    {
                        Cols1 = new List <DataStorage.WarewolfAtom>
                        {
                            DataStorage.WarewolfAtom.NewDataString("a")
                        }
                    }
                },
                DisplayText  = "a",
                FalseArmText = "ErrorArm",
                TrueArmText  = "true Arm",
                Version      = "2",
                Mode         = Dev2DecisionMode.AND,
            };
            var jsonSerializer = new Dev2JsonSerializer();

            switchActivity.ExpressionText = jsonSerializer.Serialize(dev2DecisionStack);
            var assignId = Guid.NewGuid().ToString();
            var chart    = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfMultiAssignActivity
                    {
                        FieldsCollection = new List <ActivityDTO>
                        {
                            new ActivityDTO("field1", "field1", 1),
                            new ActivityDTO("field2", "field2", 4),
                            new ActivityDTO("field3", "field3", 3),
                            new ActivityDTO("field3", "field3", 2),
                        },
                        UniqueID = assignId
                    },
                    Next = new FlowSwitch <string>
                    {
                        DisplayName = "DisplayName",
                        Default     = new FlowStep
                        {
                            Action = ActivityBuilderFactory.BuildActivity(typeof(DsfCalculateActivity))
                        },
                        Expression = switchActivity
                    }
                }
            };

            var otherChart = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfMultiAssignActivity
                    {
                        FieldsCollection = new List <ActivityDTO>
                        {
                            new ActivityDTO("field1", "field1", 1),
                            new ActivityDTO("field2", "field2", 2),
                            new ActivityDTO("field2", "fff", 4),
                            new ActivityDTO("field3", "field3", 3),
                        },
                        UniqueID = assignId
                    },
                    Next = new FlowSwitch <string>
                    {
                        DisplayName = "DisplayName",
                        Default     = new FlowStep
                        {
                            Action = ActivityBuilderFactory.BuildActivity(typeof(DsfCalculateActivity))
                        },
                        Expression = switchActivity
                    }
                }
            };

            var current = ParserTestHelper.CreateContextualResourceModel(otherChart);
            var diff    = ParserTestHelper.CreateContextualResourceModel(chart);

            var psd = new ServiceDifferenceParser();

            var(currentTree, diffTree) = psd.GetDifferences(current, diff);

            var currConflicts = currentTree;
            var diffConflicts = diffTree;

            var count = currConflicts.Count + diffConflicts.Count;

            Assert.AreEqual(6, count);

            Assert.IsFalse(diffTree.First().IsInConflict);
            Assert.IsFalse(currentTree.First().IsInConflict);

            Assert.IsFalse(diffTree.Last().IsInConflict);
            Assert.IsFalse(currentTree.Last().IsInConflict);

            Assert.AreEqual(assignId, diffTree[0].UniqueId);
            Assert.AreEqual(assignId, currentTree[0].UniqueId);
        }
        public void FlowDecision_GetDifferences_WhenArmToolsTheSame_DecisionHasNoConflict()
        {
            var activityParser = new ActivityParser();
            var shellView      = new Mock <IShellViewModel>();
            var serverMock     = new Mock <IServer>();

            shellView.Setup(model => model.ActiveServer).Returns(serverMock.Object);
            CustomContainer.Register(shellView.Object);
            CustomContainer.Register <IActivityParser>(activityParser);
            var bb                = new DsfFlowDecisionActivity();
            var jsonSerializer    = new Dev2JsonSerializer();
            var toolId1           = Guid.NewGuid().ToString();
            var toolId2           = Guid.NewGuid().ToString();
            var dev2DecisionStack = new Dev2DecisionStack
            {
                TheStack = new List <Dev2Decision>
                {
                    new Dev2Decision
                    {
                        Cols1 = new List <DataStorage.WarewolfAtom>
                        {
                            DataStorage.WarewolfAtom.NewDataString("a")
                        }
                    },
                    new Dev2Decision
                    {
                        Cols1 = new List <DataStorage.WarewolfAtom>
                        {
                            DataStorage.WarewolfAtom.NewDataString("a")
                        }
                    }
                },
                DisplayText  = "a",
                FalseArmText = "ErrorArm",
                TrueArmText  = "true Arm",
                Version      = "2",
                Mode         = Dev2DecisionMode.AND
            };

            bb.ExpressionText = jsonSerializer.Serialize(dev2DecisionStack);

            var assignId = Guid.NewGuid().ToString();
            var chart    = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfMultiAssignActivity
                    {
                        FieldsCollection = new List <ActivityDTO>
                        {
                            new ActivityDTO("field1", "field1", 1),
                            new ActivityDTO("field2", "field2", 4),
                            new ActivityDTO("field3", "field3", 3),
                            new ActivityDTO("field3", "field3", 2),
                        },
                        UniqueID = assignId
                    },
                    Next = new FlowDecision
                    {
                        DisplayName = "DisplayName",
                        True        = new FlowStep
                        {
                            Action = ActivityBuilderFactory.BuildActivity(typeof(DsfCalculateActivity), toolId1),
                            Next   = new FlowStep
                            {
                                Action = ActivityBuilderFactory.BuildActivity(typeof(DsfBaseConvertActivity), toolId2)
                            }
                        },
                        Condition = bb
                    }
                }
            };

            var otherChart = new Flowchart
            {
                StartNode = new FlowStep
                {
                    Action = new DsfMultiAssignActivity
                    {
                        FieldsCollection = new List <ActivityDTO>
                        {
                            new ActivityDTO("field1", "field1", 1),
                            new ActivityDTO("field2", "field2", 2),
                            new ActivityDTO("field2", "fff", 4),
                            new ActivityDTO("field3", "field3", 3),
                        },
                        UniqueID = assignId
                    },
                    Next = new FlowDecision
                    {
                        DisplayName = "DisplayName",
                        True        = new FlowStep
                        {
                            Action = ActivityBuilderFactory.BuildActivity(typeof(DsfCalculateActivity), toolId1),
                            Next   = new FlowStep
                            {
                                Action = ActivityBuilderFactory.BuildActivity(typeof(DsfBaseConvertActivity), toolId2)
                            }
                        },
                        Condition = bb
                    }
                }
            };

            var current = ParserTestHelper.CreateContextualResourceModel(otherChart);
            var diff    = ParserTestHelper.CreateContextualResourceModel(chart);

            var psd = new ServiceDifferenceParser();

            var(currentTree, diffTree) = psd.GetDifferences(current, diff);

            var currConflicts = currentTree;
            var diffConflicts = diffTree;

            var count = currConflicts.Count + diffConflicts.Count;

            Assert.AreEqual(8, count);

            Assert.IsFalse(diffTree.Any(d => d.IsInConflict));
            Assert.IsFalse(currentTree.Any(d => d.IsInConflict));
            Assert.AreEqual(assignId, diffTree[0].UniqueId);
            Assert.AreEqual(assignId, currentTree[0].UniqueId);

            //First Node chart
            var tupleDifference = diffTree[0];
            var tupleCurrent    = currentTree[0];

            Assert.IsNotNull(tupleDifference);
            Assert.IsNotNull(tupleCurrent);

            var devActivityDiff = tupleDifference.Activity;
            var devActivityCurr = tupleCurrent.Activity;

            Assert.IsNotNull(devActivityDiff);
            Assert.IsNotNull(devActivityCurr);
            Assert.AreEqual(assignId, devActivityCurr.UniqueID);
            Assert.AreEqual(assignId, devActivityDiff.UniqueID);

            //Decision Node chart
            var tupleDifference1 = diffTree[1];
            var tupleCurrent1    = currentTree[1];

            Assert.IsNotNull(tupleDifference1);
            Assert.IsNotNull(tupleCurrent1);

            var devActivityDiff1 = tupleDifference1.Activity;
            var devActivityCurr1 = tupleCurrent1.Activity;

            Assert.IsNotNull(devActivityDiff1);
            Assert.IsNotNull(devActivityCurr1);
            Assert.IsTrue(devActivityDiff1.Equals(devActivityCurr1));
        }
Ejemplo n.º 15
0
        public void ActivityParser_ParseToLinkedFlatList()
        {
            var topLevelActivity = new DsfDotNetMultiAssignActivity
            {
                DisplayName = "Assign (1)",
                UniqueID    = "d006a409-333a-49d3-8e1c-7c908f6ba461",
            };

            var suspendExecutionActivityOne = new SuspendExecutionActivity
            {
                DisplayName = "Suspend Execution",
                UniqueID    = "66b7c885-9ea4-4d75-b822-13ff5ef28128",
            };

            topLevelActivity.NextNodes = new List <IDev2Activity> {
                suspendExecutionActivityOne
            };

            var dev2DecisionStackOne = new Dev2DecisionStack {
                DisplayText = "If [[a]] Is = 2"
            };
            var flowDecisionActivityOne = new DsfDecision
            {
                DisplayName = "If [[a]] Is = 2",
                UniqueID    = "1764efe9-4e0e-423a-8510-b35dc9b053f4",
                NextNodes   = null,
                Conditions  = dev2DecisionStackOne
            };

            var fileWriteActivityOne = new FileWriteActivity
            {
                DisplayName = "Write File",
                UniqueID    = "8e35adbf-d0c4-443b-ab04-2a83ca1aaa62",
            };

            flowDecisionActivityOne.TrueArm = new [] { fileWriteActivityOne };

            var flowDecisionActivityOneFalseArmAssign = new DsfDotNetMultiAssignActivity
            {
                DisplayName = "Assign (1)",
                UniqueID    = "23b599b7-49f4-40a8-8304-f034d227d3dd",
            };

            var flowDecisionActivityOneFalseArmFileWrite = new FileWriteActivity
            {
                DisplayName = "Write File",
                UniqueID    = "baad2ce3-371b-4fec-81f4-0da4112078c8",
            };

            flowDecisionActivityOneFalseArmAssign.NextNodes = new List <IDev2Activity> {
                flowDecisionActivityOneFalseArmFileWrite
            };
            flowDecisionActivityOneFalseArmFileWrite.NextNodes = new List <IDev2Activity> {
                suspendExecutionActivityOne
            };

            flowDecisionActivityOne.FalseArm = new [] { flowDecisionActivityOneFalseArmAssign };

            suspendExecutionActivityOne.NextNodes = new List <IDev2Activity> {
                flowDecisionActivityOne
            };

            var suspendExecutionActivityTwo = new SuspendExecutionActivity
            {
                DisplayName = "Suspend Execution",
                UniqueID    = "f72ab5fe-efc9-46c5-8944-f2032f0613eb",
            };

            fileWriteActivityOne.NextNodes = new List <IDev2Activity> {
                suspendExecutionActivityTwo
            };

            var dev2DecisionStackTwo = new Dev2DecisionStack {
                DisplayText = "If [[a]] Is = 4"
            };
            var flowDecisionActivityTwo = new DsfDecision
            {
                DisplayName = "If [[a]] Is = 4",
                UniqueID    = "9ad7861e-6fe8-449f-8640-92147259f919",
                NextNodes   = null,
                Conditions  = dev2DecisionStackTwo
            };

            var fileWriteActivityTwo = new FileWriteActivity
            {
                DisplayName = "Write File",
                UniqueID    = "88deb70e-ad45-4735-8a87-a77f7eb54d83",
            };

            var flowDecisionActivityTwoFalseArmAssign = new DsfDotNetMultiAssignActivity
            {
                DisplayName = "Assign (1)",
                UniqueID    = "c511b3e4-819f-4c38-81f6-6579ae3f52df",
            };

            var flowDecisionActivityTwoFalseArmFileWrite = new FileWriteActivity
            {
                DisplayName = "Write File",
                UniqueID    = "3c477009-7b12-432f-908c-b0ad613e8c57",
            };

            flowDecisionActivityTwoFalseArmAssign.NextNodes = new List <IDev2Activity> {
                flowDecisionActivityTwoFalseArmFileWrite
            };
            flowDecisionActivityTwoFalseArmFileWrite.NextNodes = new List <IDev2Activity> {
                suspendExecutionActivityTwo
            };

            flowDecisionActivityTwo.NextNodes = null;
            flowDecisionActivityTwo.TrueArm   = new [] { fileWriteActivityTwo };
            flowDecisionActivityTwo.FalseArm  = new [] { flowDecisionActivityTwoFalseArmAssign };

            suspendExecutionActivityTwo.NextNodes = new List <IDev2Activity> {
                flowDecisionActivityTwo
            };

            var activityParser = new ActivityParser();
            var activities     = activityParser.ParseToLinkedFlatList(topLevelActivity);

            Assert.IsNotNull(activities);

            var dev2Activities = activities.ToList();

            Assert.AreEqual(13, dev2Activities.Count);
        }