public void TestPartialUpdateOperation_Remove()
        {
            RecordWithPartialUpdateOperation <string> record = new RecordWithPartialUpdateOperation <string>
            {
                ObjectID = "myID",
                Update   = PartialUpdateOperation <string> .Remove("something"),
            };

            string json = JsonConvert.SerializeObject(record, JsonConfig.AlgoliaJsonSerializerSettings);

            Assert.AreEqual(json, "{\"objectID\":\"myID\",\"update\":{\"_operation\":\"Remove\",\"value\":\"something\"}}");
        }
        public void TestPartialUpdateOperation_Decrement()
        {
            RecordWithPartialUpdateOperation <int> record = new RecordWithPartialUpdateOperation <int>
            {
                ObjectID = "myID",
                Update   = PartialUpdateOperation <int> .Decrement(2),
            };

            string json = JsonConvert.SerializeObject(record, JsonConfig.AlgoliaJsonSerializerSettings);

            Assert.AreEqual(json, "{\"objectID\":\"myID\",\"update\":{\"_operation\":\"Decrement\",\"value\":2}}");
        }
示例#3
0
        private async Task PatchTagsForUserDevicesAsync(Guid userId, UpdateOperationType op, string tag)
        {
            var devices = await _deviceRepository.GetManyByUserIdAsync(userId);

            var operation = new PartialUpdateOperation
            {
                Operation = op,
                Path      = "/tags",
                Value     = tag
            };

            foreach (var device in devices)
            {
                await _client.PatchInstallationAsync(device.Id.ToString(), new List <PartialUpdateOperation> {
                    operation
                });
            }
        }
        private async Task PatchTagsForUserDevicesAsync(IEnumerable <string> deviceIds, UpdateOperationType op,
                                                        string tag)
        {
            if (!deviceIds.Any())
            {
                return;
            }

            var operation = new PartialUpdateOperation
            {
                Operation = op,
                Path      = "/tags"
            };

            if (op == UpdateOperationType.Add)
            {
                operation.Value = tag;
            }
            else if (op == UpdateOperationType.Remove)
            {
                operation.Path += $"/{tag}";
            }

            foreach (var id in deviceIds)
            {
                try
                {
                    await RenewClientAndExecuteAsync(async client =>
                                                     await client.PatchInstallationAsync(id, new List <PartialUpdateOperation> {
                        operation
                    }));
                }
                catch (Exception e)
                {
                    if (e.InnerException == null || !e.InnerException.Message.Contains("(404) Not Found"))
                    {
                        throw e;
                    }
                }
            }
        }
示例#5
0
        private async Task PatchTagsForUserDevicesAsync(IEnumerable <string> deviceIds, UpdateOperationType op, string tag)
        {
            if (!deviceIds.Any())
            {
                return;
            }

            var operation = new PartialUpdateOperation
            {
                Operation = op,
                Path      = "/tags",
                Value     = tag
            };

            foreach (var id in deviceIds)
            {
                await _client.PatchInstallationAsync(id, new List <PartialUpdateOperation> {
                    operation
                });
            }
        }