Пример #1
0
        void FileUploadTask(string targetUrl)  //TODO: blocking call
        {
            Assert.IsNull(m_TusClient);
            m_TusClient            = new TusClient.TusClient();
            m_TusClient.Uploading += UploadingDelegate;

            m_TusClient.Autorization = "Basic " + m_ClientApi;
            ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
            //string fileURL = m_TusClient.Create(targetUrl, m_UploadedFile);
            try
            {
                m_TusClient.Upload(targetUrl, m_UploadedFile);
            }
            catch (TusClient.TusException e)
            {
                if (e.Status == System.Net.WebExceptionStatus.RequestCanceled)
                {
                    Debug.Log("Upload Cancelled");
                    m_IsError = true;
                }
                else
                {
                    Debug.Log("Another error");
                    m_IsError = true;
                }
            }
            m_TusClient = null;
        }
Пример #2
0
        private static void UploadExampleStream()
        {
            var testfile = GenFileText(sizeInMb: 32);

            Dictionary <string, string> metadata = new Dictionary <string, string>();

            metadata["filena"] = testfile.Name;

            TusClient.TusClient tc = new TusClient.TusClient();
            tc.Uploading += (long bytesTransferred, long bytesTotal) =>
            {
                decimal perc = (Decimal)(bytesTransferred / (double)bytesTotal * 100.0);
                Console.WriteLine("Up {0:0.00}% {1} of {2}", perc, bytesTransferred, bytesTotal);
            };

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

            using (System.IO.FileStream fs = new System.IO.FileStream(testfile.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                tc.Upload(fileURL, fs);
            }


            tc.Delete(fileURL);

            // Cleanup
            //System.IO.File.Delete(testfile.FullName);
        }
Пример #3
0
 public void StartUpload()
 {
     CheckConnection();
     CheckParameters();
     m_TusClient = null; //TODO: should be checked before
     m_TaskList[m_CurrentTask].startAction();
 }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        private static void UploadExampleMinimal()
        {
            var testfile = GenFileText(sizeInMb: 32);

            TusClient.TusClient tc = new TusClient.TusClient();
            tc.Uploading += (long bytesTransferred, long bytesTotal) =>
            {
                decimal perc = (decimal)(bytesTransferred / (double)bytesTotal * 100.0);
                Console.WriteLine("Up {0:0.00}% {1} of {2}", perc, bytesTransferred, bytesTotal);
            };

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

            tc.Upload(fileURL, testfile);

            tc.Delete(fileURL);

            // Cleanup
            //System.IO.File.Delete(testfile.FullName);
        }
Пример #7
0
        private static void UploadConnectionInterrupted()
        {
            var testfile = GenFileBinary(sizeInMb: 64);

            decimal PreviousPercentage           = 0;
            decimal PreviousPercentageDisconnect = 0;

            TusClient.TusClient tc = new TusClient.TusClient();
            tc.Uploading += (long bytesTransferred, long bytesTotal) =>
            {
                decimal perc = (decimal)(bytesTransferred / (double)bytesTotal * 100.0);
                perc = Math.Truncate(perc);
                if (perc != PreviousPercentage)
                {
                    Console.WriteLine("Up {0:0.00}% {1} of {2}", perc, HumanizeBytes(bytesTransferred), HumanizeBytes(bytesTotal));
                    PreviousPercentage = perc;
                }

                if (perc > PreviousPercentageDisconnect & perc > 0 & Math.Ceiling(perc) % 20 == 0)
                {
                    //StopTusdServer();
                    //StartTusdServer();

                    PreviousPercentageDisconnect = Math.Ceiling(perc);
                }
            };

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

            tc.Upload(fileURL, testfile);

            //VerifyUpload(fileURL, testfile);

            // Cleanup
            //System.IO.File.Delete(testfile.FullName);
        }
Пример #8
0
        private static void CancelResumeExample()
        {
            var testfile = GenFileText(sizeInMb: 32);

            int lastperc = 0;

            TusClient.TusClient tc = new TusClient.TusClient();
            tc.Uploading += (long bytesTransferred, long bytesTotal) =>
            {
                decimal perc = (decimal)(bytesTransferred / (double)bytesTotal * 100.0);
                if (perc - lastperc > 1)
                {
                    Console.WriteLine("Up {0:0.00}% {1} of {2}", perc, bytesTransferred, bytesTotal);
                    lastperc = (int)perc;
                }
                if (perc > 50)
                {
                    tc.Cancel();
                }
            };

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

            try
            {
                tc.Upload(fileURL, testfile);
            }
            catch (TusClient.TusException ex)
            {
                if (ex.Status == System.Net.WebExceptionStatus.RequestCanceled)
                {
                    Console.WriteLine("Upload Cancelled");
                }
                else
                {
                    throw;
                }
            }

            System.Threading.Thread.Sleep(2000);

            tc            = new TusClient.TusClient(); // Have to create new client to resume with same URL
            tc.Uploading += (long bytesTransferred, long bytesTotal) =>
            {
                decimal perc = (decimal)(bytesTransferred / (double)bytesTotal * 100.0);
                if (perc - lastperc > 1)
                {
                    Console.WriteLine("Up {0:0.00}% {1} of {2}", perc, bytesTransferred, bytesTotal);
                    lastperc = (int)perc;
                }
            };

            Console.WriteLine("Upload Resumed");
            tc.Upload(fileURL, testfile);

            Console.WriteLine("Upload Complete");
            //tc.Delete(fileURL);

            // Cleanup
            //System.IO.File.Delete(testfile.FullName);
        }