internal void FetchProducts(Action <List <ProductDefinition> > callback)
 {
     m_AsyncUtil.Get(m_CatalogURL,
                     response =>
     {
         var result = ParseProductsFromJSON(response, m_StoreName, m_Logger);
         if (result == null)
         {
             m_Logger.LogError("Failed to fetch IAP catalog due to malformed response for " + m_StoreName, "response: " + response);
             handleCachedCatalog(callback);
         }
         else
         {
             if (m_cachedStoreCatalogReference != null)
             {
                 m_cachedStoreCatalogReference.Save(response);
             }
             callback(result);
         }
     },
                     error =>
     {
         handleCachedCatalog(callback);
     }
                     );
 }
Example #2
0
 internal void FetchProducts(Action <HashSet <ProductDefinition> > callback, int delayInSeconds)
 {
     m_Logger.Log("Fetching IAP cloud catalog...");
     m_AsyncUtil.Get(m_CatalogURL,
                     response =>
     {
         m_Logger.Log("Fetched catalog");
         try
         {
             var result = ParseProductsFromJSON(response, m_StoreName);
             TryPersistCatalog(response);
             callback(result);
         }
         catch (SerializationException s)
         {
             m_Logger.LogError("Error parsing IAP catalog", s);
             m_Logger.Log(response);
             callback(TryLoadCachedCatalog());
         }
     },
                     error =>
     {
         // Fallback to cache if available,
         // otherwise backoff and retry.
         var cached = TryLoadCachedCatalog();
         if (cached != null && cached.Count > 0)
         {
             m_Logger.Log("Failed to fetch IAP catalog, using cache.");
             callback(cached);
         }
         else
         {
             delayInSeconds = Math.Max(5, delayInSeconds * 2);
             delayInSeconds = Math.Min(kMaxRetryDelayInSeconds, delayInSeconds);
             m_AsyncUtil.Schedule(() => FetchProducts(callback, delayInSeconds), delayInSeconds);
         }
     }
                     );
 }
// this could certainly be generalized and improved significantly...
// and yes, as the name implies we should be queueing these and batch sending retries etc,
//
        internal bool SendEvent(EventDestType dest, string json, string url = null, int?delayInSeconds = null)
        {
            if (m_AsyncUtil == null)
            {
                return(false);
            }

            string target;

            switch (dest)
            {
            case EventDestType.IAP:
                target = (url != null) ? url : EventUrl;
                if ((target == null) || (json == null))
                {
                    break;
                }
                m_AsyncUtil.Post(target, json,
                                 response =>
                {
                    // Console.WriteLine("IAP Event OK");
                },
                                 error =>
                {
                    // Console.WriteLine("IAP Event Failed: " + error);
                    if (delayInSeconds != null)
                    {
                        // This is that weird CloudCatalog retry code, needs improvement
                        delayInSeconds = Math.Max(5, (int)delayInSeconds * 2);
                        delayInSeconds = Math.Min(kMaxRetryDelayInSeconds, (int)delayInSeconds);
                        m_AsyncUtil.Schedule(() => SendEvent(dest, json, target, delayInSeconds), (int)delayInSeconds);
                    }
                }
                                 );
                return(true);

            case EventDestType.AdsTracking:
                target = (url != null) ? url : TrackingUrl;
                if (target == null)
                {
                    break;
                }
                m_AsyncUtil.Get(target,
                                response =>
                {
                    // Console.WriteLine("AdsTracking Event OK");
                },
                                error =>
                {
                    // Console.WriteLine("AdsTracking Event Failed: " + error);
                }
                                );
                return(true);

            case EventDestType.AdsIPC:
                return(AdsIPC.SendEvent(json));

            default:
                return(false);
            }
            return(false);
        }