Example #1
0
        public void WriteNewtonsoft()
        {
            var serializer = Newtonsoft.Json.JsonSerializer.CreateDefault();
            var writer     = new Newtonsoft.Json.JsonTextWriter(new StreamWriter(Stream.Null))
            {
                ArrayPool = this
            };

            serializer.Serialize(writer, Objects);
            writer.Close();
        }
Example #2
0
        public static void Serialize(System.IO.TextWriter tw, object value)
        {
            // if(value == null)
            System.Type type = value.GetType();

            Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer();

            json.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;

            json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
            json.MissingMemberHandling  = Newtonsoft.Json.MissingMemberHandling.Ignore;
            json.ReferenceLoopHandling  = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

            if (type == typeof(System.Data.DataRow))
            {
                json.Converters.Add(new DataRowConverter());
            }
            else if (type == typeof(System.Data.DataTable))
            {
                json.Converters.Add(new DataTableConverter());
            }
            else if (type == typeof(System.Data.DataSet))
            {
                json.Converters.Add(new DataSetConverter());
            }


            using (Newtonsoft.Json.JsonTextWriter writer = new Newtonsoft.Json.JsonTextWriter(tw))
            {
                // if (this.FormatJsonOutput)
#if DEBUG
                writer.Formatting = Newtonsoft.Json.Formatting.Indented;
#else
                writer.Formatting = Newtonsoft.Json.Formatting.None;
#endif

                writer.QuoteChar = '"';
                json.Serialize(writer, value);

                writer.Flush();
                tw.Flush();

                tw.Close();
                writer.Close();
            } // End Using writer
        }     // End Sub Serialize
Example #3
0
 /// <summary>
 /// Flushes all serialized data to the JSON file, then closes this writer.
 /// </summary>
 public void Dispose()
 {
     writer.WriteEndObject();
     writer.Close();
 }
Example #4
0
        private void SaveData(object sender, EventArgs e)
        {
            try
            {
                if (!System.IO.Directory.Exists(
                    Application.StartupPath + "/_DarkestQuirksBackup/"))
                {
                    System.IO.Directory.CreateDirectory(
                        Application.StartupPath + "/_DarkestQuirksBackup/");
                }

                if (!System.IO.File.Exists(
                    Application.StartupPath + "/_DarkestQuirksBackup/quirk_library.json"))
                {
                    System.IO.File.Move(Application.StartupPath + "/shared/quirk/quirk_library.json",
                        Application.StartupPath + "/_DarkestQuirksBackup/quirk_library.json");
                }
                else goto BACKUPS_EXIST;

                if (!System.IO.File.Exists(
                    Application.StartupPath + "/_DarkestQuirksBackup/quirks.string_table.xml"))
                {
                    System.IO.File.Move(Application.StartupPath + "/localization/quirks.string_table.xml",
                        Application.StartupPath + "/_DarkestQuirksBackup/quirks.string_table.xml");
                }
                else goto BACKUPS_EXIST;

                if (!System.IO.File.Exists(
                    Application.StartupPath + "/_DarkestQuirksBackup/dialogue.string_table.xml"))
                {
                    System.IO.File.Move(Application.StartupPath + "/localization/dialogue.string_table.xml",
                        Application.StartupPath + "/_DarkestQuirksBackup/dialogue.string_table.xml");
                }

                BACKUPS_EXIST:

                using (System.IO.FileStream fs = System.IO.File.OpenWrite(
                    Application.StartupPath + "/shared/quirk/quirk_library.json"))
                using (System.IO.StreamWriter sw =
                    new System.IO.StreamWriter(fs))
                using (Newtonsoft.Json.JsonWriter jw =
                    new Newtonsoft.Json.JsonTextWriter(sw))
                {
                    jw.Formatting = Newtonsoft.Json.Formatting.Indented;

                    Newtonsoft.Json.JsonSerializer js = new Newtonsoft.Json.JsonSerializer();

                    quirk_data.quirks = quirks.ToArray();

                    js.Serialize(jw, quirk_data);

                    jw.Close();
                }

                descriptions.Save(
                    Application.StartupPath + "/localization/quirks.string_table.xml");

                dialogue.Save(
                    Application.StartupPath + "/localization/dialogue.string_table.xml");

                MessageBox.Show("Modifications saved");
            }
            catch //(Exception ex)
            {
                //System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Example #5
0
 public string ToBson()
 {
     StringBuilder sb = new StringBuilder();
     System.IO.StringWriter sWriter = new System.IO.StringWriter(sb);
     Newtonsoft.Json.JsonWriter writer = new Newtonsoft.Json.JsonTextWriter(sWriter);
     Newtonsoft.Json.JsonSerializer jSerial = new Newtonsoft.Json.JsonSerializer();
     writer.Formatting = Newtonsoft.Json.Formatting.None;
     Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer {
         NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
         ContractResolver = new Misc.BSONResolver(),
     };
     serializer.Serialize(writer, this);
     writer.Close();
     sWriter.Close();
     return sb.ToString();
 }