コード例 #1
0
 internal RuntimeConfig(string configKey)
 {
     this.configKey  = configKey;
     config          = new RCConfig(configKey);
     metadata        = new RCConfig(configKey + "Metadata");
     origin          = ConfigOrigin.Default;
     config.Updated += Config_Updated;
 }
コード例 #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);
        }
コード例 #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);
         }
     }
 }
コード例 #4
0
 void Config_Updated(bool wasUpdatedFromServer)
 {
     origin = wasUpdatedFromServer ? ConfigOrigin.Remote : ConfigOrigin.Cached;
 }