From a4be2b8bb553c11839ef2c93d9be883be5b071a8 Mon Sep 17 00:00:00 2001 From: oneRain Date: Mon, 19 Apr 2021 16:28:31 +0800 Subject: [PATCH] doc: storage --- Storage/Storage.Unity/Public/LCApplication.cs | 15 +++ Storage/Storage/Public/LCACL.cs | 90 +++++++++++++++- Storage/Storage/Public/LCCloud.cs | 7 ++ Storage/Storage/Public/LCFile.cs | 60 +++++++++++ .../Storage/Public/LCFollowersAndFollowees.cs | 15 +++ Storage/Storage/Public/LCFriendship.cs | 20 ++++ Storage/Storage/Public/LCFriendshipRequest.cs | 4 + Storage/Storage/Public/LCGeoPoint.cs | 33 ++++++ Storage/Storage/Public/LCHookObject.cs | 17 +++ Storage/Storage/Public/LCObject.cs | 102 ++++++++++++++++-- Storage/Storage/Public/LCQuery.cs | 69 +++++++++++- Storage/Storage/Public/LCRelation.cs | 21 +++- Storage/Storage/Public/LCRole.cs | 13 ++- Storage/Storage/Public/LCSMSClient.cs | 6 ++ Storage/Storage/Public/LCStatus.cs | 44 ++++++++ Storage/Storage/Public/LCStatusCount.cs | 9 ++ Storage/Storage/Public/LCStatusQuery.cs | 20 ++++ Storage/Storage/Public/LCStorage.cs | 3 +- Storage/Storage/Public/LCUser.cs | 15 +++ 19 files changed, 544 insertions(+), 19 deletions(-) diff --git a/Storage/Storage.Unity/Public/LCApplication.cs b/Storage/Storage.Unity/Public/LCApplication.cs index 56b7287..aa76d2f 100644 --- a/Storage/Storage.Unity/Public/LCApplication.cs +++ b/Storage/Storage.Unity/Public/LCApplication.cs @@ -3,7 +3,15 @@ using LeanCloud.Storage; using LeanCloud.Storage.Internal.Persistence; namespace LeanCloud { + /// + /// LCApplication contains static functions that handle global configuration + /// for LeanCloud services. + /// public class LCApplication { + /// + /// Whether or not ths SDK using master key. + /// Default is false. + /// public static bool UseMasterKey { get => LCCore.UseMasterKey; set { @@ -11,6 +19,13 @@ namespace LeanCloud { } } + /// + /// Initialize LeanCloud services. + /// + /// The application id provided in LeanCloud dashboard. + /// The application key provided in LeanCloud dashboard. + /// The server url bound by yourself. + /// The application master key provided in LeanCloud dashboard. public static void Initialize(string appId, string appKey, string server = null, diff --git a/Storage/Storage/Public/LCACL.cs b/Storage/Storage/Public/LCACL.cs index 3180eae..f504294 100644 --- a/Storage/Storage/Public/LCACL.cs +++ b/Storage/Storage/Public/LCACL.cs @@ -3,21 +3,28 @@ using System.Collections.Generic; namespace LeanCloud.Storage { /// - /// LeanCloud Access Control Lists. + /// LCACL is used to control which users and roles can access or modify + /// a particular object. Each LCObject can have its own LCObject. /// public class LCACL { const string PublicKey = "*"; const string RoleKeyPrefix = "role:"; - public Dictionary ReadAccess { + internal Dictionary ReadAccess { get; } = new Dictionary(); - public Dictionary WriteAccess { + internal Dictionary WriteAccess { get; } = new Dictionary(); + /// + /// Creates a LCACL that is allowed to read and write this object + /// for the user. + /// + /// The user. + /// public static LCACL CreateWithOwner(LCUser owner) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); @@ -28,6 +35,9 @@ namespace LeanCloud.Storage { return acl; } + /// + /// Gets or sets whether the public is allowed to read this object. + /// public bool PublicReadAccess { get { return GetAccess(ReadAccess, PublicKey); @@ -36,6 +46,9 @@ namespace LeanCloud.Storage { } } + /// + /// Gets or sets whether the public is allowed to write this object. + /// public bool PublicWriteAccess { get { return GetAccess(WriteAccess, PublicKey); @@ -44,6 +57,14 @@ namespace LeanCloud.Storage { } } + /// + /// Gets whether the given user id is *explicitly* allowed to read this + /// object. Even if this returns false, the user may still be able to read + /// it if is true or a role that the user + /// belongs to has read access. + /// + /// The user ObjectId to check. + /// public bool GetUserIdReadAccess(string userId) { if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); @@ -51,6 +72,11 @@ namespace LeanCloud.Storage { return GetAccess(ReadAccess, userId); } + /// + /// Set whether the given user id is allowed to read this object. + /// + /// The ObjectId of the user. + /// Whether the user has permission. public void SetUserIdReadAccess(string userId, bool value) { if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); @@ -58,6 +84,13 @@ namespace LeanCloud.Storage { SetAccess(ReadAccess, userId, value); } + /// + /// Gets whether the given user id is *explicitly* allowed to write this + /// object. Even if this returns false, the user may still be able to write + /// it if is true or a role that the user + /// belongs to has read access. + /// + /// T public bool GetUserIdWriteAccess(string userId) { if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); @@ -65,6 +98,11 @@ namespace LeanCloud.Storage { return GetAccess(WriteAccess, userId); } + /// + /// Set whether the given user id is allowed to write this object. + /// + /// The ObjectId of the user. + /// Whether the user has permission. public void SetUserIdWriteAccess(string userId, bool value) { if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException(nameof(userId)); @@ -72,6 +110,14 @@ namespace LeanCloud.Storage { SetAccess(WriteAccess, userId, value); } + /// + /// Gets whether the given user is *explicitly* allowed to read this + /// object. Even if this returns false, the user may still be able to read + /// it if is true or a role that the user + /// belongs to has read access. + /// + /// The user to check. + /// public bool GetUserReadAccess(LCUser user) { if (user == null) { throw new ArgumentNullException(nameof(user)); @@ -79,6 +125,11 @@ namespace LeanCloud.Storage { return GetUserIdReadAccess(user.ObjectId); } + /// + /// Set whether the given user is allowed to read this object. + /// + /// The user. + /// Whether the user has permission. public void SetUserReadAccess(LCUser user, bool value) { if (user == null) { throw new ArgumentNullException(nameof(user)); @@ -86,6 +137,14 @@ namespace LeanCloud.Storage { SetUserIdReadAccess(user.ObjectId, value); } + /// + /// Gets whether the given user is *explicitly* allowed to write this + /// object. Even if this returns false, the user may still be able to write + /// it if is true or a role that the user + /// belongs to has write access. + /// + /// The user to check. + /// public bool GetUserWriteAccess(LCUser user) { if (user == null) { throw new ArgumentNullException(nameof(user)); @@ -93,6 +152,11 @@ namespace LeanCloud.Storage { return GetUserIdWriteAccess(user.ObjectId); } + /// + /// Set whether the given user is allowed to write this object. + /// + /// The user. + /// Whether the user has permission. public void SetUserWriteAccess(LCUser user, bool value) { if (user == null) { throw new ArgumentNullException(nameof(user)); @@ -100,6 +164,11 @@ namespace LeanCloud.Storage { SetUserIdWriteAccess(user.ObjectId, value); } + /// + /// Get whether the given role are allowed to read this object. + /// + /// The role to check. + /// public bool GetRoleReadAccess(LCRole role) { if (role == null) { throw new ArgumentNullException(nameof(role)); @@ -108,6 +177,11 @@ namespace LeanCloud.Storage { return GetAccess(ReadAccess, roleKey); } + /// + /// Sets whether the given role are allowed to read this object. + /// + /// The role. + /// Whether the role has access. public void SetRoleReadAccess(LCRole role, bool value) { if (role == null) { throw new ArgumentNullException(nameof(role)); @@ -116,6 +190,11 @@ namespace LeanCloud.Storage { SetAccess(ReadAccess, roleKey, value); } + /// + /// Get whether the given role are allowed to write this object. + /// + /// The role to check. + /// public bool GetRoleWriteAccess(LCRole role) { if (role == null) { throw new ArgumentNullException(nameof(role)); @@ -124,6 +203,11 @@ namespace LeanCloud.Storage { return GetAccess(WriteAccess, roleKey); } + /// + /// Sets whether the given role are allowed to write this object. + /// + /// The role. + /// Whether the role has access. public void SetRoleWriteAccess(LCRole role, bool value) { if (role == null) { throw new ArgumentNullException(nameof(role)); diff --git a/Storage/Storage/Public/LCCloud.cs b/Storage/Storage/Public/LCCloud.cs index e957dd4..a5dcb01 100644 --- a/Storage/Storage/Public/LCCloud.cs +++ b/Storage/Storage/Public/LCCloud.cs @@ -37,6 +37,13 @@ namespace LeanCloud.Storage { return response; } + /// + /// Invokes a cloud function. + /// + /// The type of return value. + /// Cloud function name. + /// Parameters of cloud function. + /// public static async Task Run(string name, Dictionary parameters = null) { Dictionary response = await Run(name, parameters); diff --git a/Storage/Storage/Public/LCFile.cs b/Storage/Storage/Public/LCFile.cs index 01cabc4..94607d6 100644 --- a/Storage/Storage/Public/LCFile.cs +++ b/Storage/Storage/Public/LCFile.cs @@ -7,9 +7,15 @@ using LeanCloud.Storage.Internal.File; using LeanCloud.Storage.Internal.Object; namespace LeanCloud.Storage { + /// + /// LCFile is a local representation of a file that is saved to LeanCloud. + /// public class LCFile : LCObject { public const string CLASS_NAME = "_File"; + /// + /// Gets the name of the file. + /// public string Name { get { return this["name"] as string; @@ -18,6 +24,9 @@ namespace LeanCloud.Storage { } } + /// + /// Gets the MIME type of the file. + /// public string MimeType { get { return this["mime_type"] as string; @@ -26,6 +35,9 @@ namespace LeanCloud.Storage { } } + /// + /// Gets the url of the file. + /// public string Url { get { return this["url"] as string; @@ -34,6 +46,9 @@ namespace LeanCloud.Storage { } } + /// + /// Gets the metadata of the file. + /// public Dictionary MetaData { get { return this["metaData"] as Dictionary; @@ -44,30 +59,58 @@ namespace LeanCloud.Storage { readonly Stream stream; + /// + /// Creates a new file. + /// public LCFile() : base(CLASS_NAME) { MetaData = new Dictionary(); } + /// + /// Creates a new file from a byte array and a name. + /// + /// + /// public LCFile(string name, byte[] bytes) : this() { Name = name; stream = new MemoryStream(bytes); } + /// + /// Creates a new file from a local file and a name. + /// + /// + /// public LCFile(string name, string path) : this() { Name = name; MimeType = LCMimeTypeMap.GetMimeType(path); stream = new FileStream(path, FileMode.Open); } + /// + /// Creates a new file from an url and a name. + /// + /// + /// public LCFile(string name, Uri url) : this() { Name = name; Url = url.AbsoluteUri; } + /// + /// Add metadata. + /// + /// + /// public void AddMetaData(string key, object value) { MetaData[key] = value; } + /// + /// Saves the file to LeanCloud. + /// + /// + /// public async Task Save(Action onProgress = null) { if (!string.IsNullOrEmpty(Url)) { // 外链方式 @@ -108,6 +151,10 @@ namespace LeanCloud.Storage { return this; } + /// + /// Deletes the file from LeanCloud. + /// + /// public new async Task Delete() { if (string.IsNullOrEmpty(ObjectId)) { return; @@ -116,6 +163,15 @@ namespace LeanCloud.Storage { await LCCore.HttpClient.Delete(path); } + /// + /// Gets the thumbnail url of image file. + /// + /// + /// + /// + /// + /// + /// public string GetThumbnailUrl(int width, int height, int quality = 100, bool scaleToFit = true, string format = "png") { int mode = scaleToFit ? 2 : 1; return $"{Url}?imageView/{mode}/w/{width}/h/{height}/q/{quality}/format/{format}"; @@ -132,6 +188,10 @@ namespace LeanCloud.Storage { return await LCCore.HttpClient.Post>("fileTokens", data: data); } + /// + /// Gets LCQuery of LCFile. + /// + /// public static LCQuery GetQuery() { return new LCQuery(CLASS_NAME); } diff --git a/Storage/Storage/Public/LCFollowersAndFollowees.cs b/Storage/Storage/Public/LCFollowersAndFollowees.cs index 3677490..33885a3 100644 --- a/Storage/Storage/Public/LCFollowersAndFollowees.cs +++ b/Storage/Storage/Public/LCFollowersAndFollowees.cs @@ -1,19 +1,34 @@ using System.Collections.Generic; namespace LeanCloud.Storage { + /// + /// LCFollowersAndFollowees is a result that contains followers and followees. + /// public class LCFollowersAndFollowees { + /// + /// The followers. + /// public List Followers { get; internal set; } + /// + /// The followees. + /// public List Followees { get; internal set; } + /// + /// The count of followers. + /// public int FollowersCount { get; internal set; } + /// + /// The count of followees. + /// public int FolloweesCount { get; internal set; } diff --git a/Storage/Storage/Public/LCFriendship.cs b/Storage/Storage/Public/LCFriendship.cs index d128d84..191a701 100644 --- a/Storage/Storage/Public/LCFriendship.cs +++ b/Storage/Storage/Public/LCFriendship.cs @@ -5,7 +5,16 @@ using LeanCloud.Common; using LeanCloud.Storage.Internal.Codec; namespace LeanCloud.Storage { + /// + /// LCFriendship contains static functions that handle the friendship of LeanCloud. + /// public static class LCFriendship { + /// + /// Requests to add friend. + /// + /// The user id to add. + /// The additional attributes for the friendship. + /// public static async Task Request(string userId, Dictionary attributes = null) { LCUser user = await LCUser.GetCurrent(); if (user == null) { @@ -23,6 +32,12 @@ namespace LeanCloud.Storage { await LCCore.HttpClient.Post>(path, data: data); } + /// + /// Accepts the request of add friend. + /// + /// The request. + /// The additional attributes for the friendship. + /// public static async Task AcceptRequest(LCFriendshipRequest request, Dictionary attributes = null) { if (request == null) { throw new ArgumentNullException(nameof(request)); @@ -37,6 +52,11 @@ namespace LeanCloud.Storage { await LCCore.HttpClient.Put>(path, data: data); } + /// + /// Declines the request of add friend. + /// + /// The request. + /// public static async Task DeclineRequest(LCFriendshipRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); diff --git a/Storage/Storage/Public/LCFriendshipRequest.cs b/Storage/Storage/Public/LCFriendshipRequest.cs index 6306a62..0dddfc3 100644 --- a/Storage/Storage/Public/LCFriendshipRequest.cs +++ b/Storage/Storage/Public/LCFriendshipRequest.cs @@ -1,4 +1,8 @@ namespace LeanCloud.Storage { + /// + /// LCFriendshipRequest is a local representation of a friend request that + /// is saved to LeanCloud. + /// public class LCFriendshipRequest : LCObject { public const string CLASS_NAME = "_FriendshipRequest"; diff --git a/Storage/Storage/Public/LCGeoPoint.cs b/Storage/Storage/Public/LCGeoPoint.cs index 1cb3f44..58ca7a9 100644 --- a/Storage/Storage/Public/LCGeoPoint.cs +++ b/Storage/Storage/Public/LCGeoPoint.cs @@ -1,26 +1,49 @@ using System; namespace LeanCloud.Storage { + /// + /// LCGeoPoint represents a latitude and longitude point that may be associated + /// with a key in a LCObject or used as a reference point for queries. + /// public class LCGeoPoint { + /// + /// Gets the latitude of the LCGeoPoint. + /// public double Latitude { get; } + /// + /// Gets the longitude of the LCGeoPoint. + /// public double Longitude { get; } + /// + /// Constructs a LCGeoPoint with the specified latitude and longitude. + /// + /// + /// public LCGeoPoint(double latitude, double longtitude) { Latitude = latitude; Longitude = longtitude; } + /// + /// The original LCGeoPoint. + /// public static LCGeoPoint Origin { get { return new LCGeoPoint(0, 0); } } + /// + /// Calculate the distance in kilometer between this point and another GeoPoint. + /// + /// + /// public double KilometersTo(LCGeoPoint point) { if (point == null) { throw new ArgumentNullException(nameof(point)); @@ -28,6 +51,11 @@ namespace LeanCloud.Storage { return RadiansTo(point) * 6371.0; } + /// + /// Calculate the distance in mile between this point and another GeoPoint. + /// + /// + /// public double MilesTo(LCGeoPoint point) { if (point == null) { throw new ArgumentNullException(nameof(point)); @@ -35,6 +63,11 @@ namespace LeanCloud.Storage { return RadiansTo(point) * 3958.8; } + /// + /// Calculate the distance in radians between this point and another GeoPoint. + /// + /// + /// public double RadiansTo(LCGeoPoint point) { if (point == null) { throw new ArgumentNullException(nameof(point)); diff --git a/Storage/Storage/Public/LCHookObject.cs b/Storage/Storage/Public/LCHookObject.cs index afb8568..62b0f2a 100644 --- a/Storage/Storage/Public/LCHookObject.cs +++ b/Storage/Storage/Public/LCHookObject.cs @@ -5,6 +5,9 @@ using System.Linq; using LeanCloud.Storage.Internal.Operation; namespace LeanCloud.Storage { + /// + /// LCClassHook represents the hooks for saving / updating / deleting LCObject. + /// public static class LCClassHook { public const string BeforeSave = "beforeSave"; public const string AfterSave = "afterSave"; @@ -17,6 +20,9 @@ namespace LeanCloud.Storage { public partial class LCObject { internal const string IgnoreHooksKey = "__ignore_hooks"; + /// + /// Disable to hook before saving / updating / deleting LCObject. + /// public void DisableBeforeHook() { Ignore( LCClassHook.BeforeSave, @@ -24,6 +30,9 @@ namespace LeanCloud.Storage { LCClassHook.BeforeDelete); } + /// + /// Disable to hook after saving / updating / deleting LCObject. + /// public void DisableAfterHook() { Ignore( LCClassHook.AfterSave, @@ -31,6 +40,10 @@ namespace LeanCloud.Storage { LCClassHook.AfterDelete); } + /// + /// Ignores the hook for this LCObject. + /// + /// public void IgnoreHook(string hookName) { if (hookName != LCClassHook.BeforeSave && hookName != LCClassHook.AfterSave && hookName != LCClassHook.BeforeUpdate && hookName != LCClassHook.AfterUpdate && @@ -46,6 +59,10 @@ namespace LeanCloud.Storage { ApplyOperation(IgnoreHooksKey, op); } + /// + /// Gets the updated keys of this LCObject. + /// + /// public ReadOnlyCollection GetUpdatedKeys() { if (this["_updatedKeys"] == null) { return null; diff --git a/Storage/Storage/Public/LCObject.cs b/Storage/Storage/Public/LCObject.cs index 0b2398c..8aa072e 100644 --- a/Storage/Storage/Public/LCObject.cs +++ b/Storage/Storage/Public/LCObject.cs @@ -11,51 +11,60 @@ using LeanCloud.Storage.Internal.Codec; namespace LeanCloud.Storage { /// - /// LeanCloud Object + /// The LCObject is a local representation of data that can be saved and + /// retrieved from the LeanCloud. /// public partial class LCObject { - /// - /// Last synced data. - /// internal LCObjectData data; - /// - /// Estimated data. - /// internal Dictionary estimatedData; - /// - /// Operations. - /// internal Dictionary operationDict; static readonly Dictionary subclassTypeDict = new Dictionary(); static readonly Dictionary subclassNameDict = new Dictionary(); + /// + /// Gets the class name for the LCObject. + /// public string ClassName { get { return data.ClassName; } } + /// + /// Gets the object id. An object id is assigned as son as an object is + /// saved to the server. The combination of a and + /// an uniquely identifies an object in your application. + /// public string ObjectId { get { return data.ObjectId; } } + /// + /// Gets the first time of this object was saved the server. + /// public DateTime CreatedAt { get { return data.CreatedAt; } } + /// + /// Gets the last time of this object was updated the server. + /// public DateTime UpdatedAt { get { return data.UpdatedAt; } } + /// + /// Gets or sets the LCACL governing this object. + /// public LCACL ACL { get { return this["ACL"] as LCACL ; @@ -72,6 +81,12 @@ namespace LeanCloud.Storage { } } + /// + /// Constructs a new LCObject with no data in it. A LCObject constructed + /// in this way will not have an ObjectedId and will not persist to database + /// until is called. + /// + /// The className for the LCObject. public LCObject(string className) { if (string.IsNullOrEmpty(className)) { throw new ArgumentNullException(nameof(className)); @@ -84,6 +99,13 @@ namespace LeanCloud.Storage { isNew = true; } + /// + /// Creates a reference to an existing LCObject for use in creating + /// associations between LCObjects. + /// + /// The className for the LCObject. + /// The object id for the LCObject. + /// public static LCObject CreateWithoutData(string className, string objectId) { if (string.IsNullOrEmpty(objectId)) { throw new ArgumentNullException(nameof(objectId)); @@ -94,6 +116,12 @@ namespace LeanCloud.Storage { return obj; } + /// + /// Creates a reference to an existing LCObject for use in creating + /// associations between LCObjects. + /// + /// The className for the LCObject. + /// public static LCObject Create(string className) { if (subclassNameDict.TryGetValue(className, out LCSubclassInfo subclassInfo)) { return subclassInfo.Constructor.Invoke(); @@ -108,6 +136,12 @@ namespace LeanCloud.Storage { return null; } + /// + /// Gets or sets a value on the object. It is forbidden to name keys + /// with '_'. + /// + /// The value for key. + /// public object this[string key] { get { if (estimatedData.TryGetValue(key, out object value)) { @@ -148,6 +182,11 @@ namespace LeanCloud.Storage { } + /// + /// Creates a value for a key. + /// + /// + /// public void AddRelation(string key, LCObject value) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException(nameof(key)); @@ -159,6 +198,11 @@ namespace LeanCloud.Storage { ApplyOperation(key, op); } + /// + /// Removes a value for a key. + /// + /// + /// public void RemoveRelation(string key, LCObject value) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException(nameof(key)); @@ -324,6 +368,12 @@ namespace LeanCloud.Storage { } } + /// + /// Saves this object to the server. + /// + /// Whether or not fetch data when saved. + /// The condition for saving. + /// public async Task Save(bool fetchWhenSave = false, LCQuery query = null) { if (LCBatch.HasCircleReference(this, new HashSet())) { throw new ArgumentException("Found a circle dependency when save."); @@ -350,6 +400,11 @@ namespace LeanCloud.Storage { return this; } + /// + /// Saves each object in the provided list. + /// + /// The objects to save. + /// public static async Task> SaveAll(IEnumerable objects) { if (objects == null) { throw new ArgumentNullException(nameof(objects)); @@ -364,6 +419,10 @@ namespace LeanCloud.Storage { return objects.ToList(); } + /// + /// Deletes this object on the server. + /// + /// public async Task Delete() { if (ObjectId == null) { return; @@ -372,6 +431,11 @@ namespace LeanCloud.Storage { await LCCore.HttpClient.Delete(path); } + /// + /// Deletes each object in the provided list. + /// + /// + /// public static async Task DeleteAll(IEnumerable objects) { if (objects == null || objects.Count() == 0) { throw new ArgumentNullException(nameof(objects)); @@ -390,6 +454,12 @@ namespace LeanCloud.Storage { await LCCore.HttpClient.Post>("batch", data: data); } + /// + /// Fetches this object from server. + /// + /// The keys for fetching. + /// The include keys for fetching. + /// public async Task Fetch(IEnumerable keys = null, IEnumerable includes = null) { Dictionary queryParams = new Dictionary(); if (keys != null) { @@ -405,6 +475,11 @@ namespace LeanCloud.Storage { return this; } + /// + /// Fetches all of the objects in the provided list. + /// + /// The objects for fetching. + /// public static async Task> FetchAll(IEnumerable objects) { if (objects == null || objects.Count() == 0) { throw new ArgumentNullException(nameof(objects)); @@ -442,6 +517,13 @@ namespace LeanCloud.Storage { return objects; } + /// + /// Registers a custom subclass type with LeanCloud SDK, enabling strong-typing + /// of those LCObjects whenever they appear. + /// + /// The LCObject subclass type to register. + /// The className on server. + /// The constructor for creating an object. public static void RegisterSubclass(string className, Func constructor) where T : LCObject { Type classType = typeof(T); LCSubclassInfo subclassInfo = new LCSubclassInfo(className, classType, constructor); diff --git a/Storage/Storage/Public/LCQuery.cs b/Storage/Storage/Public/LCQuery.cs index 5e37364..2cacc61 100644 --- a/Storage/Storage/Public/LCQuery.cs +++ b/Storage/Storage/Public/LCQuery.cs @@ -9,7 +9,13 @@ using LeanCloud.Storage.Internal.Query; using LeanCloud.Storage.Internal.Object; namespace LeanCloud.Storage { + /// + /// The LCQuery class defines a query that is used to fetch LCObjects. + /// public class LCQuery { + /// + /// The classname of this query. + /// public string ClassName { get; internal set; } @@ -18,6 +24,10 @@ namespace LeanCloud.Storage { get; internal set; } + /// + /// Constructs a LCQuery for class. + /// + /// public LCQuery(string className) { ClassName = className; Condition = new LCCompositionalCondition(); @@ -172,16 +182,35 @@ namespace LeanCloud.Storage { return this; } + /// + /// The value corresponding to key is near the point. + /// + /// + /// + /// public LCQuery WhereNear(string key, LCGeoPoint point) { Condition.WhereNear(key, point); return this; } + /// + /// The value corresponding to key is in the given rectangular geographic bounding box. + /// + /// + /// + /// + /// public LCQuery WhereWithinGeoBox(string key, LCGeoPoint southwest, LCGeoPoint northeast) { Condition.WhereWithinGeoBox(key, southwest, northeast); return this; } + /// + /// The value corresponding to key is related to the parent. + /// + /// + /// + /// public LCQuery WhereRelatedTo(LCObject parent, string key) { Condition.WhereRelatedTo(parent, key); return this; @@ -255,13 +284,21 @@ namespace LeanCloud.Storage { return this; } - + /// + /// Sorts the results in ascending order by the given key. + /// + /// + /// public LCQuery OrderByAscending(string key) { Condition.OrderByAscending(key); return this; } - + /// + /// Sorts the results in descending order by the given key. + /// + /// + /// public LCQuery OrderByDescending(string key) { Condition.OrderByDescending(key); return this; @@ -338,6 +375,10 @@ namespace LeanCloud.Storage { return this; } + /// + /// Counts the number of objects that match this query. + /// + /// public async Task Count() { string path = $"classes/{ClassName}"; Dictionary parameters = BuildParams(); @@ -347,6 +388,12 @@ namespace LeanCloud.Storage { return (int)ret["count"]; } + /// + /// Constructs a LCObject whose id is already known by fetching data + /// from the server. + /// + /// + /// public async Task Get(string objectId) { if (string.IsNullOrEmpty(objectId)) { throw new ArgumentNullException(nameof(objectId)); @@ -363,6 +410,10 @@ namespace LeanCloud.Storage { return DecodeLCObject(response); } + /// + /// Retrieves a list of LCObjects that satisfy the query from Server. + /// + /// public async Task> Find() { string path = $"classes/{ClassName}"; Dictionary parameters = BuildParams(); @@ -376,6 +427,10 @@ namespace LeanCloud.Storage { return list.AsReadOnly(); } + /// + /// Retrieves at most one LCObject that satisfies this query. + /// + /// public async Task First() { Limit(1); ReadOnlyCollection results = await Find(); @@ -385,6 +440,11 @@ namespace LeanCloud.Storage { return null; } + /// + /// Constructs a query that is the and of the given queries. + /// + /// + /// public static LCQuery And(IEnumerable> queries) { if (queries == null || queries.Count() < 1) { throw new ArgumentNullException(nameof(queries)); @@ -402,6 +462,11 @@ namespace LeanCloud.Storage { return compositionQuery; } + /// + /// Constructs a query that is the or of the given queries. + /// + /// + /// public static LCQuery Or(IEnumerable> queries) { if (queries == null || queries.Count() < 1) { throw new ArgumentNullException(nameof(queries)); diff --git a/Storage/Storage/Public/LCRelation.cs b/Storage/Storage/Public/LCRelation.cs index bc989ef..cfeb47a 100644 --- a/Storage/Storage/Public/LCRelation.cs +++ b/Storage/Storage/Public/LCRelation.cs @@ -1,21 +1,40 @@ namespace LeanCloud.Storage { - + /// + /// LCRelation provides access to all of the children of a many-to-many + /// relationship. + /// + /// The type of the child objects. public class LCRelation where T : LCObject { + /// + /// The key of this LCRelation. + /// public string Key { get; set; } + /// + /// The parent of this LCRelation. + /// public LCObject Parent { get; set; } + /// + /// The className of this LCRelation. + /// public string TargetClass { get; set; } + /// + /// Constructs a LCRelation. + /// public LCRelation() { } + /// + /// Gets a query that can be used to query the objects in this relation. + /// public LCQuery Query { get { LCQuery query = new LCQuery(TargetClass); diff --git a/Storage/Storage/Public/LCRole.cs b/Storage/Storage/Public/LCRole.cs index 49d949c..d3e6ce8 100644 --- a/Storage/Storage/Public/LCRole.cs +++ b/Storage/Storage/Public/LCRole.cs @@ -5,7 +5,9 @@ public class LCRole : LCObject { public const string CLASS_NAME = "_Role"; - + /// + /// The name of LCRole. + /// public string Name { get { return this["name"] as string; @@ -40,9 +42,18 @@ } } + /// + /// Constructs a LCRole. + /// public LCRole() : base(CLASS_NAME) { } + /// + /// Constructs a LCRole with a name and a LCACL. + /// + /// + /// + /// public static LCRole Create(string name, LCACL acl) { LCRole role = new LCRole() { Name = name, diff --git a/Storage/Storage/Public/LCSMSClient.cs b/Storage/Storage/Public/LCSMSClient.cs index 8f6e9ca..aa85503 100644 --- a/Storage/Storage/Public/LCSMSClient.cs +++ b/Storage/Storage/Public/LCSMSClient.cs @@ -61,6 +61,12 @@ namespace LeanCloud.Storage { await LCCore.HttpClient.Post>(path, data: data); } + /// + /// Verifies the mobile number with the verification code. + /// + /// + /// + /// public static async Task VerifyMobilePhone(string mobile, string code) { string path = $"verifySmsCode/{code}"; Dictionary data = new Dictionary { diff --git a/Storage/Storage/Public/LCStatus.cs b/Storage/Storage/Public/LCStatus.cs index 12f166c..e2f5942 100644 --- a/Storage/Storage/Public/LCStatus.cs +++ b/Storage/Storage/Public/LCStatus.cs @@ -7,6 +7,9 @@ using LeanCloud.Storage.Internal.Object; using LC.Newtonsoft.Json; namespace LeanCloud.Storage { + /// + /// LCStatus is a local representation of a status in LeanCloud. + /// public class LCStatus : LCObject { public const string CLASS_NAME = "_Status"; @@ -22,25 +25,42 @@ namespace LeanCloud.Storage { public const string OwnerKey = "owner"; public const string MessageIdKey = "messageId"; + /// + /// The id of this status. + /// public int MessageId { get; internal set; } + /// + /// The inboxType of this status. + /// public string InboxType { get; internal set; } private LCQuery query; + /// + /// The data of this status. + /// public Dictionary Data { get; set; } + /// + /// Constructs a LCStatus. + /// public LCStatus() : base(CLASS_NAME) { InboxType = InboxTypeDefault; Data = new Dictionary(); } + /// + /// Sends the status to the followers of this user. + /// + /// + /// public static async Task SendToFollowers(LCStatus status) { if (status == null) { throw new ArgumentNullException(nameof(status)); @@ -62,6 +82,12 @@ namespace LeanCloud.Storage { return await status.Send(); } + /// + /// Sends the status to the user with targetId privatedly. + /// + /// + /// + /// public static async Task SendPrivately(LCStatus status, string targetId) { if (status == null) { throw new ArgumentNullException(nameof(status)); @@ -84,6 +110,10 @@ namespace LeanCloud.Storage { return await status.Send(); } + /// + /// Send this status. + /// + /// public async Task Send() { LCUser user = await LCUser.GetCurrent(); if (user == null) { @@ -118,6 +148,10 @@ namespace LeanCloud.Storage { return this; } + /// + /// Deletes this status. + /// + /// public new async Task Delete() { LCUser user = await LCUser.GetCurrent(); if (user == null) { @@ -137,6 +171,11 @@ namespace LeanCloud.Storage { } } + /// + /// Gets the count of the status with inboxType. + /// + /// + /// public static async Task GetCount(string inboxType) { LCUser user = await LCUser.GetCurrent(); if (user == null) { @@ -158,6 +197,11 @@ namespace LeanCloud.Storage { return statusCount; } + /// + /// Reset the count of the status to be zero. + /// + /// + /// public static async Task ResetUnreadCount(string inboxType = null) { LCUser user = await LCUser.GetCurrent(); if (user == null) { diff --git a/Storage/Storage/Public/LCStatusCount.cs b/Storage/Storage/Public/LCStatusCount.cs index 56ce6b4..763ada3 100644 --- a/Storage/Storage/Public/LCStatusCount.cs +++ b/Storage/Storage/Public/LCStatusCount.cs @@ -1,9 +1,18 @@ namespace LeanCloud.Storage { + /// + /// LCStatusCount is a result that contains the count of status. + /// public class LCStatusCount { + /// + /// The total count. + /// public int Total { get; set; } + /// + /// The unread count. + /// public int Unread { get; set; } diff --git a/Storage/Storage/Public/LCStatusQuery.cs b/Storage/Storage/Public/LCStatusQuery.cs index b3de9c5..510212d 100644 --- a/Storage/Storage/Public/LCStatusQuery.cs +++ b/Storage/Storage/Public/LCStatusQuery.cs @@ -9,25 +9,45 @@ using LeanCloud.Storage.Internal.Codec; using LeanCloud.Storage.Internal.Object; namespace LeanCloud.Storage { + /// + /// LCStatusQuery is the query of LCStatus. + /// public class LCStatusQuery : LCQuery { + /// + /// The inboxType for query. + /// public string InboxType { get; set; } + /// + /// The id since the query. + /// public int SinceId { get; set; } + /// + /// The max id for the query. + /// public int MaxId { get; set; } + /// + /// Constructs a LCStatusQuery with inboxType. + /// + /// public LCStatusQuery(string inboxType = LCStatus.InboxTypeDefault) : base("_Status") { InboxType = inboxType; SinceId = 0; MaxId = 0; } + /// + /// Retrieves a list of LCStatus that satisfy the query from Server. + /// + /// public new async Task> Find() { LCUser user = await LCUser.GetCurrent(); if (user == null) { diff --git a/Storage/Storage/Public/LCStorage.cs b/Storage/Storage/Public/LCStorage.cs index 9b5635d..0ba1102 100644 --- a/Storage/Storage/Public/LCStorage.cs +++ b/Storage/Storage/Public/LCStorage.cs @@ -1,5 +1,4 @@ -using System; -using LeanCloud.Common; +using LeanCloud.Common; namespace LeanCloud.Storage { public class LCStorage { diff --git a/Storage/Storage/Public/LCUser.cs b/Storage/Storage/Public/LCUser.cs index cf03635..09ff403 100644 --- a/Storage/Storage/Public/LCUser.cs +++ b/Storage/Storage/Public/LCUser.cs @@ -6,6 +6,9 @@ using LeanCloud.Common; using LeanCloud.Storage.Internal.Object; namespace LeanCloud.Storage { + /// + /// LCUser represents a user for a LeanCloud application. + /// public class LCUser : LCObject { public const string CLASS_NAME = "_User"; @@ -79,6 +82,11 @@ namespace LeanCloud.Storage { static LCUser currentUser; + /// + /// Gets the currently logged in LCUser with a valid session, either from + /// memory or disk if necessary. + /// + /// public static async Task GetCurrent() { if (currentUser != null) { return currentUser; @@ -700,6 +708,13 @@ namespace LeanCloud.Storage { .Include("followee"); } + /// + /// Gets the followers and followees of the currently logged in user. + /// + /// + /// + /// + /// public async Task GetFollowersAndFollowees(bool includeFollower = false, bool includeFollowee = false, bool returnCount = false) { Dictionary queryParams = new Dictionary();