Ejemplo n.º 1
0
		public void Restart()
		{
			Stage = AttachmentStage.Pending;
			CurrentChunk = 0;
			UploadedBytes = 0;
			DeckCloudFileResponse = null;
			DeckVersionResponse = null;
			Status = AttachmentStatus.Pending;
			DownloadLink = null;
		}
Ejemplo n.º 2
0
		public DeckCloudFileResponse InitiateChunking(DeckVersionResponse deckResponse)
		{
			if (string.IsNullOrEmpty(_deviceToken))
			{
				throw new Exception("Device token is blank.");
			}

			// Initiating file chunk uploading.
			Logger.LogDebug("Initiating file chunk uploading.");

			string uri = string.Format("{0}/cloud_files/{1}.xml", m_hostServer, deckResponse.FileDataId);

			var parameters = new List<NamedData>
             	{
             		new NamedData("initiate_multipart", "true")
             	};

			// Specify a schema to ensure the response is as expected.
			string xmlSchema = Resources.DeckCloudFileXmlSchema;
			DataSet dset = MultipartFormDataPut(uri, parameters, xmlSchema);
			return new DeckCloudFileResponse(dset, DeckCloudFileResponse.RequestType.InitiateChunking);
		}
Ejemplo n.º 3
0
		public void UploadWholeFile(Action<long, double> callbackIncrementProgress, string filePath, DeckVersionResponse deckResponse)
		{
		    try
		    {
		        // Upload the file as a whole.
		        Logger.LogDebug(string.Format("Uploading whole file \"{0}\".", filePath));

		        string uri = deckResponse.UploadInfo.Action;

		        int bufferLength = 0;
		        using (var fileStream = new FileStream(filePath, FileMode.Open))
		        {
		            bufferLength = fileStream.Read(m_buffer, 0, (int) fileStream.Length);
		        }
		        string fileName = Path.GetFileName(filePath);

		        var parameters = new List<NamedData>
		                         {
		                             new NamedData("key", deckResponse.UploadInfo.Key),
		                             new NamedData("AWSAccessKeyId", deckResponse.UploadInfo.AWSAccessKeyId),
		                             new NamedData("acl", deckResponse.UploadInfo.Acl),
		                             new NamedData("success_action_redirect", deckResponse.UploadInfo.Success_action_redirect),
		                             new NamedData("policy", deckResponse.UploadInfo.Policy),
		                             new NamedData("signature", deckResponse.UploadInfo.Signature),
		                             new NamedData("Content-Type", deckResponse.UploadInfo.ContentType),
		                             new NamedData("x-amz-server-side-encryption",
		                                 deckResponse.UploadInfo.XAmzServerSideEncryption),
		                             new NamedData("file",
		                                 new FileParameter(m_buffer, bufferLength, fileName,
		                                 deckResponse.UploadInfo.ContentType))
		                         };

		        if (!string.IsNullOrEmpty(deckResponse.UploadInfo.CacheControl))
		        {
		            // Only add this if it exists. Place it after the "key" parameter, but before everything else.
		            parameters.Insert(1, new NamedData("Cache-Control", deckResponse.UploadInfo.CacheControl));
		        }
		        var start = DateTime.Now;
		        MultipartFormDataPost(uri, parameters, true, true, null);
		        var duration = DateTime.Now - start;
		        var byteRate = ((double) bufferLength)/duration.TotalSeconds;
		        if (callbackIncrementProgress != null)
		        {
		            Logger.LogDebug("Calling delegate to increment progress.");
		            callbackIncrementProgress(bufferLength, byteRate);
		        }
		    }
		    catch (Exception e)
		    {
		        Logger.LogError(e);
		        throw;
		    }
			finally
			{
				Array.Clear(m_buffer, 0, m_buffer.Length);
			}

		}