Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / MS / Internal / AppModel / DeploymentExceptionMapper.cs / 2 / DeploymentExceptionMapper.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: DeploymentExceptionMapper class definition. // // History: // 2005/02/08 : [....] - Created // 2005/08/22 : [....] - Added boot WinFX functionality // 2007/08/01 : [....] - Added detection of System.Core.dll to infer required platform version. // Because WPF v3.5 still has WindowsBase v3.0.0.0, the original heuristic failed. // //--------------------------------------------------------------------------- using System; using System.Collections; using System.Globalization; using System.Resources; using System.Reflection; using System.Windows; using System.Deployment.Application; namespace MS.Internal { internal enum MissingDependencyType { Others = 0, WinFX = 1, CLR = 2 } internal static class DeploymentExceptionMapper { // This is the hardcoded fwlink query parameters, the only dynamic data we pass to fwlink server // is the WinFX or CLR version we parse from the ClickOnce error message. // Product ID is always 11953 which is the WinFX Runtime Components and subproduct is always bootwinfx // The winfxsetup.exe is language neutral so we always specify 0x409 for languages. const string fwlinkPrefix = "http://go.microsoft.com/fwlink?prd=11953&sbp=Bootwinfx&pver="; const string fwlinkSuffix = "&plcid=0x409&clcid=0x409&"; //----------------------------------------------------- // // Internal Methods // //----------------------------------------------------- #region Internal Methods // Check if the platform exception is due to missing WinFX or CLR dependency // Parse the exception message and find out the dependent WinFX version and create the // corresponding fwlink Uri. static internal MissingDependencyType GetWinFXRequirement(Exception e, InPlaceHostingManager hostingManager, out string version, out Uri fwlinkUri) { version = String.Empty; fwlinkUri = null; // Load the clickonce resource and use it to parse the exception message Assembly deploymentDll = Assembly.GetAssembly(hostingManager.GetType()); if (deploymentDll == null) { return MissingDependencyType.Others; } ResourceManager resourceManager = new ResourceManager("System.Deployment", deploymentDll); if (resourceManager == null) { return MissingDependencyType.Others; } String clrProductName = resourceManager.GetString("PlatformMicrosoftCommonLanguageRuntime", CultureInfo.CurrentUICulture); String versionString = resourceManager.GetString("PlatformDependentAssemblyVersion", CultureInfo.CurrentUICulture); if ((clrProductName == null) || (versionString == null)) { return MissingDependencyType.Others; } // Need to trim off the parameters in the ClickOnce strings: // "{0} Version {1}" -> "Version" // "Microsoft Common Language Runtime Version {0}" -> "Microsoft Common Language Runtime Version" clrProductName = clrProductName.Replace("{0}", ""); versionString = versionString.Replace("{0}", ""); versionString = versionString.Replace("{1}", ""); const string baseAssemblyName = "WindowsBase"; // A reference to System.Core is what makes an application target .NET v3.5. // Because WindowsBase still has v3.0.0.0, it's not the one that fails the platform requirements // test when a v3.5 app is run on the v3 runtime. (This additional check added for v3 SP1.) const string newSentinelAssemblyName = "System.Core"; // Parse the required version and trim it to major and minor only string excpMsg = e.Message; int index = excpMsg.IndexOf(versionString, StringComparison.Ordinal); if (index != -1) { // ClickOnce exception message is ErrorMessage_Platform* // from clickonce/system.deployment.txt version = String.Copy(excpMsg.Substring(index + versionString.Length)); int indexToFirstDot = version.IndexOf(".", StringComparison.Ordinal); int indexToSecondDot = version.IndexOf(".", indexToFirstDot+1, StringComparison.Ordinal); // Defense in depth here in case Avalon change the version scheme to major + minor only // and we might never see the second dot if (indexToSecondDot != -1) { version = version.Substring(0, indexToSecondDot); } if (excpMsg.IndexOf(clrProductName, StringComparison.Ordinal) != -1) { // prepend CLR to distinguish CLR version fwlink query // vs. WinFX version query. string clrVersion = String.Concat("CLR", version); return (ConstructFwlinkUrl(clrVersion, out fwlinkUri) ? MissingDependencyType.CLR : MissingDependencyType.Others); } else if (excpMsg.IndexOf(baseAssemblyName, StringComparison.Ordinal) == -1 && excpMsg.IndexOf(newSentinelAssemblyName, StringComparison.Ordinal) == -1) { version = String.Empty; } } return (ConstructFwlinkUrl(version, out fwlinkUri) ? MissingDependencyType.WinFX : MissingDependencyType.Others); } static internal void GetErrorTextFromException(Exception e, out string errorTitle, out string errorMessage) { errorTitle = String.Empty; errorMessage = String.Empty; if (e == null) { errorTitle = SR.Get(SRID.CancelledTitle); errorMessage = SR.Get(SRID.CancelledText); } else if (e is DependentPlatformMissingException) { errorTitle = SR.Get(SRID.PlatformRequirementTitle); errorMessage = e.Message; } else if (e is InvalidDeploymentException) { errorTitle = SR.Get(SRID.InvalidDeployTitle); errorMessage = SR.Get(SRID.InvalidDeployText); } else if (e is TrustNotGrantedException) { errorTitle = SR.Get(SRID.TrustNotGrantedTitle); errorMessage = SR.Get(SRID.TrustNotGrantedText); } else if (e is DeploymentDownloadException) { errorTitle = SR.Get(SRID.DownloadTitle); errorMessage = SR.Get(SRID.DownloadText); } else if (e is DeploymentException) { errorTitle = SR.Get(SRID.DeployTitle); errorMessage = SR.Get(SRID.DeployText); } else { errorTitle = SR.Get(SRID.UnknownErrorTitle); errorMessage = SR.Get(SRID.UnknownErrorText) + "\n\n" + e.Message; } } static internal bool ConstructFwlinkUrl(string version, out Uri fwlinkUri) { string fwlink = String.Empty; fwlinkUri = null; if (version != String.Empty) { fwlink = String.Copy(fwlinkPrefix); fwlink = String.Concat(fwlink, version); fwlink = String.Concat(fwlink, fwlinkSuffix); // Mitigate against proxy server caching, append today's day to the fwlink // query. This matches the fwlink query from unmanaged bootwap functionality // in IE7. DateTime today = System.DateTime.Today; fwlink = String.Concat(fwlink, today.Year.ToString()); fwlink = String.Concat(fwlink, today.Month.ToString()); fwlink = String.Concat(fwlink, today.Day.ToString()); fwlinkUri = new Uri(fwlink); return true; } return false; } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StructuredProperty.cs
- CommandHelpers.cs
- PerfCounters.cs
- OleAutBinder.cs
- FormsAuthentication.cs
- SqlInfoMessageEvent.cs
- SQLDecimalStorage.cs
- EventHandlers.cs
- MemberExpression.cs
- ObjectCloneHelper.cs
- IsolatedStorageFileStream.cs
- CacheVirtualItemsEvent.cs
- DefaultAssemblyResolver.cs
- Viewport2DVisual3D.cs
- DynamicResourceExtension.cs
- SqlUnionizer.cs
- Misc.cs
- DynamicResourceExtensionConverter.cs
- TextDecorationCollection.cs
- TextBoxBase.cs
- Visitor.cs
- TraceListeners.cs
- TryCatchDesigner.xaml.cs
- ByteConverter.cs
- ImageAttributes.cs
- GradientBrush.cs
- RefreshEventArgs.cs
- FunctionParameter.cs
- ContainerParagraph.cs
- UriWriter.cs
- AnnotationService.cs
- OdbcPermission.cs
- RegistryExceptionHelper.cs
- CapiHashAlgorithm.cs
- SqlFileStream.cs
- Script.cs
- Exceptions.cs
- DockPattern.cs
- Int32RectConverter.cs
- ToolStripSeparator.cs
- Regex.cs
- SocketPermission.cs
- OAVariantLib.cs
- OleDbError.cs
- RijndaelManagedTransform.cs
- BeginStoryboard.cs
- GeneratedView.cs
- RTLAwareMessageBox.cs
- ListBoxChrome.cs
- StorageFunctionMapping.cs
- ZipIOLocalFileDataDescriptor.cs
- _StreamFramer.cs
- XmlLoader.cs
- XmlnsDefinitionAttribute.cs
- TreeViewAutomationPeer.cs
- DataBoundControl.cs
- BaseDataBoundControl.cs
- ExpandCollapsePattern.cs
- FlowDocumentPageViewerAutomationPeer.cs
- SmtpFailedRecipientException.cs
- Win32Exception.cs
- DataGridHeaderBorder.cs
- XmlFormatWriterGenerator.cs
- RemotingConfigParser.cs
- HttpContextBase.cs
- TouchPoint.cs
- IntegerValidator.cs
- TextRangeEditLists.cs
- TemplateControlCodeDomTreeGenerator.cs
- WmpBitmapEncoder.cs
- GridViewDeleteEventArgs.cs
- ByteArrayHelperWithString.cs
- RequestResponse.cs
- StandardToolWindows.cs
- SettingsPropertyIsReadOnlyException.cs
- MimeTypeMapper.cs
- ReadWriteControlDesigner.cs
- CqlWriter.cs
- LogExtentCollection.cs
- MessageSecurityVersionConverter.cs
- EntitySetBaseCollection.cs
- ToggleButtonAutomationPeer.cs
- ConfigurationSectionCollection.cs
- TextPointerBase.cs
- BaseDataList.cs
- DefinitionUpdate.cs
- DocumentXPathNavigator.cs
- SByteConverter.cs
- PrivilegedConfigurationManager.cs
- UnauthorizedWebPart.cs
- TransportReplyChannelAcceptor.cs
- SymmetricAlgorithm.cs
- ThreadSafeList.cs
- CharKeyFrameCollection.cs
- _ConnectionGroup.cs
- HttpRequestTraceRecord.cs
- MediaScriptCommandRoutedEventArgs.cs
- FacetDescription.cs
- ConditionalExpression.cs
- cookie.cs