Exemple #1
0
        /// <summary>
        /// Saves all content to folder hierarchy
        /// </summary>
        /// <param name="project"></param>
        /// <param name="path"></param>
        public static void Save(DocProject project, string path, Dictionary <string, DocObject> mapEntity, FolderStorageOptions options)
        {
            bool bExportSchema    = ((options & FolderStorageOptions.Schemas) != 0);
            bool bExportExchanges = ((options & FolderStorageOptions.Exchanges) != 0);
            bool bExportExamples  = ((options & FolderStorageOptions.Examples) != 0);
            bool bExportLocalize  = ((options & FolderStorageOptions.Localization) != 0);

            Compiler compiler = new Compiler(project, null, null, false);

            System.Reflection.Emit.AssemblyBuilder assembly = compiler.Assembly;

            // -exchanges (or mvd?)
            //  {exchange}.mvdxml - definition
            //  {exchange}.cs     - C# partial classes for capturing exchange --- later
            //  templates.mvdxml - shared templates
            // -figures -- manually added
            // -formats
            //  -json
            //  -step
            //  -ttl
            //  -xml
            // -samples
            //  {sample}.ifcxml - ifcxml is native format for easier browsing, comparing, and validating
            //  {sample}.htm    - documentation for example
            //  {sample}.png    - preview image of example
            //  {sample} - subdirectory if children
            // -schemas
            //  {version}
            //   {schema}
            //    {class}.cs   - definition in C#
            //    {class}.htm  - documentation in HTML
            //    schema.cs    - functions and
            //    schema.htm   - documentation of schema in HTML
            //    schema.svg   - diagram of schema in SVG
            //    templates.ifcxml - property and quantity templates
            //   localization
            //   {locale}.txt    - localized definitions
            //  ifc.csproj

            if (bExportSchema)
            {
                string pathClasses = path + @"\schemas\" + project.GetSchemaIdentifier();
                System.IO.Directory.CreateDirectory(pathClasses);
                FormatCSC.GenerateCode(project, pathClasses, mapEntity, DocCodeEnum.All);

                // generate ifcxml for templates
                DocumentationISO.DoExport(project, null, pathClasses + @"\templates.ifcxml", null, null, DocDefinitionScopeEnum.Default, null, mapEntity);

                // XSD configuration // not needed -- can re-read from C# classes
                //DocumentationISO.DoExport(project, null, pathClasses + @"\xsdconfig.xml", null, null, DocDefinitionScopeEnum.Default, null, mapEntity);
            }

            if (bExportExchanges)
            {
                string pathExchanges = path + @"\exchanges";
                System.IO.Directory.CreateDirectory(pathExchanges);
                foreach (DocModelView docView in project.ModelViews)
                {
                    string pathView = pathExchanges + @"\" + DocumentationISO.MakeLinkName(docView);
                    DocumentationISO.DoExport(project, null, pathView + ".mvdxml", new DocModelView[] { docView }, null, DocDefinitionScopeEnum.Default, null, mapEntity);

                    //... future: once it works flawlessly...FormatCSC.GenerateExchange(project, docView, pathView, mapEntity);
                }
            }

            if (bExportExamples)
            {
                // compile schema into assembly
                Type typeProject = Compiler.CompileProject(project);

                string pathSamples    = path + @"\examples";
                string pathSamplesWeb = "examples";
                System.IO.Directory.CreateDirectory(pathSamples);
                using (StreamWriter writerIndex = new StreamWriter(Stream.Null))                //...pathSamples + @"\index.htm"))
                {
                    writerIndex.WriteLine("<html><body>");

                    writerIndex.WriteLine("<table>");
                    foreach (DocExample docExam in project.Examples)
                    {
                        // generate ifcxml for each sample
                        ExportExample(pathSamples, pathSamplesWeb, typeProject, docExam, writerIndex);
                    }
                    writerIndex.WriteLine("</table>");

                    writerIndex.WriteLine("</body></html>");
                }
            }

            // terms, abbreviations, references, bibliography, ...
#if false
            string pathTerms = path + @"\terms";
            System.IO.Directory.CreateDirectory(pathSamples);
            foreach (DocTerm docTerm in this.m_project.Terms)
            {
            }
#endif

            // localization
            SortedList <string, string> listLocale = new SortedList <string, string>();
            foreach (DocObject eachobj in mapEntity.Values)
            {
                if (eachobj.Localization != null)
                {
                    foreach (DocLocalization doclocal in eachobj.Localization)
                    {
                        // only deal with languages, not regions
                        if (doclocal.Locale != null && doclocal.Locale.Length >= 2)
                        {
                            string language = doclocal.Locale.Substring(0, 2);

                            if (!listLocale.ContainsKey(language))
                            {
                                listLocale.Add(language, doclocal.Locale);
                            }
                        }
                    }
                }
            }

            if (bExportLocalize)
            {
                string pathLocalize = path + @"\localize";
                System.IO.Directory.CreateDirectory(pathLocalize);
                foreach (string locale in listLocale.Keys)
                {
                    string pathLocale = path + @"\localize\" + locale + ".txt";
                    using (FormatCSV format = new FormatCSV(pathLocale))
                    {
                        format.Instance = project;
                        format.Locales  = new string[] { locale };
                        format.Scope    = DocDefinitionScopeEnum.Default;
                        format.Save();
                    }
                }
            }
        }
