public Task ExecuteParseInstallationSaveHookAsync(AVInstallation installation) { return(Task.Run(() => { installation.SetIfDifferent("badge", installation.Badge); })); }
public Task SubscribeAsync(IEnumerable <string> channels, CancellationToken cancellationToken) { AVInstallation installation = AVInstallation.CurrentInstallation; installation.AddRangeUniqueToList("channels", channels); return(installation.SaveAsync(cancellationToken)); }
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 TestChannelGetterSetter() { var channels = new List <string>() { "the", "richard" }; IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "channels", channels } } }; AVInstallation installation = AVObjectExtensions.FromState <AVInstallation>(state, "_Installation"); Assert.NotNull(installation); Assert.AreEqual("the", installation.Channels[0]); Assert.AreEqual("richard", installation.Channels[1]); installation.Channels = new List <string>() { "mr", "kevin" }; Assert.AreEqual("mr", installation.Channels[0]); Assert.AreEqual("kevin", installation.Channels[1]); }
public Task UnsubscribeAsync(IEnumerable <string> channels, CancellationToken cancellationToken) { AVInstallation installation = AVInstallation.CurrentInstallation; installation.RemoveAllFromList("channels", channels); return(installation.SaveAsync(cancellationToken)); }
public Task SetAsync(AVInstallation installation, CancellationToken cancellationToken) { return(taskQueue.Enqueue(toAwait => { return toAwait.ContinueWith(_ => { if (installation == null) { AVClient.ApplicationSettings.Remove("CurrentInstallation"); } else { // TODO (hallucinogen): we need to use AVCurrentCoder instead of this janky encoding var data = installation.ServerDataToJSONObjectForSerialization(); data["objectId"] = installation.ObjectId; if (installation.CreatedAt != null) { data["createdAt"] = installation.CreatedAt.Value.ToString(AVClient.DateFormatString); } if (installation.UpdatedAt != null) { data["updatedAt"] = installation.UpdatedAt.Value.ToString(AVClient.DateFormatString); } AVClient.ApplicationSettings["CurrentInstallation"] = Json.Encode(data); } CurrentInstallation = installation; }); }, cancellationToken)); }
public Task ExecuteParseInstallationSaveHookAsync(AVInstallation installation) { return(GetChannelTask.ContinueWith(t => { installation.SetIfDifferent("deviceUris", new Dictionary <string, string> { { defaultChannelTag, t.Result.Uri } }); })); }
public Task ExecuteParseInstallationSaveHookAsync(AVInstallation installation) { return getToastUriTask.Value.ContinueWith(t => { installation.SetIfDifferent("deviceUris", t.Result == null ? null : new Dictionary<string, string> { { toastChannelTag, t.Result } }); }); }
public Task ExecuteParseInstallationSaveHookAsync(AVInstallation installation) { return(getToastUriTask.Value.ContinueWith(t => { installation.SetIfDifferent("deviceUris", t.Result == null ? null : new Dictionary <string, string> { { toastChannelTag, t.Result } }); })); }
public void TestTimeZoneGetter() { IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "timeZone", "America/Los_Angeles" } } }; AVInstallation installation = AVObjectExtensions.FromState <AVInstallation>(state, "_Installation"); Assert.NotNull(installation); Assert.AreEqual("America/Los_Angeles", installation.TimeZone); }
public void TestLocaleIdentifierGetter() { IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "localeIdentifier", "en-US" } } }; AVInstallation installation = AVObjectExtensions.FromState <AVInstallation>(state, "_Installation"); Assert.NotNull(installation); Assert.AreEqual("en-US", installation.LocaleIdentifier); }
public IDictionary <string, object> Encode(AVInstallation installation) { var state = installation.GetState(); var data = PointerOrLocalIdEncoder.Instance.Encode(state.ToDictionary(x => x.Key, x => x.Value)) as IDictionary <string, object>; data["objectId"] = state.ObjectId; if (state.CreatedAt != null) { data["createdAt"] = state.CreatedAt.Value.ToString(ISO8601Format); } if (state.UpdatedAt != null) { data["updatedAt"] = state.UpdatedAt.Value.ToString(ISO8601Format); } return(data); }
public void TestAppVersionGetterSetter() { IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "appVersion", "1.2.3" } } }; AVInstallation installation = AVObjectExtensions.FromState <AVInstallation>(state, "_Installation"); Assert.NotNull(installation); Assert.AreEqual("1.2.3", installation.AppVersion); Assert.Throws <InvalidOperationException>(() => installation["appVersion"] = "1.2.4"); installation.SetIfDifferent("appVersion", "1.2.4"); Assert.AreEqual("1.2.4", installation.AppVersion); }
public void TestAppIdentifierGetterSetter() { IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "appIdentifier", "com.parse.app" } } }; AVInstallation installation = AVObjectExtensions.FromState <AVInstallation>(state, "_Installation"); Assert.NotNull(installation); Assert.AreEqual("com.parse.app", installation.AppIdentifier); Assert.Throws <InvalidOperationException>(() => installation["appIdentifier"] = "com.parse.newapp"); installation.SetIfDifferent("appIdentifier", "com.parse.newapp"); Assert.AreEqual("com.parse.newapp", installation.AppIdentifier); }
public void TestDeviceTypeGetterSetter() { IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "deviceType", "parseOS" } } }; AVInstallation installation = AVObjectExtensions.FromState <AVInstallation>(state, "_Installation"); Assert.NotNull(installation); Assert.AreEqual("parseOS", installation.DeviceType); Assert.Throws <InvalidOperationException>(() => installation["deviceType"] = "gogoOS"); installation.SetIfDifferent("deviceType", "gogoOS"); Assert.AreEqual("gogoOS", installation.DeviceType); }
public void TestInstallationIdGetterSetter() { var guid = Guid.NewGuid(); IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "installationId", guid.ToString() } } }; AVInstallation installation = AVObjectExtensions.FromState <AVInstallation>(state, "_Installation"); Assert.NotNull(installation); Assert.AreEqual(guid, installation.InstallationId); var newGuid = Guid.NewGuid(); Assert.Throws <InvalidOperationException>(() => installation["installationId"] = newGuid); installation.SetIfDifferent <string>("installationId", newGuid.ToString()); Assert.AreEqual(newGuid, installation.InstallationId); }
public void Initialize() { // We can only set some values here since we can be sure that Initialize is always called // from main thread. appBuildVersion = Application.version; appName = Application.productName; RegisterDeviceTokenRequest(deviceToken => { if (deviceToken == null) { return; } AVInstallation installation = AVInstallation.CurrentInstallation; installation.SetDeviceTokenFromData(deviceToken); // Optimistically assume this will finish. installation.SaveAsync(); }); }
public Task SetAsync(AVInstallation installation, CancellationToken cancellationToken) { return(taskQueue.Enqueue(toAwait => { return toAwait.ContinueWith(_ => { Task saveTask = storageController.LoadAsync().OnSuccess(storage => { if (installation == null) { return storage.Result.RemoveAsync(ParseInstallationKey); } else { var data = installationCoder.Encode(installation); return storage.Result.AddAsync(ParseInstallationKey, Json.Encode(data)); } }).Unwrap(); CurrentInstallation = installation; return saveTask; }).Unwrap(); }, cancellationToken)); }
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 void TestGetCurrentInstallation() { var guid = Guid.NewGuid(); IObjectState state = new MutableObjectState { ServerData = new Dictionary <string, object>() { { "installationId", guid.ToString() } } }; AVInstallation installation = AVObjectExtensions.FromState <AVInstallation>(state, "_Installation"); var mockController = new Mock <IAVCurrentInstallationController>(); mockController.Setup(obj => obj.GetAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(installation)); AVPushPlugins.Instance = new AVPushPlugins { CurrentInstallationController = mockController.Object }; var currentInstallation = AVInstallation.CurrentInstallation; Assert.NotNull(currentInstallation); Assert.AreEqual(guid, currentInstallation.InstallationId); }
public Task ExecuteParseInstallationSaveHookAsync(AVInstallation installation) { return Task.FromResult<object>(null); }
public void ClearFromMemory() { CurrentInstallation = null; }
public void ClearFromMemory() { CurrentInstallation = null; }
public Task SetAsync(AVInstallation installation, CancellationToken cancellationToken) { return taskQueue.Enqueue(toAwait => { return toAwait.ContinueWith(_ => { Task saveTask = storageController.LoadAsync().OnSuccess(storage => { if (installation == null) { return storage.Result.RemoveAsync(ParseInstallationKey); } else { var data = installationCoder.Encode(installation); return storage.Result.AddAsync(ParseInstallationKey, Json.Encode(data)); } }).Unwrap(); CurrentInstallation = installation; return saveTask; }).Unwrap(); }, cancellationToken); }
public bool IsCurrent(AVInstallation installation) { return CurrentInstallation == installation; }
public Task ExecuteParseInstallationSaveHookAsync(AVInstallation installation) { return(Task.FromResult <object>(null)); }
public Task ExecuteParseInstallationSaveHookAsync(AVInstallation installation) { return Task.Run(() => { installation.SetIfDifferent("badge", installation.Badge); }); }
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 Task ExecuteParseInstallationSaveHookAsync(AVInstallation installation) { return GetChannelTask.ContinueWith(t => { installation.SetIfDifferent("deviceUris", new Dictionary<string, string> { { defaultChannelTag, t.Result.Uri } }); }); }
public bool IsCurrent(AVInstallation installation) { return(CurrentInstallation == installation); }