Save() public method

public Save ( ) : void
return void
Exemplo n.º 1
0
        /// <summary>
        /// Exports file according to format.
        /// </summary>
        /// <param name="filepath">File path to export.</param>
        /// <param name="templates">Optional filter of templates to export.</param>
        /// <param name="views">Optional filter of views to export.</param>
        /// <param name="schemas">Optional filter of schemas to export.</param>
        /// <param name="locales">Optional filter of locales to export.</param>
        public static void DoExport(DocProject docProject, string filepath, DocModelView[] views, string[] locales, Dictionary<long, SEntity> instances)
        {
            string ext = System.IO.Path.GetExtension(filepath).ToLower();

            Dictionary<DocObject, bool> included = null;
            if (views != null)
            {
                included = new Dictionary<DocObject, bool>();
                foreach (DocModelView docView in views)
                {
                    docProject.RegisterObjectsInScope(docView, included);
                }
            }

            switch (ext)
            {
                case ".ifc":
                    using (FormatSPF format = new FormatSPF(filepath, Schema.IFC.SchemaIfc.Types, instances))
                    {
                        format.InitHeaders(docProject.Annotations[0].Code, "IFC4");
                        Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                        Program.ExportIfc(ifcProject, docProject, included);
                        format.Save();
                    }
                    break;

                case ".ifcxml":
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.IFC.IfcProject), "http://www.buildingsmart-tech.org/ifcXML/IFC4"))
                    {
                        Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                        Program.ExportIfc(ifcProject, docProject, included);
                        format.Instance = ifcProject;
                        format.Save();
                    }
                    break;

                case ".mvdxml":
                    using (FormatXML format = new FormatXML(filepath, typeof(mvdXML), mvdXML.DefaultNamespace))
                    {
                        mvdXML mvd = new mvdXML();
                        Program.ExportMvd(mvd, docProject, included);
                        format.Instance = mvd;
                        format.Save();
                    }
                    break;

                case ".cs":
                    using (FormatCSC format = new FormatCSC(filepath))
                    {
                        format.Instance = docProject;
                        format.Save();
                    }
                    break;

                case ".exp":
                    // use currently visible model view(s)
                    using (FormatEXP format = new FormatEXP(filepath))
                    {
                        format.Instance = docProject;
                        format.ModelViews = views;
                        format.Save();
                    }
                    break;

                case ".xsd":
                    // use currently visible model view(s)
                    using (FormatXSD format = new FormatXSD(filepath))
                    {
                        format.Instance = docProject;
                        format.ModelViews = views;
                        format.Save();
                    }
                    break;

                case ".xml": // Express XSD Configuration
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.CNF.configuration), null, Schema.CNF.SchemaCNF.Prefixes))
                    {
                        Schema.CNF.configuration config = new Schema.CNF.configuration();
                        Program.ExportCnf(config, docProject, views, included);
                        format.Instance = config;
                        format.Save();
                    }
                    break;

                case ".txt":
                    // pick locale
                    using (FormatCSV format = new FormatCSV(filepath))
                    {
                        format.Instance = docProject;
                        format.Locales = locales;
                        format.Save();
                    }
                    break;

                case ".sch":
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.SCH.schema), "http://purl.oclc.org/dsdl/schematron"))
                    {
                        Schema.SCH.schema sch = new Schema.SCH.schema();
                        Program.ExportSch(sch, docProject, included);
                        format.Instance = sch;
                        format.Save();
                    }
                    break;
            }

        }
Exemplo n.º 2
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();
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Exports file according to format.
        /// </summary>
        /// <param name="filepath">File path to export.</param>
        /// <param name="templates">Optional filter of templates to export.</param>
        /// <param name="views">Optional filter of views to export.</param>
        /// <param name="schemas">Optional filter of schemas to export.</param>
        /// <param name="locales">Optional filter of locales to export.</param>
        public static void DoExport(DocProject docProject, string filepath, DocModelView[] views, string[] locales, Dictionary<long, SEntity> instances)
        {
            string ext = System.IO.Path.GetExtension(filepath).ToLower();

            Dictionary<DocObject, bool> included = null;
            if (views != null)
            {
                included = new Dictionary<DocObject, bool>();
                foreach (DocModelView docView in views)
                {
                    docProject.RegisterObjectsInScope(docView, included);
                }
            }

            // special case for zip files -- determine based on special naming; make configurable in future
            Type typeExport = null;
            if (filepath.EndsWith("-psd.zip"))
            {
                typeExport = typeof(DocPropertySet);
            }
            else if(filepath.EndsWith("-qto.zip"))
            {
                typeExport = typeof(DocQuantitySet);
            }

            switch (ext)
            {
                case ".ifc":
                    using (FormatSPF format = new FormatSPF(filepath, Schema.IFC.SchemaIfc.Types, instances))
                    {
                        string filename = System.IO.Path.GetFileName(filepath);
                        format.InitHeaders(filename, "IFC4"); // we always use IFC4 (not later schema) for exporting templates, as that is the earliest version required.
                        Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                        Program.ExportIfc(ifcProject, docProject, included);
                        format.Save();
                    }
                    break;

                case ".ifcxml":
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.IFC.IfcProject), "http://www.buildingsmart-tech.org/ifcXML/IFC4"))
                    {
                        Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                        Program.ExportIfc(ifcProject, docProject, included);
                        format.Instance = ifcProject;
                        format.Save();
                    }
                    break;

                case ".mvdxml":
                    using (FormatXML format = new FormatXML(filepath, typeof(mvdXML), mvdXML.DefaultNamespace))
                    {
                        mvdXML mvd = new mvdXML();
                        Program.ExportMvd(mvd, docProject, included);
                        format.Instance = mvd;
                        format.Save();
                    }
                    break;

                case ".cs":
                    using (FormatCSC format = new FormatCSC(filepath))
                    {
                        format.Instance = docProject;
                        format.Save();
                    }
                    break;

                case ".exp":
                    // use currently visible model view(s)
                    using (FormatEXP format = new FormatEXP(filepath))
                    {
                        format.Instance = docProject;
                        format.ModelViews = views;
                        format.Save();
                    }
                    break;

                case ".xsd":
                    // use currently visible model view(s)
                    using (FormatXSD format = new FormatXSD(filepath))
                    {
                        format.Instance = docProject;
                        format.ModelViews = views;
                        format.Save();
                    }
                    break;

                case ".xml": // Express XSD Configuration
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.CNF.configuration), null, Schema.CNF.SchemaCNF.Prefixes))
                    {
                        Schema.CNF.configuration config = new Schema.CNF.configuration();
                        Program.ExportCnf(config, docProject, views, included);
                        format.Instance = config;
                        format.Save();
                    }
                    break;

                case ".txt":
                    // pick locale
                    using (FormatCSV format = new FormatCSV(filepath))
                    {
                        format.Instance = docProject;
                        format.Locales = locales;
                        format.Save();
                    }
                    break;

                case ".sch":
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.SCH.schema), "http://purl.oclc.org/dsdl/schematron"))
                    {
                        Schema.SCH.schema sch = new Schema.SCH.schema();
                        Program.ExportSch(sch, docProject, included);
                        format.Instance = sch;
                        format.Save();
                    }
                    break;

                case ".zip":
                    using (FormatZIP format = new FormatZIP(new System.IO.FileStream(filepath, System.IO.FileMode.Create), docProject, included, typeExport))
                    {
                        format.Save();
                    }
                    break;

            }
        }