示例#1
0
        // Live doesn't need to be diffed; just diff against the server shadow and that will show what has changed
        //public D DiffApplyLive()
        //{
        //    var liveDiff = Live.PollForLocalDifferencesOrNull();

        //    if (liveDiff != null)
        //    {
        //        Live.Apply(liveDiff, null, false);
        //        // Save the time these local modifications where made to which field, and add to the timestamp dictionary,
        //        // so that we can ensure we always send if we have the latest, or receive the latest if we don't:
        //    }

        //    return liveDiff;
        //}
        public D DiffApplyShadow(DateTime newDiffTimestamp)
        {
            if (Global.ENABLEDEBUGINFO)
            {
                Debug.WriteLine("DiffApplyShadow");
            }
            // 1 a & b : Take Live client vs Shadow (last server sync) difference as a diff, which gives local updates relative to server shadow
            var diff = Live.DiffAgainst(Shadow, newDiffTimestamp);

            if (diff != null)
            {
                Live.Version++;
                if (Global.ENABLEDEBUGINFO)
                {
                    Debug.WriteLine("Live version =" + Live.Version);
                }

                // 2 : Save the diff in the unconfirmed stack edit to be sent to our peer
                UnconfirmedEdits.Add(diff);

                // 3 : Apply the diff from live to our shadow, now that we have sent out the edit that will bring our peer up to date.
                Shadow.Apply(diff, null, true);
                Shadow.Version = Live.Version;
            }
            return(diff);
        }
示例#2
0
        public List <D> ProcessEditsToShadow(Message <D> LatestEditsReceived)
        {
            var editsApplied = new List <D>();

            if (LatestEditsReceived == null)
            {
                return(editsApplied);
            }

            // Either backupshadow or shadow should match the peer's version given
            foreach (var edit in LatestEditsReceived.Get().OrderBy(e => e.Version))
            {
                if (edit.Version != Shadow.PeerVersion)
                {
                    continue;
                }

                // Apply these changes to the shadow
                Shadow.Apply(edit, LatestEditsReceived.IsResponse, true);
                Shadow.PeerVersion++;

                editsApplied.Add(edit);
            }

            return(editsApplied);
        }