public override void RunThread() { int attempt = WORKING; while (attempt == WORKING) { attempt = AttemptConversion(); } if (attempt == FAILURE) { System.Diagnostics.Debug.WriteLine("Unable to convert media."); } else if (attempt == SUCCESS) { System.Diagnostics.Debug.WriteLine("Media converted successfully."); if (!VDXApplicationSettings.IsLocalEnviornment()) { VDXCloudBlob storageService = new VDXCloudBlob(this.file_name); if (storageService.ExecuteActionLocal(VDXCloudAction.WRITE, this.dest_path)) { string blob_uri = storageService.GetBlobPath(); DatabaseOps.UploadNotification(this.title, this.user, this.date, blob_uri); } } else { DatabaseOps.UploadNotification(this.title, this.user, this.date, this.dest_path); } } else { System.Diagnostics.Debug.WriteLine("Something went horribly wrong."); } this.ConversionStatus = attempt; Abort(); }
public void OpenStream() { System.IO.Stream iStream = null; byte[] buffer = new Byte[4096]; int length; long dataToRead; try { if (VDXApplicationSettings.IsLocalEnviornment()) { iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); } else { VDXCloudBlob blobService = new VDXCloudBlob(this.filename); iStream = blobService.ExecuteActionStream(VDXCloudAction.READ); } // Total bytes to read: dataToRead = iStream.Length; Response.AddHeader("Accept-Ranges", "bytes"); Response.ContentType = "video/mp4"; int startbyte = 0; if (!String.IsNullOrEmpty(Request.Headers["Range"])) { string[] range = Request.Headers["Range"].Split(new char[] { '=', '-' }); startbyte = Int32.Parse(range[1]); iStream.Seek(startbyte, SeekOrigin.Begin); Response.StatusCode = 206; Response.AddHeader("Content-Range", String.Format(" bytes {0}-{1}/{2}", startbyte, dataToRead - 1, dataToRead)); } while (dataToRead > 0) { // Verify that the client is connected. if (Response.IsClientConnected) { // Read the data in buffer. length = iStream.Read(buffer, 0, buffer.Length); // Write the data to the current output stream. Response.OutputStream.Write(buffer, 0, buffer.Length); // Flush the data to the HTML output. Response.Flush(); buffer = new Byte[buffer.Length]; dataToRead = dataToRead - buffer.Length; } else { //prevent infinite loop if user disconnects dataToRead = -1; } } } catch (HttpException htx) { if (VDXApplicationSettings.IsLocalEnviornment()) { System.Diagnostics.Debug.WriteLine("HttpException: " + htx.Message); } else { CloudLogError.ErrorMsg(htx.Message); } } catch (Exception ex) { if (VDXApplicationSettings.IsLocalEnviornment()) { System.Diagnostics.Debug.WriteLine("HttpException: " + ex.Message); } else { CloudLogError.ErrorMsg(ex.Message); } } finally { if (iStream != null) { //Close the file. iStream.Close(); } Response.Close(); } }