[M] sync n3
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ThinkingSDK.PC.Utils;
|
||||
using ThinkingSDK.PC.Request;
|
||||
using ThinkingSDK.PC.Constant;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace ThinkingSDK.PC.Config
|
||||
{
|
||||
public enum Mode
|
||||
{
|
||||
/* normal mode, the data will be stored in the cache and reported in batches */
|
||||
NORMAL,
|
||||
/* debug mode, the data will be reported one by one */
|
||||
DEBUG,
|
||||
/* debug only mode, only verify the data, and will not store it */
|
||||
DEBUG_ONLY
|
||||
}
|
||||
public class ThinkingSDKConfig
|
||||
{
|
||||
private string mToken;
|
||||
private string mServerUrl;
|
||||
private string mNormalUrl;
|
||||
private string mDebugUrl;
|
||||
private string mConfigUrl;
|
||||
private string mInstanceName;
|
||||
private Mode mMode = Mode.NORMAL;
|
||||
private TimeZoneInfo mTimeZone;
|
||||
public int mUploadInterval = 30;
|
||||
public int mUploadSize = 30;
|
||||
private List<string> mDisableEvents = new List<string>();
|
||||
private static Dictionary<string, ThinkingSDKConfig> sInstances = new Dictionary<string, ThinkingSDKConfig>();
|
||||
private ResponseHandle mCallback;
|
||||
private ThinkingSDKConfig(string token,string serverUrl, string instanceName)
|
||||
{
|
||||
//verify server url
|
||||
serverUrl = this.VerifyUrl(serverUrl);
|
||||
this.mServerUrl = serverUrl;
|
||||
this.mNormalUrl = serverUrl + "/sync";
|
||||
this.mDebugUrl = serverUrl + "/data_debug";
|
||||
this.mConfigUrl = serverUrl + "/config";
|
||||
this.mToken = token;
|
||||
this.mInstanceName = instanceName;
|
||||
try
|
||||
{
|
||||
this.mTimeZone = TimeZoneInfo.Local;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//if (ThinkingSDKPublicConfig.IsPrintLog()) ThinkingSDKLogger.Print("TimeZoneInfo initial failed :" + e.Message);
|
||||
}
|
||||
}
|
||||
private string VerifyUrl(string serverUrl)
|
||||
{
|
||||
Uri uri = new Uri(serverUrl);
|
||||
serverUrl = uri.Scheme + "://" + uri.Host + ":" + uri.Port;
|
||||
return serverUrl;
|
||||
}
|
||||
public void SetMode(Mode mode)
|
||||
{
|
||||
this.mMode = mode;
|
||||
}
|
||||
public Mode GetMode()
|
||||
{
|
||||
return this.mMode;
|
||||
}
|
||||
public string DebugURL()
|
||||
{
|
||||
return this.mDebugUrl;
|
||||
}
|
||||
public string NormalURL()
|
||||
{
|
||||
return this.mNormalUrl;
|
||||
}
|
||||
public string ConfigURL()
|
||||
{
|
||||
return this.mConfigUrl;
|
||||
}
|
||||
public string Server()
|
||||
{
|
||||
return this.mServerUrl;
|
||||
}
|
||||
public string InstanceName()
|
||||
{
|
||||
return this.mInstanceName;
|
||||
}
|
||||
public static ThinkingSDKConfig GetInstance(string token, string server, string instanceName)
|
||||
{
|
||||
ThinkingSDKConfig config = null;
|
||||
if (!string.IsNullOrEmpty(instanceName))
|
||||
{
|
||||
if (sInstances.ContainsKey(instanceName))
|
||||
{
|
||||
config = sInstances[instanceName];
|
||||
}
|
||||
else
|
||||
{
|
||||
config = new ThinkingSDKConfig(token, server, instanceName);
|
||||
sInstances.Add(instanceName, config);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sInstances.ContainsKey(token))
|
||||
{
|
||||
config = sInstances[token];
|
||||
}
|
||||
else
|
||||
{
|
||||
config = new ThinkingSDKConfig(token, server, null);
|
||||
sInstances.Add(token, config);
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
public void SetTimeZone(TimeZoneInfo timeZoneInfo)
|
||||
{
|
||||
this.mTimeZone = timeZoneInfo;
|
||||
}
|
||||
public TimeZoneInfo TimeZone()
|
||||
{
|
||||
return this.mTimeZone;
|
||||
}
|
||||
public List<string> DisableEvents() {
|
||||
return this.mDisableEvents;
|
||||
}
|
||||
public bool IsDisabledEvent(string eventName)
|
||||
{
|
||||
if (this.mDisableEvents == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.mDisableEvents.Contains(eventName);
|
||||
}
|
||||
}
|
||||
public void UpdateConfig(MonoBehaviour mono, ResponseHandle callback = null)
|
||||
{
|
||||
mCallback = callback;
|
||||
mono.StartCoroutine(this.GetWithFORM(this.mConfigUrl,this.mToken,null, ConfigResponseHandle));
|
||||
}
|
||||
|
||||
private void ConfigResponseHandle(Dictionary<string, object> result)
|
||||
{
|
||||
try
|
||||
{
|
||||
int code = int.Parse(result["code"].ToString());
|
||||
if (result != null && code == 0)
|
||||
{
|
||||
Dictionary<string, object> data = (Dictionary<string, object>)result["data"];
|
||||
if (ThinkingSDKPublicConfig.IsPrintLog()) ThinkingSDKLogger.Print("Get remote config success: " + ThinkingSDKJSON.Serialize(data));
|
||||
foreach (KeyValuePair<string, object> kv in data)
|
||||
{
|
||||
if (kv.Key == "sync_interval")
|
||||
{
|
||||
this.mUploadInterval = int.Parse(kv.Value.ToString());
|
||||
}
|
||||
else if (kv.Key == "sync_batch_size")
|
||||
{
|
||||
this.mUploadSize = int.Parse(kv.Value.ToString());
|
||||
}
|
||||
else if (kv.Key == "disable_event_list")
|
||||
{
|
||||
foreach (var item in (List<object>)kv.Value)
|
||||
{
|
||||
this.mDisableEvents.Add((string)item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ThinkingSDKPublicConfig.IsPrintLog()) ThinkingSDKLogger.Print("Get remote config failed: " + ThinkingSDKJSON.Serialize(result));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ThinkingSDKPublicConfig.IsPrintLog()) ThinkingSDKLogger.Print("Get remote config failed: " + ex.Message);
|
||||
}
|
||||
if (mCallback != null)
|
||||
{
|
||||
mCallback();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator GetWithFORM (string url, string appId, Dictionary<string, object> param, ResponseHandle responseHandle) {
|
||||
yield return ThinkingSDKBaseRequest.GetWithFORM_2(this.mConfigUrl,this.mToken,param,responseHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 472854a90c78a4dd4a16616ba3d3437d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
namespace ThinkingSDK.PC.Config
|
||||
{
|
||||
public class ThinkingSDKPublicConfig
|
||||
{
|
||||
// Whether to print log
|
||||
bool isPrintLog;
|
||||
// sdk version
|
||||
string version = "1.0";
|
||||
// sdk name
|
||||
string name = "Unity";
|
||||
private static readonly ThinkingSDKPublicConfig config = null;
|
||||
|
||||
static ThinkingSDKPublicConfig()
|
||||
{
|
||||
config = new ThinkingSDKPublicConfig();
|
||||
}
|
||||
|
||||
private static ThinkingSDKPublicConfig GetConfig()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
public ThinkingSDKPublicConfig()
|
||||
{
|
||||
isPrintLog = false;
|
||||
}
|
||||
public static void SetIsPrintLog(bool isPrint)
|
||||
{
|
||||
GetConfig().isPrintLog = isPrint;
|
||||
}
|
||||
public static bool IsPrintLog()
|
||||
{
|
||||
return GetConfig().isPrintLog;
|
||||
}
|
||||
public static void SetVersion(string libVersion)
|
||||
{
|
||||
GetConfig().version = libVersion;
|
||||
}
|
||||
public static void SetName(string libName)
|
||||
{
|
||||
GetConfig().name = libName;
|
||||
}
|
||||
public static string Version()
|
||||
{
|
||||
return GetConfig().version;
|
||||
}
|
||||
public static string Name()
|
||||
{
|
||||
return GetConfig().name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47e9c09a25d664062bd8264d072b2f34
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user