IfcDoc.FormatCSV.Save C# (CSharp) Méthode

Save() public méthode

public Save ( ) : void
Résultat void
        public void Save()
        {
            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(this.m_filename, false, Encoding.Unicode))
            {
                // header
                writer.Write("Name");
                if (this.m_locales != null)
                {
                    foreach (string locale in this.m_locales)
                    {
                        writer.Write("\tName(");
                        writer.Write(locale);
                        writer.Write(")\tDescription(");
                        writer.Write(locale);
                        writer.Write(")");
                    }
                }
                writer.WriteLine();

                // blank line separates row data
                writer.WriteLine();

                // split into two lists alphabetically for easier translation
                SortedList<string, DocObject> sortlistEntity = new SortedList<string, DocObject>();
                SortedList<string, DocObject> sortlistType = new SortedList<string, DocObject>();
                SortedList<string, DocObject> sortlistPset = new SortedList<string, DocObject>();
                SortedList<string, DocObject> sortlistQset = new SortedList<string, DocObject>();
                SortedList<string, DocObject> sortlistEnum = new SortedList<string, DocObject>();

                // rows
                foreach (DocSection docSection in this.m_project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        if ((this.m_scope & DocDefinitionScopeEnum.Entity) != 0)
                        {
                            foreach (DocEntity docEntity in docSchema.Entities) // have attributes
                            {
                                sortlistEntity.Add(docEntity.Name, docEntity);
                            }
                        }

                        if ((this.m_scope & DocDefinitionScopeEnum.Type) != 0)
                        {
                            foreach (DocType docEntity in docSchema.Types) //docEnumeration docConstant
                            {
                                sortlistType.Add(docEntity.Name, docEntity);
                            }
                        }

                        if ((this.m_scope & DocDefinitionScopeEnum.PEnum) != 0)
                        {
                            foreach (DocPropertyEnumeration docPE in docSchema.PropertyEnums) //docPropertyConstant
                            {
                                sortlistEnum.Add(docPE.Name, docPE);
                            }
                        }

                        if ((this.m_scope & DocDefinitionScopeEnum.Pset) != 0)
                        {
                            foreach (DocPropertySet docPset in docSchema.PropertySets) //Property
                            {
                                sortlistPset.Add(docPset.Name, docPset);
                            }
                        }

                        if ((this.m_scope & DocDefinitionScopeEnum.Qset) != 0)
                        {
                            foreach (DocQuantitySet docQset in docSchema.QuantitySets) //Quantities
                            {
                                sortlistQset.Add(docQset.Name, docQset);
                            }
                        }
                    }
                }

                WriteList(writer, sortlistEntity);
                WriteList(writer, sortlistType);
                WriteList(writer, sortlistPset);
                WriteList(writer, sortlistEnum);
                WriteList(writer, sortlistQset);
            }
        }

Usage Example

        /// <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;
            }

        }
All Usage Examples Of IfcDoc.FormatCSV::Save