public Task ExecuteParseInstallationSaveHookAsync(ParseInstallation installation) {
   return GetChannelTask.ContinueWith(t => {
     installation.SetIfDifferent("deviceUris", new Dictionary<string, string> {
       { defaultChannelTag, t.Result.Uri }
     });
   });
 }
        public Task SubscribeAsync(IEnumerable <string> channels, CancellationToken cancellationToken)
        {
            ParseInstallation installation = ParseInstallation.CurrentInstallation;

            installation.AddRangeUniqueToList("channels", channels);
            return(installation.SaveAsync(cancellationToken));
        }
示例#3
0
        public void TestChannelGetterSetter()
        {
            var channels = new List <string>()
            {
                "the", "richard"
            };
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "channels", channels }
                }
            };
            ParseInstallation installation = ParseObject.FromState <ParseInstallation>(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]);
        }
示例#4
0
        public Task <ParseInstallation> GetAsync(CancellationToken cancellationToken)
        {
            ParseInstallation cachedCurrent;

            cachedCurrent = CurrentInstallation;

            if (cachedCurrent != null)
            {
                return(Task <ParseInstallation> .FromResult(cachedCurrent));
            }

            return(taskQueue.Enqueue(toAwait => {
                return toAwait.ContinueWith(t => {
                    object temp;
                    ParseClient.ApplicationSettings.TryGetValue("CurrentInstallation", out temp);
                    var installationDataString = temp as string;
                    ParseInstallation installation = null;
                    if (installationDataString != null)
                    {
                        var installationData = ParseClient.DeserializeJsonString(installationDataString);
                        installation = ParseObject.CreateWithoutData <ParseInstallation>(null);
                        installation.HandleFetchResult(ParseObjectCoder.Instance.Decode(installationData, ParseDecoder.Instance));
                    }
                    else
                    {
                        installation = ParseObject.Create <ParseInstallation>();
                        installation.SetIfDifferent("installationId", installationIdController.Get().ToString());
                    }

                    CurrentInstallation = installation;
                    return installation;
                });
            }, cancellationToken));
        }
        public void TestGetCurrentInstallation()
        {
            var          guid  = Guid.NewGuid();
            IObjectState state = new MutableObjectState
            {
                ServerData = new Dictionary <string, object>()
                {
                    { "installationId", guid.ToString() }
                }
            };
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(state, "_Installation");
            var mockController             = new Mock <IParseCurrentInstallationController>();

            mockController.Setup(obj => obj.GetAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(installation));

            ParsePushPlugins.Instance = new ParsePushPlugins
            {
                CurrentInstallationController = mockController.Object
            };

            var currentInstallation = ParseInstallation.CurrentInstallation;

            Assert.IsNotNull(currentInstallation);
            Assert.AreEqual(guid, currentInstallation.InstallationId);
        }
示例#6
0
        public Task SetAsync(ParseInstallation installation, CancellationToken cancellationToken)
        {
            return(taskQueue.Enqueue(toAwait => {
                return toAwait.ContinueWith(_ => {
                    if (installation == null)
                    {
                        ParseClient.ApplicationSettings.Remove("CurrentInstallation");
                    }
                    else
                    {
                        // TODO (hallucinogen): we need to use ParseCurrentCoder instead of this janky encoding
                        var data = installation.ServerDataToJSONObjectForSerialization();
                        data["objectId"] = installation.ObjectId;
                        if (installation.CreatedAt != null)
                        {
                            data["createdAt"] = installation.CreatedAt.Value.ToString(ParseClient.DateFormatString);
                        }
                        if (installation.UpdatedAt != null)
                        {
                            data["updatedAt"] = installation.UpdatedAt.Value.ToString(ParseClient.DateFormatString);
                        }

                        ParseClient.ApplicationSettings["CurrentInstallation"] = Json.Encode(data);
                    }
                    CurrentInstallation = installation;
                });
            }, cancellationToken));
        }
