コード例 #1
0
        internal DDNAImpl(DDNA ddna) : base(ddna)
        {
            string eventStorePath = null;

            if (Settings.UseEventStore)
            {
                eventStorePath = Settings.EVENT_STORAGE_PATH
                                 .Replace("{persistent_path}", Application.persistentDataPath);
                if (!Utils.IsDirectoryWritable(eventStorePath))
                {
                    Logger.LogWarning("Event store path unwritable, event caching disabled.");
                    Settings.UseEventStore = false;
                }
            }

            eventStore = new EventStore(eventStorePath);
            if (Settings.UseEventStore && !eventStore.IsInitialised)
            {
                // failed to access files for some reason
                Logger.LogWarning("Failed to access event store path, event caching disabled.");
                Settings.UseEventStore = false;
                eventStore             = new EventStore(eventStorePath);
            }
            engageCache = new EngageCache(Settings);
            actionStore = new ActionStore(Settings.ACTIONS_STORAGE_PATH
                                          .Replace("{persistent_path}", Application.persistentDataPath));
            ImageMessageStore     = new ImageMessageStore(ddna);
            executionCountManager = new ExecutionCountManager();

            EngageFactory = new EngageFactory(this);
        }
コード例 #2
0
        public void SavePersistsCache()
        {
            uut.Put("dp1", "flavour", "data1");
            uut.Put("dp2", "flavour", "data2");
            uut.Save();

            uut = new EngageCache(settings);
            Expect(uut.Get("dp1", "flavour"), Is.EqualTo("data1"));
            Expect(uut.Get("dp2", "flavour"), Is.EqualTo("data2"));
        }
コード例 #3
0
ファイル: DDNAImpl.cs プロジェクト: Glaedar/deltaDNA-Task
        internal DDNAImpl(DDNA ddna) : base(ddna)
        {
            string eventStorePath = null;

            if (Settings.UseEventStore)
            {
                eventStorePath = Settings.EVENT_STORAGE_PATH
                                 .Replace("{persistent_path}", Application.persistentDataPath);
                if (!Utils.IsDirectoryWritable(eventStorePath))
                {
                    Logger.LogWarning("Event store path unwritable, event caching disabled.");
                    Settings.UseEventStore = false;
                }
            }

            eventStore = new EventStore(eventStorePath);
            if (Settings.UseEventStore && !eventStore.IsInitialised)
            {
                // failed to access files for some reason
                Logger.LogWarning("Failed to access event store path, event caching disabled.");
                Settings.UseEventStore = false;
                eventStore             = new EventStore(eventStorePath);
            }
            engageCache = new EngageCache(Settings);
            actionStore = new ActionStore(Settings.ACTIONS_STORAGE_PATH
                                          .Replace("{persistent_path}", Application.persistentDataPath));
            ImageMessageStore     = new ImageMessageStore(ddna);
            executionCountManager = new ExecutionCountManager();

            #if DDNA_SMARTADS
            // initialise SmartAds so it can register for events
            var smartAds = SmartAds.Instance.Config(engageCache);
            smartAds.transform.parent = gameObject.transform;

            EngageFactory = new EngageFactory(this, smartAds);

            Application.RequestAdvertisingIdentifierAsync(
                (string advertisingId, bool trackingEnabled, string error) => {
                if (trackingEnabled)
                {
                    PlayerPrefs.SetString(DDNA.PF_KEY_ADVERTISING_ID, advertisingId);
                }
            }
                );
            #else
            EngageFactory = new EngageFactory(this, null);
            #endif
        }
コード例 #4
0
        internal static IEnumerator Request(
            MonoBehaviour caller,
            EngageCache cache,
            EngageRequest request,
            EngageResponse response,
            bool useConfigurationTimeout = false)
        {
            string requestJSON = request.ToJSON();
            string url         = DDNA.Instance.ResolveEngageURL(requestJSON);

            HttpRequest httpRequest = new HttpRequest(url);

            httpRequest.HTTPMethod     = HttpRequest.HTTPMethodType.POST;
            httpRequest.HTTPBody       = requestJSON;
            httpRequest.TimeoutSeconds = useConfigurationTimeout ? DDNA.Instance.Settings.HttpRequestConfigurationTimeoutSeconds : DDNA.Instance.Settings.HttpRequestEngageTimeoutSeconds;
            httpRequest.setHeader("Content-Type", "application/json");

            Action <int, string, string> httpHandler = (statusCode, data, error) => {
                if (error == null && statusCode >= 200 && statusCode < 300)
                {
                    cache.Put(request.DecisionPoint, request.Flavour, data);
                }
                else
                {
                    Logger.LogDebug("Engagement failed with " + statusCode + " " + error);
                    var isClientError = statusCode >= 400 && statusCode < 500;
                    var cached        = cache.Get(request.DecisionPoint, request.Flavour);
                    if (cached != null && !isClientError)
                    {
                        Logger.LogDebug("Using cached response");
                        data = "{\"isCachedResponse\":true," + cached.Substring(1);
                    }
                    else
                    {
                        data = "{}";
                    }
                }

                response(data, statusCode, error);
            };

            yield return(caller.StartCoroutine(Network.SendRequest(httpRequest, httpHandler)));
        }
コード例 #5
0
 internal SmartAds Config(EngageCache engageCache)
 {
     this.engageCache = engageCache;
     return(this);
 }
コード例 #6
0
 public void SetUp()
 {
     settings = new Settings();
     uut      = new EngageCache(settings);
 }