예제 #1
0
        private static void UploadWithProgress()
        {
            var testfile = GenFileText(sizeInMb: 32);

            Stopwatch sw = new Stopwatch();
            long      bytesTransferredLast = 0;
            decimal   transferRate         = 0;

            decimal PreviousPercentage = 0;

            TusClient.TusClient tc = new TusClient.TusClient();
            tc.Uploading += (long bytesTransferred, long bytesTotal) =>
            {
                if (sw.Elapsed.TotalSeconds > 0)
                {
                    transferRate = (decimal)((bytesTransferred - bytesTransferredLast) / sw.Elapsed.TotalSeconds);
                }

                decimal perc = (decimal)(bytesTransferred / (double)bytesTotal * 100.0);
                perc = Math.Truncate(perc);

                if (perc != PreviousPercentage)
                {
                    Console.WriteLine("Up {0:0.00}% {1} of {2} @ {3}/second", perc, HumanizeBytes(bytesTransferred), HumanizeBytes(bytesTotal), HumanizeBytes((long)transferRate));
                    PreviousPercentage = perc;
                }

                if (sw.Elapsed.TotalSeconds > 1)
                {
                    bytesTransferredLast = bytesTransferred;
                    sw.Restart();
                }
            };



            var fileURL = tc.Create(ServerURL, testfile);

            sw.Start();
            tc.Upload(fileURL, testfile);
            sw.Stop();

            //VerifyUpload(fileURL, testfile);

            var serverInfo = tc.getServerInfo(ServerURL);

            //if (serverInfo.SupportsDelete)
            //{
            //    if (tc.Delete(fileURL))
            //        Console.WriteLine("Upload Terminated");
            //    else
            //        Console.WriteLine("Upload Terminated FAILED");
            //}


            // Cleanup
            //System.IO.File.Delete(testfile.FullName);
        }
예제 #2
0
        private static void ServerInfo()
        {
            TusClient.TusClient tc = new TusClient.TusClient();
            var serverInfo         = tc.getServerInfo(ServerURL);

            Console.WriteLine("Version:{0}", serverInfo.Version);
            Console.WriteLine("Supported Protocols:{0}", serverInfo.SupportedVersions);
            Console.WriteLine("Extensions:{0}", serverInfo.Extensions);
            Console.WriteLine("MaxSize:{0}", serverInfo.MaxSize);
        }