Exemplo n.º 1
0
 public bool writeProfile(string path, Profiles pro)
 {
     doc = new FileInfo(path);
     try
     {
         //If there is no current file, then create a new one
         if (!File.Exists(path))
         {
             StreamWriter stream = doc.CreateText();
             LitJson.JsonWriter writer = new LitJson.JsonWriter(stream);
             LitJson.JsonMapper.ToJson(pro, writer);
             stream.Close();
             return true;
         }
         else //If there is already a file
         {
             StreamWriter stream = new StreamWriter(doc.FullName);
             LitJson.JsonWriter writer = new LitJson.JsonWriter(stream);
             LitJson.JsonMapper.ToJson(pro, writer);
             stream.Close();
             return true;
         }
     }
     catch (Exception ex)
     {
         MeCore.Dispatcher.Invoke(new System.Windows.Forms.MethodInvoker(delegate
         {
             new ErrorReport(ex).Show();
         }));
         return false;
     }
 }
Exemplo n.º 2
0
        static int __CreateInstance(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (LuaAPI.lua_gettop(L) == 1)
                {
                    LitJson.JsonWriter gen_ret = new LitJson.JsonWriter();
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 2 && translator.Assignable <System.Text.StringBuilder>(L, 2))
                {
                    System.Text.StringBuilder _sb = (System.Text.StringBuilder)translator.GetObject(L, 2, typeof(System.Text.StringBuilder));

                    LitJson.JsonWriter gen_ret = new LitJson.JsonWriter(_sb);
                    translator.Push(L, gen_ret);

                    return(1);
                }
                if (LuaAPI.lua_gettop(L) == 2 && translator.Assignable <System.IO.TextWriter>(L, 2))
                {
                    System.IO.TextWriter _writer = (System.IO.TextWriter)translator.GetObject(L, 2, typeof(System.IO.TextWriter));

                    LitJson.JsonWriter gen_ret = new LitJson.JsonWriter(_writer);
                    translator.Push(L, gen_ret);

                    return(1);
                }
            }
            catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(LuaAPI.luaL_error(L, "invalid arguments to LitJson.JsonWriter constructor!"));
        }
Exemplo n.º 3
0
        public static void ToJson(ISerializable val, LitJson.JsonWriter writer)
        {
            writer.WriteObjectStart();
            var s = new Serializer(writer);

            val.ToJson(s);
            writer.WriteObjectEnd();
        }
Exemplo n.º 4
0
 static void JsonExportPointF(PointF pt, LitJson.JsonWriter writer)
 {
     writer.WriteObjectStart();
     writer.WritePropertyName("X");
     writer.Write(pt.X);
     writer.WritePropertyName("Y");
     writer.Write(pt.Y);
     writer.WriteObjectEnd();
 }
Exemplo n.º 5
0
 public static void ToJson(IList <int> val, LitJson.JsonWriter writer)
 {
     writer.WriteArrayStart();
     foreach (var elem in val)
     {
         ToJson(elem, writer);
     }
     writer.WriteArrayEnd();
 }
Exemplo n.º 6
0
 public static void ToJson(IDictionary <string, LitJson.JsonData> val, LitJson.JsonWriter writer)
 {
     writer.WriteObjectStart();
     foreach (var pair in val)
     {
         writer.WritePropertyName(pair.Key);
         ToJson(pair.Value, writer);
     }
     writer.WriteObjectEnd();
 }
Exemplo n.º 7
0
 public static void ToJson <T>(IList <T> val, LitJson.JsonWriter writer)
     where T : ISerializable
 {
     writer.WriteArrayStart();
     foreach (var elem in val)
     {
         ToJson(elem, writer);
     }
     writer.WriteArrayEnd();
 }
Exemplo n.º 8
0
 public static void ToJson <T>(IDictionary <string, T> val, LitJson.JsonWriter writer)
     where T : ISerializable
 {
     writer.WriteObjectStart();
     foreach (var pair in val)
     {
         writer.WritePropertyName(pair.Key);
         ToJson(pair.Value, writer);
     }
     writer.WriteObjectEnd();
 }
