Example #1
0
        private void TransformChanges(string pcmModel, string changes, string target, Action <Root_MM06, Root_MM06> compareResults)
        {
            var repository  = new ModelRepository();
            var model       = repository.Resolve(pcmModel + ".xmi");
            var targetModel = PcmToComponentBasedSystems.Transform(model, NMF.Transformations.ChangePropagationMode.OneWay);
            var targetRoot  = targetModel.RootElements[0] as Root_MM06;

            repository.Save(targetModel, string.Format(target, "initial"));

            for (int i = 0; i < PcmChangeGenerator.NumChanges; i++)
            {
                var change   = repository.Resolve(string.Format(changes, i)).RootElements[0] as ModelChangeSet;
                var recorder = new ModelChangeRecorder();
                recorder.Start(targetModel);
                foreach (var subChange in change.Changes)
                {
                    subChange.Apply();
                }
                recorder.Stop();
                if (compareResults != null)
                {
                    compareResults(targetRoot, PcmToComponentBasedSystems.Transform(model, NMF.Transformations.ChangePropagationMode.None).RootElements[0] as Root_MM06);
                }
                var targetChange = recorder.GetModelChanges();
                repository.Save(targetChange, string.Format(target, i));
            }
        }
Example #2
0
        private ModelChangeSet GetDiff <T>(T from, T to)
            where T : class, IModelElement
        {
            var recorder = new ModelChangeRecorder(false);

            recorder.Start(from);
            transformation.Synchronize(ref from, ref to, SynchronizationDirection.RightToLeftForced, ChangePropagationMode.None);
            recorder.Stop();
            return(recorder.GetModelChanges());
        }
Example #3
0
        public void Rollback()
        {
            _recorder.Stop();
            var modelChanges = _recorder.GetModelChanges();

            var inverted = modelChanges.CreateInvertedChangeSet();

            inverted.Apply();

            _engine.RollbackTransaction();
        }
Example #4
0
        public void OperationDoesNotDoAnything()
        {
            var recorder = new ModelChangeRecorder();

            recorder.Start(model);
            b.PullUpFeature("no such feature");
            recorder.Stop();
            var changes = recorder.GetModelChanges();

            Assert.AreEqual(1, changes.Changes.Count);
            Assert.IsInstanceOfType(changes.Changes[0], typeof(OperationCall));
        }
Example #5
0
        public void InvertChangeTransaction()
        {
            var rec = new ModelChangeRecorder(true);

            rec.Start(railway1);

            railway1.Semaphores.RemoveAt(0);
            rec.Stop();
            var changes = rec.GetModelChanges().Changes[0];

            foreach (var inverted in changes.Invert())
            {
                inverted.Apply();
            }

            Assert.AreEqual(railway1.Semaphores.Count, railway2.Semaphores.Count);
        }
Example #6
0
        public void TestPullUpInverted()
        {
            var method   = b.Encapsulates[0];
            var recorder = new ModelChangeRecorder();

            recorder.Start(model);
            b.PullUpFeature("b");
            recorder.Stop();
            var changes = recorder.GetModelChanges();

            Assert.AreEqual(0, b.Encapsulates.Count);

            changes.Invert();

            Assert.AreEqual(1, b.Encapsulates.Count);
            Assert.AreEqual(method, b.Encapsulates[0]);
        }
Example #7
0
 private static void StartNextRecorder(Model model, string target, bool last, ref int i, ref ModelChangeRecorder recorder)
 {
     if (target != null)
     {
         if (recorder != null)
         {
             recorder.Stop();
             var changes = recorder.GetModelChanges();
             (model.Repository as ModelRepository).Save(changes, string.Format(target, i++));
         }
         if (!last)
         {
             recorder = new ModelChangeRecorder();
             recorder.Start(model);
         }
     }
 }
Example #8
0
        public void TestPullUpCorrectlyRecorded()
        {
            var recorder = new ModelChangeRecorder();

            recorder.Start(model);
            b.PullUpFeature("b");
            recorder.Stop();
            var changes = recorder.GetModelChanges();

            Assert.AreEqual(1, changes.Changes.Count);
            Assert.IsInstanceOfType(changes.Changes[0], typeof(ChangeTransaction));
            var t = changes.Changes[0] as ChangeTransaction;

            Assert.IsInstanceOfType(t.SourceChange, typeof(OperationCall));
            var call = t.SourceChange as OperationCall;

            Assert.AreEqual("b", (call.Arguments[0] as ValueArgument).Value);
        }
