示例#1
0
        public void Update(TimeSpan frameTime)
        {
            List <object> toRemove = new List <object>();

            foreach (KeyValuePair <ISyncable, Dictionary <object, BufferedData> > fieldBuffer in
                     FieldWatcher.BufferedChanges)
            {
                ISyncable syncable = fieldBuffer.Key;
                foreach (KeyValuePair <object, BufferedData> instanceBuffer in fieldBuffer.Value)
                {
                    object instance = instanceBuffer.Key;
                    if (CheckShouldRemove(syncable, instance, instanceBuffer.Value))
                    {
                        toRemove.Add(instanceBuffer.Key);
                    }
                    else if (!instanceBuffer.Value.Sent)
                    {
                        ISyncable field = fieldBuffer.Key;
                        field.GetSyncHandler(instance)?.Invoke(instanceBuffer.Value.ToSend);
                        field.GetSyncHandler(SyncableInstance.Any)
                        ?.Invoke(instanceBuffer.Value.ToSend);
                        instanceBuffer.Value.Sent = true;
                    }
                }

                toRemove.ForEach(o => fieldBuffer.Value.Remove(o));
                toRemove.Clear();
            }

            m_RailClient.Update();
        }
示例#2
0
        public static T GetParent <T>(this ISyncable syncable) where T : class, ISyncable
        {
            var parent = (syncable as TextElement).Parent;

            while (parent != null)
            {
                if (parent is T)
                {
                    return(parent as T);
                }
                else if (parent is TextElement)
                {
                    var textElement = (parent as TextElement);
                    if (textElement != null)
                    {
                        parent = textElement.Parent;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            return(parent as T);
        }
示例#3
0
        public void MergeAndKeepLocalIdentity(IDataStore dataStore, ISyncable localEntity, ISyncable remoteEntity)
        {
            var entityInfo = CreateIdentityChange(dataStore, remoteEntity, remoteEntity.Id, localEntity.Id);

            localEntity.MergeWithRemoteValue(dataStore, remoteEntity);
            dataStore.Update(localEntity);
            CreateAndAddPreResolution(entityInfo, OperationTypes.Delete, remoteEntity);
            CreateAndAddMergeResolution(entityInfo, OperationTypes.Insert, localEntity);
        }
示例#4
0
        public void MergeDistinctEntity(IDataStore dataStore, ISyncable localEntity, ISyncable remoteEntity)
        {
            var idBeforeMerge = remoteEntity.Id;

            dataStore.Insert(remoteEntity);
            CreateIdentityChange(dataStore, remoteEntity, idBeforeMerge, remoteEntity.Id);
            CreateAndAddMergeResolution(dataStore, OperationTypes.Update, localEntity);
            CreateAndAddMergeResolution(dataStore, OperationTypes.Insert, remoteEntity);
        }
示例#5
0
        protected SyncableEntity(ISyncable syncable)
            : base(syncable)
        {
            if (syncable == null)
            {
                return;
            }

            CreatedAt = syncable.CreatedAt;
            UpdatedAt = syncable.UpdatedAt;
        }
示例#6
0
        private IEntityInfo CreateIdentityChange(IDataStore dataStore, ISyncable remoteEntity, long idBeforeMerge, long idAfterMerge)
        {
            var entityInfo = dataStore.GetEntityInfo(remoteEntity);

            _identityChange = new IdentityChange
            {
                EntityName = entityInfo.GetNameInStore(),
                OldValue   = idBeforeMerge,
                NewValue   = idAfterMerge
            };
            return(entityInfo);
        }
示例#7
0
        private void OnSyncProgress(ISyncable item, SyncEngine.ProgressType type, int filesTransferred, int totalItems)
        {
            using (new OperationLogger())
            {
                string displayName = null;
                string format      = null;
                if (item != null)
                {
                    displayName = item.Properties.ObjectForKey("Name") as string;
                    if (string.IsNullOrEmpty(displayName))
                    {
                        ISyncableMedia media = item as ISyncableMedia;
                        if (media != null)
                        {
                            displayName = media.DisplayName;
                        }
                        if (string.IsNullOrEmpty(displayName) && (item.Location != null))
                        {
                            displayName = item.Location.LocalPath;
                        }
                    }
                }
                switch (type)
                {
                case SyncEngine.ProgressType.Add:
                case SyncEngine.ProgressType.Update:
                    format = Resources.TransferProgressCopyText;
                    break;

                case SyncEngine.ProgressType.Delete:
                    format = Resources.TransferProgressDeleteText;
                    break;

                case SyncEngine.ProgressType.WaitingForDeferred:
                    format = Resources.TranferProgressTranscoding;
                    break;

                case SyncEngine.ProgressType.Retrying:
                    format = Resources.TransferProgressRetryText;
                    break;

                default:
                    throw new ArgumentException("invalid value", "type");
                }
                string caption   = string.Format(CultureInfo.CurrentCulture, format, new object[] { string.IsNullOrEmpty(displayName) ? Resources.UnknownFileNameText : displayName });
                string subHeader = string.Format(CultureInfo.CurrentCulture, Resources.SyncProgressRemainingItems, new object[] { totalItems - filesTransferred });
                this.UpdateProgressBar(null, subHeader, caption, (float)(filesTransferred * 100), (float)(totalItems * 100), false);
            }
        }
示例#8
0
        /// <summary>
        ///     To be called before changing a syncable in a patched method.
        /// </summary>
        /// <param name="syncable"></param>
        /// <param name="target"></param>
        public static void Watch(this ISyncable syncable, object target)
        {
            object value = null;

            if (BufferedChanges.ContainsKey(syncable) &&
                BufferedChanges[syncable].TryGetValue(target, out BufferedData cache))
            {
                value = cache.ToSend;
                syncable.Set(target, value);
            }
            else
            {
                value = syncable.Get(target);
            }

            ActiveFields.Push(new SyncableData(syncable, target, value));
        }
示例#9
0
        private static void Postfix()
        {
            while (ActiveFields.Count > 0)
            {
                SyncableData data = ActiveFields.Pop();
                if (data == null)
                {
                    break; // The marker
                }

                ISyncable field = data.Syncable;

                object newValue = data.Syncable.Get(data.Target);
                bool   changed  = !Equals(newValue, data.Value);

                Dictionary <object, BufferedData> fieldBuffer = BufferedChanges.Assert(field);
                if (fieldBuffer.TryGetValue(data.Target, out BufferedData cached))
                {
                    if (changed && cached.Sent)
                    {
                        cached.Sent = false;
                    }

                    cached.ToSend = newValue;
                    field.Set(data.Target, cached.Actual);
                    continue;
                }

                if (!changed)
                {
                    continue;
                }

                fieldBuffer[data.Target] = new BufferedData
                {
                    Actual = data.Value,
                    ToSend = newValue
                };
                field.Set(data.Target, data.Value);
            }
        }
        public static void SendEvent(ISyncable syncable, byte eventCode, string name, int keyID)
        {
            if (!syncable.PUNSyncEnabled || !PhotonNetwork.inRoom || syncable.MuteNetworkBroadcasting)
            {
                return;
            }

            var raiseEventOptions = new RaiseEventOptions()
            {
                CachingOption = syncable.CachingOptions,
                Receivers     = ReceiverGroup.Others
            };

            var content = new object[]
            {
                name,
                keyID,
            };

            PhotonNetwork.RaiseEvent(eventCode, content, true, raiseEventOptions);
        }
示例#11
0
        private bool CheckShouldRemove(ISyncable syncable, object instance, BufferedData buffer)
        {
            if (buffer.Sent && Equals(buffer.ToSend, buffer.Actual))
            {
                return(true);
            }

            object currentValue = syncable.Get(instance);

            if (Equals(currentValue, buffer.Actual))
            {
                return(false);
            }

            if (buffer.Sent)
            {
                return(true);
            }

            buffer.Actual = currentValue;
            return(false);
        }
        public static void SendEventParam <T>(ISyncable syncable, string name, int keyID, T parameter)
        {
            if (!syncable.PUNSyncEnabled || !PhotonNetwork.inRoom || syncable.MuteNetworkBroadcasting)
            {
                return;
            }

            var raiseEventOptions = new RaiseEventOptions()
            {
                CachingOption = syncable.CachingOptions,
                Receivers     = ReceiverGroup.Others
            };

            var content = new object[]
            {
                name,
                keyID,
                parameter
            };

            PhotonNetwork.RaiseEvent(TypeToCode(typeof(T)), content, true, raiseEventOptions);
        }
示例#13
0
        private void documentScrollViewer_dictation_SelectionChanged(object sender, EventArgs e)
        {
            ISyncable first = null, last = null;

            foreach (var element in this.documentScrollViewer_dictation.SelectedElements)
            {
                var syncObj = element as ISyncable;
                if (syncObj != null)
                {
                    if (first == null)
                    {
                        first = syncObj;
                    }
                    last = syncObj;
                }
            }

            if (first != null && last != null)
            {
                this.AudioPlayer.PlayRange(first.BeginTime, last.EndTime);
            }
        }
示例#14
0
 public TimelineEventArgs(ISyncable syncable)
 {
     this.SyncableObjects = new List <ISyncable>();
     this.SyncableObjects.Add(syncable);
 }
示例#15
0
 public static bool ContainsTimeSpan(this ISyncable syncObj, TimeSpan timeSpan)
 {
     return(syncObj.BeginTime < timeSpan && timeSpan < syncObj.EndTime);
 }
示例#16
0
 public static string ComputeHash <T>(this ISyncable <T> @this) => JsonConvert.SerializeObject(@this, Formatting.None).ComputeHash();
示例#17
0
文件: OrderSync.cs 项目: PChou/CodeOf
        public static void Sync(ISyncable Left, ISyncable Right)
        {
            if (Left == null || Right == null)
            {
                return;
            }
            IEnumerator lefter  = Left.GetEnumerator();
            IEnumerator righter = Right.GetEnumerator();

            if (lefter == null || righter == null)
            {
                return;
            }

            IComparable a = null; //repesent the left current node
            IComparable b = null; //repesent the right current node

            if (lefter.MoveNext())
            {
                a = (IComparable)lefter.Current;
            }
            if (righter.MoveNext())
            {
                b = (IComparable)righter.Current;
            }

            while (a != null && b != null)
            {
                if (a.CompareTo(b) == 0)
                {
                    Left.DoEqualStep(a, b);
                    Right.DoEqualStep(b, a);
                    if (lefter.MoveNext() == false)
                    {
                        a = null;
                    }
                    else
                    {
                        a = (IComparable)lefter.Current;
                    }
                    if (righter.MoveNext() == false)
                    {
                        b = null;
                    }
                    else
                    {
                        b = (IComparable)righter.Current;
                    }
                }
                else if (a.CompareTo(b) > 0)
                {
                    Right.DoLessStep(b, a);
                    if (righter.MoveNext() == false)
                    {
                        b = null;
                    }
                    else
                    {
                        b = (IComparable)righter.Current;
                    }
                }
                else if (a.CompareTo(b) < 0)
                {
                    Left.DoLessStep(a, b);
                    if (lefter.MoveNext() == false)
                    {
                        a = null;
                    }
                    else
                    {
                        a = (IComparable)lefter.Current;
                    }
                }
            }

            if (a == null && b != null)
            {
                do
                {
                    b = (IComparable)righter.Current;
                    Right.DoMoreStep(b);
                }while (righter.MoveNext());
            }

            else if (b == null && a != null)
            {
                do
                {
                    a = (IComparable)lefter.Current;
                    Left.DoMoreStep(a);
                }while (lefter.MoveNext());
            }
        }
示例#18
0
        private static void MarkFileType(ISyncable item, SqmSyncContentStream stream)
        {
            string localPath = null;
            if (item.OriginalLocation != null)
            {
                localPath = item.OriginalLocation.LocalPath;
            }
            if (string.IsNullOrEmpty(localPath))
            {
                localPath = (string) item.Properties.FirstObjectForKeys(new string[] { ZMEDIAITEM_STRINGATTRIBUTE.ZMEDIAITEM_ATTRIBUTE_FILEPATH.ToString(), "DevicePath" });
            }
            if (string.IsNullOrEmpty(localPath))
            {
                localPath = (string) item.Properties.ObjectForKey("Location");
            }
            string extension = Path.GetExtension(localPath);
            if (extension != null)
            {
                switch (extension.ToUpperInvariant())
                {
                    case ".JPG":
                    case ".JPEG":
                        stream.MarkFileType(SqmFileTypes.jpg, true);
                        return;

                    case ".PNG":
                        stream.MarkFileType(SqmFileTypes.png, true);
                        return;

                    case ".GIF":
                        stream.MarkFileType(SqmFileTypes.gif, true);
                        return;

                    case ".MP3":
                        stream.MarkFileType(SqmFileTypes.mp3, true);
                        return;

                    case ".WMA":
                        stream.MarkFileType(SqmFileTypes.wma, true);
                        return;

                    case ".AAC":
                        stream.MarkFileType(SqmFileTypes.aac, true);
                        return;

                    case ".MP4":
                        stream.MarkFileType(SqmFileTypes.mp4, true);
                        return;

                    case ".WMV":
                        stream.MarkFileType(SqmFileTypes.wmv, true);
                        return;

                    case ".M4R":
                        stream.MarkFileType(SqmFileTypes.m4r, true);
                        return;
                }
                stream.MarkFileType(SqmFileTypes.other, true);
            }
        }
示例#19
0
 public EntitySync(ISyncable syncable)
     : base(syncable)
 {
 }
示例#20
0
 public DownloadOnlyEntitySync(ISyncable syncable)
     : base(syncable)
 {
 }
示例#21
0
 public void Merge(IDataStore dataStore, ISyncable localEntity, ISyncable remoteEntity)
 {
     localEntity.MergeWithRemoteValue(dataStore, remoteEntity);
     dataStore.Update(localEntity);
     CreateAndAddMergeResolution(dataStore, OperationTypes.Update, localEntity);
 }
示例#22
0
        public static void InsertInLocal(IDataStore localDataStore, ISyncSessionInfo syncSessionInfo, ISyncable remoteEntity)
        {
            var entityInfo = localDataStore.GetEntityInfo(remoteEntity);

            var mergeResolution = new MergeResolution
            {
                OperationType = OperationTypes.Insert,
                Entity        = EntityChange.Create(entityInfo, remoteEntity)
            };

            mergeResolution.ApplyResolution(localDataStore as ISqlDataStore, syncSessionInfo);
        }
示例#23
0
 public SyncableData([NotNull] ISyncable syncable, object target, object value)
 {
     Syncable = syncable;
     Target   = target;
     Value    = value;
 }
        public void Selection_Changed(object sender, EventArgs e)
        {
            //this.Dely(200);
            this.SelectedElements.Cast <DependencyObject>().ToList().ForEach(
                (dpo) => {
                SyncExtension.SetIsCurrent(dpo, false);
            });
            this.SelectedElements.Clear();

            var selection = this.flowDocumentViewer.Selection;

            TextElement first = null;

            switch (this.SelectMode)
            {
            case SyncControl.SelectMode.Word:
                first = this.GetSelectedSyncable <SyncableWord>(selection.Start);

                break;

            case SyncControl.SelectMode.Phrase:
                first = this.GetSelectedSyncable <DMPhrase>(selection.Start);
                break;

            case SyncControl.SelectMode.Sentence:
                first = this.GetSelectedSyncable <DMSentence>(selection.Start);
                break;

            case SyncControl.SelectMode.Paragraph:
                first = this.GetSelectedSyncable <DMParagraph>(selection.Start);
                break;
            }


            ISyncable begin = null, end = null;

            if (first != null)
            {
                begin = first as ISyncable;
                var next = first;

                while (next != null && next.ElementStart.CompareTo(selection.End) == -1)
                {
                    this.SelectedElements.Add(next);

                    if (next is ISyncable)
                    {
                        end            = next as ISyncable;
                        this.BeginTime = begin.BeginTime;
                        this.EndTime   = end.EndTime;
                    }
                    if (next is Inline)
                    {
                        next = (next as Inline).NextInline;
                    }
                    else if (next is Block)
                    {
                        next = (next as Block).NextBlock;
                    }
                    else
                    {
                        break;
                    }
                }



                this.flowDocumentViewer.Selection.Changed -= Selection_Changed;
                this.flowDocumentViewer.Selection.Select(first.ElementStart, this.SelectedElements.Last().ContentEnd);
                this.flowDocumentViewer.Selection.Changed += Selection_Changed;
            }

            if (this.SelectionChanged != null)
            {
                this.SelectionChanged(this, new EventArgs());
            }

            this.SelectedElements.Cast <DependencyObject>().ToList().ForEach(
                (dpo) => {
                SyncExtension.SetIsCurrent(dpo, true);
            });
        }
示例#25
0
        private static void MarkFileType(ISyncable item, SqmSyncContentStream stream)
        {
            string localPath = null;

            if (item.OriginalLocation != null)
            {
                localPath = item.OriginalLocation.LocalPath;
            }
            if (string.IsNullOrEmpty(localPath))
            {
                localPath = (string)item.Properties.FirstObjectForKeys(new string[] { ZMEDIAITEM_STRINGATTRIBUTE.ZMEDIAITEM_ATTRIBUTE_FILEPATH.ToString(), "DevicePath" });
            }
            if (string.IsNullOrEmpty(localPath))
            {
                localPath = (string)item.Properties.ObjectForKey("Location");
            }
            string extension = Path.GetExtension(localPath);

            if (extension != null)
            {
                switch (extension.ToUpperInvariant())
                {
                case ".JPG":
                case ".JPEG":
                    stream.MarkFileType(SqmFileTypes.jpg, true);
                    return;

                case ".PNG":
                    stream.MarkFileType(SqmFileTypes.png, true);
                    return;

                case ".GIF":
                    stream.MarkFileType(SqmFileTypes.gif, true);
                    return;

                case ".MP3":
                    stream.MarkFileType(SqmFileTypes.mp3, true);
                    return;

                case ".WMA":
                    stream.MarkFileType(SqmFileTypes.wma, true);
                    return;

                case ".AAC":
                    stream.MarkFileType(SqmFileTypes.aac, true);
                    return;

                case ".MP4":
                    stream.MarkFileType(SqmFileTypes.mp4, true);
                    return;

                case ".WMV":
                    stream.MarkFileType(SqmFileTypes.wmv, true);
                    return;

                case ".M4R":
                    stream.MarkFileType(SqmFileTypes.m4r, true);
                    return;
                }
                stream.MarkFileType(SqmFileTypes.other, true);
            }
        }
示例#26
0
 public UpdloadOnlyEntitySync(ISyncable syncable)
     : base(syncable)
 {
 }
        private void OnSyncProgress(ISyncable item, SyncEngine.ProgressType type, int filesTransferred, int totalItems)
        {
            using (new OperationLogger())
            {
                string displayName = null;
                string format = null;
                if (item != null)
                {
                    displayName = item.Properties.ObjectForKey("Name") as string;
                    if (string.IsNullOrEmpty(displayName))
                    {
                        ISyncableMedia media = item as ISyncableMedia;
                        if (media != null)
                        {
                            displayName = media.DisplayName;
                        }
                        if (string.IsNullOrEmpty(displayName) && (item.Location != null))
                        {
                            displayName = item.Location.LocalPath;
                        }
                    }
                }
                switch (type)
                {
                    case SyncEngine.ProgressType.Add:
                    case SyncEngine.ProgressType.Update:
                        format = Resources.TransferProgressCopyText;
                        break;

                    case SyncEngine.ProgressType.Delete:
                        format = Resources.TransferProgressDeleteText;
                        break;

                    case SyncEngine.ProgressType.WaitingForDeferred:
                        format = Resources.TranferProgressTranscoding;
                        break;

                    case SyncEngine.ProgressType.Retrying:
                        format = Resources.TransferProgressRetryText;
                        break;

                    default:
                        throw new ArgumentException("invalid value", "type");
                }
                string caption = string.Format(CultureInfo.CurrentCulture, format, new object[] { string.IsNullOrEmpty(displayName) ? Resources.UnknownFileNameText : displayName });
                string subHeader = string.Format(CultureInfo.CurrentCulture, Resources.SyncProgressRemainingItems, new object[] { totalItems - filesTransferred });
                this.UpdateProgressBar(null, subHeader, caption, (float) (filesTransferred * 100), (float) (totalItems * 100), false);
            }
        }