示例#1
0
        public void Execute()
        {
            var filesInRemote = _remote.ListFiles();
            var filesInCache  = _cacheManager.ListFiles();

            var filesToUpload = filesInCache.Except(filesInRemote).Select(x => x.Name).ToArray();

            if (filesToUpload.Length == 0)
            {
                GitBinConsole.Write("All chunks already present on remote");
            }
            else
            {
                if (filesToUpload.Length == 1)
                {
                    GitBinConsole.Write("Uploading 1 chunk: ");
                }
                else
                {
                    GitBinConsole.Write("Uploading {0} chunks: ", filesToUpload.Length);
                }

                AsyncFileProcessor.ProcessFiles(filesToUpload,
                                                (files, index) =>
                {
                    var file = filesToUpload[index];
                    _remote.UploadFile(_cacheManager.GetPathForFile(file), file);
                });
            }
            Console.WriteLine();
        }
示例#2
0
        private void DownloadMissingFiles(IEnumerable <string> chunkHashes)
        {
            var filesToDownload = _cacheManager.GetFilenamesNotInCache(chunkHashes);

            if (filesToDownload.Length == 0)
            {
                GitBinConsole.WriteLineNoPrefix(" All chunks already present in cache\n");
            }
            else
            {
                if (filesToDownload.Length == 1)
                {
                    GitBinConsole.WriteLineNoPrefix(" Downloading 1 chunk...");
                }
                else
                {
                    GitBinConsole.WriteLineNoPrefix(" Downloading {0} chunks...", filesToDownload.Length);
                }

                for (int i = 0; i < filesToDownload.Length; i++)
                {
                    using (new RemoteProgressPrinter(i + 1, filesToDownload.Length, _remote))
                    {
                        var file = filesToDownload[i];
                        _remote.DownloadFile(_cacheManager.GetPathForFile(file), file);
                    }
                }
            }
        }
示例#3
0
        public void Execute()
        {
            GitBinConsole.WriteLine("Cleaning {0}", _filename);

            var document = new GitBinDocument(_filename);

            var chunkBuffer = new byte[_configurationProvider.ChunkSize];
            int numberOfBytesRead;

            var stdin = Console.OpenStandardInput();

            do
            {
                numberOfBytesRead = stdin.Read(chunkBuffer, 0, chunkBuffer.Length);

                if (numberOfBytesRead > 0)
                {
                    var hash = GetHashForChunk(chunkBuffer, numberOfBytesRead);
                    _cacheManager.WriteFileToCache(hash, chunkBuffer, numberOfBytesRead);
                    document.RecordChunk(hash);
                }
            } while (numberOfBytesRead == chunkBuffer.Length);

            Console.Write(GitBinDocument.ToYaml(document));
            Console.Out.Flush();
        }
示例#4
0
        public void Execute()
        {
            var filesInRemote = _remote.ListFiles();
            var filesInCache  = _cacheManager.ListFiles();

            var filesToUpload = filesInCache.Except(filesInRemote).ToList();

            if (filesToUpload.Count == 0)
            {
                GitBinConsole.WriteLine("All chunks already present on remote");
            }
            else
            {
                if (filesToUpload.Count == 1)
                {
                    GitBinConsole.WriteLine("Uploading 1 chunk");
                }
                else
                {
                    GitBinConsole.WriteLine("Uploading {0} chunks", filesToUpload.Count);
                }

                for (int i = 0; i < filesToUpload.Count; i++)
                {
                    using (new RemoteProgressPrinter(i + 1, filesToUpload.Count, _remote))
                    {
                        var file = filesToUpload[i];
                        _remote.UploadFile(_cacheManager.GetPathForFile(file.Name), file.Name);
                    }
                }
            }
        }
示例#5
0
        public void Execute()
        {
            GitBinConsole.WriteLine("Cleaning {0}", _filename);

            var document = new GitBinDocument(_filename);

            var chunkBuffer = new byte[_configurationProvider.ChunkSize];
            int numberOfBytesRead;
            int totalBytesInChunk = 0;

            var stdin = Console.OpenStandardInput();

            do
            {
                numberOfBytesRead = stdin.Read(chunkBuffer, totalBytesInChunk, chunkBuffer.Length - totalBytesInChunk);

                totalBytesInChunk += numberOfBytesRead;

                if ((totalBytesInChunk == chunkBuffer.Length || numberOfBytesRead == 0) && totalBytesInChunk > 0)
                {
                    var hash = GetHashForChunk(chunkBuffer, totalBytesInChunk);
                    _cacheManager.WriteFileToCache(hash, chunkBuffer, totalBytesInChunk);
                    document.RecordChunk(hash);
                    totalBytesInChunk = 0;
                }
            } while (numberOfBytesRead > 0);

            var yamlString = GitBinDocument.ToYaml(document);

            Console.Write(yamlString);
            Console.Out.Flush();
        }
示例#6
0
        public RemoteProgressPrinter(int chunkNumber, int totalChunks, IRemote remote)
        {
            GitBinConsole.WriteNoPrefix("  [{0}/{1}] -> ", chunkNumber, totalChunks);

            _remote = remote;
            _remote.ProgressChanged += OnProgressChanged;

            _percentagesToReport = new List <int> {
                0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
            };
        }