Exemple #2
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            this.buttonLogin.Enabled = false;

            try
            {
                this.progressBar.Visible = true;
                this.progressBar.Style   = ProgressBarStyle.Marquee;

                this.m_dictionary = DataDictionary.Connect(this.textBoxUrl.Text, this.textBoxUsername.Text, this.textBoxPassword.Text);

                this.comboBoxContext.Items.Clear();
                this.m_contexts = this.m_dictionary.ReadContexts(!this.m_download);
                if (this.m_contexts != null)
                {
                    foreach (string key in this.m_contexts.Keys)
                    {
                        string val = this.m_contexts[key];
                        this.comboBoxContext.Items.Add(val);
                    }
                    if (this.comboBoxContext.Items.Count > 0)
                    {
                        this.comboBoxContext.SelectedIndex = 0;
                        this.comboBoxContext.Enabled       = true;
                    }
                }
                else
                {
                    this.errorProvider.SetError(this.labelError, "The account provided does not have any write access.");
                }

                if (this.m_download)
                {
                    this.progressBar.Style = ProgressBarStyle.Continuous;

                    this.treeViewContainer.Nodes.Clear();

                    Dictionary <string, object> objs = this.m_dictionary.ReadNamespace("BuildingSmart.IFC4X1");
                    foreach (object o in objs.Values)
                    {
                        if (o is string)
                        {
                            TreeNode tnRoot = new TreeNode();
                            tnRoot.Text               = o.ToString();
                            tnRoot.ImageIndex         = 24;
                            tnRoot.SelectedImageIndex = 24;
                            this.treeViewContainer.Nodes.Add(tnRoot);

                            Dictionary <string, object> subs = this.m_dictionary.ReadNamespace(tnRoot.Text);
                            foreach (object s in subs.Values)
                            {
                                if (s is Type)
                                {
                                    Type     t     = (Type)s;
                                    TreeNode tnSub = new TreeNode();
                                    tnSub.Tag                = s;
                                    tnSub.Text               = t.Name;
                                    tnSub.ImageIndex         = 5;
                                    tnSub.SelectedImageIndex = 5;
                                }
                            }

                            //TreeNode tnSub = new TreeNode();
                            //tnSub.Text = "Loading...";
                            //tnRoot.Nodes.Add(tnSub);

                            //tnRoot.Expand(); // was trigger event notification to load
                        }
                    }
                }
                else
                {
                    // generate types
                    this.m_typeProject = Compiler.CompileProject(this.m_project, true);
                    if (this.m_typeProject != null)
                    {
                        // get the root type -- only write types that derive from the semantic base class (IfcRoot)
                        Type typeBase = m_typeProject;
                        while (typeBase.BaseType != null)
                        {
                            typeBase = typeBase.BaseType;
                        }

                        // publish types
                        SortedDictionary <string, SortedDictionary <string, Type> > mapNamespace = new SortedDictionary <string, SortedDictionary <string, Type> >();

                        Type[] types = m_typeProject.Assembly.GetTypes();

                        this.progressBar.Style = ProgressBarStyle.Continuous;

                        foreach (Type t in types)
                        {
                            if (t.IsClass)
                            {
                                SortedDictionary <string, Type> listNS = null;
                                if (!mapNamespace.TryGetValue(t.Namespace, out listNS))
                                {
                                    listNS = new SortedDictionary <string, Type>();
                                    mapNamespace.Add(t.Namespace, listNS);
                                }
                                listNS.Add(t.Name, t);
                            }
                        }

                        foreach (string ns in mapNamespace.Keys)
                        {
                            TreeNode tn = new TreeNode();
                            tn.Tag                = ns;
                            tn.Text               = ns;
                            tn.ImageIndex         = 24;
                            tn.SelectedImageIndex = 24;
                            this.treeViewContainer.Nodes.Add(tn);

                            SortedDictionary <string, Type> listNS = mapNamespace[ns];
                            foreach (string typename in listNS.Keys)
                            {
                                Type     t      = listNS[typename];
                                TreeNode tnType = new TreeNode();
                                tnType.Tag                = t;
                                tnType.Text               = t.Name;
                                tnType.ImageIndex         = 5;
                                tnType.SelectedImageIndex = 5;

                                tn.Nodes.Add(tnType);
                            }
                        }
                    }
                    else
                    {
                        this.errorProvider.SetError(this.labelError, "No data has been defined that can be uploaded.");
                    }
                }
            }
            catch (Exception xx)
            {
                this.progressBar.Style   = ProgressBarStyle.Continuous;
                this.progressBar.Visible = false;
                this.errorProvider.SetError(this.labelError, xx.Message);
            }


            this.buttonOK.Enabled = true;
        }