/// <summary> /// Creates a push which will target every device. The Data field must be set before calling SendAsync. /// </summary> public ParsePush() { mutex = new object(); // Default to everyone. state = new MutablePushState { Query = ParseInstallation.Query }; }
public IDictionary<string, object> Encode(IPushState state) { if (state.Alert == null && state.Data == null) { throw new InvalidOperationException("A push must have either an Alert or Data"); } if (state.Channels == null && state.Query == null) { throw new InvalidOperationException("A push must have either Channels or a Query"); } var data = state.Data ?? new Dictionary<string, object> { { "alert", state.Alert } }; var query = state.Query ?? ParseInstallation.Query; if (state.Channels != null) { query = query.WhereContainedIn("channels", state.Channels); } var payload = new Dictionary<string, object> { { "data", data }, { "where", query.BuildParameters(false).GetOrDefault("where", new Dictionary<string, object>()) }, }; if (state.Expiration.HasValue) { payload["expiration_time"] = state.Expiration.Value.ToString("yyyy-MM-ddTHH:mm:ssZ"); } else if (state.ExpirationInterval.HasValue) { payload["expiration_interval"] = state.ExpirationInterval.Value.TotalSeconds; } if (state.PushTime.HasValue) { payload["push_time"] = state.PushTime.Value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"); } return payload; }
private void MutateState(Action <MutablePushState> func) { lock (mutex) { state = state.MutatedClone(func); } }
IParsePushController GetMockedPushController(IPushState expectedPushState) { Mock <IParsePushController> mockedController = new Mock <IParsePushController>(MockBehavior.Strict); mockedController.Setup(obj => obj.SendPushNotificationAsync(It.Is <IPushState>(s => s.Equals(expectedPushState)), It.IsAny <IServiceHub>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(false)); return(mockedController.Object); }
/// <summary> /// Creates a push which will target every device. The Data field must be set before calling SendAsync. /// </summary> public AVPush() { mutex = new object(); // Default to everyone. state = new MutablePushState { Query = AVInstallation.Query }; }
public Task SendPushNotificationAsync(IPushState state, String sessionToken, CancellationToken cancellationToken) { var command = new ParseCommand("/1/push", method: "POST", sessionToken: sessionToken, data: ParsePushEncoder.Instance.Encode(state)); return ParseClient.ParseCommandRunner.RunCommandAsync(command, cancellationToken: cancellationToken); }
public Task SendPushNotificationAsync(IPushState state, String sessionToken, CancellationToken cancellationToken) { var command = new ParseCommand("/1/push", method: "POST", sessionToken: sessionToken, data: ParsePushEncoder.Instance.Encode(state)); return(ParseClient.ParseCommandRunner.RunCommandAsync(command, cancellationToken: cancellationToken)); }
public void TestMutatedClone() { MutablePushState state = new MutablePushState(); IPushState mutated = state.MutatedClone(s => s.Alert = "test"); Assert.AreEqual(null, state.Alert); Assert.AreEqual("test", mutated.Alert); }
public Task SendPushNotificationAsync(IPushState state, CancellationToken cancellationToken) { return currentUserController.GetCurrentSessionTokenAsync(cancellationToken).OnSuccess(sessionTokenTask => { var command = new ParseCommand("push", method: "POST", sessionToken: sessionTokenTask.Result, data: ParsePushEncoder.Instance.Encode(state)); return commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken); }).Unwrap(); }
public Task SendPushNotificationAsync(IPushState state, CancellationToken cancellationToken) { return(currentUserController.GetCurrentSessionTokenAsync(cancellationToken).OnSuccess(sessionTokenTask => { var command = new ParseCommand("push", method: "POST", sessionToken: sessionTokenTask.Result, data: ParsePushEncoder.Instance.Encode(state)); return commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken); }).Unwrap()); }
private IParsePushController GetMockedPushController(IPushState expectedPushState) { Mock<IParsePushController> mockedController = new Mock<IParsePushController>(MockBehavior.Strict); mockedController.Setup( obj => obj.SendPushNotificationAsync( It.Is<IPushState>(s => s.Equals(expectedPushState)), It.IsAny<CancellationToken>() ) ).Returns(Task.FromResult(false)); return mockedController.Object; }
public IDictionary <string, object> Encode(IPushState state) { if (state.Alert is null && state.Data is null) { throw new InvalidOperationException("A push must have either an Alert or Data"); } if (state.Channels is null && state.Query is null) { throw new InvalidOperationException("A push must have either Channels or a Query"); } ParseQuery <ParseInstallation> query = state.Query ?? ParseInstallation.Query; if (state.Channels != null) { query = query.WhereContainedIn("channels", state.Channels); } Dictionary <string, object> payload = new Dictionary <string, object> { ["data"] = state.Data ?? new Dictionary <string, object> { ["alert"] = state.Alert }, ["where"] = query.BuildParameters().GetOrDefault("where", new Dictionary <string, object> { }), }; if (state.Expiration.HasValue) { payload["expiration_time"] = state.Expiration.Value.ToString("yyyy-MM-ddTHH:mm:ssZ"); } else if (state.ExpirationInterval.HasValue) { payload["expiration_interval"] = state.ExpirationInterval.Value.TotalSeconds; } if (state.PushTime.HasValue) { payload["push_time"] = state.PushTime.Value.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"); } return(payload); }
public IDictionary <string, object> Encode(IPushState state) { if (state.Alert is null && state.Data is null) { throw new InvalidOperationException("A push must have either an Alert or Data"); } if (state.Channels is null && state.Query is null) { throw new InvalidOperationException("A push must have either Channels or a Query"); } IDictionary <string, object> data = state.Data ?? new Dictionary <string, object> { ["alert"] = state.Alert }; #warning Verify that it is fine to instantiate a ParseQuery<ParseInstallation> here with a default(IServiceHub). ParseQuery <ParseInstallation> query = state.Query ?? new ParseQuery <ParseInstallation>(default, "_Installation")
public IDictionary <string, object> Encode(IPushState state) { if (state.Alert == null && state.Data == null) { throw new InvalidOperationException("A push must have either an Alert or Data"); } if (state.Channels == null && state.Query == null) { throw new InvalidOperationException("A push must have either Channels or a Query"); } var data = state.Data ?? new Dictionary <string, object> { { "alert", state.Alert } }; var query = state.Query ?? AVInstallation.Query; if (state.Channels != null) { query = query.WhereContainedIn("channels", state.Channels); } var payload = new Dictionary <string, object> { { "data", data }, { "where", query.BuildParameters(false).GetOrDefault("where", new Dictionary <string, object>()) }, }; if (state.Expiration.HasValue) { payload["expiration_time"] = state.Expiration.Value.ToString("yyyy-MM-ddTHH:mm:ssZ"); } else if (state.ExpirationInterval.HasValue) { payload["expiration_interval"] = state.ExpirationInterval.Value.TotalSeconds; } return(payload); }
private void MutateState(Action<MutablePushState> func) { lock (mutex) { state = state.MutatedClone(func); } }
public Task SendPushNotificationAsync(IPushState state, CancellationToken cancellationToken) => CurrentUserController.GetCurrentSessionTokenAsync(cancellationToken).OnSuccess(sessionTokenTask => CommandRunner.RunCommandAsync(new ParseCommand("push", "POST", sessionTokenTask.Result, data: ParsePushEncoder.Instance.Encode(state)), cancellationToken: cancellationToken)).Unwrap();