예제 #1
0
        private void Flow(IProgressWindow prgWin)
        {
            prgWin.AppendLog("获取信息中", 10);
            IUpdateInfo info = InfoGetter.Get();

            prgWin.AppendLog("获取信息完毕,正在解析", 20);
            prgWin.SetUpdateContent(info.UpdateContent);

            IEnumerable <IFile> needUpdateFile = Differ.Diff(info.Files, GetLocalFiles());

            if (needUpdateFile.Count() == 0)
            {
                prgWin.AppendLog("无需更新!", 100);
                Thread.Sleep(4000);
                prgWin.Finish();
                return;
            }
            int downloadingFile = 0;

            Downloader.DownloadedAFile += (s, e) =>
            {
                downloadingFile++;
                prgWin.SetProgress(20 + (100 / needUpdateFile.Count() * downloadingFile * 80));
                prgWin.AppendLog($"正在下载并更新{downloadingFile}/{needUpdateFile.Count()}");
            };

            Downloader.Download(needUpdateFile);
            prgWin.AppendLog("结束,三秒后退出", 100);
            Thread.Sleep(3000);
            prgWin.Finish();
        }
예제 #2
0
        public IHttpActionResult GetDiff(string id)
        {
            Initialize();
            var left  = _dataManager.TryRetrieve($"{id}-left", string.Empty);
            var right = _dataManager.TryRetrieve($"{id}-right", string.Empty);

            if (string.IsNullOrEmpty(left) || string.IsNullOrEmpty(right))
            {
                return(BadRequest("Left or right data is missing. Please validate"));
            }

            DiffResult result = _differ.Diff(left, right);


            return(Ok(result));
        }
예제 #3
0
        public void RootDiffObjectShouldShowDifferencesInRootObject()
        {
            var diff = _differ.Diff("A", "B");

            Assert.AreEqual("self", diff.PropertyName);
            Assert.AreEqual("A", diff.NewValue);
            Assert.AreEqual("B", diff.OldValue);
        }
예제 #4
0
        public Client(
            TRemoteState initialRemoteState,
            IReadOnlyDictionary <int, TLocalState> localStatesByTick,
            IDiffer <TLocalState> localStateDiffer,
            IDiffer <TRemoteState> remoteStateDiffer,
            EndPoint localEndPoint,
            EndPoint remoteEndPoint,
            TimeSpan sendInterval
            )
        {
            if (!remoteStatesByTick.TryAdd(0, initialRemoteState))
            {
                throw new InvalidOperationException("Could not add initial tick.");
            }

            connection = new Connection(
                localEndPoint,
                remoteEndPoint,
                (buffer, index, size) => {
                using (var reader = new BinaryReader(new MemoryStream(buffer, index, size, writable: false))) {
                    totalBytesReceived += size;
                    AckedLocalTick      = reader.ReadInt32();

                    int oldRemoteTick = reader.ReadInt32();
                    int newRemoteTick = reader.ReadInt32();

                    //Console.WriteLine($"Received: ackedLocalTick = {ackedLocalTick}, oldRemoteTick = {oldRemoteTick}, newRemoteTick = {newRemoteTick}, ackingRemoteTick = {ackingRemoteTick}");

                    // only patch remote state if newer
                    if (AckingRemoteTick < newRemoteTick)
                    {
                        var remoteState = remoteStatesByTick[oldRemoteTick];
                        remoteStateDiffer.Patch(ref remoteState, reader);
                        if (!remoteStatesByTick.TryAdd(newRemoteTick, remoteState))
                        {
                            throw new InvalidOperationException($"Could not add new tick {newRemoteTick}.");
                        }

                        AckingRemoteTick = newRemoteTick;
                    }
                }
            });

            sendThread = new Thread(() => {
                var memoryStream = new MemoryStream();
                FixedTimer(_ => {
                    if (!Connected)
                    {
                        return;
                    }

                    using (var writer = new BinaryWriter(memoryStream, Encoding.UTF8, leaveOpen: true)) {
                        writer.SetOffset(0);
                        writer.Write(AckingRemoteTick);

                        TLocalState ackedLocalState;
                        TLocalState localState;
                        bool ticked;
                        lock (localTickMutex) {
                            writer.Write(AckedLocalTick);
                            writer.Write(localTick);

                            //Console.WriteLine($"Sending: ackingRemoteTick = {ackingRemoteTick}, ackedLocalTick = {ackedLocalTick}, localTick = {localTick}");
                            ticked = AckedLocalTick < localTick;

                            ackedLocalState = localStatesByTick[AckedLocalTick];
                            localState      = localStatesByTick[localTick];
                        }

                        if (ticked)
                        {
                            localStateDiffer.Diff(ackedLocalState, localState, writer);
                        }

                        if (memoryStream.Position > int.MaxValue)
                        {
                            throw new OverflowException();
                        }

                        connection.SendMessage(memoryStream.GetBuffer(), 0, writer.GetOffset());
                        totalBytesSent += writer.GetOffset();
                    }
                }, sendInterval, cancellationTokenSource.Token);
            });
            sendThread.Start();
        }
        public void Diff(string folderName)
        {
            var result = _differ.Diff(folderName);

            Assert.NotNull(result);
        }