Ejemplo n.º 1
0
        public void TestDotNetTypeCreation()
        {
            _MOF mof;
            _UML uml;
            XmiTests.CreateUmlAndMofInstance(out mof, out uml);

            var mofFactory = new MofFactory();
            var dotNetTypeCreator = new DotNetTypeGenerator(mofFactory, uml);
            var dotNetClass = dotNetTypeCreator.CreateTypeFor(typeof(ZipCode));

            Assert.That(dotNetClass.get(_UML._CommonStructure._NamedElement.name), Is.EqualTo("ZipCode"));

            var ownedAttributes = dotNetClass.get(_UML._Classification._Classifier.attribute) as IEnumerable<object>;
            Assert.That(ownedAttributes, Is.Not.Null);

            var asList = ownedAttributes.ToList();
            Assert.That(asList.Count, Is.GreaterThanOrEqualTo(5));

            Assert.That(asList[0] as IElement, Is.Not.Null);
            var firstProperty = (asList[0] as IElement).get(_UML._CommonStructure._NamedElement.name);
            Assert.That(firstProperty, Is.Not.Null);
            Assert.That(firstProperty.ToString(), Is.EqualTo("Id"));

            Assert.That(asList[1] as IElement, Is.Not.Null);
            var secondProperty = (asList[1] as IElement).get(_UML._CommonStructure._NamedElement.name);
            Assert.That(secondProperty, Is.Not.Null);
            Assert.That(secondProperty.ToString(), Is.EqualTo("Zip"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Integrates the Types into the extent
        /// </summary>
        /// <param name="typeExtent">Extent to be used</param>
        public void Into(IExtent typeExtent)
        {
            var layerOfTypes = _dataLayerLogic.GetDataLayerOfExtent(typeExtent);
            var layerOfUml = _dataLayerLogic.GetMetaLayerFor(layerOfTypes);
            var uml = _dataLayerLogic.Get<_UML>(layerOfUml);
            var factory = new MofFactory();

            var typeProvider = new DotNetTypeGenerator(factory, uml);
            var typeForZipCodes = typeProvider.CreateTypeFor(typeof (Model.ZipCode));
            typeExtent.elements().add(typeForZipCodes);
        }
Ejemplo n.º 3
0
        public void Start()
        {
            var typeExtent = _workspaceCollection.FindExtent("dm:///types");
            var layerOfTypes = _dataLayerLogic.GetDataLayerOfExtent(typeExtent);
            var layerOfUml = _dataLayerLogic.GetMetaLayerFor(layerOfTypes);
            var uml = _dataLayerLogic.Get<_UML>(layerOfUml);
            var factory = new MofFactory();

            var typeProvider = new DotNetTypeGenerator(factory, uml);
            var typeForZipCodes = typeProvider.CreateTypeFor(typeof(Model.ZipCode));
            typeExtent.elements().add(typeForZipCodes);
        }
Ejemplo n.º 4
0
        public void TestDotNetTypeCreation()
        {
            _MOF mof;
            _UML uml;
            XmiTests.CreateUmlAndMofInstance(out mof, out uml);

            var mofFactory= new MofFactory();
            var dotNetTypeCreator = new DotNetTypeGenerator(mofFactory, uml);
            var dotNetClass = dotNetTypeCreator.CreateTypeFor(typeof (TestClass));

            Assert.That(dotNetClass.get(_UML._CommonStructure._NamedElement.name), Is.EqualTo("TestClass"));
        }
Ejemplo n.º 5
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);
        }