Beispiel #1
0
 protected override void DownloadAllFiles()
 {
     if (ServicePointManager.SecurityProtocol != (ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12))
     {
         Logger.AddInternalState(" Current TLS Protocol = " + ServicePointManager.SecurityProtocol.ToString());
         ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
         Logger.AddInternalState(string.Format(" Default TLS protocol is changed to = {0} with implicit fallback ", (object)ServicePointManager.SecurityProtocol.ToString()));
     }
     do
     {
         FileDownloader.DownloadQueueItem next = (FileDownloader.DownloadQueueItem)null;
         lock (this._fileQueue)
         {
             if (this._fileQueue.Count > 0)
             {
                 next = (FileDownloader.DownloadQueueItem) this._fileQueue.Dequeue();
             }
         }
         if (next != null)
         {
             this.DownloadSingleFile(next);
         }
         else
         {
             break;
         }
     }while (!this._fCancelPending);
     if (this._fCancelPending)
     {
         throw new DownloadCancelledException();
     }
 }
Beispiel #2
0
 public void AddFile(Uri sourceUri, string targetFilePath, object cookie, HashCollection hashCollection, int maxFileSize)
 {
     UriHelper.ValidateSupportedScheme(sourceUri);
     FileDownloader.DownloadQueueItem downloadQueueItem = new FileDownloader.DownloadQueueItem();
     downloadQueueItem._sourceUri      = sourceUri;
     downloadQueueItem._targetPath     = targetFilePath;
     downloadQueueItem._cookie         = cookie;
     downloadQueueItem._hashCollection = hashCollection;
     downloadQueueItem._maxFileSize    = maxFileSize;
     lock (this._fileQueue)
     {
         this._fileQueue.Enqueue((object)downloadQueueItem);
         ++this._eventArgs._filesTotal;
     }
 }
        protected void DownloadSingleFile(FileDownloader.DownloadQueueItem next)
        {
            Logger.AddMethodCall("DownloadSingleFile called");
            Logger.AddInternalState("DownloadQueueItem : " + ((next != null) ? next.ToString() : "null"));
            WebRequest request = WebRequest.Create(next._sourceUri);

            request.Credentials = CredentialCache.DefaultCredentials;
            RequestCachePolicy policy = new RequestCachePolicy(RequestCacheLevel.BypassCache);

            request.CachePolicy = policy;
            HttpWebRequest httpreq = request as HttpWebRequest;

            if (httpreq != null)
            {
                httpreq.UnsafeAuthenticatedConnectionSharing = true;
                httpreq.AutomaticDecompression = DecompressionMethods.GZip;
                httpreq.CookieContainer        = GetUriCookieContainer(httpreq.RequestUri);
                IWebProxy defaultWebProxy = WebRequest.DefaultWebProxy;
                if (defaultWebProxy != null)
                {
                    defaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
                }
                Logger.AddInternalState("HttpWebRequest=" + Logger.Serialize(httpreq));
            }
            if (!base._fCancelPending)
            {
                WebResponse response = null;
                try
                {
                    response = request.GetResponse();
                    UriHelper.ValidateSupportedScheme(response.ResponseUri);
                    if (!base._fCancelPending)
                    {
                        base._eventArgs._fileSourceUri   = next._sourceUri;
                        base._eventArgs._fileResponseUri = response.ResponseUri;
                        base._eventArgs.FileLocalPath    = next._targetPath;
                        base._eventArgs.Cookie           = null;
                        if (response.ContentLength > 0L)
                        {
                            base.CheckForSizeLimit((ulong)response.ContentLength, false);
                            base._accumulatedBytesTotal += response.ContentLength;
                        }
                        base.SetBytesTotal();
                        base.OnModified();
                        Stream responseStream   = null;
                        Stream outputFileStream = null;
                        int    tickCount        = Environment.TickCount;
                        try
                        {
                            responseStream = response.GetResponseStream();
                            Directory.CreateDirectory(Path.GetDirectoryName(next._targetPath));
                            outputFileStream = GetOutputFileStream(next._targetPath);
                            if (outputFileStream != null)
                            {
                                int  num3;
                                long num2 = 0L;
                                if (response.ContentLength > 0L)
                                {
                                    outputFileStream.SetLength(response.ContentLength);
                                }
                                do
                                {
                                    if (base._fCancelPending)
                                    {
                                        return;
                                    }
                                    num3 = responseStream.Read(base._buffer, 0, base._buffer.Length);
                                    if (num3 > 0)
                                    {
                                        outputFileStream.Write(base._buffer, 0, num3);
                                    }
                                    base._eventArgs._bytesCompleted += num3;
                                    if (response.ContentLength <= 0L)
                                    {
                                        base._accumulatedBytesTotal += num3;
                                        base.SetBytesTotal();
                                    }
                                    num2 += num3;
                                    if ((next._maxFileSize != -1) && (num2 > next._maxFileSize))
                                    {
                                        throw new InvalidDeploymentException(ExceptionTypes.FileSizeValidation, string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_FileBeingDownloadedTooLarge"), new object[] { next._sourceUri.ToString(), next._maxFileSize }));
                                    }
                                    base.CheckForSizeLimit((ulong)num3, true);
                                    if (base._eventArgs._bytesTotal > 0L)
                                    {
                                        base._eventArgs._progress = (int)((base._eventArgs._bytesCompleted * 100L) / base._eventArgs._bytesTotal);
                                    }
                                    base.OnModifiedWithThrottle(ref tickCount);
                                }while (num3 > 0);
                                if (response.ContentLength != num2)
                                {
                                    outputFileStream.SetLength(num2);
                                }
                            }
                        }
                        finally
                        {
                            if (responseStream != null)
                            {
                                responseStream.Close();
                            }
                            if (outputFileStream != null)
                            {
                                outputFileStream.Close();
                            }
                        }
                        base._eventArgs.Cookie = next._cookie;
                        base._eventArgs._filesCompleted++;
                        Logger.AddInternalState("HttpWebResponse=" + Logger.Serialize(response));
                        base.OnModified();
                        DownloadResult result = new DownloadResult {
                            ResponseUri = response.ResponseUri
                        };
                        result.ServerInformation.Server        = response.Headers["Server"];
                        result.ServerInformation.PoweredBy     = response.Headers["X-Powered-By"];
                        result.ServerInformation.AspNetVersion = response.Headers["X-AspNet-Version"];
                        base._downloadResults.Add(result);
                    }
                }
                catch (InvalidOperationException exception)
                {
                    throw new DeploymentDownloadException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[] { next._sourceUri }), exception);
                }
                catch (IOException exception2)
                {
                    throw new DeploymentDownloadException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[] { next._sourceUri }), exception2);
                }
                catch (UnauthorizedAccessException exception3)
                {
                    throw new DeploymentDownloadException(string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[] { next._sourceUri }), exception3);
                }
                finally
                {
                    if (response != null)
                    {
                        response.Close();
                    }
                }
            }
        }
