// Encrypt the receipts and save them to file.
        static void ToCache(IList <Receipt> receipts, string gamerUuid)
        {
            OuyaFacade.Log("Caching receipts");
            var json  = new JSONObject();
            var array = new JSONArray();

            foreach (var receipt in receipts)
            {
                var r = new JSONObject();
                r.Put("identifier", receipt.Identifier);
                // PriceInCents is now deprecated. Use LocalPrice and CurrencyCode instead.
                // Retain field for compatibility.
                r.Put("priceInCents", 0);
                r.Put("purchaseDate", receipt.PurchaseDate.ToGMTString());
                r.Put("generatedDate", receipt.GeneratedDate.ToGMTString());
                r.Put("gamerUuid", receipt.Gamer);
                r.Put("uuid", receipt.Uuid);
                r.Put("localPrice", receipt.LocalPrice);
                r.Put("currencyCode", receipt.Currency);
                array.Put(r);
            }
            json.Accumulate("receipts", array);
            var text = json.ToString();
            var encryptedReceipts = CryptoHelper.Encrypt(text, gamerUuid);

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var writer = new StreamWriter(store.OpenFile(receiptsFileName, FileMode.OpenOrCreate)))
                {
                    writer.Write(encryptedReceipts);
                }
            }
        }
Example #2
0
        // Encrypt the receipts and save them to file.
        void ToCache(IList <Receipt> receipts)
        {
            OuyaFacade.Log("Caching receipts");
            var json  = new JSONObject();
            var array = new JSONArray();

            foreach (var receipt in receipts)
            {
                var r = new JSONObject();
                r.Put("identifier", receipt.Identifier);
                r.Put("priceInCents", receipt.PriceInCents);
                r.Put("purchaseDate", receipt.PurchaseDate.ToGMTString());
                r.Put("generatedDate", receipt.GeneratedDate.ToGMTString());
                r.Put("gamerUuid", receipt.Gamer);
                r.Put("uuid", receipt.Uuid);
                array.Put(r);
            }
            json.Accumulate("receipts", array);
            var text = json.ToString();
            var encryptedReceipts = CryptoHelper.Encrypt(text, _gamerUuid);

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var writer = new StreamWriter(store.OpenFile(receiptsFileName, FileMode.OpenOrCreate)))
                {
                    writer.Write(encryptedReceipts);
                }
            }
        }
Example #3
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 07JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Scan the content following the named tag, attaching it to the context.
         * @param x       The JSONXMLTokener containing the source str.
         * @param context The JSONObject that will include the new material.
         * @param name    The tag name.
         * @return true if the close tag is processed.
         * @
         */
        private static bool Parse(JSONXMLTokener x, JSONObject context,
                                  string name)
        {
            JSONObject o;
            string     s;

            // Test for and skip past these forms:
            //      <!-- ... -->
            //      <!   ...   >
            //      <![  ... ]]>
            //      <?   ...  ?>
            // Report errors for these forms:
            //      <>
            //      <=
            //      <<

            var t = x.NextToken();

            // <!

            if (t == (object)BANG)
            {
                var c = x.Next();
                if (c == '-')
                {
                    if (x.Next() == '-')
                    {
                        x.SkipPast("-->");
                        return(false);
                    }
                    x.Back();
                }
                else if (c == '[')
                {
                    t = x.NextToken();
                    if (t.Equals("CDATA"))
                    {
                        if (x.Next() == '[')
                        {
                            s = x.NextCDATA();
                            if (s.Length > 0)
                            {
                                context.Accumulate("content", s);
                            }
                            return(false);
                        }
                    }
                    throw x.SyntaxError("Expected 'CDATA['");
                }
                var i = 1;
                do
                {
                    t = x.NextMeta();
                    if (t == null)
                    {
                        throw x.SyntaxError("Missing '>' after '<!'.");
                    }
                    if (t == (object)LT)
                    {
                        i += 1;
                    }
                    else if (t == (object)GT)
                    {
                        i -= 1;
                    }
                } while (i > 0);
                return(false);
            }
            if (t == (object)QUEST)
            {
                // <?

                x.SkipPast("?>");
                return(false);
            }
            if (t == (object)SLASH)
            {
                // Close tag </

                if (name == null || !x.NextToken().Equals(name))
                {
                    throw x.SyntaxError("Mismatched close tag");
                }
                if (x.NextToken() != (object)GT)
                {
                    throw x.SyntaxError("Misshaped close tag");
                }
                return(true);
            }
            if (t is char)
            {
                throw x.SyntaxError("Misshaped tag");

                // Open tag <
            }
            string n = (string)t;

            t = null;
            o = new JSONObject();
            for (; ;)
            {
                if (t == null)
                {
                    t = x.NextToken();
                }

                // attribute = value

                if (t is string)
                {
                    s = (string)t;
                    t = x.NextToken();
                    if (t == (object)EQ)
                    {
                        t = x.NextToken();
                        if (!(t is string))
                        {
                            throw x.SyntaxError("Missing value");
                        }
                        o.Accumulate(s, t);
                        t = null;
                    }
                    else
                    {
                        o.Accumulate(s, "");
                    }

                    // Empty tag <.../>
                }
                else if (t == (object)SLASH)
                {
                    if (x.NextToken() != (object)GT)
                    {
                        throw x.SyntaxError("Misshaped tag");
                    }
                    context.Accumulate(n, o);
                    return(false);

                    // Content, between <...> and </...>
                }
                else if (t == (object)GT)
                {
                    for (; ;)
                    {
                        t = x.NextContent();
                        if (t == null)
                        {
                            if (name != null)
                            {
                                throw x.SyntaxError("Unclosed tag " + name);
                            }
                            return(false);
                        }
                        if (t is string)
                        {
                            s = (string)t;
                            if (s.Length > 0)
                            {
                                o.Accumulate("content", s);
                            }

                            // Nested element
                        }
                        else if (t == (object)LT)
                        {
                            if (Parse(x, o, n))
                            {
                                if (o.Length() == 0)
                                {
                                    context.Accumulate(n, "");
                                }
                                else if (o.Length() == 1 &&
                                         o.Opt("content") != null)
                                {
                                    context.Accumulate(n, o.Opt("content"));
                                }
                                else
                                {
                                    context.Accumulate(n, o);
                                }
                                return(false);
                            }
                        }
                    }
                }
                else
                {
                    throw x.SyntaxError("Misshaped tag");
                }
            }
        }