diff --git a/Storage/Storage/Internal/Utilities/AVUserExtensions.cs b/Storage/Storage/Internal/Utilities/AVUserExtensions.cs deleted file mode 100644 index 936dc37..0000000 --- a/Storage/Storage/Internal/Utilities/AVUserExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace LeanCloud.Storage.Internal -{ - /// - /// So here's the deal. We have a lot of internal APIs for AVObject, AVUser, etc. - /// - /// These cannot be 'internal' anymore if we are fully modularizing things out, because - /// they are no longer a part of the same library, especially as we create things like - /// Installation inside push library. - /// - /// So this class contains a bunch of extension methods that can live inside another - /// namespace, which 'wrap' the intenral APIs that already exist. - /// - public static class AVUserExtensions - { - - } -} diff --git a/Storage/Storage/Public/AVFile.cs b/Storage/Storage/Public/AVFile.cs index b359119..204ba21 100644 --- a/Storage/Storage/Public/AVFile.cs +++ b/Storage/Storage/Public/AVFile.cs @@ -23,7 +23,7 @@ namespace LeanCloud { /// await obj.SaveAsync(); /// /// - public partial class AVFile : IJsonConvertible { + public class AVFile : IJsonConvertible { internal static int objectCounter = 0; internal static readonly object Mutex = new object(); private FileState state; @@ -45,7 +45,7 @@ namespace LeanCloud { MimeType = mimeType, MetaData = metaData }; - this.dataStream = data; + dataStream = data; lock (Mutex) { objectCounter++; state.counter = objectCounter; @@ -132,7 +132,7 @@ namespace LeanCloud { objectCounter++; state.counter = objectCounter; } - this.isExternal = true; + isExternal = true; } /// @@ -187,7 +187,7 @@ namespace LeanCloud { } internal AVFile(FileState filestate) { - this.state = filestate; + state = filestate; } internal AVFile(string objectId) : this(new FileState() { @@ -258,7 +258,7 @@ namespace LeanCloud { #endregion IDictionary IJsonConvertible.ToJSON() { - if (this.IsDirty) { + if (IsDirty) { throw new InvalidOperationException( "AVFile must be saved before it can be serialized."); } @@ -292,14 +292,14 @@ namespace LeanCloud { internal Task SaveExternal() { Dictionary strs = new Dictionary() { - { "url", this.Url.ToString() }, - { "name",this.Name }, - { "mime_type",this.MimeType}, - { "metaData",this.MetaData} + { "url", Url.ToString() }, + { "name", Name }, + { "mime_type", MimeType}, + { "metaData", MetaData} }; AVCommand cmd = null; - if (!string.IsNullOrEmpty(this.ObjectId)) { + if (!string.IsNullOrEmpty(ObjectId)) { cmd = new AVCommand { Path = $"files/{ObjectId}", Method = HttpMethod.Put, @@ -331,7 +331,7 @@ namespace LeanCloud { public string ObjectId { get { string str; - lock (this.mutex) { + lock (mutex) { str = state.ObjectId; } return str; @@ -359,8 +359,7 @@ namespace LeanCloud { } static AVFile() { - Dictionary strs = new Dictionary() - { + Dictionary strs = new Dictionary { { "ai", "application/postscript" }, { "aif", "audio/x-aiff" }, { "aifc", "audio/x-aiff" }, @@ -550,15 +549,15 @@ namespace LeanCloud { { "xyz", "chemical/x-xyz" }, { "zip", "application/zip" }, }; - AVFile.MIMETypesDictionary = strs; + MIMETypesDictionary = strs; } internal static string GetMIMEType(string fileName) { try { string str = Path.GetExtension(fileName).Remove(0, 1); - if (!AVFile.MIMETypesDictionary.ContainsKey(str)) { + if (!MIMETypesDictionary.ContainsKey(str)) { return "unknown/unknown"; } - return AVFile.MIMETypesDictionary[str]; + return MIMETypesDictionary[str]; } catch { return "unknown/unknown"; } @@ -585,11 +584,12 @@ namespace LeanCloud { } public static AVFile CreateWithData(string objectId, string name, string url, IDictionary metaData) { - var fileState = new FileState(); - fileState.Name = name; - fileState.ObjectId = objectId; - fileState.Url = new Uri(url); - fileState.MetaData = metaData; + var fileState = new FileState { + Name = name, + ObjectId = objectId, + Url = new Uri(url), + MetaData = metaData + }; return CreateWithState(fileState); } /// @@ -602,7 +602,7 @@ namespace LeanCloud { } internal void MergeFromJSON(IDictionary jsonData) { - lock (this.mutex) { + lock (mutex) { state.ObjectId = jsonData["objectId"] as string; state.Url = new Uri(jsonData["url"] as string, UriKind.Absolute); if (jsonData.ContainsKey("name")) { diff --git a/Storage/Storage/Public/AVObject.cs b/Storage/Storage/Public/AVObject.cs index 05e77b2..fa31756 100644 --- a/Storage/Storage/Public/AVObject.cs +++ b/Storage/Storage/Public/AVObject.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using System.Net; -using System.Reflection; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -13,19 +11,8 @@ using System.Collections; namespace LeanCloud { /// - /// The AVObject is a local representation of data that can be saved and - /// retrieved from the LeanCloud cloud. - /// - /// - /// The basic workflow for creating new data is to construct a new AVObject, - /// use the indexer to fill it with data, and then use SaveAsync() to persist to the - /// database. - /// - /// - /// The basic workflow for accessing existing data is to use a AVQuery - /// to specify which existing data to retrieve. - /// - /// + /// AVObject + /// public class AVObject : IEnumerable>, INotifyPropertyChanged, INotifyPropertyUpdated, INotifyCollectionPropertyUpdated { private static readonly string AutoClassName = "_Automatic"; @@ -615,7 +602,7 @@ string propertyName var saveDirtyFileTasks = DeepTraversal(obj, true) .OfType() .Where(f => f.IsDirty) - .Select(f => f.SaveAsync(cancellationToken)).ToList(); + .Select(f => f.SaveAsync(cancellationToken: cancellationToken)).ToList(); return Task.WhenAll(saveDirtyFileTasks).OnSuccess(_ => { IEnumerable remaining = new List(uniqueObjects); @@ -740,7 +727,7 @@ string propertyName /// The list passed in for convenience. public static Task> FetchAllIfNeededAsync( IEnumerable objects, CancellationToken cancellationToken) where T : AVObject { - return AVObject.EnqueueForAll(objects.Cast(), (Task toAwait) => { + return EnqueueForAll(objects.Cast(), (Task toAwait) => { return FetchAllInternalAsync(objects, false, toAwait, cancellationToken); }, cancellationToken); } @@ -763,7 +750,7 @@ string propertyName /// The list passed in for convenience. public static Task> FetchAllAsync( IEnumerable objects, CancellationToken cancellationToken) where T : AVObject { - return AVObject.EnqueueForAll(objects.Cast(), (Task toAwait) => { + return EnqueueForAll(objects.Cast(), (Task toAwait) => { return FetchAllInternalAsync(objects, true, toAwait, cancellationToken); }, cancellationToken); } @@ -872,7 +859,7 @@ string propertyName var uniqueObjects = new HashSet(objects.OfType().ToList(), new IdentityEqualityComparer()); - return AVObject.EnqueueForAll(uniqueObjects, toAwait => { + return EnqueueForAll(uniqueObjects, toAwait => { var states = uniqueObjects.Select(t => t.state).ToList(); return toAwait.OnSuccess(_ => { var deleteTasks = ObjectController.DeleteAllAsync(states, cancellationToken);