chore: 简化 AVClient

oneRain 2019-08-27 16:37:53 +08:00
parent 671b137721
commit 13b0789d2b
1 changed files with 18 additions and 86 deletions

View File

@ -13,8 +13,7 @@ using Newtonsoft.Json;
namespace LeanCloud { namespace LeanCloud {
/// <summary> /// <summary>
/// AVClient contains static functions that handle global /// LeanCloud SDK 客户端类
/// configuration for the LeanCloud library.
/// </summary> /// </summary>
public static class AVClient { public static class AVClient {
public static readonly string[] DateFormatStrings = { public static readonly string[] DateFormatStrings = {
@ -27,51 +26,22 @@ namespace LeanCloud {
}; };
/// <summary> /// <summary>
/// Represents the configuration of the LeanCloud SDK. /// LeanCloud SDK 配置
/// </summary> /// </summary>
public struct Configuration { public struct Configuration {
/// <summary> /// <summary>
/// In the event that you would like to use the LeanCloud SDK /// App Id
/// from a completely portable project, with no platform-specific library required,
/// to get full access to all of our features available on LeanCloud.com
/// (A/B testing, slow queries, etc.), you must set the values of this struct
/// to be appropriate for your platform.
///
/// Any values set here will overwrite those that are automatically configured by
/// any platform-specific migration library your app includes.
/// </summary>
public struct VersionInformation {
/// <summary>
/// The build number of your app.
/// </summary>
public String BuildVersion { get; set; }
/// <summary>
/// The human friendly version number of your happ.
/// </summary>
public String DisplayVersion { get; set; }
/// <summary>
/// The operating system version of the platform the SDK is operating in..
/// </summary>
public String OSVersion { get; set; }
}
/// <summary>
/// The LeanCloud application ID of your app.
/// </summary> /// </summary>
public string ApplicationId { get; set; } public string ApplicationId { get; set; }
/// <summary> /// <summary>
/// The LeanCloud application key for your app. /// App Key
/// </summary> /// </summary>
public string ApplicationKey { get; set; } public string ApplicationKey { get; set; }
/// <summary> /// <summary>
/// The LeanCloud master key for your app. /// Master Key
/// </summary> /// </summary>
/// <value>The master key.</value>
public string MasterKey { get; set; } public string MasterKey { get; set; }
/// <summary> /// <summary>
@ -79,11 +49,6 @@ namespace LeanCloud {
/// </summary> /// </summary>
public IDictionary<string, string> AdditionalHTTPHeaders { get; set; } public IDictionary<string, string> AdditionalHTTPHeaders { get; set; }
/// <summary>
/// The version information of your application environment.
/// </summary>
public VersionInformation VersionInfo { get; set; }
/// <summary> /// <summary>
/// 存储服务器地址 /// 存储服务器地址
/// </summary> /// </summary>
@ -119,7 +84,7 @@ namespace LeanCloud {
} }
/// <summary> /// <summary>
/// The current configuration that LeanCloud has been initialized with. /// LeanCloud SDK 当前配置
/// </summary> /// </summary>
public static Configuration CurrentConfiguration { get; internal set; } public static Configuration CurrentConfiguration { get; internal set; }
@ -129,31 +94,23 @@ namespace LeanCloud {
} }
} }
public static string Name { internal static string Name {
get { get {
return "LeanCloud-CSharp-SDK"; return "LeanCloud-CSharp-SDK";
} }
} }
/// <summary> internal static string Version {
/// 当前 SDK 版本号
/// </summary>
public static string Version {
get { get {
return "0.1.0"; return "0.1.0";
} }
} }
/// <summary> /// <summary>
/// Authenticates this client as belonging to your application. This must be /// 初始化 LeanCloud SDK
/// called before your application can use the LeanCloud library. The recommended
/// way is to put a call to <c>AVClient.Initialize</c> in your
/// Application startup.
/// </summary> /// </summary>
/// <param name="applicationId">The Application ID provided in the LeanCloud dashboard. /// <param name="applicationId">App Id</param>
/// </param> /// <param name="applicationKey">App Key</param>
/// <param name="applicationKey">The .NET API Key provided in the LeanCloud dashboard.
/// </param>
public static void Initialize(string applicationId, string applicationKey) { public static void Initialize(string applicationId, string applicationKey) {
Initialize(new Configuration { Initialize(new Configuration {
ApplicationId = applicationId, ApplicationId = applicationId,
@ -179,60 +136,35 @@ namespace LeanCloud {
} }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether send the request to production server or staging server. /// 是否使用生产环境
/// </summary> /// </summary>
/// <value><c>true</c> if use production; otherwise, <c>false</c>.</value>
public static bool UseProduction { public static bool UseProduction {
get; set; get; set;
} }
/// <summary>
/// 是否使用 MasterKey
/// </summary>
public static bool UseMasterKey { public static bool UseMasterKey {
get; set; get; set;
} }
/// <summary> /// <summary>
/// Authenticates this client as belonging to your application. This must be /// 初始化 LeanCloud
/// called before your application can use the LeanCloud library. The recommended
/// way is to put a call to <c>AVClient.Initialize</c> in your
/// Application startup.
/// </summary> /// </summary>
/// <param name="configuration">The configuration to initialize LeanCloud with. /// <param name="configuration">初始化配置</param>
/// </param>
public static void Initialize(Configuration configuration) { public static void Initialize(Configuration configuration) {
Config(configuration); CurrentConfiguration = configuration;
AVObject.RegisterSubclass<AVUser>(); AVObject.RegisterSubclass<AVUser>();
AVObject.RegisterSubclass<AVRole>(); AVObject.RegisterSubclass<AVRole>();
} }
internal static void Config(Configuration configuration) {
lock (mutex) {
CurrentConfiguration = configuration;
}
}
internal static void Clear() { internal static void Clear() {
AVPlugins.Instance.AppRouterController.Clear(); AVPlugins.Instance.AppRouterController.Clear();
AVPlugins.Instance.Reset(); AVPlugins.Instance.Reset();
} }
/// <summary>
/// Switch app.
/// </summary>
/// <param name="configuration">Configuration.</param>
public static void Switch(Configuration configuration) {
Clear();
Initialize(configuration);
}
public static void Switch(string applicationId, string applicationKey) {
var configuration = new Configuration {
ApplicationId = applicationId,
ApplicationKey = applicationKey
};
Switch(configuration);
}
public static string BuildQueryString(IDictionary<string, object> parameters) { public static string BuildQueryString(IDictionary<string, object> parameters) {
return string.Join("&", (from pair in parameters return string.Join("&", (from pair in parameters
let valueString = pair.Value as string let valueString = pair.Value as string