Ejemplo n.º 1
0
        public IParseble Parse(SimpleJSON.JSONNode userNode)
        {
            if (userNode ["requisites"].Count > 1)
            {
                requisites = new Requisites(userNode ["requisites"] ["value"], userNode ["requisites"] ["isVisible"].AsBool, userNode ["requisites"] ["id_allow_modify"].AsBool);
            }
            country = new Country(userNode ["country"] ["value"], userNode ["country"] ["allow_modify"].AsBool);
            local   = userNode ["local"];
            savedPaymentMethodCount = userNode ["savedPaymentMethodCount"].AsInt;
            acceptLanguage          = userNode ["acceptLanguage"];
            acceptEncoding          = userNode ["acceptEncoding"];
            if ((userNode["user_balance"]["currency"] != null) && (userNode["user_balance"]["amount"] != null))
            {
                userBalance = new VirtualUserBalance(userNode["user_balance"]["currency"], userNode["user_balance"]["amount"].AsDecimal);
            }

            if (userNode["virtual_currency_balance"]["amount"] != null)
            {
                if (userNode["virtual_currency_balance"]["amount"] != null)
                {
                    virtualCurrencyBalance = new VirtualCurrencyBalance(userNode["virtual_currency_balance"]["amount"].AsDouble);
                }
            }

            return(this);
        }
Ejemplo n.º 2
0
 public void upload_complete_dialog(int remote_status_code, SimpleJSON.JSONNode response)
 {
     show_dialog(remote_status_code == 200 ? "Upload Complete" : "Upload Error", "", d => {
         if (remote_status_code == 200)
         {
             string craft_url      = response["url"];
             string craft_full_url = KerbalX.api.url_to(craft_url);
             label("Your Craft has been uploaded!", "h2");
             button("It is now available here:\n" + craft_full_url, "hyperlink.bold", () => {
                 Application.OpenURL(craft_full_url);
                 close_dialog();
             });
             button(StyleSheet.assets["logo_large"], "centered", 664, 120, () => {
                 Application.OpenURL(craft_full_url);
                 close_dialog();
             });
             section(() => {
                 fspace();
                 label("click the url or the logo to see your craft on KerbalX", "compact");
             });
         }
         else
         {
             label("There was a problem uploading your craft. Error code " + remote_status_code, "h3");
             label(response); //TODO: make this nicer.
         }
         section(() => {
             fspace();
             button("close", close_dialog);
         });
         return("");
     });
 }
