コード例 #1
0
        // Methods

        public (Byte[] Result, DeltaFileTransaction Transaction) Restore(FileNode node, LogEntry entry)
        {
            Byte[] result     = null;
            Byte[] lastRead   = null;
            var    logEntries = node.LogEntries.Where(x => x.CreatedAt <= entry.CreatedAt);
            var    strategy   = _fileHandlingStrategySelector.Select(node);

            foreach (var current in logEntries)
            {
                switch (current.Type)
                {
                case LogEntryTypes.Genesis:
                    result = _archiveManager.Read(node.FileName, node);
                    break;

                case LogEntryTypes.Normal:
                    var delta = _archiveManager.Read(current.DiffName, node);
                    lastRead = result;
                    result   = _deltaPatcher.Patch(result, delta);
                    break;

                default:
                    break;
                }
            }

            var newSignature = _signatureCreator.CreateSignature(result);
            var newDelta     = _deltaCreator.BuildDelta(newSignature, lastRead);
            var transaction  = new DeltaFileTransaction(node,
                                                        new Signature($"{Guid.NewGuid().ToString()}.signature", newSignature),
                                                        new Delta($"{Guid.NewGuid().ToString()}.delta", newDelta));

            return(result, transaction);
        }
コード例 #2
0
        private async Task Watcher_FileChanged(FileInfo fileInfo)
        {
            var node     = _configuration.FirstOrDefault(x => Path.Combine(x.Directory, x.FileName) == fileInfo.FullName);
            var strategy = _fileHandlingStrategySelector.Select(node);

            strategy.Handled += Strategy_Handled;
            await strategy.HandleAsync(node);

            OnNodeUpdated(node);
        }