Billing.PurchaseDatabase.UpdatePurchase C# (CSharp) Метод

UpdatePurchase() приватный Метод

private UpdatePurchase ( string orderId, string productId, Consts purchaseState, long purchaseTime, string developerPayload ) : int
orderId string
productId string
purchaseState Consts
purchaseTime long
developerPayload string
Результат int
        public virtual int UpdatePurchase(string orderId, string productId, Consts.PurchaseState purchaseState, long purchaseTime, string developerPayload)
        {
            InsertOrder(orderId, productId, purchaseState, purchaseTime, developerPayload);
            ICursor cursor = mDb.Query(PURCHASE_HISTORY_TABLE_NAME, HISTORY_COLUMNS, HISTORY_PRODUCT_ID_COL + "=?", new string[] { productId }, null, null, null, null);
            if (cursor == null)
            {
                return 0;
            }
            int quantity = 0;
            try
            {
                // Count the number of times the product was purchased
                while (cursor.MoveToNext())
                {
                    int stateIndex = cursor.GetInt(2);
                    Consts.PurchaseState state = (Consts.PurchaseState)stateIndex;
                    // Note that a refunded purchase is treated as a purchase. Such
                    // a friendly refund policy is nice for the user.
                    if (state == Consts.PurchaseState.PURCHASED || state == Consts.PurchaseState.REFUNDED)
                    {
                        quantity += 1;
                    }
                }

                // Update the "purchased items" table
                UpdatePurchasedItem(productId, quantity);
            }
            finally
            {
                if (cursor != null)
                {
                    cursor.Close();
                }
            }
            return quantity;
        }

Usage Example

        /// <summary>
        /// Notifies the application of purchase state changes. The application
        /// can offer an item for sale to the user via
        /// <seealso cref="BillingService#requestPurchase(String)"/>. The BillingService
        /// calls this method after it gets the response. Another way this method
        /// can be called is if the user bought something on another device running
        /// this same app. Then Android Market notifies the other devices that
        /// the user has purchased an item, in which case the BillingService will
        /// also call this method. Finally, this method can be called if the item
        /// was refunded. </summary>
        /// <param name="purchaseState"> the state of the purchase request (PURCHASED,
        ///     CANCELED, or REFUNDED) </param>
        /// <param name="productId"> a string identifying a product for sale </param>
        /// <param name="orderId"> a string identifying the order </param>
        /// <param name="purchaseTime"> the time the product was purchased, in milliseconds
        ///     since the epoch (Jan 1, 1970) </param>
        /// <param name="developerPayload"> the developer provided "payload" associated with
        ///     the order </param>
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
        //ORIGINAL LINE: public static void purchaseResponse(final android.content.Context context, final com.example.dungeons.Consts.PurchaseState purchaseState, final String productId, final String orderId, final long purchaseTime, final String developerPayload)
        public static void PurchaseResponse(Context context, Consts.PurchaseState purchaseState, string productId, string orderId, long purchaseTime, string developerPayload)
        {
            // Update the database with the purchase state. We shouldn't do that
            // from the main thread so we do the work in a background thread.
            // We don't update the UI here. We will update the UI after we update
            // the database because we need to read and update the current quantity
            // first.
            //JAVA TO C# CONVERTER TODO TASK: Anonymous inner classes are not converted to C# if the base type is not defined in the code being converted:
            new Thread(new Runnable(() =>
                {
                    PurchaseDatabase db = new PurchaseDatabase(context);
                    int quantity = db.UpdatePurchase(orderId, productId, purchaseState, purchaseTime, developerPayload);
                    db.Close();

                    // This needs to be synchronized because the UI thread can change the
                    // value of sPurchaseObserver.
                    lock (context)
                    {
                        if (sPurchaseObserver != null)
                        {
                            sPurchaseObserver.PostPurchaseStateChange(purchaseState, productId, quantity, purchaseTime, developerPayload);
                        }
                    }
                })).Start();
        }