Esempio n. 1
0
        public void TestFindByUri()
        {
            var workspace = new Workspace<IExtent>("data", "No annotation");

            var extent = new MofUriExtent("http://test/");
            var factory = new MofFactory();
            var element = factory.create(null);
            extent.elements().add(element);

            workspace.AddExtent(extent);

            var elementAsMofElement = (MofElement) element;
            var guid = elementAsMofElement.Id;

            // Now check, if everything is working
            var found = extent.element("http://test/#" + guid);
            Assert.That(found, Is.EqualTo(element));

            var anotherFound = workspace.FindElementByUri("http://test/#" + guid);
            Assert.That(anotherFound, Is.EqualTo(element));
        }
Esempio n. 2
0
        public static void GenerateSourceFor(SourceGeneratorOptions options)
        {
            var uml = new _UML();
            var extent = new MofUriExtent("dm:///sourcegenerator");
            var factory = new MofFactory();

            // Creates the dotnet types to real MOF Types
            var dotNetProvider = new DotNetTypeGenerator(factory, uml);
            var package = factory.create(uml.Packages.__Package);
            package.set("name", options.Name);

            // Do the conversion
            var elements = new List<IElement>();
            foreach (var type in options.Types)
            {
                var typeObject = dotNetProvider.CreateTypeFor(type);
                elements.Add(typeObject);
            }

            package.set(_UML._Packages._Package.packagedElement, elements);

            // Adds the package
            extent.elements().add(package);

            var sourceParser = new ElementSourceParser(uml);

            // Creates the class tree
            var classTreeGenerator = new ClassTreeGenerator(sourceParser)
            {
                Namespace = options.Namespace
            };

            classTreeGenerator.Walk(extent);
            var sourceClass = classTreeGenerator.Result.ToString();

            var pathOfClassTree =
                Path.ChangeExtension(
                    Path.Combine(
                        options.Path,
                        options.Name),
                    ".class.cs");

            File.WriteAllText(pathOfClassTree, sourceClass);

            // Creates now the filler
            var fillerGenerator = new FillClassTreeByExtentCreator(options.Name + "Filler", sourceParser)
            {
                Namespace = options.Namespace,
                ClassNameOfTree = classTreeGenerator.UsedClassName
            };

            fillerGenerator.Walk(extent);
            var sourceFiller = fillerGenerator.Result.ToString();

            var pathOfFillerTree =
                Path.ChangeExtension(
                    Path.Combine(
                        options.Path,
                        options.Name),
                    ".filler.cs");

            File.WriteAllText(pathOfFillerTree, sourceFiller);
        }