Represents a standard model repository
Наследование: IModelRepository
Пример #1
0
        public void A2BTestSuceeds()
        {
            //absolute path is needed for the execution from a junit test
            var absolutePathInputModel1 = "A2B\\SampleInput.xmi";

            //load input models
            var repository = new ModelRepository();
            var inputModel1 = repository.Resolve(absolutePathInputModel1);

            if (inputModel1 == null)
            {
                throw new FileNotFoundException("One of the Input Models was not found");
            }

            var inputModelContainer = new InputModelContainer(inputModel1);
            var outputModelContainer = new OutputModelContainer();

            var direction = SynchronizationDirection.LeftToRight;
            var changePropagartion = ChangePropagationMode.OneWay;
            A2BHelperWithoutContext transformation = new A2BHelperWithoutContext();

            A2BHelperWithoutContext.InputModelContainer = inputModelContainer;

            var context = transformation.Synchronize<InputModelContainer, OutputModelContainer>(transformation.SynchronizationRule<A2BHelperWithoutContext.Model2ModelMainRule>(), ref inputModelContainer, ref outputModelContainer, direction, changePropagartion);
        }
Пример #2
0
 public void LoadRailwayModel()
 {
     repository = new ModelRepository();
     var railwayModel = repository.Resolve(new Uri(BaseUri), "railway.railway").Model;
     Assert.IsNotNull(railwayModel);
     railway = railwayModel.RootElements.Single() as RailwayContainer;
     Assert.IsNotNull(railway);
 }
Пример #3
0
 private RailwayContainer LoadRailwayModel(ModelRepository repository)
 {
     var railwayModel = repository.Resolve(new Uri(BaseUri), "railway.railway").Model;
     Assert.IsNotNull(railwayModel);
     var railway = railwayModel.RootElements.Single() as RailwayContainer;
     Assert.IsNotNull(railway);
     return railway;
 }
Пример #4
0
        public void SerializationIntegration()
        {
            //Load the model
            var repository = new ModelRepository();
            var model = LoadRailwayModel(repository);

            //Create the recorder
            var recorder = new ModelChangeRecorder();
            recorder.Start(model);

            //Change the model
            var route = new Route() { Id = 42 };
            model.Routes.Add(route);
            model.Routes[0].DefinedBy.RemoveAt(0);
            model.Routes[0].DefinedBy[0].Elements.RemoveAt(0);
            model.Semaphores[0].Signal = Signal.FAILURE;

            //Parse the changes
            var changes = recorder.GetModelChanges();

            //Serialize the changes
            var types = changes.TraverseFlat().Select(t => t.GetType()).Distinct();
            var serializer = new XmiSerializer(types);
            string xmi;
            using (var writer = new StringWriter())
            {
                serializer.Serialize(changes, writer);
                xmi = writer.ToString();
            }

            //Deserialize the XMI
            ModelChangeCollection newChanges;
            using (var reader = new StringReader(xmi))
            {
                newChanges = serializer.Deserialize(reader) as ModelChangeCollection;
            }

            Assert.IsNotNull(newChanges);
            //Since model elements don't implement Equals() we can only test for property equality
            var newRoute = ((ListInsertionComposition<IRoute>)((ChangeTransaction)newChanges.Changes[0]).SourceChange).NewElements[0];
            Assert.AreEqual(route.Id, newRoute.Id);
            //We have to leave out the changes with model elements in them when tesing for equality
            CollectionAssert.AreEqual(changes.Changes.Skip(1).ToArray(), newChanges.Changes.Skip(1).ToArray());

            //Load second instance of the model
            var newRepository = new ModelRepository();
            var newModel = LoadRailwayModel(newRepository);

            //Apply changes to the new model
            newChanges.Apply(newRepository);

            Assert.AreEqual(model.Routes.Count, newModel.Routes.Count);
            Assert.AreEqual(model.Routes[0].DefinedBy.Count, newModel.Routes[0].DefinedBy.Count);
            Assert.AreEqual(model.Routes[0].DefinedBy[0].Elements.Count, newModel.Routes[0].DefinedBy[0].Elements.Count);
            Assert.AreEqual(model.Semaphores[0].Signal, newModel.Semaphores[0].Signal);
        }
