internal RuntimeConfig(string configKey)
 {
     this.configKey  = configKey;
     config          = new RCConfig(configKey);
     metadata        = new RCConfig(configKey + "Metadata");
     origin          = ConfigOrigin.Default;
     config.Updated += Config_Updated;
 }
Esempio n. 2
0
        private static void OnRawResponseReturned(ConfigOrigin origin, Dictionary <string, string> headers, string body)
        {
            if (body == null || headers == null)
            {
                return;
            }
            var configResponse = new ConfigResponse()
            {
                requestOrigin = origin,
                status        = ConfigRequestStatus.Pending
            };

            foreach (var validationFunc in rawResponseValidators)
            {
                if (validationFunc(headers, body) == false)
                {
                    configResponse.status = ConfigRequestStatus.Failed;
                    requestStatus         = configResponse.status;
                    FetchCompleted?.Invoke(configResponse);
                    return;
                }
            }

            RawResponseValidated?.Invoke(origin, headers, body);


            JObject responseJObj = null;

            try
            {
                responseJObj          = JObject.Parse(body);
                configResponse.status = ConfigRequestStatus.Success;
            }
            catch
            {
                configResponse.status = ConfigRequestStatus.Failed;
            }
            ResponseParsed?.Invoke(configResponse, responseJObj);

            requestStatus = configResponse.status;
            FetchCompleted?.Invoke(configResponse);
        }
Esempio n. 3
0
 static void SaveCache(ConfigOrigin origin, Dictionary <string, string> headers, string result)
 {
     if (origin == ConfigOrigin.Remote)
     {
         try
         {
             using (StreamWriter writer = File.CreateText(Path.Combine(Application.persistentDataPath, "RemoteConfig.json")))
             {
                 writer.Write(result);
             }
             using (StreamWriter writer = File.CreateText(Path.Combine(Application.persistentDataPath, "RemoteConfigHeaders.json")))
             {
                 writer.Write(JsonConvert.SerializeObject(headers));
             }
         }
         catch (Exception e)
         {
             Debug.LogError(e);
         }
     }
 }
 void Config_Updated(bool wasUpdatedFromServer)
 {
     origin = wasUpdatedFromServer ? ConfigOrigin.Remote : ConfigOrigin.Cached;
 }