Beispiel #1
0
        public void Send()
        {
            try
            {
                //send first chunk, start upload.

                FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
                client.Endpoint.Address      = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
                client.BeginUploadCompleted += new EventHandler <Uploader.Client.FileReceiver.BeginUploadCompletedEventArgs>(client_BeginUploadCompleted);
                FileReceiver.ChunkUploadRequest req = new Uploader.Client.FileReceiver.ChunkUploadRequest();
                using (FileStream fs = this.File.OpenRead())
                {
                    //get full hash first.
                    this.FileLength = fs.Length;

                    //setup progress bar.
                    this.Steps = (int)(this.FileLength / (long)Utility.chunkSize);
                    this.uxProgress.Minimum = 0;
                    this.uxProgress.Maximum = this.Steps;

                    int    read   = 0;
                    byte[] buffer = null;

                    if (fs.Length <= Utility.chunkSize)
                    {
                        buffer = new byte[(int)fs.Length];
                    }
                    else
                    {
                        buffer = new byte[Utility.chunkSize];
                    }

                    read = fs.Read(buffer, 0, Utility.chunkSize);

                    this.FilePosition += read;

                    req.Chunk     = buffer;
                    req.ChunkSize = buffer.Length;
                    req.Hash      = Utility.GetSHA256Hash(buffer);

                    client.BeginUploadAsync(req);
                }
            }
            catch (Exception ex)
            {
                //show error.
                this.uxText.Text = ex.Message;
            }
        }
Beispiel #2
0
        void FinishUpload(Guid token)
        {
            FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
            client.Endpoint.Address       = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
            client.FinishUploadCompleted += new EventHandler <Uploader.Client.FileReceiver.FinishUploadCompletedEventArgs>(client_FinishUploadCompleted);

            FileReceiver.FinishRequest req = new Uploader.Client.FileReceiver.FinishRequest();
            using (FileStream fs = this.File.OpenRead())
            {
                req.Extension = this.File.Extension;
                req.FullHash  = Utility.GetSHA256Hash(fs);
            }
            req.Token = token;

            client.FinishUploadAsync(req);
        }
		public void Send()
		{
			try
			{
				//send first chunk, start upload. 

				FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
				client.Endpoint.Address = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
				client.BeginUploadCompleted += new EventHandler<Uploader.Client.FileReceiver.BeginUploadCompletedEventArgs>(client_BeginUploadCompleted);
				FileReceiver.ChunkUploadRequest req = new Uploader.Client.FileReceiver.ChunkUploadRequest();
				using (FileStream fs = this.File.OpenRead())
				{
					//get full hash first. 
					this.FileLength = fs.Length;

					//setup progress bar. 
					this.Steps = (int)(this.FileLength / (long)Utility.chunkSize);
					this.uxProgress.Minimum = 0;
					this.uxProgress.Maximum = this.Steps;

					int read = 0;
					byte[] buffer = null;

					if (fs.Length <= Utility.chunkSize)
						buffer = new byte[(int)fs.Length];
					else
						buffer = new byte[Utility.chunkSize];

					read = fs.Read(buffer, 0, Utility.chunkSize);

					this.FilePosition += read;

					req.Chunk = buffer;
					req.ChunkSize = buffer.Length;
					req.Hash = Utility.GetSHA256Hash(buffer);

					client.BeginUploadAsync(req);
				}
			}
			catch (Exception ex)
			{
				//show error. 
				this.uxText.Text = ex.Message;
			}
		}
Beispiel #4
0
        void SendNextChunk(Guid token)
        {
            try
            {
                FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
                client.Endpoint.Address         = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
                client.ContinueUploadCompleted += new EventHandler <Uploader.Client.FileReceiver.ContinueUploadCompletedEventArgs>(client_ContinueUploadCompleted);

                FileReceiver.ChunkUploadRequest req = new Uploader.Client.FileReceiver.ChunkUploadRequest();
                using (FileStream fs = this.File.OpenRead())
                {
                    int    read     = 0;
                    byte[] buffer   = null;
                    int    readSize = Utility.chunkSize;

                    long diff = this.FileLength - this.FilePosition;
                    if (diff < Utility.chunkSize)
                    {
                        readSize = (int)diff;
                    }

                    buffer = new byte[readSize];

                    fs.Seek(this.FilePosition, SeekOrigin.Begin);
                    read = fs.Read(buffer, 0, readSize);

                    this.FilePosition += read;

                    req.ChunkSize = buffer.Length;
                    req.Hash      = Utility.GetSHA256Hash(buffer);
                    req.Chunk     = buffer;
                    req.Token     = token;

                    client.ContinueUploadAsync(req);
                }
            }
            catch (Exception ex)
            {
                //show error.
                this.uxText.Text = ex.Message;
            }
        }
		void SendNextChunk(Guid token)
		{
			try
			{
				FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
				client.Endpoint.Address = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
				client.ContinueUploadCompleted += new EventHandler<Uploader.Client.FileReceiver.ContinueUploadCompletedEventArgs>(client_ContinueUploadCompleted);

				FileReceiver.ChunkUploadRequest req = new Uploader.Client.FileReceiver.ChunkUploadRequest();
				using (FileStream fs = this.File.OpenRead())
				{
					int read = 0;
					byte[] buffer = null;
					int readSize = Utility.chunkSize;

					long diff = this.FileLength - this.FilePosition;
					if (diff < Utility.chunkSize)
						readSize = (int)diff;

					buffer = new byte[readSize];

					fs.Seek(this.FilePosition, SeekOrigin.Begin);
					read = fs.Read(buffer, 0, readSize);

					this.FilePosition += read;

					req.ChunkSize = buffer.Length;
					req.Hash = Utility.GetSHA256Hash(buffer);
					req.Chunk = buffer;
					req.Token = token;

					client.ContinueUploadAsync(req);
				}
			}
			catch (Exception ex)
			{
				//show error. 
				this.uxText.Text = ex.Message;
			}
		}
		void FinishUpload(Guid token)
		{
			FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
			client.Endpoint.Address = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
			client.FinishUploadCompleted += new EventHandler<Uploader.Client.FileReceiver.FinishUploadCompletedEventArgs>(client_FinishUploadCompleted);

			FileReceiver.FinishRequest req = new Uploader.Client.FileReceiver.FinishRequest();
			using (FileStream fs = this.File.OpenRead())
			{
				req.Extension = this.File.Extension;
				req.FullHash = Utility.GetSHA256Hash(fs);
			}
			req.Token = token;

			client.FinishUploadAsync(req);
		}