public async Task Handle(SynchronizedObjectUpdatedNotification notification,
                                 CancellationToken cancellationToken)
        {
            var participantGroups = notification.Participants.Select(CoreHubGroups.OfParticipant);

            if (notification.PreviousValue == null)
            {
                var payload = new SyncObjPayload <object>(notification.SyncObjId, notification.Value);
                await _hubContext.Clients.Groups(participantGroups)
                .OnSynchronizeObjectState(payload, cancellationToken);
            }
            else
            {
                var patch = JsonPatchFactory.Create(notification.PreviousValue, notification.Value, JsonConfig.Default,
                                                    JsonPatchFactory.DefaultOptions);

                if (!patch.Operations.Any())
                {
                    return;
                }

                var payload = new SyncObjPayload <JsonPatchDocument>(notification.SyncObjId, patch);

                await _hubContext.Clients.Groups(participantGroups)
                .OnSynchronizedObjectUpdated(payload, cancellationToken);
            }
        }
Beispiel #2
0
        public void TestPatch(string original, string modified, string expectedPatch, string comment)
        {
            var originalToken = JToken.Parse(original);
            var modifiedToken = JToken.Parse(modified);

            // generate patch
            var actualPatch = JsonPatchFactory.Create(originalToken, modifiedToken, JsonPatchFactory.DefaultOptions);

            // assert
            var originalObj = originalToken.ToObject <dynamic>();

            actualPatch.ApplyTo(originalObj);

            var resultingToken = JToken.FromObject(originalObj);

            Assert.True(JToken.DeepEquals(resultingToken, modifiedToken),
                        $"Comment: {comment}\r\nexpected patch: {expectedPatch}\r\nactual patch: {JToken.FromObject(actualPatch)}\r\nexpected: {modifiedToken}\r\nactual: {resultingToken}");
        }