示例#7
0
        public async Task <string> SaveToParseServerAsync(string msgToSave)
        {
            string            result       = msgToSave;
            ParseInstallation installation = ParseInstallation.CurrentInstallation;

            this.InstallationId = installation.InstallationId.ToString();

            // create a ParseObject and set the message data
            var world = new ParseObject("World");

            world["message"]      = "Hello world!";
            world["installation"] = installation; // if removed saves every time without exception

            // Attempt to save to the parse-server
            var contTask = world.SaveAsync();
            await contTask.ContinueWith((antecedant) =>
            {
                if (antecedant.Status == TaskStatus.Faulted)
                {
                    result = antecedant.Exception.InnerException.ToString();
                }
            });

            return(result);
        }
    public Task<ParseInstallation> GetAsync(CancellationToken cancellationToken) {
      ParseInstallation cachedCurrent;
      cachedCurrent = CurrentInstallation;

      if (cachedCurrent != null) {
        return Task<ParseInstallation>.FromResult(cachedCurrent);
      }

      return taskQueue.Enqueue(toAwait => {
        return toAwait.ContinueWith(t => {
          object temp;
          ParseClient.ApplicationSettings.TryGetValue("CurrentInstallation", out temp);
          var installationDataString = temp as string;
          ParseInstallation installation = null;
          if (installationDataString != null) {
            var installationData = ParseClient.DeserializeJsonString(installationDataString);
            installation = ParseObject.CreateWithoutData<ParseInstallation>(null);
            installation.HandleFetchResult(ParseObjectCoder.Instance.Decode(installationData, ParseDecoder.Instance));
          } else {
            installation = ParseObject.Create<ParseInstallation>();
            installation.SetIfDifferent("installationId" , installationIdController.Get().ToString());
          }

          CurrentInstallation = installation;
          return installation;
        });
      }, cancellationToken);
    }
示例#9
0
        public void TestGetCurrentInstallation()
        {
            MutableServiceHub hub = new MutableServiceHub {
            };
            ParseClient client    = new ParseClient(new ServerConnectionData {
                Test = true
            }, hub);

            Guid guid = Guid.NewGuid();

            ParseInstallation installation = client.GenerateObjectFromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["installationId"] = guid.ToString()
                }
            }, "_Installation");

            Mock <IParseCurrentInstallationController> mockController = new Mock <IParseCurrentInstallationController>();

            mockController.Setup(obj => obj.GetAsync(It.IsAny <IServiceHub>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(installation));

            hub.CurrentInstallationController = mockController.Object;

            ParseInstallation currentInstallation = client.GetCurrentInstallation();

            Assert.IsNotNull(currentInstallation);
            Assert.AreEqual(guid, currentInstallation.InstallationId);
        }
        public Task UnsubscribeAsync(IEnumerable <string> channels, CancellationToken cancellationToken)
        {
            ParseInstallation installation = ParseInstallation.CurrentInstallation;

            installation.RemoveAllFromList("channels", channels);
            return(installation.SaveAsync(cancellationToken));
        }
示例#11
0
        public Task TestExistsAsync()
        {
            var mockInstallationIdController = new Mock <IInstallationIdController>();
            var guid = Guid.NewGuid();

            mockInstallationIdController.Setup(obj => obj.Get()).Returns(guid);

            var controller   = new ParseCurrentInstallationController(mockInstallationIdController.Object);
            var installation = new ParseInstallation();

            return(controller.SetAsync(installation, CancellationToken.None).OnSuccess(_ => {
                Assert.AreEqual(installation, controller.CurrentInstallation);
                return controller.ExistsAsync(CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.IsTrue(t.Result);

                controller.ClearFromMemory();

                return controller.ExistsAsync(CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.IsTrue(t.Result);

                controller.ClearFromDisk();

                return controller.ExistsAsync(CancellationToken.None);
            }).Unwrap()
                   .OnSuccess(t => {
                Assert.IsFalse(t.Result);
            }));
        }
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            ParseInstallation installation = ParseInstallation.CurrentInstallation;

            installation.SetDeviceTokenFromData(deviceToken);

            installation.SaveAsync();
        }
 public Task ExecuteParseInstallationSaveHookAsync(ParseInstallation installation) {
   return getToastUriTask.Value.ContinueWith(t => {
     installation.SetIfDifferent("deviceUris", t.Result == null ? null :
       new Dictionary<string, string> {
       { toastChannelTag, t.Result }
     });
   });
 }
 public Task ExecuteParseInstallationSaveHookAsync(ParseInstallation installation)
 {
     return(GetChannelTask.ContinueWith(t => {
         installation.SetIfDifferent("deviceUris", new Dictionary <string, string> {
             { defaultChannelTag, t.Result.Uri }
         });
     }));
 }
 public Task ExecuteParseInstallationSaveHookAsync(ParseInstallation installation)
 {
     return(getToastUriTask.Value.ContinueWith(t => {
         installation.SetIfDifferent("deviceUris", t.Result == null ? null :
                                     new Dictionary <string, string> {
             { toastChannelTag, t.Result }
         });
     }));
 }
        public void TestTimeZoneGetter()
        {
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["timeZone"] = "America/Los_Angeles"
                }
            }, "_Installation");

            Assert.IsNotNull(installation);
            Assert.AreEqual("America/Los_Angeles", installation.TimeZone);
        }
        public void TestLocaleIdentifierGetter()
        {
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["localeIdentifier"] = "en-US"
                }
            }, "_Installation");

            Assert.IsNotNull(installation);
            Assert.AreEqual("en-US", installation.LocaleIdentifier);
        }
