Пример #1
0
        //METHODS
        #region Methods

        /*
         * This method has the responsbility of ensuring that all the file generation is completed
         * successfully.
         */
        public void CreateFiles(object observer)
        {
            List<UMLFile> files;
            List<IUMLElement> rootItems;
            UMLPackage package;
            bool obsValid = false;

            if (observer != null) 
            {
                if (observer is IGenerationStageObserver)
                {
                    obsValid = true;
                }
            }

            //1. Setup the environment
            UMLModelCollection models = UMLProject.GetInstance().GetUMLModels();

            //find if package-root already exists
            UMLModel pkgRoot = models.Find(FindPackageRoot);
            if (pkgRoot == null)
            {
                pkgRoot = new UMLModel();
                pkgRoot.Name = this._packageRoot;
                pkgRoot.Owner = UMLProject.GetInstance();  
                pkgRoot.Save();
            }

            //find if package already exists
            rootItems = pkgRoot.GetOwnedElements();
            package = (UMLPackage)(rootItems.Find(FindPackage));
            if (package != null)
            {
                package.Delete();
            }
            package = new UMLPackage();
            package.Owner = pkgRoot;
            package.Name = this._packageName;
            package.Save();

            if (obsValid == true)
            {
                ((IGenerationStageObserver)observer).setStage(1);
            }

            //2. Analyze the model
            UMLClassCollection classes = UMLProject.GetInstance().GetUMLClasses();
            IDictionary relationships = HelperRelationships.GetRelationships((UMLClassCollection)classes);
            files = analyzer.CreateFiles(relationships);

            if (obsValid == true)
            {
                ((IGenerationStageObserver)observer).setStage(2);
            }


            //3. Save the files to StarUML
            foreach (UMLFile file in files)
            {
                file.Owner = package;
                file.Stereotype = TUPUX.Entity.Constants.UMLFile.STEREOTYPE;
                file.Save();
                foreach (UMLAttribute a in file.Attributes)
                {
                    a.Owner = file;
                    a.Save();
                }
            }

            if (obsValid == true)
            {
                ((IGenerationStageObserver)observer).setStage(3);
            }

        }
Пример #2
0
        //METHODS
        #region Methods

        /*
         * This method has the responsbility of ensuring that all the file generation is completed
         * successfully.
         */
        public void CreateFiles(object observer)
        {
            List <UMLFile>     files;
            List <IUMLElement> rootItems;
            UMLPackage         package;
            bool obsValid = false;

            if (observer != null)
            {
                if (observer is IGenerationStageObserver)
                {
                    obsValid = true;
                }
            }

            //1. Setup the environment
            UMLModelCollection models = UMLProject.GetInstance().GetUMLModels();

            //find if package-root already exists
            UMLModel pkgRoot = models.Find(FindPackageRoot);

            if (pkgRoot == null)
            {
                pkgRoot       = new UMLModel();
                pkgRoot.Name  = this._packageRoot;
                pkgRoot.Owner = UMLProject.GetInstance();
                pkgRoot.Save();
            }

            //find if package already exists
            rootItems = pkgRoot.GetOwnedElements();
            package   = (UMLPackage)(rootItems.Find(FindPackage));
            if (package != null)
            {
                package.Delete();
            }
            package       = new UMLPackage();
            package.Owner = pkgRoot;
            package.Name  = this._packageName;
            package.Save();

            if (obsValid == true)
            {
                ((IGenerationStageObserver)observer).setStage(1);
            }

            //2. Analyze the model
            UMLClassCollection classes       = UMLProject.GetInstance().GetUMLClasses();
            IDictionary        relationships = HelperRelationships.GetRelationships((UMLClassCollection)classes);

            files = analyzer.CreateFiles(relationships);

            if (obsValid == true)
            {
                ((IGenerationStageObserver)observer).setStage(2);
            }


            //3. Save the files to StarUML
            foreach (UMLFile file in files)
            {
                file.Owner      = package;
                file.Stereotype = TUPUX.Entity.Constants.UMLFile.STEREOTYPE;
                file.Save();
                foreach (UMLAttribute a in file.Attributes)
                {
                    a.Owner = file;
                    a.Save();
                }
            }

            if (obsValid == true)
            {
                ((IGenerationStageObserver)observer).setStage(3);
            }
        }