Example #9
0
        internal void GenerateChanges(Options options)
        {
            Console.WriteLine("Initializing repository");
            var repository = new ModelRepository();

            Console.WriteLine("Loading CIM model");
            cim = repository.Resolve(options.CimPath).RootElements[0] as CIM.CIMRoot;
            Console.WriteLine("Loading COSEM model");
            cosem = repository.Resolve(options.CosemPath).RootElements[0] as COSEM.COSEMRoot;
            Console.WriteLine("Loading Substandard model");
            substation = repository.Resolve(options.SubstationPath).RootElements[0] as SubstationStandard.Substandard;

            Console.WriteLine("Performing changes");

            var actions = new Action[]
            {
                ToggleRandomConnection,
                IncreaseRandomElectricityValues,
                CreateNewMeterAsset,
                DeleteMeterAsset,

                IncreaseMMXUVoltage,
                CreateMMXU,
                ChangeMMXULocation,
                ChangePosition
            };

            var probabilities = new int[]
            {
                10,
                30,
                10,
                10,

                20,
                10,
                5,
                5
            };

            var sum = probabilities.Sum();

            CreateDirectory(options.CimOutPath);
            CreateDirectory(options.CosemOutPath);
            CreateDirectory(options.SubstationOutPath);

            Console.WriteLine("Saving modified CIM model");
            var cimPath = options.CimOutPath + string.Format("-out{0:000}.xmi", 0);

            repository.Save(cim, cimPath);
            cim.Model.ModelUri = new Uri(Path.GetFullPath(cimPath));
            Console.WriteLine("Saving modified COSEM model");
            var cosemPath = options.CosemOutPath + string.Format("-out{0:000}.xmi", 0);

            repository.Save(cosem, cosemPath);
            cosem.Model.ModelUri = new Uri(Path.GetFullPath(cosemPath));
            Console.WriteLine("Saving modified Substandard model");
            var subStandardPath = options.SubstationOutPath + string.Format("-out{0:000}.xmi", 0);

            repository.Save(substation, subStandardPath);
            substation.Model.ModelUri = new Uri(Path.GetFullPath(subStandardPath));

            for (int d = 1; d <= options.Deltas; d++)
            {
                var cimRecorder        = new ModelChangeRecorder();
                var cosemRecorder      = new ModelChangeRecorder();
                var substationRecorder = new ModelChangeRecorder();

                cimRecorder.Start(cim);
                cosemRecorder.Start(cosem);
                substationRecorder.Start(substation);

                Console.WriteLine($"Generating change {d}");
                for (int i = 0; i < options.Changes; i++)
                {
                    var dice = rnd.Next(sum);
                    for (int j = 0; j < actions.Length; j++)
                    {
                        if (dice < probabilities[j])
                        {
                            actions[j]();
                            break;
                        }
                        else
                        {
                            dice -= probabilities[j];
                        }
                    }
                }

                cimRecorder.Stop();
                cosemRecorder.Stop();
                substationRecorder.Stop();

                Console.WriteLine("Saving modified CIM model");
                repository.Serializer.Serialize(cim, options.CimOutPath + string.Format("-out{0:000}.xmi", d));
                Console.WriteLine("Saving modified COSEM model");
                repository.Serializer.Serialize(cosem, options.CosemOutPath + string.Format("-out{0:000}.xmi", d));
                Console.WriteLine("Saving modified Substandard model");
                repository.Serializer.Serialize(substation, options.SubstationOutPath + string.Format("-out{0:000}.xmi", d));

                Console.WriteLine("Saving CIM changes");
                repository.Save(cimRecorder.GetModelChanges(), options.CimOutPath + string.Format("-delta{0:000}.xmi", d));
                Console.WriteLine("Saving COSEM changes");
                repository.Save(cosemRecorder.GetModelChanges(), options.CosemOutPath + string.Format("-delta{0:000}.xmi", d));
                Console.WriteLine("Saving Substandard changes");
                repository.Save(substationRecorder.GetModelChanges(), options.SubstationOutPath + string.Format("-delta{0:000}.xmi", d));
            }
        }