XenAPI.HTTP.Put C# (CSharp) Method

Put() public static method

A general HTTP PUT method, with delegates for progress and cancelling. May throw various exceptions.
public static Put ( UpdateProgressDelegate progressDelegate, FuncBool cancellingDelegate, Uri uri, IWebProxy proxy, string path, int timeout_ms ) : void
progressDelegate UpdateProgressDelegate Delegate called periodically (500ms) with percent complete
cancellingDelegate FuncBool Delegate called periodically to see if need to cancel
uri System.Uri URI to PUT to
proxy IWebProxy A proxy to handle the HTTP connection
path string Path to file to put
timeout_ms int Timeout for the connection in ms. 0 for no timeout.
return void
        public static void Put(UpdateProgressDelegate progressDelegate, FuncBool cancellingDelegate,
            Uri uri, IWebProxy proxy, string path, int timeout_ms)
        {
            using (Stream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read),
                requestStream = PUT(uri, proxy, fileStream.Length, timeout_ms))
            {
                long len = fileStream.Length;
                DataCopiedDelegate dataCopiedDelegate = delegate(long bytes)
                    {
                        if (progressDelegate != null && len > 0)
                            progressDelegate((int)((bytes * 100) / len));
                    };

                CopyStream(fileStream, requestStream, dataCopiedDelegate, cancellingDelegate);
            }
        }

Usage Example

Example #1
0
 private static void Put(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
                         string hostname, string remotePath, IWebProxy proxy, string localPath, params object[] args)
 {
     HTTP.Put(progressDelegate, cancellingDelegate, HTTP.BuildUri(hostname, remotePath, args), proxy, localPath, timeout_ms);
 }