Пример #1
0
        private void LoadCacheSegmentConfig()
        {
            string text = _storePath + SegmentConfigCacheFilePath;

            if (!File.Exists(text))
            {
                _cachedSegmentConfig = _clientDefaultConfig;
            }
            else
            {
                try
                {
                    using (StreamReader streamReader = new StreamReader(text))
                    {
                        string json = streamReader.ReadToEnd();
                        _cachedSegmentConfig = SegmentConfig.fromJsonDictionary(json);
                    }
                }
                catch (Exception ex)
                {
                    _cachedSegmentConfig = _clientDefaultConfig;
                    UnityEngine.Debug.LogError("autotune error processing cached config file: " + text + " , error: " + ex);
                }
            }
        }
Пример #2
0
        private void wc_UploadDataCompleted(object sender,
                                            UploadDataCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                Debug.Log("autotune request canceled");
                lock (this)
                {
                    _isError      = true;
                    _updateNeeded = true;
                }
            }
            else if (e.Error != null)
            {
                // something happened, send the default config
                Debug.Log("autotune request error: ");
                Debug.LogError(e.Error);

                lock (this)
                {
                    _isError      = true;
                    _updateNeeded = true;
                }
            }
            else
            {
                try {
                    var jsonStr = System.Text.Encoding.UTF8.GetString(e.Result);
                    var resp    = Json.Deserialize(jsonStr) as Dictionary <string, object>;
                    Debug.LogFormat("autotune response payload: {0}", jsonStr);
                    var newSegmentConfig = ParseResponse(resp);

                    lock (this)
                    {
                        // configuration changed, save it to file
                        if (_cachedSegmentConfig.config_hash != newSegmentConfig.config_hash)
                        {
                            CacheSegmentConfig(newSegmentConfig);
                        }
                        else
                        {
                            // TODO - remove once server provided hash is in place
                            CacheSegmentConfig(newSegmentConfig);
                        }

                        _cachedSegmentConfig = newSegmentConfig;
                        _updateNeeded        = true;
                    }
                }
                catch (Exception ex) {
                    Debug.LogError("autotune error parsing response: " + ex);
                    lock (this)
                    {
                        _isError      = true;
                        _updateNeeded = true;
                    }
                }
            }
        }
Пример #3
0
 private void wc_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
 {
     if (e.Cancelled)
     {
         lock (this)
         {
             _isError      = true;
             _updateNeeded = true;
         }
     }
     else if (e.Error != null)
     {
         UnityEngine.Debug.LogError(e.Error);
         lock (this)
         {
             _isError      = true;
             _updateNeeded = true;
         }
     }
     else
     {
         try
         {
             string @string = Encoding.UTF8.GetString(e.Result);
             Dictionary <string, object> response = Json.Deserialize(@string) as Dictionary <string, object>;
             SegmentConfig segmentConfig          = ParseResponse(response);
             lock (this)
             {
                 if (_cachedSegmentConfig.config_hash != segmentConfig.config_hash)
                 {
                     CacheSegmentConfig(segmentConfig);
                 }
                 else
                 {
                     CacheSegmentConfig(segmentConfig);
                 }
                 _cachedSegmentConfig = segmentConfig;
                 _updateNeeded        = true;
             }
         }
         catch (Exception arg)
         {
             UnityEngine.Debug.LogError("autotune error parsing response: " + arg);
             lock (this)
             {
                 _isError      = true;
                 _updateNeeded = true;
             }
         }
     }
     _requestTime = getCurrentTimestamp() - _startTime;
 }
Пример #4
0
        private void CacheSegmentConfig(SegmentConfig config)
        {
            string path = _storePath + AutoTuneDir;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string path2 = _storePath + SegmentConfigCacheFilePath;

            using (StreamWriter streamWriter = new StreamWriter(path2))
            {
                streamWriter.Write(config.ToJsonDictionary());
            }
        }
Пример #5
0
        private void CacheSegmentConfig(SegmentConfig config)
        {
            var dirPath = _storePath + AutoTuneDir;

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            var filePath = _storePath + SegmentConfigCacheFilePath;

            Debug.Log("autotune storing segment config to file: " + filePath);
            using (var writer = new StreamWriter(filePath)) {
                writer.Write(config.ToJsonDictionary());
            }
        }