示例#18
0
        public void TestTimeZoneGetter()
        {
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "timeZone", "America/Los_Angeles" }
                }
            };
            ParseInstallation installation = ParseObject.FromState <ParseInstallation>(state, "_Installation");

            Assert.NotNull(installation);
            Assert.AreEqual("America/Los_Angeles", installation.TimeZone);
        }
示例#19
0
        public void TestLocaleIdentifierGetter()
        {
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "localeIdentifier", "en-US" }
                }
            };
            ParseInstallation installation = ParseObject.FromState <ParseInstallation>(state, "_Installation");

            Assert.NotNull(installation);
            Assert.AreEqual("en-US", installation.LocaleIdentifier);
        }
        public void TestAppVersionGetterSetter()
        {
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["appVersion"] = "1.2.3"
                }
            }, "_Installation");

            Assert.IsNotNull(installation);
            Assert.AreEqual("1.2.3", installation.AppVersion);

            Assert.ThrowsException <InvalidOperationException>(() => installation["appVersion"] = "1.2.4");
            installation.SetIfDifferent("appVersion", "1.2.4");
            Assert.AreEqual("1.2.4", installation.AppVersion);
        }
        public void TestAppIdentifierGetterSetter()
        {
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["appIdentifier"] = "com.parse.app"
                }
            }, "_Installation");

            Assert.IsNotNull(installation);
            Assert.AreEqual("com.parse.app", installation.AppIdentifier);

            Assert.ThrowsException <InvalidOperationException>(() => installation["appIdentifier"] = "com.parse.newapp");
            installation.SetIfDifferent("appIdentifier", "com.parse.newapp");
            Assert.AreEqual("com.parse.newapp", installation.AppIdentifier);
        }
        public void TestDeviceTypeGetterSetter()
        {
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["deviceType"] = "parseOS"
                }
            }, "_Installation");

            Assert.IsNotNull(installation);
            Assert.AreEqual("parseOS", installation.DeviceType);

            Assert.ThrowsException <InvalidOperationException>(() => installation["deviceType"] = "gogoOS");
            installation.SetIfDifferent("deviceType", "gogoOS");
            Assert.AreEqual("gogoOS", installation.DeviceType);
        }
        public IDictionary <string, object> Encode(ParseInstallation 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);
        }
示例#24
0
        public void TestAppNameGetterSetter()
        {
            ParseInstallation installation = Client.GenerateObjectFromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["appName"] = "parseApp"
                }
            }, "_Installation");

            Assert.IsNotNull(installation);
            Assert.AreEqual("parseApp", installation.AppName);

            Assert.ThrowsException <InvalidOperationException>(() => installation["appName"] = "gogoApp");

            installation.SetIfDifferent("appName", "gogoApp");
            Assert.AreEqual("gogoApp", installation.AppName);
        }
示例#25
0
        public Task <ParseInstallation> GetAsync(CancellationToken cancellationToken)
        {
            ParseInstallation cachedCurrent;

            cachedCurrent = CurrentInstallation;

            if (cachedCurrent != null)
            {
                return(Task <ParseInstallation> .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;
                        ParseInstallation 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 = ParseObject.Create <ParseInstallation>();
                            fetchTask = installationIdController.GetAsync().ContinueWith(t =>
                            {
                                installation.SetIfDifferent("installationId", t.Result.ToString());
                            }, Parse.ParseClient.DefaultTaskContinuationOptions);
                        }

                        CurrentInstallation = installation;
                        return fetchTask.ContinueWith(t =>
                        {
                            return installation;
                        }, Parse.ParseClient.DefaultTaskContinuationOptions);
                    });
                }, Parse.ParseClient.DefaultTaskContinuationOptions).Unwrap().Unwrap();
            }, cancellationToken));
        }
    public Task SetAsync(ParseInstallation 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 void TestAppNameGetterSetter()
        {
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "appName", "parseApp" }
                }
            };
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(state, "_Installation");

            Assert.NotNull(installation);
            Assert.AreEqual("parseApp", installation.AppName);

            Assert.Throws <InvalidOperationException>(() => installation["appName"] = "gogoApp");
            installation.SetIfDifferent("appName", "gogoApp");
            Assert.AreEqual("gogoApp", installation.AppName);
        }
