Esempio n. 1
0
 public JObject ToJSON(string filename)
 {
     BaseClassIfc.SetJsonOptions options = new BaseClassIfc.SetJsonOptions()
     {
     };
     return(ToJSON(filename, options));
 }
Esempio n. 2
0
        public JObject ToJSON(string filename)
        {
            CultureInfo current = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            JObject ifcFile         = new JObject();
            JObject header          = new JObject();
            JObject fileDescription = new JObject();

            fileDescription["description"]          = "ViewDefinition[" + viewDefinition + "]";
            fileDescription["implementation_level"] = "2;1";
            header["FILE_DESCRIPTION"] = fileDescription;
            JObject fileName = new JObject();

            fileName["name"] = filename;
            DateTime now = DateTime.Now;

            fileName["time_stamp"]           = now.Year + "-" + (now.Month < 10 ? "0" : "") + now.Month + "-" + (now.Day < 10 ? "0" : "") + now.Day + "T" + (now.Hour < 10 ? "0" : "") + now.Hour + ":" + (now.Minute < 10 ? "0" : "") + now.Minute + ":" + (now.Second < 10 ? "0" : "") + now.Second;
            fileName["author"]               = System.Environment.UserName;
            fileName["organization"]         = IfcOrganization.Organization;
            fileName["preprocessor_version"] = mFactory.ToolkitName;
            fileName["originating_system"]   = Factory.ApplicationFullName;
            fileName["authorization"]        = "None";
            header["FILE_NAME"]              = fileName;
            JObject fileSchema = new JObject();

            fileSchema["schema_identifiers"] = mRelease == ReleaseVersion.IFC2x3 ? "IFC2X3" : "IFC4";
            header["FILE_SCHEMA"]            = fileSchema;
            ifcFile["HEADER"] = header;

            JArray     data    = new JArray();
            IfcContext context = this.mContext;

            BaseClassIfc.SetJsonOptions options = new BaseClassIfc.SetJsonOptions()
            {
                LengthDigitCount = mLengthDigits, Version = this.Release
            };
            if (context != null)
            {
                JObject jcontext = context.getJson(null, options);                 //null);//
                data.Add(jcontext);
            }
            if (context == null || (context.mIsDecomposedBy.Count == 0 && context.Declares.Count == 0))
            {
                foreach (BaseClassIfc e in this)
                {
                    if (!string.IsNullOrEmpty(e.mGlobalId))
                    {
                        if (!options.Encountered.Contains(e.mGlobalId))
                        {
                            data.Add(e.getJson(null, options));
                        }
                    }
                    else
                    {
                        NamedObjectIfc named = e as NamedObjectIfc;
                        if (named != null)
                        {
                            data.Add(named.getJson(null, options));
                        }
                    }
                }
            }
            ifcFile["DATA"] = data;
            if (!string.IsNullOrEmpty(filename))
            {
                StreamWriter sw = new StreamWriter(filename);
#if (DEBUG)
                sw.Write(ifcFile.ToString());
#else
                sw.Write(ifcFile.ToString(Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonConverter[0]));
#endif
                sw.Close();
            }
            Thread.CurrentThread.CurrentUICulture = current;
            return(ifcFile);
        }
Esempio n. 3
0
 public JObject getJson(BaseClassIfc host, BaseClassIfc.SetJsonOptions options)
 {
     return(DatabaseIfc.extract(this));
 }