Beispiel #4
0
 private void PatchFiles(SubscriptionState subState)
 {
     if (!subState.IsInstalled)
     {
         Logger.AddInternalState("Subscription is not installed. No patching.");
     }
     else
     {
         Store.IPathLock pathLock1 = (Store.IPathLock)null;
         Store.IPathLock pathLock2 = (Store.IPathLock)null;
         using (subState.SubscriptionStore.AcquireSubscriptionReaderLock(subState))
         {
             if (!subState.IsInstalled)
             {
                 Logger.AddInternalState("Subscription is not installed. No patching.");
                 return;
             }
             Hashtable hashtable = new Hashtable();
             try
             {
                 pathLock1 = subState.SubscriptionStore.LockApplicationPath(subState.CurrentBind);
                 FileDownloader.AddFilesInHashtable(hashtable, subState.CurrentApplicationManifest, pathLock1.Path);
                 try
                 {
                     if (subState.PreviousBind != null)
                     {
                         pathLock2 = subState.SubscriptionStore.LockApplicationPath(subState.PreviousBind);
                         FileDownloader.AddFilesInHashtable(hashtable, subState.PreviousApplicationManifest, pathLock2.Path);
                     }
                     Queue queue = new Queue();
                     do
                     {
                         FileDownloader.DownloadQueueItem downloadQueueItem = (FileDownloader.DownloadQueueItem)null;
                         lock (this._fileQueue)
                         {
                             if (this._fileQueue.Count > 0)
                             {
                                 downloadQueueItem = (FileDownloader.DownloadQueueItem) this._fileQueue.Dequeue();
                             }
                         }
                         if (downloadQueueItem != null)
                         {
                             if (!this.PatchSingleFile(downloadQueueItem, hashtable))
                             {
                                 queue.Enqueue((object)downloadQueueItem);
                             }
                         }
                         else
                         {
                             break;
                         }
                     }while (!this._fCancelPending);
                     lock (this._fileQueue)
                     {
                         while (this._fileQueue.Count > 0)
                         {
                             queue.Enqueue(this._fileQueue.Dequeue());
                         }
                         this._fileQueue = queue;
                     }
                 }
                 finally
                 {
                     if (pathLock2 != null)
                     {
                         pathLock2.Dispose();
                     }
                 }
             }
             finally
             {
                 if (pathLock1 != null)
                 {
                     pathLock1.Dispose();
                 }
             }
         }
         if (this._fCancelPending)
         {
             throw new DownloadCancelledException();
         }
     }
 }
