public Task <AVInstallation> GetAsync(CancellationToken cancellationToken) { AVInstallation cachedCurrent; cachedCurrent = CurrentInstallation; if (cachedCurrent != null) { return(Task <AVInstallation> .FromResult(cachedCurrent)); } return(taskQueue.Enqueue(toAwait => { return toAwait.ContinueWith(t => { object temp; AVClient.ApplicationSettings.TryGetValue("CurrentInstallation", out temp); var installationDataString = temp as string; AVInstallation installation = null; if (installationDataString != null) { var installationData = AVClient.DeserializeJsonString(installationDataString); installation = AVObject.CreateWithoutData <AVInstallation>(null); installation.HandleFetchResult(AVObjectCoder.Instance.Decode(installationData, AVDecoder.Instance)); } else { installation = AVObject.Create <AVInstallation>(); installation.SetIfDifferent("installationId", installationIdController.Get().ToString()); } CurrentInstallation = installation; return installation; }); }, cancellationToken)); }
public void TestRemove() { AVObject obj = AVObject.Create("Corgi"); obj["gogo"] = true; Assert.True(obj.ContainsKey("gogo")); obj.Remove("gogo"); Assert.False(obj.ContainsKey("gogo")); IObjectState state = new MutableObjectState { ObjectId = "waGiManPutr4Pet1r", ClassName = "Pagi", CreatedAt = new DateTime(), ServerData = new Dictionary <string, object>() { { "username", "kevin" }, { "sessionToken", "se551onT0k3n" } } }; obj = AVObjectExtensions.FromState <AVObject>(state, "Corgi"); Assert.True(obj.ContainsKey("username")); Assert.True(obj.ContainsKey("sessionToken")); obj.Remove("username"); Assert.False(obj.ContainsKey("username")); Assert.True(obj.ContainsKey("sessionToken")); }
public void TestIndexGetterSetter() { AVObject obj = AVObject.Create("Corgi"); obj["gogo"] = true; obj["list"] = new List <string>(); obj["dict"] = new Dictionary <string, object>(); obj["fakeACL"] = new AVACL(); obj["obj"] = new AVObject("Corgi"); Assert.True(obj.ContainsKey("gogo")); Assert.IsInstanceOf <bool>(obj["gogo"]); Assert.True(obj.ContainsKey("list")); Assert.IsInstanceOf <IList <string> >(obj["list"]); Assert.True(obj.ContainsKey("dict")); Assert.IsInstanceOf <IDictionary <string, object> >(obj["dict"]); Assert.True(obj.ContainsKey("fakeACL")); Assert.IsInstanceOf <AVACL>(obj["fakeACL"]); Assert.True(obj.ContainsKey("obj")); Assert.IsInstanceOf <AVObject>(obj["obj"]); Assert.Throws <KeyNotFoundException>(() => { var gogo = obj["missingItem"]; }); }
public void TestDeepTraversal() { AVObject obj = AVObject.Create("Corgi"); IDictionary <string, object> someDict = new Dictionary <string, object>() { { "someList", new List <object>() } }; obj["obj"] = AVObject.Create("Pug"); obj["obj2"] = AVObject.Create("Pug"); obj["list"] = new List <object>(); obj["dict"] = someDict; obj["someBool"] = true; obj["someInt"] = 23; IEnumerable <object> traverseResult = AVObjectExtensions.DeepTraversal(obj, true, true); Assert.AreEqual(8, traverseResult.Count()); // Don't traverse beyond the root (since root is AVObject) traverseResult = AVObjectExtensions.DeepTraversal(obj, false, true); Assert.AreEqual(1, traverseResult.Count()); traverseResult = AVObjectExtensions.DeepTraversal(someDict, false, true); Assert.AreEqual(2, traverseResult.Count()); // Should ignore root traverseResult = AVObjectExtensions.DeepTraversal(obj, true, false); Assert.AreEqual(7, traverseResult.Count()); }
public void TestRegisterSubclass() { Assert.Throws <InvalidCastException>(() => AVObject.Create <SubClass>()); AVObject.RegisterSubclass <SubClass>(); Assert.DoesNotThrow(() => AVObject.Create <SubClass>()); AVPlugins.Instance.SubclassingController.UnregisterSubclass(typeof(UnregisteredSubClass)); Assert.DoesNotThrow(() => AVObject.Create <SubClass>()); AVPlugins.Instance.SubclassingController.UnregisterSubclass(typeof(SubClass)); Assert.Throws <InvalidCastException>(() => AVObject.Create <SubClass>()); }
public void TestRevert() { AVObject obj = AVObject.Create("Corgi"); obj["gogo"] = true; Assert.True(obj.IsDirty); Assert.AreEqual(1, obj.GetCurrentOperations().Count); Assert.True(obj.ContainsKey("gogo")); obj.Revert(); Assert.True(obj.IsDirty); Assert.AreEqual(0, obj.GetCurrentOperations().Count); Assert.False(obj.ContainsKey("gogo")); }
public void TestParseObjectCreate() { AVObject obj = AVObject.Create("Corgi"); Assert.AreEqual("Corgi", obj.ClassName); Assert.Null(obj.CreatedAt); Assert.True(obj.IsDataAvailable); Assert.True(obj.IsDirty); AVObject obj2 = AVObject.CreateWithoutData("Corgi", "waGiManPutr4Pet1r"); Assert.AreEqual("Corgi", obj2.ClassName); Assert.AreEqual("waGiManPutr4Pet1r", obj2.ObjectId); Assert.Null(obj2.CreatedAt); Assert.False(obj2.IsDataAvailable); Assert.False(obj2.IsDirty); }
public void TestParseObjectCreateWithGeneric() { AVObject.RegisterSubclass <SubClass>(); AVObject obj = AVObject.Create <SubClass>(); Assert.AreEqual("SubClass", obj.ClassName); Assert.Null(obj.CreatedAt); Assert.True(obj.IsDataAvailable); Assert.True(obj.IsDirty); AVObject obj2 = AVObject.CreateWithoutData <SubClass>("waGiManPutr4Pet1r"); Assert.AreEqual("SubClass", obj2.ClassName); Assert.AreEqual("waGiManPutr4Pet1r", obj2.ObjectId); Assert.Null(obj2.CreatedAt); Assert.False(obj2.IsDataAvailable); Assert.False(obj2.IsDirty); }
private async void SaveUser() { var studentInfo = await app.Assist.GetStudentDetails(); var user = AVObject.Create <AVUser>(); // var user = new AVUser(); var username = app.Assist.Username; var password = studentInfo.Id + studentInfo.GaokaoId; user.Username = username; user.Password = password; user.Email = user.Username + "@mail.bnu.edu.cn"; user["RegistrationTime"] = studentInfo.RegistrationTime; user["Nationality"] = studentInfo.Nationality; user["AdmitSpeciality"] = studentInfo.Speciality; user["MiddleSchool"] = studentInfo.MiddleSchool; user["ClassName"] = studentInfo.ClassName; user["CollegeWill"] = studentInfo.CollegeWill; user["SchoolSystem"] = studentInfo.SchoolSystem; user["EducationLevel"] = studentInfo.EducationLevel; user["Name"] = studentInfo.Name; user["Number"] = studentInfo.Number; user["College"] = studentInfo.College; user["Gender"] = studentInfo.Gender; user["Address"] = studentInfo.Address; user["Pinyin"] = studentInfo.Pinyin; user["mobile"] = studentInfo.Mobile; user["RegistrationGrade"] = studentInfo.RegistrationGrade; user["Birthday"] = studentInfo.Birthday; await user.SignUpAsync().ContinueWith(async t => { await AVUser.LogInAsync(username, password).ContinueWith(t2 => { }); }); }
public Task <AVInstallation> GetAsync(CancellationToken cancellationToken) { AVInstallation cachedCurrent; cachedCurrent = CurrentInstallation; if (cachedCurrent != null) { return(Task <AVInstallation> .FromResult(cachedCurrent)); } return(taskQueue.Enqueue(toAwait => { return toAwait.ContinueWith(_ => { return storageController.LoadAsync().OnSuccess(stroage => { Task fetchTask; object temp; stroage.Result.TryGetValue(ParseInstallationKey, out temp); var installationDataString = temp as string; AVInstallation installation = null; if (installationDataString != null) { var installationData = Json.Parse(installationDataString) as IDictionary <string, object>; installation = installationCoder.Decode(installationData); fetchTask = Task.FromResult <object>(null); } else { installation = AVObject.Create <AVInstallation>(); fetchTask = installationIdController.GetAsync().ContinueWith(t => { installation.SetIfDifferent("installationId", t.Result.ToString()); }); } CurrentInstallation = installation; return fetchTask.ContinueWith(t => installation); }); }).Unwrap().Unwrap(); }, cancellationToken)); }
public static AVObject ToAv(this object obj) { if (obj == null) { throw new NullReferenceException(); } var avObject = AVObject.Create(obj.GetType().Name); foreach (var field in obj.GetType().GetFields()) { if (!field.IsPublic) { continue; } var value = field.GetValue(obj); if (value == null) { continue; } avObject[field.Name] = value; } foreach (var property in obj.GetType().GetProperties()) { var value = property.GetValue(obj); if (value == null) { continue; } avObject[property.Name] = value; } return(avObject); }
public void TestParseObjectCreateWithGenericFailWithoutSubclass() { Assert.Throws <InvalidCastException>(() => AVObject.Create <SubClass>()); }