示例#7
0
        public void Execute()
        {
            var stdin    = Console.OpenStandardInput();
            var document = GitBinDocument.FromYaml(new StreamReader(stdin));

            GitBinConsole.Write("Smudging {0}:", document.Filename);

            DownloadMissingFiles(document.ChunkHashes);

            OutputReassembledChunks(document.ChunkHashes);
        }
示例#8
0
 public void Execute()
 {
     if (_isDryRun)
     {
         GitBinConsole.WriteLine("clear dry run: would remove " +
                                 GitBinFileInfoUtils.GetHumanReadableSize(_cacheManager.ListFiles()));
     }
     else
     {
         _cacheManager.ClearCache();
     }
 }
示例#9
0
 public void Execute()
 {
     GitBinConsole.WriteLineNoPrefix("usage: git bin [--version]");
     GitBinConsole.WriteLineNoPrefix("               <command> [<args>]");
     GitBinConsole.WriteNoPrefix(Environment.NewLine);
     GitBinConsole.WriteLineNoPrefix("List of available commands:");
     GitBinConsole.WriteLineNoPrefix("  clean    Clean filter. Should only be used with .gitattributes filtering");
     GitBinConsole.WriteLineNoPrefix("  clear    Remove all files in the local cache directory. Requires -n or -f");
     GitBinConsole.WriteLineNoPrefix("  push     Upload changed files to the remote file repository");
     GitBinConsole.WriteLineNoPrefix("  smudge   Smudge filter. Should only be used with .gitattributes filtering");
     GitBinConsole.WriteLineNoPrefix("  status   Display status of the local cache. [-r], include the remote repo");
 }
示例#10
0
        private void OnProgressChanged(int percentageComplete)
        {
            var percentagesToPrint = GetPercentagesBelowOrEqual(percentageComplete);

            foreach (var percentToPrint in percentagesToPrint)
            {
                GitBinConsole.WriteNoPrefix("{0}{1}", _hasPrintedAnything ? ".." : string.Empty, percentToPrint);
                _hasPrintedAnything = true;
                _percentagesToReport.Remove(percentToPrint);
            }

            GitBinConsole.Flush();
        }
示例#11
0
        private void PrintStatusAboutRemote()
        {
            var remoteFiles = _remote.ListFiles();

            GitBinConsole.WriteLineNoPrefix("\nRemote repo:");
            GitBinConsole.WriteLineNoPrefix("  items: {0}", remoteFiles.Length);
            GitBinConsole.WriteLineNoPrefix("  size:  {0}", GitBinFileInfoUtils.GetHumanReadableSize(remoteFiles));

            var filesToPush = _filesInLocalCache.Except(remoteFiles).ToList();

            GitBinConsole.WriteLineNoPrefix("\nTo push:");
            GitBinConsole.WriteLineNoPrefix("  items: {0}", filesToPush.Count);
            GitBinConsole.WriteLineNoPrefix("  size:  {0}", GitBinFileInfoUtils.GetHumanReadableSize(filesToPush));
        }
示例#12
0
        public void Execute()
        {
            var stdin    = Console.OpenStandardInput();
            var document = GitBinDocument.FromYaml(new StreamReader(stdin));

            GitBinConsole.Write("Smudging {0}...", document.Filename);

            DownloadMissingFiles(document.ChunkHashes);
            OutputReassembledChunks(document.ChunkHashes);

/* TODO: move to SparkleShare
 *          string filepath = Path.Combine (Environment.CurrentDirectory,
 *              document.Filename.Replace("/", Path.DirectorySeparatorChar.ToString()));
 *
 *          FileInfo fileInfo         = new FileInfo(filepath);
 *          fileInfo.CreationTimeUtc  = new DateTime(1970, 1, 1).AddSeconds(document.CreationTime);
 *          fileInfo.LastWriteTimeUtc = new DateTime(1970, 1, 1).AddSeconds(document.LastWriteTime);
 */
        }
示例#13
0
        private void DownloadMissingFiles(IEnumerable <string> chunkHashes)
        {
            var filesToDownload = _cacheManager.GetFilenamesNotInCache(chunkHashes);

            if (filesToDownload.Length == 0)
            {
                GitBinConsole.WriteNoPrefix(" All chunks already present in cache");
            }
            else
            {
                if (filesToDownload.Length == 1)
                {
                    GitBinConsole.WriteNoPrefix(" Downloading 1 chunk: ");
                }
                else
                {
                    GitBinConsole.WriteNoPrefix(" Downloading {0} chunks: ", filesToDownload.Length);
                }

                AsyncFileProcessor.ProcessFiles(filesToDownload, DownloadFile);
            }

            GitBinConsole.WriteLine();
        }
示例#14
0
 public void Execute()
 {
     GitBinConsole.WriteLine(_message);
 }
示例#15
0
 private void PrintStatusAboutCache()
 {
     GitBinConsole.WriteLineNoPrefix("Local cache:");
     GitBinConsole.WriteLineNoPrefix("  items: {0}", _filesInLocalCache.Length);
     GitBinConsole.WriteLineNoPrefix("  size:  {0}", GitBinFileInfoUtils.GetHumanReadableSize(_filesInLocalCache));
 }
示例#16
0
        public void Dispose()
        {
            GitBinConsole.WriteNoPrefix(Environment.NewLine);

            _remote.ProgressChanged -= OnProgressChanged;
        }