Esempio n. 1
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;
     }
 }
        public void AddFile(Uri sourceUri, string targetFilePath, object cookie, HashCollection hashCollection, int maxFileSize)
        {
            UriHelper.ValidateSupportedScheme(sourceUri);
            DownloadQueueItem item = new DownloadQueueItem {
                _sourceUri      = sourceUri,
                _targetPath     = targetFilePath,
                _cookie         = cookie,
                _hashCollection = hashCollection,
                _maxFileSize    = maxFileSize
            };

            lock (this._fileQueue)
            {
                this._fileQueue.Enqueue(item);
                this._eventArgs._filesTotal++;
            }
        }
Esempio n. 3
0
        public static Uri UriFromRelativeFilePath(Uri baseUri, string path)
        {
            if (!UriHelper.IsValidRelativeFilePath(path))
            {
                throw new ArgumentException(Resources.GetString("Ex_InvalidRelativePath"));
            }
            if (path.IndexOf('%') >= 0)
            {
                path = path.Replace("%", Uri.HexEscape('%'));
            }
            if (path.IndexOf('#') >= 0)
            {
                path = path.Replace("#", Uri.HexEscape('#'));
            }
            Uri uri = new Uri(baseUri, path);

            UriHelper.ValidateSupportedScheme(uri);
            return(uri);
        }
 public void CommitApplication(ref SubscriptionState subState, CommitApplicationParams commitParams)
 {
     Logger.AddMethodCall("CommitApplication called.");
     using (this.AcquireSubscriptionWriterLock(subState))
     {
         if (commitParams.CommitDeploy)
         {
             Logger.AddInternalState("Commiting Deployment :  subscription metadata.");
             UriHelper.ValidateSupportedScheme(commitParams.DeploySourceUri);
             this.CheckDeploymentSubscriptionState(subState, commitParams.DeployManifest);
             this.ValidateFileAssoctiation(subState, commitParams);
             if (commitParams.IsUpdate && !commitParams.IsUpdateInPKTGroup)
             {
                 CheckInstalled(subState);
             }
         }
         if (commitParams.CommitApp)
         {
             Logger.AddInternalState("Commiting Application:  application binaries.");
             UriHelper.ValidateSupportedScheme(commitParams.AppSourceUri);
             if (commitParams.AppGroup != null)
             {
                 CheckInstalled(subState);
             }
             this.CheckApplicationPayload(commitParams);
         }
         bool      flag = false;
         bool      identityGroupFound       = false;
         bool      locationGroupFound       = false;
         string    identityGroupProductName = "";
         ArrayList list = this._compStore.CollectCrossGroupApplications(commitParams.DeploySourceUri, commitParams.DeployManifest.Identity, ref identityGroupFound, ref locationGroupFound, ref identityGroupProductName);
         if (list.Count > 0)
         {
             flag = true;
             Logger.AddInternalState("This installation is a Cross Group: identityGroupFound=" + identityGroupFound.ToString() + ",locationGroupFound=" + locationGroupFound.ToString());
         }
         if ((subState.IsShellVisible && identityGroupFound) && locationGroupFound)
         {
             throw new DeploymentException(ExceptionTypes.GroupMultipleMatch, string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_GroupMultipleMatch"), new object[] { identityGroupProductName }));
         }
         subState = this.GetSubscriptionState(commitParams.DeployManifest);
         this._compStore.CommitApplication(subState, commitParams);
         if (flag)
         {
             uint num;
             Logger.AddInternalState("Performing cross group migration.");
             System.Deployment.Internal.Isolation.IActContext context = System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(subState.CurrentBind.ComPointer);
             context.PrepareForExecution(IntPtr.Zero, IntPtr.Zero);
             context.SetApplicationRunningState(0, 1, out num);
             context.SetApplicationRunningState(0, 2, out num);
             Logger.AddInternalState("Uninstalling all cross groups.");
             foreach (ComponentStore.CrossGroupApplicationData data in list)
             {
                 if (data.CrossGroupType == ComponentStore.CrossGroupApplicationData.GroupType.LocationGroup)
                 {
                     if (data.SubState.appType == AppType.CustomHostSpecified)
                     {
                         Logger.AddInternalState("UninstallCustomHostSpecifiedSubscription : " + ((data.SubState.SubscriptionId != null) ? data.SubState.SubscriptionId.ToString() : "null"));
                         this.UninstallCustomHostSpecifiedSubscription(data.SubState);
                     }
                     else if (data.SubState.appType == AppType.CustomUX)
                     {
                         Logger.AddInternalState("UninstallCustomUXSubscription : " + ((data.SubState.SubscriptionId != null) ? data.SubState.SubscriptionId.ToString() : "null"));
                         this.UninstallCustomUXSubscription(data.SubState);
                     }
                     else if (data.SubState.IsShellVisible)
                     {
                         Logger.AddInternalState("UninstallSubscription : " + ((data.SubState.SubscriptionId != null) ? data.SubState.SubscriptionId.ToString() : "null"));
                         this.UninstallSubscription(data.SubState);
                     }
                 }
                 else if (data.CrossGroupType == ComponentStore.CrossGroupApplicationData.GroupType.IdentityGroup)
                 {
                     Logger.AddInternalState("Not uninstalled :" + ((data.SubState.SubscriptionId != null) ? data.SubState.SubscriptionId.ToString() : "null") + ". It is in the identity group.");
                 }
             }
         }
         if ((commitParams.IsConfirmed && subState.IsInstalled) && (subState.IsShellVisible && (commitParams.appType != AppType.CustomUX)))
         {
             this.UpdateSubscriptionExposure(subState);
         }
         if (commitParams.appType == AppType.CustomUX)
         {
             ShellExposure.ShellExposureInformation shellExposureInformation = ShellExposure.ShellExposureInformation.CreateShellExposureInformation(subState.SubscriptionId);
             ShellExposure.UpdateShellExtensions(subState, ref shellExposureInformation);
         }
         OnDeploymentAdded(subState);
     }
 }
        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();
                    }
                }
            }
        }
Esempio n. 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();
                }
            }
        }