XenAPI.HTTP.Get C# (CSharp) Method

Get() public static method

A general HTTP GET method, with delegates for progress and cancelling. May throw various exceptions.
public static Get ( DataCopiedDelegate dataCopiedDelegate, FuncBool cancellingDelegate, Uri uri, IWebProxy proxy, string path, int timeout_ms ) : void
dataCopiedDelegate DataCopiedDelegate
cancellingDelegate FuncBool Delegate called periodically to see if need to cancel
uri System.Uri URI to GET from
proxy IWebProxy A proxy to handle the HTTP connection
path string Path to file to receive the data
timeout_ms int Timeout for the connection in ms. 0 for no timeout.
return void
        public static void Get(DataCopiedDelegate dataCopiedDelegate, FuncBool cancellingDelegate,
            Uri uri, IWebProxy proxy, string path, int timeout_ms)
        {
            string tmpFile = Path.GetTempFileName();
            try
            {
                using (Stream fileStream = new FileStream(tmpFile, FileMode.Create, FileAccess.Write, FileShare.None),
                    downloadStream = GET(uri, proxy, timeout_ms))
                {
                    CopyStream(downloadStream, fileStream, dataCopiedDelegate, cancellingDelegate);
                    fileStream.Flush();
                }

                File.Delete(path);
                File.Move(tmpFile, path);
            }
            finally
            {
                File.Delete(tmpFile);
            }
        }

Usage Example

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