示例#28
0
        public void TestAppIdentifierGetterSetter()
        {
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "appIdentifier", "com.parse.app" }
                }
            };
            ParseInstallation installation = ParseObject.FromState <ParseInstallation>(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);
        }
示例#29
0
        public void TestAppVersionGetterSetter()
        {
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "appVersion", "1.2.3" }
                }
            };
            ParseInstallation installation = ParseObject.FromState <ParseInstallation>(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);
        }
示例#30
0
        public void TestDeviceTypeGetterSetter()
        {
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "deviceType", "parseOS" }
                }
            };
            ParseInstallation installation = ParseObject.FromState <ParseInstallation>(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()
        {
            Guid guid = Guid.NewGuid();
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["installationId"] = guid.ToString()
                }
            }, "_Installation");

            Assert.IsNotNull(installation);
            Assert.AreEqual(guid, installation.InstallationId);

            Guid newGuid = Guid.NewGuid();

            Assert.ThrowsException <InvalidOperationException>(() => installation["installationId"] = newGuid);
            installation.SetIfDifferent("installationId", newGuid.ToString());
            Assert.AreEqual(newGuid, installation.InstallationId);
        }
示例#32
0
        public void TestInstallationIdGetterSetter()
        {
            var          guid  = Guid.NewGuid();
            IObjectState state = new MutableObjectState {
                ServerData = new Dictionary <string, object>()
                {
                    { "installationId", guid.ToString() }
                }
            };
            ParseInstallation installation = ParseObject.FromState <ParseInstallation>(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);
        }
示例#33
0
        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;
                }

                ParseInstallation installation = ParseInstallation.CurrentInstallation;
                installation.SetDeviceTokenFromData(deviceToken);

                // Optimistically assume this will finish.
                installation.SaveAsync();
            });
        }
        public void TestChannelGetterSetter()
        {
            ParseInstallation installation = ParseObjectExtensions.FromState <ParseInstallation>(new MutableObjectState {
                ServerData = new Dictionary <string, object> {
                    ["channels"] = new List <string> {
                        "the", "richard"
                    }
                }
            }, "_Installation");

            Assert.IsNotNull(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 SetAsync(ParseInstallation installation, CancellationToken cancellationToken) {
      return taskQueue.Enqueue(toAwait => {
        return toAwait.ContinueWith(_ => {
          if (installation == null) {
            ParseClient.ApplicationSettings.Remove("CurrentInstallation");
          } else {
            // TODO (hallucinogen): we need to use ParseCurrentCoder instead of this janky encoding
            var data = installation.ServerDataToJSONObjectForSerialization();
            data["objectId"] = installation.ObjectId;
            if (installation.CreatedAt != null) {
              data["createdAt"] = installation.CreatedAt.Value.ToString(ParseClient.DateFormatString);
            }
            if (installation.UpdatedAt != null) {
              data["updatedAt"] = installation.UpdatedAt.Value.ToString(ParseClient.DateFormatString);
            }

            ParseClient.ApplicationSettings["CurrentInstallation"] = Json.Encode(data);
          }
          CurrentInstallation = installation;
        });
      }, cancellationToken);
    }
 public void ClearFromMemory() {
   CurrentInstallation = null;
 }
 public bool IsCurrent(ParseInstallation installation) {
   return CurrentInstallation == installation;
 }
    public Task<ParseInstallation> GetAsync(CancellationToken cancellationToken) {
      ParseInstallation cachedCurrent;
      cachedCurrent = CurrentInstallation;

      if (cachedCurrent != null) {
        return Task<ParseInstallation>.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;
            ParseInstallation 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 = ParseObject.Create<ParseInstallation>();
              fetchTask = installationIdController.GetAsync().ContinueWith(t => {
                installation.SetIfDifferent("installationId" , t.Result.ToString());
              });
            }

            CurrentInstallation = installation;
            return fetchTask.ContinueWith(t => installation);
          });
        }).Unwrap().Unwrap();
      }, cancellationToken);
    }
 public Task ExecuteParseInstallationSaveHookAsync(ParseInstallation installation) {
   return Task.FromResult<object>(null);
 }
 public Task ExecuteParseInstallationSaveHookAsync(ParseInstallation installation) {
   return Task.Run(() => {
     installation.SetIfDifferent("badge", installation.Badge);
   });
 }