Resolve() public method

Resolves the given Uri and returns the model element
public Resolve ( Uri uri, bool loadOnDemand = true ) : IModelElement
uri System.Uri The Uri where to look for the model element
loadOnDemand bool A boolean flag indicating whether the uri should be attempted /// to load, if the model is not already registered with the repository
return IModelElement
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
0
 public void LoadModel()
 {
     familiesToPersons = new FamiliesToPersons();
     familiesToPersons.Initialize();
     repository = new ModelRepository();
     familyModel = repository.Resolve("SampleFamilies.xmi");
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
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;
            }
        }