Exemplo n.º 9
0
        static int _s_set_LowerCaseProperties(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                LitJson.JsonWriter gen_to_be_invoked = (LitJson.JsonWriter)translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.LowerCaseProperties = LuaAPI.lua_toboolean(L, 2);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
Exemplo n.º 10
0
        static int _s_set_IndentValue(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                LitJson.JsonWriter gen_to_be_invoked = (LitJson.JsonWriter)translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.IndentValue = LuaAPI.xlua_tointeger(L, 2);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
Exemplo n.º 11
0
        static int _g_get_Validate(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                LitJson.JsonWriter gen_to_be_invoked = (LitJson.JsonWriter)translator.FastGetCSObj(L, 1);
                LuaAPI.lua_pushboolean(L, gen_to_be_invoked.Validate);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(1);
        }
Exemplo n.º 12
0
        public void Save()
        {
            var settings_file = Path.Combine(BaseDir, ProjectName + ".json");

            using (StreamWriter writer = new StreamWriter(settings_file))
            {
                LitJson.JsonWriter jwriter = new LitJson.JsonWriter(writer);
                jwriter.PrettyPrint = true;
                jwriter.IndentValue = 4;
                LitJson.JsonMapper.ToJson(Sprites, jwriter);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a new anonymous stomt on the specified target with an image attached to it.
        /// </summary>
        /// <param name="positive">The stomt type. True for "I like" and false for "I wish".</param>
        /// <param name="target">The target to post the stomt to.</param>
        /// <param name="text">The stomt message.</param>
        /// <param name="image">The image texture to upload and attach to the stomt.</param>
        public void CreateStomtWithImage(bool positive, string target, string text, Texture2D image)
        {
            if (image == null)
            {
                CreateStomt(positive, target, text);
                return;
            }

            byte[] imageBytes = image.EncodeToPNG();

            if (imageBytes == null)
            {
                return;
            }

            var jsonImage   = new StringBuilder();
            var writerImage = new LitJson.JsonWriter(jsonImage);

            writerImage.WriteObjectStart();
            writerImage.WritePropertyName("images");
            writerImage.WriteObjectStart();
            writerImage.WritePropertyName("stomt");
            writerImage.WriteArrayStart();
            writerImage.WriteObjectStart();
            writerImage.WritePropertyName("data");
            writerImage.Write(Convert.ToBase64String(imageBytes));
            writerImage.WriteObjectEnd();
            writerImage.WriteArrayEnd();
            writerImage.WriteObjectEnd();
            writerImage.WriteObjectEnd();

            var jsonStomt   = new StringBuilder();
            var writerStomt = new LitJson.JsonWriter(jsonStomt);

            writerStomt.WriteObjectStart();
            writerStomt.WritePropertyName("anonym");
            writerStomt.Write(true);
            writerStomt.WritePropertyName("positive");
            writerStomt.Write(positive);
            writerStomt.WritePropertyName("target_id");
            writerStomt.Write(target);
            writerStomt.WritePropertyName("text");
            writerStomt.Write(text);
            writerStomt.WritePropertyName("img_name");
            writerStomt.Write("{img_name}");
            writerStomt.WriteObjectEnd();

            StartCoroutine(CreateStomtWithImageAsync(jsonImage.ToString(), jsonStomt.ToString()));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a new anonymous stomt on the specified target.
        /// </summary>
        /// <param name="positive">The stomt type. True for "I like" and false for "I wish".</param>
        /// <param name="target">The target to post the stomt to.</param>
        /// <param name="text">The stomt message.</param>
        public void CreateStomt(bool positive, string target, string text)
        {
            var json   = new StringBuilder();
            var writer = new LitJson.JsonWriter(json);

            writer.WriteObjectStart();
            writer.WritePropertyName("anonym");
            writer.Write(true);
            writer.WritePropertyName("positive");
            writer.Write(positive);
            writer.WritePropertyName("target_id");
            writer.Write(target);
            writer.WritePropertyName("text");
            writer.Write(text);
            writer.WriteObjectEnd();

            StartCoroutine(CreateStomtAsync(json.ToString()));
        }
Exemplo n.º 15
0
        public void InitiliazeConfig(string path)
        {
            var filePath = $"{path}\\PicPrompt.json";

            if (!File.Exists(filePath))
            {
                var writer = new LitJson.JsonWriter();

                writer.WriteObjectStart();
                writer.WritePropertyName("start-with-windows-enabled");
                writer.Write(false);
                writer.WritePropertyName("allow-background-work");
                writer.Write(true);
                writer.WriteObjectEnd();

                File.WriteAllText(filePath, writer.ToString());
            }

            Config.Load(filePath);
        }
Exemplo n.º 16
0
        static int _m_WriteObjectStart(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                LitJson.JsonWriter gen_to_be_invoked = (LitJson.JsonWriter)translator.FastGetCSObj(L, 1);



                {
                    gen_to_be_invoked.WriteObjectStart(  );



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemplo n.º 17
0
        public static void CustomSerialization(Dictionary <string, object> dict, LitJson.JsonWriter jsonWriter)
        {
            jsonWriter.WriteObjectStart();
            foreach (var dictKey in dict.Keys)
            {
                var val = dict[dictKey];

                if (_customTypes.Contains(val.GetType()))
                {
                    // 可以写入的类型
                    jsonWriter.WritePropertyName(dictKey);
                    WriteValue(jsonWriter, val);
                }
                else if (val is Dictionary <string, object> subDic)
                {
                    jsonWriter.WritePropertyName(dictKey);
                    CustomSerialization(subDic, jsonWriter);
                }
            }
            jsonWriter.WriteObjectEnd();
        }
Exemplo n.º 18
0
        static int _m_ToString(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                LitJson.JsonWriter gen_to_be_invoked = (LitJson.JsonWriter)translator.FastGetCSObj(L, 1);



                {
                    string gen_ret = gen_to_be_invoked.ToString(  );
                    LuaAPI.lua_pushstring(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemplo n.º 19
0
        static int _m_WritePropertyName(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                LitJson.JsonWriter gen_to_be_invoked = (LitJson.JsonWriter)translator.FastGetCSObj(L, 1);



                {
                    string _property_name = LuaAPI.lua_tostring(L, 2);

                    gen_to_be_invoked.WritePropertyName(_property_name);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemplo n.º 20
0
        static int _m_ToJson_xlua_st_(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);



                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1 && translator.Assignable <object>(L, 1))
                {
                    object _obj = translator.GetObject(L, 1, typeof(object));

                    string gen_ret = LitJson.JsonMapper.ToJson(_obj);
                    LuaAPI.lua_pushstring(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 2 && translator.Assignable <object>(L, 1) && translator.Assignable <LitJson.JsonWriter>(L, 2))
                {
                    object             _obj    = translator.GetObject(L, 1, typeof(object));
                    LitJson.JsonWriter _writer = (LitJson.JsonWriter)translator.GetObject(L, 2, typeof(LitJson.JsonWriter));

                    LitJson.JsonMapper.ToJson(_obj, _writer);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to LitJson.JsonMapper.ToJson!"));
        }
Exemplo n.º 21
0
        static int _m_ToJson(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                LitJson.JsonMockWrapper gen_to_be_invoked = (LitJson.JsonMockWrapper)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 1)
                {
                    var gen_ret = gen_to_be_invoked.ToJson(  );
                    LuaAPI.lua_pushstring(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 2 && translator.Assignable <LitJson.JsonWriter>(L, 2))
                {
                    LitJson.JsonWriter _writer = (LitJson.JsonWriter)translator.GetObject(L, 2, typeof(LitJson.JsonWriter));

                    gen_to_be_invoked.ToJson(_writer);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to LitJson.JsonMockWrapper.ToJson!"));
        }
Exemplo n.º 22
0
        private void onSaveClicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Settings.Default.DataPath))
            {
                if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                Settings.Default.DataPath = saveFileDialog1.FileName;
            }

            using (StreamWriter streamWriter = new StreamWriter(Settings.Default.DataPath))
            {
                var writer = new LitJson.JsonWriter();
                writer.PrettyPrint = true;
                LitJson.JsonMapper.ToJson(mTableStore, writer);
                string config = writer.ToString();
                streamWriter.Write(config);
            }

            Settings.Default.Save();

            mDirty = false;
        }
Exemplo n.º 23
0
        private static void WriteValue(LitJson.JsonWriter jsonWriter, object val)
        {
            if (jsonWriter == null)
            {
                return;
            }

            if (val is int iVal)
            {
                jsonWriter.Write(iVal);
            }
            else if (val is long lVal)
            {
                jsonWriter.Write(lVal);
            }
            else if (val is ulong ulVal)
            {
                jsonWriter.Write(ulVal);
            }
            else if (val is double doVal)
            {
                jsonWriter.Write(doVal);
            }
            else if (val is decimal deVal)
            {
                jsonWriter.Write(deVal);
            }
            else if (val is bool bVal)
            {
                jsonWriter.Write(bVal);
            }
            else if (val is string sVal)
            {
                jsonWriter.Write(sVal);
            }
        }
Exemplo n.º 24
0
        private void LitJsonSerializationBtn_OnClick(object sender, RoutedEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            LitJson.JsonWriter jsonWriter = new LitJson.JsonWriter(sb);

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic["name"]  = "smx";
            dic["age"]   = 18;
            dic["score"] = 19.9;

            var subDic = new Dictionary <string, object>();

            subDic["chinese"] = 100;
            subDic["math"]    = 99;
            subDic["english"] = 98;

            dic["scores"] = subDic;

            LitJsonUtil.CustomSerialization(dic, jsonWriter);

            Console.WriteLine(sb.ToString());
        }
Exemplo n.º 25
0
        public static void Serialize <T>(System.IO.TextWriter stream, T data)
        {
            var writer = new LitJson.JsonWriter(stream);

            LitJson.JsonMapper.ToJson(data, writer);
        }
Exemplo n.º 26
0
 public Serializer(LitJson.JsonWriter w)
 {
     _writer = w;
 }
Exemplo n.º 27
0
 public static void ToJson(LitJson.JsonData val, LitJson.JsonWriter writer)
 {
     val.ToJson(writer);
 }
Exemplo n.º 28
0
        static int _m_Write(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                LitJson.JsonWriter gen_to_be_invoked = (LitJson.JsonWriter)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 2))
                {
                    bool _boolean = LuaAPI.lua_toboolean(L, 2);

                    gen_to_be_invoked.Write(_boolean);



                    return(0);
                }
                if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
                {
                    double _number = LuaAPI.lua_tonumber(L, 2);

                    gen_to_be_invoked.Write(_number);



                    return(0);
                }
                if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
                {
                    int _number = LuaAPI.xlua_tointeger(L, 2);

                    gen_to_be_invoked.Write(_number);



                    return(0);
                }
                if (gen_param_count == 2 && (LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) || LuaAPI.lua_isint64(L, 2)))
                {
                    long _number = LuaAPI.lua_toint64(L, 2);

                    gen_to_be_invoked.Write(_number);



                    return(0);
                }
                if (gen_param_count == 2 && (LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) || LuaAPI.lua_isuint64(L, 2)))
                {
                    ulong _number = LuaAPI.lua_touint64(L, 2);

                    gen_to_be_invoked.Write(_number);



                    return(0);
                }
                if (gen_param_count == 2 && (LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) || translator.IsDecimal(L, 2)))
                {
                    decimal _number; translator.Get(L, 2, out _number);

                    gen_to_be_invoked.Write(_number);



                    return(0);
                }
                if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
                {
                    string _str = LuaAPI.lua_tostring(L, 2);

                    gen_to_be_invoked.Write(_str);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to LitJson.JsonWriter.Write!"));
        }
Exemplo n.º 29
0
 public static void ToJson(decimal val, LitJson.JsonWriter writer)
 {
     writer.Write(val);
 }
Exemplo n.º 30
0
 public static void Save(ServerInfo cfg = null, string file = null)
 {
     try
     {
         if (cfg == null)
         {
             cfg = MeCore.ServerCfg;
         }
         if (file == null)
         {
             ///for json
             file = MeCore.BaseDirectory + "mtmcl_server_config.json";
             ///for xml
             //file = MeCore.BaseDirectory + "mtmcl_config.xml";
         }
         //var fs = new FileStream(file, FileMode.Create);
         ///for xml
         /*var ser = new DataContractSerializer(typeof(Config));
         ser.WriteObject(fs, cfg);*/
         ///for json
         System.Text.StringBuilder sbuild = new StringBuilder();
         var jw = new LitJson.JsonWriter(sbuild);
         jw.PrettyPrint = true;
         LitJson.JsonMapper.ToJson(cfg, jw);
         File.WriteAllText(file, sbuild.ToString(), Encoding.UTF8);
         //fs.Close();
     }
     catch (Exception e)
     {
         Logger.log(e);
         MessageBox.Show("cannot save server config file");
     }
 }
Exemplo n.º 31
0
 public static void ToJson(ulong val, LitJson.JsonWriter writer)
 {
     writer.Write(val);
 }
Exemplo n.º 32
0
 public static void ToJson(double val, LitJson.JsonWriter writer)
 {
     writer.Write(val);
 }