Ejemplo n.º 3
0
        static int _m_FindPlayer(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                GameConfig gen_to_be_invoked = (GameConfig)translator.FastGetCSObj(L, 1);



                {
                    string _playerId = LuaAPI.lua_tostring(L, 2);
                    int    _lv       = LuaAPI.xlua_tointeger(L, 3);

                    SimpleJSON.JSONNode gen_ret = gen_to_be_invoked.FindPlayer(_playerId, _lv);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns an array of string data from the product. [deprecated]
        /// </summary>
        /// <param name="upcCode"></param>
        /// <returns></returns>
        public string[] GetProductDataByUPC(string upcCode)
        {
            string[] productData = new string[5];
            try
            {
                byte[] raw  = client.DownloadData("https://api.barcodelookup.com/v2/products?barcode=" + upcCode + ApiKey);
                string data = Encoding.UTF8.GetString(raw);
                SimpleJSON.JSONNode node = SimpleJSON.JSON.Parse(data);
                productData[0] = node["products"][0]["barcode_number"];
                productData[1] = node["products"][0]["product_name"];
                productData[2] = node["products"][0]["description"];
                productData[3] = node["products"][0]["images"][0];
                //quantity
                productData[4] = "1";

                if (productData[2].Length > 255)
                {
                    productData[2] = productData[2].Substring(0, 255);
                }
                productData[3] = productData[3].Replace("http://", "https://");

                return(productData);
            }
            catch
            {
                productData[0] = "";
                productData[1] = "";
                productData[2] = "";
                productData[3] = "";
                //quantity
                productData[4] = "1";
                ErrorMessage   = "Barcode not recognized";
                return(productData);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns a Product object with data.
        /// </summary>
        /// <param name="upcCode"></param>
        /// <returns></returns>
        public Product GetProductByUPC(string upcCode)
        {
            try
            {
                byte[] raw  = client.DownloadData("https://api.barcodelookup.com/v2/products?barcode=" + upcCode + ApiKey);
                string data = Encoding.UTF8.GetString(raw);
                SimpleJSON.JSONNode node    = SimpleJSON.JSON.Parse(data);
                Product             product = new Product()
                {
                    Barcode     = node["products"][0]["barcode_number"],
                    Name        = node["products"][0]["product_name"],
                    Description = node["products"][0]["description"],
                    Image       = node["products"][0]["images"][0],
                    Quantity    = "1"
                };

                if (product.Description.Length > 255)
                {
                    product.Description = product.Description.Substring(0, 255);
                }
                product.Image = product.Image.Replace("http://", "https://");

                return(product);
            }
            catch
            {
                ErrorMessage = "Barcode not recognized";
                return(new Product()
                {
                    Name = "Barcode not recognized"
                });
            }
        }
Ejemplo n.º 6
0
        public List <Item> GetUserShoppingList(string username)
        {
            string url        = dbUrl + "getshoppinglist";
            string parameters = "{\"username\":\"" + username.ToUpper() + "\",}";

            string jsonShoppingList = request.Post(url, parameters);

            if (jsonShoppingList != null)
            {
                SimpleJSON.JSONNode node = SimpleJSON.JSON.Parse(jsonShoppingList);

                List <Item> shoppingList = new List <Item>();

                for (int i = 0; i < node["shoppinglist"].Count; i++)
                {
                    SimpleJSON.JSONNode item = SimpleJSON.JSON.Parse(node["shoppinglist"][i].ToString());

                    Item shoppingListItem = new Item()
                    {
                        UPC         = item["scanid"],
                        ProductName = item["productname"],
                        Description = item["description"],
                        ImageUrl    = item["imageurl"],
                        Quantity    = item["quantity"],
                    };

                    shoppingList.Add(shoppingListItem);
                }
                return(shoppingList);
            }
            ErrorMessage = request.GetLastErrorMessage();
            return(null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns a list of 6 products to choose from.
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public Product[] GetProductsByKeyword(string keyword)
        {
            Product[] products = new Product[6];
            try
            {
                byte[] raw  = client.DownloadData("https://api.barcodelookup.com/v2/products?search=" + keyword + ApiKey);
                string data = Encoding.UTF8.GetString(raw);
                SimpleJSON.JSONNode node = SimpleJSON.JSON.Parse(data);

                for (int i = 0; i < 6; i++)
                {
                    Product product = new Product()
                    {
                        Image    = node["products"][i]["images"][0],
                        Category = node["products"][i]["category"],
                        Weight   = node["products"][i]["weight"]
                    };
                    product.Image = product.Image.Replace("http://", "https://");
                    products[i]   = product;
                }

                return(products);
            }
            catch
            {
                ErrorMessage = "No Results Found. Try using a simpler search term. (i.e. \"chicken\", \"pork\" etc.)";
                throw new Exception(ErrorMessage);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns inventory products in a 2 dimensional string array. Returns empty array upon error.
        /// </summary>
        /// <returns></returns>
        public string[,] GetUserInventory()
        {
            string url        = dbUrl + "getuserinv";
            string parameters = "{\"username\":\"" + App.Username.ToUpper() + "\",}";

            string jsonInventory = request.Post(url, parameters);

            if (jsonInventory != null)
            {
                SimpleJSON.JSONNode node = SimpleJSON.JSON.Parse(jsonInventory);
                string[,] inventory = new string[node["inventory"].Count, 5];
                for (int i = 0; i < node["inventory"].Count; i++)
                {
                    SimpleJSON.JSONNode item = SimpleJSON.JSON.Parse(node["inventory"][i].ToString());
                    inventory[i, 0] = item["scanid"];
                    inventory[i, 1] = item["productname"];
                    inventory[i, 2] = item["description"];
                    inventory[i, 3] = item["imageurl"];
                    inventory[i, 4] = item["quantity"];
                }
                return(inventory);
            }
            ErrorMessage = request.GetLastErrorMessage();
            return(null);
        }
Ejemplo n.º 9
0
        public Item GetItemFromInventory(string upcCode)
        {
            string url        = dbUrl + "getuserinv";
            string parameters = "{\"username\":\"" + App.Username.ToUpper() + "\",}";

            string jsonInventory = request.Post(url, parameters);

            if (jsonInventory != null)
            {
                SimpleJSON.JSONNode node = SimpleJSON.JSON.Parse(jsonInventory);
                string[,] inventory = new string[node["inventory"].Count, 5];
                for (int i = 0; i < node["inventory"].Count; i++)
                {
                    SimpleJSON.JSONNode item = SimpleJSON.JSON.Parse(node["inventory"][i].ToString());
                    if (item["scanid"] == upcCode)
                    {
                        return(new Item()
                        {
                            UPC = item["scanid"],
                            ProductName = item["productname"],
                            Description = item["description"],
                            ImageUrl = item["imageurl"],
                            Quantity = item["quantity"]
                        });
                    }
                }
            }
            ErrorMessage = request.GetLastErrorMessage();
            return(null);
        }
Ejemplo n.º 10
0
        static int _m_FindEntry(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                GameConfig gen_to_be_invoked = (GameConfig)translator.FastGetCSObj(L, 1);



                {
                    string _configName = LuaAPI.lua_tostring(L, 2);
                    string _columnName = LuaAPI.lua_tostring(L, 3);
                    string _value      = LuaAPI.lua_tostring(L, 4);

                    SimpleJSON.JSONNode gen_ret = gen_to_be_invoked.FindEntry(_configName, _columnName, _value);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Ejemplo n.º 11
0
 void IJsonSs.SetData(SimpleJSON.JSONNode node)
 {
     TextRu        = node.GetString("textRu");
     TextEn        = node.GetString("textEn");
     Transcription = node.GetString("transcription");
     Description   = node.GetString("description");
 }
Ejemplo n.º 12
0
        static public JsonOperationResult ExportPartial(UnityEngine.Component targetComp, JsonModifier jsonModifier)
        {
            // Conver target object to JSON object
            //   (It can take any System.Object as target)
            //   Conver to JSON string from
            string cmpJsonStr = JsonUtility.ToJson(targetComp, false);

            //   Convert to JSON object from JSON string
            SimpleJSON.JSONNode cmpJsonObj = SimpleJSON.JSON.Parse(cmpJsonStr);

            // Prepare export JSON object from template JSON string
            string expJsonTemplate = "{\"format\":\"" + jsonFormatName_partialObject + "\", objectType:null, \"hint\":{}, \"data\":{}";

            SimpleJSON.JSONNode expJsonObj = SimpleJSON.JSON.Parse(expJsonTemplate);

            // Add meta info to export JSON object
            expJsonObj["hint"].Add("PlayerSettings.productName", PlayerSettings.productName);
            var scene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();

            expJsonObj["hint"].Add("scene.name", scene.name);
            expJsonObj["hint"].Add("scene.path", scene.path);
            expJsonObj["hint"].Add("objectPath", IwsdSubInspectorWindow.GetGameObjectPath(targetComp.gameObject));
            expJsonObj["hint"].Add("created", DateTime.UtcNow.ToString("o"));
            expJsonObj.Add("objectType", targetComp.GetType().FullName); // specify type by full name

            // Copy partial elements from target JSON object to export JSON object
            JsonOperationResult r = jsonModifier(cmpJsonObj, expJsonObj);

            // Convert to portable string (from export JSON object to JSON string)
            r.Output = expJsonObj.ToString();

            return(r);

            // TODO use EditorJsonUtility
        }
Ejemplo n.º 13
0
        public static EventActivity FromJson(SimpleJSON.JSONNode activityJsonRootNode)
        {
            EventActivity eventActivity = new EventActivity();

            eventActivity.Id        = activityJsonRootNode[BotJsonProtocol.KeyId];
            eventActivity.Timestamp = Convert.ToDateTime(activityJsonRootNode[BotJsonProtocol.KeyTimestamp]);
            eventActivity.ChannelId = activityJsonRootNode[BotJsonProtocol.KeyChannelId];

            SimpleJSON.JSONNode fromJsonRootNode = activityJsonRootNode[BotJsonProtocol.KeyFrom];

            if (fromJsonRootNode != null)
            {
                eventActivity.FromId   = fromJsonRootNode[BotJsonProtocol.KeyId];
                eventActivity.FromName = fromJsonRootNode[BotJsonProtocol.KeyName];
            }

            SimpleJSON.JSONNode conversationJsonRootNode = activityJsonRootNode[BotJsonProtocol.KeyConversation];

            if (conversationJsonRootNode != null)
            {
                eventActivity.ConversationId = fromJsonRootNode[BotJsonProtocol.KeyId];
            }

            eventActivity.Text      = activityJsonRootNode[BotJsonProtocol.KeyText];
            eventActivity.ReplyToId = activityJsonRootNode[BotJsonProtocol.KeyReplyToId];

            return(eventActivity);
        }
Ejemplo n.º 14
0
 public static void refreshWallet(SimpleJSON.JSONNode data)
 {
     if (onRefreshWallet != null)
     {
         onRefreshWallet(data);
     }
 }
 public static void newPlayer(SimpleJSON.JSONNode name)
 {
     if (onAddPlayer != null)
     {
         onAddPlayer(name);
     }
 }
Ejemplo n.º 16
0
 private int valueToInt(SimpleJSON.JSONNode node, string key, HexState hexState = HexState.NONE)
 {
     if (node[key] == null)
     {
         IsValidMainStats = false;
         return(-1);
     }
     else
     {
         string result = node[key];
         if (hexState == HexState.FIRST)
         {
             string firstDigit = result.Substring(0, 1);
             string remainder  = result.Substring(1, result.Length - 1);
             int    first      = HexToInt(firstDigit) * 100000;
             return(int.Parse(remainder) + first);
         }
         else if (hexState == HexState.LEVEL)
         {
             bool hasLetter = result.Any(x => char.IsLetter(x));
             if (hasLetter)
             {
                 return(HexToInt(result)); //will give "garbage" number
             }
             else
             {
                 return(int.Parse(result));
             }
         }
         else //hexState == HexState.None
         {
             return(int.Parse(result));
         }
     }
 }
Ejemplo n.º 17
0
 public static Plugin_Data FromJSON(SimpleJSON.JSONNode data)
 {
     return(new Plugin_Data()
     {
         NAME = data["name"],
         AUTHOR = data["author"]
     });
 }
Ejemplo n.º 18
0
        public override void WriteEDATA(SimpleJSON.JSONNode inNode)
        {
            base.WriteEDATA(inNode);

            if (duration <= 0)
            {
                inNode["ext"].Remove("duration");
            }
        }
Ejemplo n.º 19
0
        public void SimpleJSONSpeedTest()
        {
            Stopwatch s = new Stopwatch();

            s.Start();
            SimpleJSON.JSONNode n = SimpleJSON.JSONNode.Parse(longlongstring);
            s.Stop();
            Console.WriteLine(s.Elapsed);
        }
Ejemplo n.º 20
0
        public void onChatReceived(ChatEvent eventObj)
        {
            Log(eventObj.getSender() + " sended " + eventObj.getMessage());
            SimpleJSON.JSONNode msg = SimpleJSON.JSON.Parse(eventObj.getMessage());

            if (eventObj.getSender() != appwarp.username)
            {
                appwarp.movePlayer(msg["x"].AsFloat, msg["y"].AsFloat, msg["z"].AsFloat);
            }
        }
Ejemplo n.º 21
0
 public float GetFloat(string path)
 {
     SimpleJSON.JSONNode node = GetNode(path);
     if (null != node)
     {
         return(node.AsFloat);
     }
     Bootstrap.Warn("StaticData.GetFloat() path not found:" + path);
     return(0.0f);
 }
Ejemplo n.º 22
0
 public string GetString(string path)
 {
     SimpleJSON.JSONNode node = GetNode(path);
     if (null != node)
     {
         return(node.Value);
     }
     Bootstrap.Warn("StaticData.GetString() path not found:" + path);
     return("");
 }
Ejemplo n.º 23
0
 private int pieceStatToInt(SimpleJSON.JSONNode node, string key)
 {
     if (node[key] == null)
     {
         IsValidPieceStats = false;
         return(-1);
     }
     else
     {
         return(int.Parse(node[key]));
     }
 }
Ejemplo n.º 24
0
        static int _g_get_AsObject(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                SimpleJSON.JSONNode gen_to_be_invoked = (SimpleJSON.JSONNode)translator.FastGetCSObj(L, 1);
                translator.Push(L, gen_to_be_invoked.AsObject);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(1);
        }
Ejemplo n.º 25
0
        static int _s_set_AsBool(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                SimpleJSON.JSONNode gen_to_be_invoked = (SimpleJSON.JSONNode)translator.FastGetCSObj(L, 1);
                gen_to_be_invoked.AsBool = LuaAPI.lua_toboolean(L, 2);
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
            return(0);
        }
Ejemplo n.º 26
0
 private void levelUp()
 {
     //TODO: Animation
     mLevel++;
     SimpleJSON.JSONNode baseStats = MonsterInfo.getMonsterInfo().baseStats[name]["stats"];
     mAtk   = Mathf.FloorToInt(Mathf.Floor((System.Int32.Parse(baseStats["attack"].ToString().Replace("\"", "")) + ivAtk) * mLevel / 100.0f + 5.0f));
     mDef   = Mathf.FloorToInt(Mathf.Floor((System.Int32.Parse(baseStats["defense"].ToString().Replace("\"", "")) + ivDef) * mLevel / 100.0f + 5.0f));
     mSpAtk = Mathf.FloorToInt(Mathf.Floor((System.Int32.Parse(baseStats["special_attack"].ToString().Replace("\"", "")) + ivSpAtk) * mLevel / 100.0f + 5.0f));
     mSpDef = Mathf.FloorToInt(Mathf.Floor((System.Int32.Parse(baseStats["special_defense"].ToString().Replace("\"", "")) + ivSpDef) * mLevel / 100.0f + 5.0f));
     mSpeed = Mathf.FloorToInt(Mathf.Floor((System.Int32.Parse(baseStats["speed"].ToString().Replace("\"", "")) + ivSpeed) * mLevel / 100.0f + 5.0f));
     mMaxHp = Mathf.FloorToInt((2 * System.Int32.Parse(baseStats["hp"].ToString().Replace("\"", "")) + ivHp) * mLevel / 100.0f + mLevel + 10.0f);
 }
Ejemplo n.º 27
0
 public IParseble Parse(SimpleJSON.JSONNode userNode)
 {
     if (userNode ["requisites"].Count > 1)
     {
         requisites = new Requisites(userNode ["requisites"] ["value"], userNode ["requisites"] ["isVisible"].AsBool);
     }
     country = new Country(userNode ["country"] ["value"], userNode ["country"] ["allow_modify"].AsBool);
     local   = userNode ["local"];
     savedPaymentMethodCount = userNode ["savedPaymentMethodCount"].AsInt;
     acceptLanguage          = userNode ["acceptLanguage"];
     acceptEncoding          = userNode ["acceptEncoding"];
     return(this);
 }
Ejemplo n.º 28
0
 public static string base64ToJson(string paramBase64)
 {
     try
     {
         SimpleJSON.JSONNode node = SimpleJSON.JSONNode.LoadFromBase64(paramBase64);
         return(node.ToString());
     }
     catch (Exception ex)
     {
         Debug.LogError(ex.Message);
         return(paramBase64);
     }
 }
Ejemplo n.º 29
0
 public static string jsonToBase64(string paramJson)
 {
     try
     {
         SimpleJSON.JSONNode node = SimpleJSON.JSON.Parse(paramJson);
         return(node.SaveToBase64());
     }
     catch (Exception ex)
     {
         Debug.LogError(ex.Message);
         return(paramJson);
     }
 }
Ejemplo n.º 30
0
        public IParseble Parse(SimpleJSON.JSONNode rootNode)
        {
            api = new XsollaApi().Parse(rootNode["api"]) as XsollaApi;

            var enumerator = rootNode.Childs.GetEnumerator();

            while (enumerator.MoveNext())
            {
                AddItem(new XsollaManagerSubscription().Parse(enumerator.Current) as XsollaManagerSubscription);
            }

            return(this);
        }
Ejemplo n.º 31
0
        public static bool LoadResources()
        {
            var shapes = UnityEngine.Resources.Load("DataObjects/shapes");
            Shapes = SimpleJSON.JSON.Parse(shapes.ToString());

            var colors = UnityEngine.Resources.Load("DataObjects/colors");
            Colors = SimpleJSON.JSON.Parse(colors.ToString());

            return true;
        }