Esempio n. 1
0
        public static void SaveJsonRecipes(string file, object obj, JsonSchema schema, string pivotKey, int bracketBlockLevel = 3)
        {
            StreamWriter write = new StreamWriter(new FileStream(Path.Combine(workspacePath, file), FileMode.Create));

            try
            {
                StringBuilder sb = new StringBuilder("{\"categories\":[");

                //Unknown stuff

                /*for (int c = 0; c < RecipeUnknown.Count; c++)
                 * {
                 *  Dictionary<string, object> item = RecipeUnknown[c].data;
                 *  string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                 *  sb.Append(schema.Serialize(item, type));
                 *  sb.Append(",");
                 * }*/
                sb.Append("\"" + string.Join("\",\"", CraftCategories) + "\"");

                sb.Append("],\"recipes\":[");

                //Recipes
                foreach (Dictionary <string, object> item in (object[])obj)
                {
                    string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                    sb.Append(schema.Serialize(item, type));
                    sb.Append(",");
                }
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("]}");

                if (FormOptions.DontFormatJson)
                {
                    write.Write(sb.ToString());
                }
                else
                {
                    write.Write(SpaceJson(sb.ToString(), bracketBlockLevel));
                }
            }
            catch (ArgumentException)
            {
                //TODO: error message
                return;
            }
            finally
            {
                write.Close();
            }
        }
Esempio n. 2
0
        public static void SaveJsonRecipes(string file, object obj, JsonSchema schema, string pivotKey, int bracketBlockLevel = 3)
        {
            StreamWriter write = new StreamWriter(new FileStream(file, FileMode.Create));

            try
            {
                StringBuilder sb = new StringBuilder("{\"categories\":[");

                //Categories
                foreach (string cat in CraftCategories)
                {
                    sb.Append('"' + cat + "\",");
                }
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("],\"recipes\":[");

                //Recipes
                foreach (Dictionary <string, object> item in (object[])obj)
                {
                    string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                    sb.Append(schema.Serialize(item, type));
                    sb.Append(",");
                }
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("]}");

                if (Options.DontFormatJson)
                {
                    write.Write(sb.ToString());
                }
                else
                {
                    write.Write(SpaceJson(sb.ToString(), bracketBlockLevel));
                }
            }
            catch (ArgumentException)
            {
                //TODO: error message
                return;
            }
            finally
            {
                write.Close();
            }
        }
Esempio n. 3
0
        public static void SaveJsonItem(string file, object obj, JsonSchema schema, string pivotKey, int bracketBlockLevel = 1)
        {
            //TODO: remove in next version
            if (GetFileType(file) == FileType.SKILLS)
            {
                return;
            }

            StreamWriter write = new StreamWriter(new FileStream(Path.Combine(workspacePath, file), FileMode.Create));

            try
            {
                StringBuilder sb = new StringBuilder("[");
                foreach (Dictionary <string, object> item in (object[])obj)
                {
                    string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                    sb.Append(schema.Serialize(item, type));
                    sb.Append(",");
                }
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("]");

                if (FormOptions.DontFormatJson)
                {
                    write.Write(sb.ToString());
                }
                else
                {
                    write.Write(SpaceJson(sb.ToString(), bracketBlockLevel));
                }
            }
            catch (ArgumentException)
            {
                //TODO: error message
                return;
            }
            finally
            {
                write.Close();
            }
        }
Esempio n. 4
0
        public static void SaveJsonItem(StreamWriter write, object obj, JsonSchema schema, string pivotKey, int bracketBlockLevel = 1)
        {
            try
            {
                StringBuilder sb = new StringBuilder("[");
                foreach (Dictionary<string, object> item in (object[])obj)
                {
                    string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                    sb.Append(schema.Serialize(item, type));
                    sb.Append(",");
                }
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("]");

                if (Options.DontFormatJson)
                    write.Write(sb.ToString());
                else
                    write.Write(SpaceJson(sb.ToString(), bracketBlockLevel));
            }
            catch (ArgumentException)
            {
                //TODO: error message
                return;
            }
        }
Esempio n. 5
0
        public static void SaveJsonRecipes(string file, object obj, JsonSchema schema, string pivotKey, int bracketBlockLevel = 3)
        {
            StreamWriter write = new StreamWriter(new FileStream(Path.Combine(workspacePath, file), FileMode.Create));
            try
            {
                StringBuilder sb = new StringBuilder("{\"categories\":[");

                //Unknown stuff
                /*for (int c = 0; c < RecipeUnknown.Count; c++)
                {
                    Dictionary<string, object> item = RecipeUnknown[c].data;
                    string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                    sb.Append(schema.Serialize(item, type));
                    sb.Append(",");
                }*/
                sb.Append("\"" + string.Join("\",\"", CraftCategories) + "\"");

                sb.Append("],\"recipes\":[");

                //Recipes
                foreach (Dictionary<string, object> item in (object[])obj)
                {
                    string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                    sb.Append(schema.Serialize(item, type));
                    sb.Append(",");
                }
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("]}");

                if (Options.DontFormatJson)
                    write.Write(sb.ToString());
                else
                    write.Write(SpaceJson(sb.ToString(), bracketBlockLevel));
            }
            catch (ArgumentException)
            {
                //TODO: error message
                return;
            }
            finally
            {
                write.Close();
            }
        }
Esempio n. 6
0
        public static void SaveJsonItem(string file, object obj, JsonSchema schema, string pivotKey, int bracketBlockLevel = 1)
        {
            //TODO: remove in next version
            if (GetFileType(file) == FileType.SKILLS)
                return;

            StreamWriter write = new StreamWriter(new FileStream(Path.Combine(workspacePath, file), FileMode.Create));
            try
            {
                StringBuilder sb = new StringBuilder("[");
                foreach (Dictionary<string, object> item in (object[])obj)
                {
                    string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                    sb.Append(schema.Serialize(item, type));
                    sb.Append(",");
                }
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("]");

                if (Options.DontFormatJson)
                    write.Write(sb.ToString());
                else
                    write.Write(SpaceJson(sb.ToString(), bracketBlockLevel));
            }
            catch (ArgumentException)
            {
                //TODO: error message
                return;
            }
            finally
            {
                write.Close();
            }
        }
Esempio n. 7
0
        public static void SaveJsonRecipes(string file, object obj, JsonSchema schema, string pivotKey, int bracketBlockLevel = 3)
        {
            StreamWriter write = new StreamWriter(new FileStream(file, FileMode.Create));
            try
            {
                StringBuilder sb = new StringBuilder("{\"categories\":[");

                //Categories
                foreach (string cat in CraftCategories)
                    sb.Append('"' + cat + "\",");
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("],\"recipes\":[");

                //Recipes
                foreach (Dictionary<string, object> item in (object[])obj)
                {
                    string type = (item.ContainsKey(pivotKey) ? (string)item[pivotKey] : "");
                    sb.Append(schema.Serialize(item, type));
                    sb.Append(",");
                }
                //Remove last comma
                sb.Remove(sb.Length - 1, 1);

                sb.Append("]}");

                if (Options.DontFormatJson)
                    write.Write(sb.ToString());
                else
                    write.Write(SpaceJson(sb.ToString(), bracketBlockLevel));
            }
            catch (ArgumentException)
            {
                //TODO: error message
                return;
            }
            finally
            {
                write.Close();
            }
        }