Пример #5
0
        public static EPackage LoadPackageFromUri(Uri uri)
        {
            var tempRepository = new ModelRepository(repository);
            var modelElement = tempRepository.Resolve(uri);

            var package = modelElement as EPackage;
            if (package != null) return package;

            return modelElement.Model.RootElements.OfType<EPackage>().FirstOrDefault();
        }
Пример #6
0
        public void LoadCrashTest()
        {
            var repository = new ModelRepository();
            var rootModelElement = repository.Resolve(new Uri(BaseUri), "railway.railway");

            ModelElement.EnforceModels = true;

            repository = new ModelRepository();
            rootModelElement = repository.Resolve(new Uri(BaseUri), "railway.railway");
        }
Пример #7
0
 public ModelRepositoryModelCollection(ModelRepository repo)
     : base(repo)
 {
 }
Пример #8
0
 public ModelRepositoryModelCollection(ModelRepository repo) : base(repo)
 {
 }
Пример #9
0
        public static INamespace LoadPackageFromFiles(IList<string> files, string overallName)
        {
            if (files == null || files.Count == 0) return null;

            var packages = new List<INamespace>();

            foreach (var ecoreFile in files)
            {
                if (Path.GetExtension(ecoreFile) == ".ecore")
                {
                    try
                    {
                        var package = EcoreInterop.LoadPackageFromFile(ecoreFile);
                        if (package != null) packages.Add(EcoreInterop.Transform2Meta(package));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred reading the Ecore file. The error message was: " + ex.Message);
                    }
                }
                else if (Path.GetExtension(ecoreFile) == ".nmf")
                {
                    try
                    {
                        var repository = new ModelRepository();
                        packages.AddRange(repository.Resolve(ecoreFile).RootElements.OfType<INamespace>());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred reading the NMeta file. The error message was: " + ex.Message);
                    }
                }
            }

            if (packages.Count == 0)
            {
                return null;
            }
            else if (packages.Count == 1)
            {
                return packages.First();
            }
            else
            {
                var package = new Namespace() { Name = overallName };
                package.ChildNamespaces.AddRange(packages);
                return package;
            }
        }
Пример #10
0
 public void LoadModel()
 {
     familiesToPersons = new FamiliesToPersons();
     familiesToPersons.Initialize();
     repository = new ModelRepository();
     familyModel = repository.Resolve("SampleFamilies.xmi");
 }
Пример #11
0
        public static INamespace LoadPackageFromFiles(IList<string> files, string overallName, IDictionary<Uri, string> resolveMappings)
        {
            if (files == null || files.Count == 0) return null;

            var packages = new List<INamespace>();
            var repository = new ModelRepository(EcoreInterop.Repository);

            if (resolveMappings != null)
            {
                repository.Locators.Add(new FileMapLocator(resolveMappings));
            }

            foreach (var ecoreFile in files)
            {
                if (Path.GetExtension(ecoreFile) == ".ecore")
                {
            #if DEBUG
                    var model = repository.Resolve(ecoreFile);
                    var ePackages = model.RootElements.OfType<EPackage>();
                    foreach (var ePackage in ePackages)
                    {
                        packages.Add(EcoreInterop.Transform2Meta(ePackage));
                    }
            #else
                    try
                    {
                        var ePackages = repository.Resolve(ecoreFile).RootElements.OfType<EPackage>();
                        foreach (var ePackage in ePackages)
                        {
                            packages.Add(EcoreInterop.Transform2Meta(ePackage));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred reading the Ecore file. The error message was: " + ex.Message);
                        Environment.ExitCode = 1;
                    }
            #endif
                }
                else if (Path.GetExtension(ecoreFile) == ".nmf" || Path.GetExtension(ecoreFile) == ".nmeta")
                {
            #if DEBUG
                    packages.AddRange(repository.Resolve(ecoreFile).RootElements.OfType<INamespace>());
            #else
                    try
                    {
                        packages.AddRange(repository.Resolve(ecoreFile).RootElements.OfType<INamespace>());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred reading the NMeta file. The error message was: " + ex.Message);
                        Environment.ExitCode = 1;
                    }
            #endif
                }
            }

            if (packages.Count == 0)
            {
                throw new InvalidOperationException("No package could be found.");
            }
            else if (packages.Count == 1)
            {
                return packages.First();
            }
            else
            {
                var package = new Namespace() { Name = overallName };
                package.ChildNamespaces.AddRange(packages);
                return package;
            }
        }