Пример #6
0
        public static T GetValue <T>(string key, T defValue)
        {
            SegmentConfig cachedSegmentConfig = GetInstance()._cachedSegmentConfig;

            try
            {
                if (cachedSegmentConfig == null)
                {
                    return(defValue);
                }
                if (cachedSegmentConfig.settings.ContainsKey(key))
                {
                    return((T)cachedSegmentConfig.settings[key]);
                }
                return(defValue);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogException(e);
                return(defValue);
            }
        }
Пример #7
0
        /// <summary>
        /// Loads from file.
        /// On failure this defaults to use client default setting.
        /// </summary>
        private void LoadCacheSegmentConfig()
        {
            var filePath = _storePath + SegmentConfigCacheFilePath;

            if (!File.Exists(filePath))
            {
                _cachedSegmentConfig = _clientDefaultConfig;
                Debug.Log("autotune did not find cached config in path: " + filePath);
                return;
            }

            try {
                using (var reader = new StreamReader(filePath)) {
                    var json = reader.ReadToEnd();
                    _cachedSegmentConfig = SegmentConfig.fromJsonDictionary(json);
                    Debug.Log("autotune loaded cached config: " + json);
                }
            }
            catch (Exception ex) {
                // for any issues with the file, use client defaults
                _cachedSegmentConfig = _clientDefaultConfig;
                Debug.LogError("autotune error processing cached config file: " + filePath + " , error: " + ex);
            }
        }
Пример #8
0
 public void Update()
 {
     if (_updateNeeded && _callback != null)
     {
         SegmentConfig cachedSegmentConfig = _cachedSegmentConfig;
         DeviceInfo    deviceInfo          = _deviceInfo;
         try
         {
             long  num  = getCurrentTimestamp() - _startTime;
             float time = Time.time;
             _callback(cachedSegmentConfig.settings, cachedSegmentConfig.group_id);
             if (deviceInfo == null)
             {
                 deviceInfo = new DeviceInfo(_projectId, _buildVersion);
             }
             AnalyticsResult analyticsResult = Analytics.CustomEvent("autotune.SegmentRequestInfo", new Dictionary <string, object>
             {
                 {
                     "segment_id",
                     cachedSegmentConfig.segment_id
                 },
                 {
                     "group_id",
                     cachedSegmentConfig.group_id
                 },
                 {
                     "error",
                     _isError
                 },
                 {
                     "player_override",
                     _isPlayerOverride
                 },
                 {
                     "request_latency",
                     _requestTime
                 },
                 {
                     "callback_latency",
                     num
                 },
                 {
                     "fetch_time",
                     _fetchInGameTime
                 },
                 {
                     "callback_time",
                     time
                 },
                 {
                     "model",
                     deviceInfo.model
                 },
                 {
                     "ram",
                     deviceInfo.ram
                 },
                 {
                     "cpu",
                     deviceInfo.cpu
                 },
                 {
                     "cpu_count",
                     deviceInfo.cpu_count
                 },
                 {
                     "gfx_name",
                     deviceInfo.gfx_name
                 },
                 {
                     "gfx_vendor",
                     deviceInfo.gfx_vendor
                 },
                 {
                     "screen",
                     deviceInfo.screen
                 },
                 {
                     "dpi",
                     deviceInfo.dpi
                 },
                 {
                     "gfx_ver",
                     deviceInfo.gfx_ver
                 },
                 {
                     "gfx_shader",
                     deviceInfo.gfx_shader
                 },
                 {
                     "max_texture_size",
                     deviceInfo.max_texture_size
                 },
                 {
                     "os_ver",
                     deviceInfo.os_ver
                 },
                 {
                     "platform_id",
                     deviceInfo.platform_id
                 },
                 {
                     "app_build_version",
                     _buildVersion
                 },
                 {
                     "plugin_version",
                     AutoTuneMeta.version
                 },
                 {
                     "project_id",
                     deviceInfo.project_id
                 },
                 {
                     "environment",
                     _endpoint
                 }
             });
         }
         catch (Exception msg)
         {
             UnityEngine.Debug.LogError(msg);
         }
         finally
         {
             _isError      = false;
             _updateNeeded = false;
         }
     }
 }