Exemple #1
0
        internal void ApplyChanges(ApplyChangesParameter parameter, ref ApplyChangesResult result)
        {
            if (parameter == null)
            {
                throw new NullReferenceException(nameof(parameter));
            }
            result = new ApplyChangesResult(parameter.PayloadAction, parameter.SynchronizationId, parameter.CustomInfo);

            parameter.Log.Add("Applying Data Type Changes...");
            parameter.Log.Add($"SyncTypes Count: {parameter.Changes.Count}");
            List <Type> postEventTypes = new List <Type>();
            Dictionary <Type, List <object> > dictDeletedIds = new Dictionary <Type, List <object> >();

            for (int i = 0; i < parameter.Changes.Count; i++)
            {
                JObject typeChanges = parameter.Changes[i].Value <JObject>();
                parameter.Log.Add($"Applying Type: {typeChanges["syncType"].Value<string>()}...");
                (Type localSyncType, List <object> appliedIds, List <object> deletedIds) = ApplyTypeChanges(parameter.Log, result.Inserts, result.Updates, result.Deletes, result.Conflicts, typeChanges, parameter.SynchronizationId, parameter.CustomInfo, null, null);
                parameter.Log.Add($"Type: {typeChanges["syncType"].Value<string>()} Applied, Count: {appliedIds.Count}");
                result.AppliedIds[localSyncType] = appliedIds;
                if (deletedIds.Count > 0)
                {
                    if (!postEventTypes.Contains(localSyncType))
                    {
                        postEventTypes.Add(localSyncType);
                    }
                    dictDeletedIds[localSyncType] = deletedIds;
                }
            }
            ProcessPostEvents(parameter.Log, postEventTypes, dictDeletedIds, parameter.SynchronizationId, parameter.CustomInfo);
        }
            public static ApplyChangesParameter FromPayload(JObject payload)
            {
                string synchronizationId = payload[nameof(SynchronizationId)].Value <string>();
                Dictionary <string, object> customInfo = payload[nameof(CustomInfo)].ToObject <Dictionary <string, object> >();
                PayloadAction         payloadAction    = (PayloadAction)Enum.Parse(typeof(PayloadAction), payload[nameof(PayloadAction)].Value <string>());
                ApplyChangesParameter parameter        = new ApplyChangesParameter(payloadAction, synchronizationId, customInfo);

                parameter.Changes = payload[nameof(Changes)].Value <JArray>();
                return(parameter);
            }