示例#1
0
 /// <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;
    }
示例#3
0
 private void MutateState(Action <MutablePushState> func)
 {
     lock (mutex)
     {
         state = state.MutatedClone(func);
     }
 }
示例#4
0
        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);
        }
示例#5
0
 /// <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);
    }
示例#7
0
        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));
        }
示例#8
0
        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();
    }
示例#10
0
        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());
        }
示例#11
0
    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;
    }
示例#12
0
        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);
        }
示例#13
0
        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")
示例#14
0
        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);
        }
示例#15
0
 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();