Beispiel #5
0
        private bool PatchSingleFile(FileDownloader.DownloadQueueItem item, Hashtable dependencyTable)
        {
            if (item._hashCollection == null)
            {
                return(false);
            }
            string str = (string)null;

            foreach (Hash hash in item._hashCollection)
            {
                string compositString = hash.CompositString;
                if (dependencyTable.Contains((object)compositString))
                {
                    str = (string)dependencyTable[(object)compositString];
                    break;
                }
            }
            if (str == null || this._fCancelPending)
            {
                return(false);
            }
            if (!FileDownloader.FileHashVerified(item._hashCollection, str))
            {
                Logger.AddInternalState("Hash verify failed for " + str + ", not using it for file patching.");
                return(false);
            }
            FileStream fileStream1 = (FileStream)null;
            FileStream fileStream2 = (FileStream)null;

            try
            {
                fileStream1 = FileDownloader.GetPatchSourceStream(str);
                if (fileStream1 == null)
                {
                    return(false);
                }
                Directory.CreateDirectory(Path.GetDirectoryName(item._targetPath));
                fileStream2 = FileDownloader.GetPatchTargetStream(item._targetPath);
                if (fileStream2 == null)
                {
                    return(false);
                }
                this._eventArgs._fileSourceUri   = item._sourceUri;
                this._eventArgs.FileLocalPath    = item._targetPath;
                this._eventArgs.Cookie           = (object)null;
                this._eventArgs._fileResponseUri = (Uri)null;
                this.CheckForSizeLimit((ulong)fileStream1.Length, true);
                this._accumulatedBytesTotal = this._accumulatedBytesTotal + fileStream1.Length;
                this.SetBytesTotal();
                this.OnModified();
                int tickCount = Environment.TickCount;
                fileStream2.SetLength(fileStream1.Length);
                fileStream2.Position = 0L;
                int count;
                do
                {
                    if (this._fCancelPending)
                    {
                        return(false);
                    }
                    count = fileStream1.Read(this._buffer, 0, this._buffer.Length);
                    if (count > 0)
                    {
                        fileStream2.Write(this._buffer, 0, count);
                    }
                    this._eventArgs._bytesCompleted += (long)count;
                    this._eventArgs._progress        = (int)(this._eventArgs._bytesCompleted * 100L / this._eventArgs._bytesTotal);
                    this.OnModifiedWithThrottle(ref tickCount);
                }while (count > 0);
            }
            finally
            {
                if (fileStream1 != null)
                {
                    fileStream1.Close();
                }
                if (fileStream2 != null)
                {
                    fileStream2.Close();
                }
            }
            this._eventArgs.Cookie = item._cookie;
            ++this._eventArgs._filesCompleted;
            this.OnModified();
            this._downloadResults.Add((object)new DownloadResult()
            {
                ResponseUri = (Uri)null
            });
            Logger.AddInternalState(item._targetPath + " is patched from store.");
            return(true);
        }
