示例#1
0
        void RequestPopup(Xwt.Rectangle rect)
        {
            var token = popupSrc.Token;

            Task.Run(async delegate {
                try {
                    foreach (var op in await codeAction.GetPreviewOperationsAsync(token))
                    {
                        if (!(op is ApplyChangesOperation ac))
                        {
                            continue;
                        }
                        var changedDocument = ac.ChangedSolution.GetDocument(documentContext.AnalysisDocument.Id);

                        var changedText       = await changedDocument.GetTextAsync(token);
                        var changedTextSource = new StringTextSource(changedText.ToString());
                        changedTextDocument   = TextEditorFactory.CreateNewDocument(changedTextSource, editor.FileName);

                        try {
                            var processor = new DiffProcessor(editor, changedTextDocument);
                            return(processor.Process());
                        } catch (Exception e) {
                            LoggingService.LogError("Error while getting preview list diff.", e);
                        }
                    }
                } catch (OperationCanceledException) { }

                return(new ProcessResult());
            }).ContinueWith(t => {
示例#2
0
        public void run()
        {
            var ll         = new LocalLister();
            var localfiles = ll.getList(pathRoot, null, fileRE);

            if (!string.IsNullOrWhiteSpace(fileRE))
            {
                var re = new System.Text.RegularExpressions.Regex(fileRE
                                                                  , System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase);

                localfiles = localfiles.Where(x => re.IsMatch(x.path)).ToList();
            }

            var locdiffs = localfiles.Select(x => new FileDiff {
                local = x, remote = null, type = DiffType.created
            });
            var dp = new DiffProcessor {
                account = account, container = container, maxTasks = 10, root = pathRoot, encKey = key
            };

            dp.noAction        = noAction;
            dp.progressHandler = progress;
            dp.runType         = RunType.upload;

            dp.add(locdiffs);
            dp.run();
        }
示例#3
0
        public void run()
        {
            var dp = new DiffProcessor
            {
                account           = account
                , container       = null
                , encKey          = key
                , maxTasks        = maxTasks
                , root            = destPath
                , noAction        = noAction
                , progressHandler = progress
                , errorHandler    = errors
                , runType         = RunType.download
            };

            var re    = new Regex(filterre, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            var files = account.service.fileCache.getContainer(account.id, cont.id, null)
                        .Where(x => re.IsMatch(x.path))
                        .Select(x => new FileDiff {
                local = null, remote = x, type = DiffType.created
            })
                        .ToList();

            if (files.Count > 10 && !noAction && account.svcName != "BackupLib.LocalService")
            {
                throw new ArgumentOutOfRangeException("filterre"
                                                      , string.Format("CopyLocal will not copy more than 10 files. This should be used to restore some files, not many. ({0} - {1} #{2})"
                                                                      , account.name, cont.name, files.Count));
            }

            dp.add(files);
            dp.run();
        }
        /// <summary>
        /// Gets the difference results asynchronously.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <CalculatedDiffsFeedback> GetDiffResultsAsync([FromUri] int id)
        {
            using (var processor = new DiffProcessor())
            {
                var feedback = await processor.TryGetDiffsForKeyIdentifierAsync(id);

                return(feedback);
            }
        }
示例#5
0
        public void Handle(ISynchronization sync)
        {
            try
            {
                var passwordRetriever = new UserRetriever(this.workerConfig);

                var message = $"Starting synchronization {sync.Id}";
                Logging.Log().Warning(message);
                this.syncLogger.Log(sync, message);

                SvcFactory factory       = new SvcFactory(sync, passwordRetriever, syncLogger);
                ISvc       source        = factory.Create(sync.Mirror.SourceRepository);
                ISvc       target        = factory.Create(sync.Mirror.TargetRepository);
                var        diffProcessor = new DiffProcessor(
                    this.workerConfig,
                    sync,
                    source,
                    target,
                    this.httpClient,
                    this.syncLogger,
                    sync.Mirror.TargetRepository.PushUser);

                source.CloneOrUpdate();
                target.CloneOrUpdate();
                var sourceLog = source.GetLog();
                var targetLog = target.GetLog();

                var comparer  = new RepositoryComparer(this.httpClient, sync.Mirror, sourceLog, targetLog);
                var revisions = comparer.GetRevisionsAwaitingForSync();

                for (int i = revisions.Count - 1; i >= 0; i--)
                {
                    var revision = revisions[i];
                    var m        = $"Applying revision {revision.Id} {revision.Author} {revision.Message}";
                    Logging.Log().Warning(m);
                    this.syncLogger.Log(sync, m);

                    diffProcessor.ApplyRevision(revision);
                }

                var o = $"Synchronization {sync.Id} OK";
                Logging.Log().Information(o);
                this.syncLogger.Log(sync, o);

                var cl = $"Cleaning up...";
                Logging.Log().Information(cl);
                this.syncLogger.Log(sync, cl);

                source.CleanUp();
                target.CleanUp();
            }
            catch (Exception ex)
            {
                this.syncLogger.Log(sync, $"Error: {ex}");
                throw;
            }
        }
示例#6
0
        public void run()
        {
            maxTasks = IOUtils.DefaultTasks(maxTasks);

            var cmp = (new DirectoryCompare
            {
                account = account
                , cache = cache
                , container = container
                , pathRoot = pathRoot
                , useRemote = useRemote
                , filter = filterRE
                , exclude = excludeRE
                , useHash = checksum
                , privateKey = privateKey
                , maxTasks = maxTasks
            })
                      .run();

            if (!string.IsNullOrWhiteSpace(filterRE))
            {
                Regex re = new Regex(filterRE, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                cmp = cmp.Where(x => re.IsMatch(x.local != null ? x.local.path : x.remote.path)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(excludeRE))
            {
                Regex reex = new Regex(excludeRE, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                cmp = cmp.Where(x => !reex.IsMatch(x.local != null ? x.local.path : x.remote.path)).ToList();
            }

            /* start with creates, updates, then deletes. */
            var dp = new DiffProcessor
            {
                container         = container
                , account         = account
                , maxTasks        = maxTasks
                , root            = pathRoot
                , encKey          = keyFile
                , noAction        = noAction
                , progressHandler = progress
                , errorHandler    = excepts
                , runType         = RunType.upload
            };

            dp.add(cmp.Where(x => x.type == DiffType.created));
            dp.run();

            dp.add(cmp.Where(x => x.type == DiffType.updated));
            dp.run();

            dp.add(cmp.Where(x => x.type == DiffType.deleted));
            dp.run();
        }
示例#7
0
        public void TestStringIsNotUpdated()
        {
            var processor = new DiffProcessor();
            var source    = "123";
            var diff      = "123";

            var result = processor.GetDiff(source, diff);

            var leftFirstString = result.LeftPan[0];

            leftFirstString.Action.Should(Be.EqualTo(DiffActionType.None));
            leftFirstString.Line.Should(Be.EqualTo(source));
            leftFirstString.LineNumber.Should(Be.EqualTo(0));

            var rightFirstString = result.RightPan[0];

            rightFirstString.Action.Should(Be.EqualTo(DiffActionType.None));
            rightFirstString.Line.Should(Be.EqualTo(diff));
            rightFirstString.LineNumber.Should(Be.EqualTo(0));
        }
示例#8
0
        public void TestStringDeleted()
        {
            var processor = new DiffProcessor();
            var source    = "123\r\n456";
            var diff      = "123";

            var result = processor.GetDiff(source, diff);

            result.LeftPan.Count.Should(Be.EqualTo(2));
            result.RightPan.Count.Should(Be.EqualTo(2));

            var leftSecondString = result.LeftPan[1];

            leftSecondString.Action.Should(Be.EqualTo(DiffActionType.Deleted));
            leftSecondString.Line.Should(Be.EqualTo("456"));
            leftSecondString.LineNumber.Should(Be.EqualTo(1));

            var rightSecondString = result.RightPan[1];

            rightSecondString.Action.Should(Be.EqualTo(DiffActionType.None));
            rightSecondString.Line.Should(Be.Empty);
            rightSecondString.LineNumber.Should(Be.EqualTo(-1));
        }