Esempio n. 1
0
 public static bool Write(CloudBlockBlob blob, Stream fileStream)
 {
     try
     {
         blob.UploadFromStream(fileStream);
         return(true);
     }
     catch (Exception e)
     {
         CloudLogError.ErrorMsg(e.Message);
         return(false);
     }
 }
Esempio n. 2
0
 public static bool Read(CloudBlockBlob blob, Stream fileStream)
 {
     try
     {
         blob.DownloadToStream(fileStream);
         return(true);
     }
     catch (Exception e)
     {
         CloudLogError.ErrorMsg(e.Message);
         return(false);
     }
 }
        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();
            }
        }