Beispiel #6
0
        protected void DownloadSingleFile(FileDownloader.DownloadQueueItem next)
        {
            Logger.AddMethodCall("DownloadSingleFile called");
            Logger.AddInternalState("DownloadQueueItem : " + (next != null ? next.ToString() : "null"));
            WebRequest webRequest = this.CreateWebRequest(next._sourceUri);

            if (this._fCancelPending)
            {
                return;
            }
            WebResponse response1 = (WebResponse)null;

            try
            {
                if (this.ClientCertificate == null)
                {
                    try
                    {
                        response1 = webRequest.GetResponse();
                    }
                    catch (WebException ex)
                    {
                        HttpWebResponse response2 = ex.Response as HttpWebResponse;
                        if (response2 != null && response2.StatusCode == HttpStatusCode.Forbidden)
                        {
                            this.ClientCertificate = this.GetClientCertificate();
                            if (this.ClientCertificate == null)
                            {
                                throw;
                            }
                            else
                            {
                                webRequest = this.CreateWebRequest(next._sourceUri);
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
                if (this.ClientCertificate != null)
                {
                    HttpWebRequest httpWebRequest = webRequest as HttpWebRequest;
                    if (httpWebRequest != null)
                    {
                        httpWebRequest.ClientCertificates.Add((X509Certificate)this.ClientCertificate);
                    }
                    response1 = webRequest.GetResponse();
                }
                UriHelper.ValidateSupportedScheme(response1.ResponseUri);
                if (this._fCancelPending)
                {
                    return;
                }
                this._eventArgs._fileSourceUri   = next._sourceUri;
                this._eventArgs._fileResponseUri = response1.ResponseUri;
                this._eventArgs.FileLocalPath    = next._targetPath;
                this._eventArgs.Cookie           = (object)null;
                if (response1.ContentLength > 0L)
                {
                    this.CheckForSizeLimit((ulong)response1.ContentLength, false);
                    this._accumulatedBytesTotal = this._accumulatedBytesTotal + response1.ContentLength;
                }
                this.SetBytesTotal();
                this.OnModified();
                Stream stream1   = (Stream)null;
                Stream stream2   = (Stream)null;
                int    tickCount = Environment.TickCount;
                try
                {
                    stream1 = response1.GetResponseStream();
                    Directory.CreateDirectory(Path.GetDirectoryName(next._targetPath));
                    stream2 = SystemNetDownloader.GetOutputFileStream(next._targetPath);
                    if (stream2 != null)
                    {
                        long num = 0;
                        if (response1.ContentLength > 0L)
                        {
                            stream2.SetLength(response1.ContentLength);
                        }
                        while (!this._fCancelPending)
                        {
                            int count = stream1.Read(this._buffer, 0, this._buffer.Length);
                            if (count > 0)
                            {
                                stream2.Write(this._buffer, 0, count);
                            }
                            this._eventArgs._bytesCompleted += (long)count;
                            if (response1.ContentLength <= 0L)
                            {
                                this._accumulatedBytesTotal = this._accumulatedBytesTotal + (long)count;
                                this.SetBytesTotal();
                            }
                            num += (long)count;
                            if (next._maxFileSize != -1 && num > (long)next._maxFileSize)
                            {
                                throw new InvalidDeploymentException(ExceptionTypes.FileSizeValidation, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_FileBeingDownloadedTooLarge"), new object[2]
                                {
                                    (object)next._sourceUri.ToString(),
                                    (object)next._maxFileSize
                                }));
                            }
                            this.CheckForSizeLimit((ulong)count, true);
                            if (this._eventArgs._bytesTotal > 0L)
                            {
                                this._eventArgs._progress = (int)(this._eventArgs._bytesCompleted * 100L / this._eventArgs._bytesTotal);
                            }
                            this.OnModifiedWithThrottle(ref tickCount);
                            if (count <= 0)
                            {
                                if (response1.ContentLength != num)
                                {
                                    stream2.SetLength(num);
                                    goto label_40;
                                }
                                else
                                {
                                    goto label_40;
                                }
                            }
                        }
                        return;
                    }
                }
                finally
                {
                    if (stream1 != null)
                    {
                        stream1.Close();
                    }
                    if (stream2 != null)
                    {
                        stream2.Close();
                    }
                }
label_40:
                this._eventArgs.Cookie = next._cookie;
                ++this._eventArgs._filesCompleted;
                Logger.AddInternalState("HttpWebResponse=" + Logger.Serialize(response1));
                this.OnModified();
                this._downloadResults.Add((object)new DownloadResult()
                {
                    ResponseUri       = response1.ResponseUri,
                    ServerInformation =
                    {
                        Server        = response1.Headers["Server"],
                        PoweredBy     = response1.Headers["X-Powered-By"],
                        AspNetVersion = response1.Headers["X-AspNet-Version"]
                    }
                });
            }
            catch (InvalidOperationException ex)
            {
                throw new DeploymentDownloadException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[1]
                {
                    (object)next._sourceUri
                }), (Exception)ex);
            }
            catch (IOException ex)
            {
                throw new DeploymentDownloadException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[1]
                {
                    (object)next._sourceUri
                }), (Exception)ex);
            }
            catch (UnauthorizedAccessException ex)
            {
                throw new DeploymentDownloadException(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_FailedWhileDownloading"), new object[1]
                {
                    (object)next._sourceUri
                }), (Exception)ex);
            }
            finally
            {
                if (response1 != null)
                {
                    response1.Close();
                }
            }
        }