Ejemplo n.º 1
0
        public static CadData?LoadJson(string fname)
        {
            StreamReader reader = new StreamReader(fname);

            reader.ReadLine(); // skip "{\n"
            string header    = reader.ReadLine();
            Regex  headerPtn = new Regex(@"version=([0-9a-fA-F]+)");

            Match m = headerPtn.Match(header);

            string version = "";

            if (m.Groups.Count >= 1)
            {
                version = m.Groups[1].Value;
            }

            string js = reader.ReadToEnd();

            reader.Close();

            js = js.Trim();
            js = js.Substring(0, js.Length - 1);
            js = "{" + js + "}";

            byte[] bin = MessagePackSerializer.ConvertFromJson(js);

            if (version == "1001")
            {
                MpCadData_v1001 mpcd = MessagePackSerializer.Deserialize <MpCadData_v1001>(bin);

                CadData cd = new CadData(
                    mpcd.GetDB(),
                    mpcd.ViewInfo.WorldScale,
                    mpcd.ViewInfo.PaperSettings.GetPaperPageSize()
                    );

                return(cd);
            }
            else if (version == "1002")
            {
                MpCadData_v1002 mpcd = MessagePackSerializer.Deserialize <MpCadData_v1002>(bin);

                CadData cd = new CadData(
                    mpcd.GetDB(),
                    mpcd.ViewInfo.WorldScale,
                    mpcd.ViewInfo.PaperSettings.GetPaperPageSize()
                    );

                return(cd);
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static void Save(string fname, CadData cd)
        {
            MpCadData_v1002 mpcd = MpUtil_v1002.CreateMpCadData_v1002(cd);

            mpcd.MpDB.GarbageCollect();

            byte[] data = MessagePackSerializer.Serialize(mpcd);

            FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.Write);

            fs.Write(Sign, 0, Sign.Length);
            fs.Write(Version, 0, Version.Length);
            fs.Write(data, 0, data.Length);

            fs.Close();
        }
Ejemplo n.º 3
0
        public static void SaveAsJson(string fname, CadData cd)
        {
            MpCadData_v1002 data = MpUtil_v1002.CreateMpCadData_v1002(cd);
            string          s    = MessagePackSerializer.SerializeToJson(data);

            s = s.Trim();

            s = s.Substring(1, s.Length - 2);

            string ss = @"{" + "\n" +
                        @"""header"":""" + "type=" + JsonSign + "," + "version=" + JsonVersion + @"""," + "\n" +
                        s + "\n" +
                        @"}";

            StreamWriter writer = new StreamWriter(fname);

            writer.Write(ss);

            writer.Close();
        }