private static Tuple <string, string> GetContentIdAndAlias(string assetId, string version = "VS.110", string locale = "en-us") { var request = new getContentRequest { contentIdentifier = assetId, locale = locale, version = version }; // get response var response = ContentServiceClient.GetContent(new appId(), request); return(Tuple.Create(response.contentId, response.contentAlias)); }
public static string GetDocFromMTPS(string shortId) { try { if (proxy == null) { proxy = new ContentServicePortTypeClient(); } var request = new getContentRequest { contentIdentifier = shortId, locale = "en-us", version = "VS.85", requestedDocuments = new[] { new requestedDocument { type = documentTypes.primary, selector = "Mtps.Xhtml" } } }; var response = proxy.GetContent(new appId { value = "Sandcastle" }, request); if (response.primaryDocuments[0].Any != null) { return(response.primaryDocuments[0].Any.OuterXml); } } catch (Exception) { } return(string.Empty); }
private async Task <string> GetDocFromMTPS(string shortId) { try { if (proxy == null) { proxy = new ContentServicePortTypeClient(ContentServicePortTypeClient.EndpointConfiguration.ContentService); } var request = new getContentRequest { contentIdentifier = shortId, locale = "en-us", version = "VS.85", requestedDocuments = new[] { new requestedDocument { type = documentTypes.primary, selector = "Mtps.Xhtml" } } }; var response = await Task.Run(() => proxy.GetContent(new appId { value = "Sandcastle" }, request)); if (response.primaryDocuments[0].Any != null) { return(response.primaryDocuments[0].Any.OuterXml); } } catch (Exception) { return(string.Empty); } return(string.Empty); }
public Uri ResolveAssetId(string assetId, Version version) { string ret; if (this._cachedMsdnUrls.TryGetValue(assetId, out ret)) { if (ret != null) return new Uri(string.Format(UrlFormat, this._locale, ret)); return null; } // filter out non-MS namespaces string name = assetId.Substring(2); if (!name.StartsWith("System", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("Microsoft", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("Accessibility", StringComparison.OrdinalIgnoreCase)) { return null; } getContentRequest msdnRequest = new getContentRequest(); msdnRequest.contentIdentifier = "AssetId:" + assetId; msdnRequest.locale = this._locale; string endpoint = null; ContentServicePortTypeClient client = new ContentServicePortTypeClient(_msdnBinding, _msdnEndpoint); try { getContentResponse msdnResponse = client.GetContent(new appId {value = "LostDoc"}, msdnRequest); endpoint = msdnResponse.contentId; } catch (FaultException<mtpsFaultDetailType>) { } finally { try { client.Close(); } catch { client.Abort(); } ((IDisposable)client).Dispose(); } this._cachedMsdnUrls.TryAdd(assetId, endpoint); if (string.IsNullOrEmpty(endpoint)) return null; return new Uri(string.Format(UrlFormat, this._locale, endpoint)); }
public Uri ResolveAssetId(string assetId, Version version) { if (this._cachedMsdnUrls.ContainsKey(assetId) && this._cachedMsdnUrls[assetId] != null) return new Uri(string.Format(UrlFormat, this._locale, this._cachedMsdnUrls[assetId])); getContentRequest msdnRequest = new getContentRequest(); msdnRequest.contentIdentifier = "AssetId:" + assetId; msdnRequest.locale = this._locale; string endpoint = null; Binding msdnBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); EndpointAddress msdnEndpoint = new EndpointAddress("http://services.msdn.microsoft.com/ContentServices/ContentService.asmx"); ContentServicePortTypeClient client = new ContentServicePortTypeClient(msdnBinding, msdnEndpoint); try { getContentResponse msdnResponse = client.GetContent(new appId {value = "LostDoc"}, msdnRequest); endpoint = msdnResponse.contentId; } catch (FaultException<mtpsFaultDetailType>) { } finally { try { client.Close(); } catch { client.Abort(); } if (client is IDisposable) ((IDisposable)client).Dispose(); } this._cachedMsdnUrls[assetId] = endpoint; if (string.IsNullOrEmpty(endpoint)) { return null; } else { return new Uri(string.Format(UrlFormat, this._locale, endpoint)); } }
public MainWindow() { InitializeComponent(); // Use the ContentService (web service) // Set up a request object getContentRequest request = new getContentRequest(); request.contentIdentifier = "abhtw0f1"; // Create the client ContentServicePortTypeClient client = new ContentServicePortTypeClient(); this.DataContext = client.GetContent(new appId(), request); }
/// <summary> /// Finds a URL from MSDN documentation. /// </summary> /// <param name="assetId">The asset id in the form "T:System.String"</param> /// <returns>A URL to MSDN or null if no URL was found</returns> public string FindUrl(string assetId) { // Only look for T:System. if (assetId.Length < 3 || !assetId.Substring(2).StartsWith("System.") || IsDisabled) { return(null); } string contentId; if (!_mapAssetIdToContentId.TryGetValue(assetId, out contentId)) { try { Logger.Message("Get MSDN URL for id [{0}]", assetId); var request = new getContentRequest { contentIdentifier = "AssetId:" + HttpUtility.UrlEncode(assetId), locale = Locale }; var appId = new appId() { value = AppId }; var response = msdnClient.GetContent(appId, request); contentId = response.contentId; } catch (EndpointNotFoundException endpointNotFound) { Logger.Warning("Unable to connect to MTPS service. MSDN resolver disabled : {0}", endpointNotFound.Message); IsDisabled = true; } catch (Exception ex) { Logger.Warning("Error while getting MSDN URL [{0}] : {1}", assetId, ex.Message); } _mapAssetIdToContentId[assetId] = contentId; SaveCacheToDisk(); } if (string.IsNullOrEmpty(contentId)) { return(null); } return(string.Format(MsdnUrlFormat, Locale, contentId)); }
// Use the standard root node to get a list of locales available. public static SortedDictionary <string, string> GetLocales() { var locales = new SortedDictionary <string, string>(); var client = new ContentServicePortTypeClient(WcfService.SERVICE_NAME); GetContentResponse1 response; var request = new GetContentRequest1(new appId(), new getContentRequest()) { getContentRequest = { contentIdentifier = RootContentItem.ContentId, locale = Defaults.LANGUAGE } }; try { response = client.GetContent(request); } catch { locales.Add(Defaults.LOCALE, Defaults.LANGUAGE); return(locales); } foreach (var versionAndLocale in response.getContentResponse.availableVersionsAndLocales) { // Use the DisplayName as the key instead of the locale because // that's how we want the collection sorted. string displayName = new CultureInfo(versionAndLocale.locale).DisplayName; if (locales.ContainsKey(displayName) == false) { locales.Add(displayName, versionAndLocale.locale.ToLower()); } } return(locales); }
// Use the standard root node to get a list of locales available. public static SortedDictionary<string, string> GetLocales() { var locales = new SortedDictionary<string, string>(); var client = new ContentServicePortTypeClient(WcfService.SERVICE_NAME); GetContentResponse1 response; var request = new GetContentRequest1(new appId(), new getContentRequest()) { getContentRequest = { contentIdentifier = RootContentItem.ContentId, locale = Defaults.LANGUAGE } }; try { response = client.GetContent(request); } catch { locales.Add(Defaults.LOCALE, Defaults.LANGUAGE); return locales; } foreach (var versionAndLocale in response.getContentResponse.availableVersionsAndLocales) { // Use the DisplayName as the key instead of the locale because // that's how we want the collection sorted. string displayName = new CultureInfo(versionAndLocale.locale).DisplayName; if (locales.ContainsKey(displayName) == false) locales.Add(displayName, versionAndLocale.locale.ToLower()); } return locales; }
// Added the loadFailSafe optimization public void Load(bool loadImages, bool loadFailSafe = true) { var request = new GetContentRequest1(new appId(), new getContentRequest()) { getContentRequest = { contentIdentifier = ContentIdentifier, locale = _locale, version = _collection + "." + _version } }; var documents = new List <requestedDocument> { new requestedDocument { type = documentTypes.common, selector = Selectors.Mtps.LINKS }, new requestedDocument { type = documentTypes.primary, selector = Selectors.Mtps.TOC }, new requestedDocument { type = documentTypes.common, selector = Selectors.Mtps.SEARCH }, new requestedDocument { type = documentTypes.feature, selector = Selectors.Mtps.ANNOTATIONS } }; if (loadFailSafe) { documents.Add(new requestedDocument { type = documentTypes.primary, selector = Selectors.Mtps.FAILSAFE }); } request.getContentRequest.requestedDocuments = documents.ToArray(); var client = new ContentServicePortTypeClient(WcfService.SERVICE_NAME); //client.GetContent() appIdValue = new appId { value = Application }; GetContentResponse1 response; try { response = client.GetContent(request); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debugger.Break(); return; } if (validateAsFilename.Match(response.getContentResponse.contentId).Success) { ContentId = response.getContentResponse.contentId; } else { throw (new BadContentIdException("ContentId contains illegal characters: [" + ContentId + "]")); } NumImages = response.getContentResponse.imageDocuments.Length; foreach (var commonDoc in response.getContentResponse.commonDocuments) { if (commonDoc.Any == null) { continue; } if (commonDoc.commonFormat.ToLowerInvariant() == Selectors.Mtps.SEARCH.ToLowerInvariant()) { Metadata = commonDoc.Any[0].OuterXml; } else if (commonDoc.commonFormat.ToLowerInvariant() == Selectors.Mtps.LINKS.ToLowerInvariant()) { Links = commonDoc.Any[0].OuterXml; } } foreach (primary primaryDoc in response.getContentResponse.primaryDocuments) { if (primaryDoc.Any == null) { continue; } if (primaryDoc.primaryFormat.ToLowerInvariant() == Selectors.Mtps.FAILSAFE.ToLowerInvariant()) { Xml = primaryDoc.Any.OuterXml; } else if (primaryDoc.primaryFormat.ToLowerInvariant() == Selectors.Mtps.TOC.ToLowerInvariant()) { Toc = primaryDoc.Any.OuterXml; } } foreach (feature featureDoc in response.getContentResponse.featureDocuments) { if (featureDoc.Any == null) { continue; } if (featureDoc.featureFormat.ToLowerInvariant() == Selectors.Mtps.ANNOTATIONS.ToLowerInvariant()) { Annotations = featureDoc.Any[0].OuterXml; } } // If we get no meta/search or wiki data, plug in NOP data because // we can't LoadXml an empty string nor pass null navigators to // the transform. if (string.IsNullOrEmpty(Metadata)) { Metadata = "<se:search xmlns:se=\"urn:mtpg-com:mtps/2004/1/search\" />"; } if (string.IsNullOrEmpty(Annotations)) { Annotations = "<an:annotations xmlns:an=\"urn:mtpg-com:mtps/2007/1/annotations\" />"; } if (loadImages) { var imageDocs = new requestedDocument[response.getContentResponse.imageDocuments.Length]; // Now that we know their names, we run a request with each image. for (int i = 0; i < response.getContentResponse.imageDocuments.Length; i++) { imageDocs[i] = new requestedDocument { type = documentTypes.image, selector = response.getContentResponse.imageDocuments[i].name + "." + response.getContentResponse.imageDocuments[i].imageFormat }; } request.getContentRequest.requestedDocuments = imageDocs; response = client.GetContent(request); foreach (image imageDoc in response.getContentResponse.imageDocuments) { var imageFilename = imageDoc.name + "." + imageDoc.imageFormat; if (validateAsFilename.Match(imageFilename).Success) { Images.Add(new Image(imageDoc.name, imageDoc.imageFormat, imageDoc.Value)); } else { throw (new BadImageNameExeception("Image filename contains illegal characters: [" + imageFilename + "]")); } } } }
public Uri ResolveAssetId(string assetId, Version version) { Uri ret; if (this._cachedMsdnUrls.TryGetValue(assetId, out ret)) return ret; // filter out non-MS namespaces string name = assetId.Substring(assetId.IndexOf(':') + 1); if (!name.StartsWith("System", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("Microsoft", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("Accessibility", StringComparison.OrdinalIgnoreCase)) { return null; } getContentRequest msdnRequest = new getContentRequest(); msdnRequest.contentIdentifier = "AssetId:" + assetId; msdnRequest.locale = this._locale; int retries = 3; do { ContentServicePortTypeClient client = new ContentServicePortTypeClient(_msdnBinding, _msdnEndpoint); try { getContentResponse msdnResponse = client.GetContent(new appId { value = "LostDoc" }, msdnRequest); if (msdnResponse.contentId != null) ret = new Uri(string.Format(UrlFormat, this._locale, msdnResponse.contentId)); break; } catch (TimeoutException) { // retry } catch (FaultException<mtpsFaultDetailType> fe) { // this is a fallback because MSDN doesn't have links for enumeration fields // so we assume that any unresolved field will be represented on it's parent type page if (assetId.StartsWith("F:")) { // TODO add logging for this string parentEnum = "T:" + assetId.Substring("F:".Length); parentEnum = parentEnum.Substring(0, parentEnum.LastIndexOf('.')); ret = this.ResolveAssetId(parentEnum, version); } break; } finally { try { client.Close(); } catch { client.Abort(); } ((IDisposable)client).Dispose(); } } while (--retries > 0); this._cachedMsdnUrls.TryAdd(assetId, ret); return ret; }
// Added the loadFailSafe optimization public void Load(bool loadImages, bool loadFailSafe = true) { var request = new GetContentRequest1(new appId(), new getContentRequest()) { getContentRequest = { contentIdentifier = ContentIdentifier, locale =_locale, version =_collection + "." + _version } }; var documents = new List<requestedDocument> { new requestedDocument {type = documentTypes.common, selector = Selectors.Mtps.LINKS}, new requestedDocument {type = documentTypes.primary, selector = Selectors.Mtps.TOC}, new requestedDocument {type = documentTypes.common, selector = Selectors.Mtps.SEARCH}, new requestedDocument {type = documentTypes.feature, selector = Selectors.Mtps.ANNOTATIONS} }; if (loadFailSafe) documents.Add(new requestedDocument { type = documentTypes.primary, selector = Selectors.Mtps.FAILSAFE }); request.getContentRequest.requestedDocuments = documents.ToArray(); var client = new ContentServicePortTypeClient(WcfService.SERVICE_NAME); //client.GetContent() appIdValue = new appId { value = Application }; GetContentResponse1 response; try { response = client.GetContent(request); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debugger.Break(); return; } if (validateAsFilename.Match(response.getContentResponse.contentId).Success) { ContentId = response.getContentResponse.contentId; } else { throw (new BadContentIdException("ContentId contains illegal characters: [" + ContentId + "]")); } NumImages = response.getContentResponse.imageDocuments.Length; foreach (var commonDoc in response.getContentResponse.commonDocuments) { if (commonDoc.Any == null) continue; if (commonDoc.commonFormat.ToLowerInvariant() == Selectors.Mtps.SEARCH.ToLowerInvariant()) { Metadata = commonDoc.Any[0].OuterXml; } else if (commonDoc.commonFormat.ToLowerInvariant() == Selectors.Mtps.LINKS.ToLowerInvariant()) { Links = commonDoc.Any[0].OuterXml; } } foreach (primary primaryDoc in response.getContentResponse.primaryDocuments) { if (primaryDoc.Any == null) continue; if (primaryDoc.primaryFormat.ToLowerInvariant() == Selectors.Mtps.FAILSAFE.ToLowerInvariant()) { Xml = primaryDoc.Any.OuterXml; } else if (primaryDoc.primaryFormat.ToLowerInvariant() == Selectors.Mtps.TOC.ToLowerInvariant()) { Toc = primaryDoc.Any.OuterXml; } } foreach (feature featureDoc in response.getContentResponse.featureDocuments) { if (featureDoc.Any == null) continue; if (featureDoc.featureFormat.ToLowerInvariant() == Selectors.Mtps.ANNOTATIONS.ToLowerInvariant()) { Annotations = featureDoc.Any[0].OuterXml; } } // If we get no meta/search or wiki data, plug in NOP data because // we can't LoadXml an empty string nor pass null navigators to // the transform. if (string.IsNullOrEmpty(Metadata)) Metadata = "<se:search xmlns:se=\"urn:mtpg-com:mtps/2004/1/search\" />"; if (string.IsNullOrEmpty(Annotations)) Annotations = "<an:annotations xmlns:an=\"urn:mtpg-com:mtps/2007/1/annotations\" />"; if (loadImages) { var imageDocs = new requestedDocument[response.getContentResponse.imageDocuments.Length]; // Now that we know their names, we run a request with each image. for (int i = 0; i < response.getContentResponse.imageDocuments.Length; i++) { imageDocs[i] = new requestedDocument { type = documentTypes.image, selector = response.getContentResponse.imageDocuments[i].name + "." + response.getContentResponse.imageDocuments[i].imageFormat }; } request.getContentRequest.requestedDocuments = imageDocs; response = client.GetContent(request); foreach (image imageDoc in response.getContentResponse.imageDocuments) { var imageFilename = imageDoc.name + "." + imageDoc.imageFormat; if (validateAsFilename.Match(imageFilename).Success) { Images.Add(new Image(imageDoc.name, imageDoc.imageFormat, imageDoc.Value)); } else { throw (new BadImageNameExeception("Image filename contains illegal characters: [" + imageFilename + "]")); } } } }
public Uri ResolveAssetId(string assetId, Version version) { string ret; if (this._cachedMsdnUrls.TryGetValue(assetId, out ret)) { if (ret != null) { return(new Uri(string.Format(UrlFormat, this._locale, ret))); } return(null); } // filter out non-MS namespaces string name = assetId.Substring(2); if (!name.StartsWith("System", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("Microsoft", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("Accessibility", StringComparison.OrdinalIgnoreCase)) { return(null); } getContentRequest msdnRequest = new getContentRequest(); msdnRequest.contentIdentifier = "AssetId:" + assetId; msdnRequest.locale = this._locale; string endpoint = null; ContentServicePortTypeClient client = new ContentServicePortTypeClient(_msdnBinding, _msdnEndpoint); try { getContentResponse msdnResponse = client.GetContent(new appId { value = "LostDoc" }, msdnRequest); endpoint = msdnResponse.contentId; } catch (FaultException <mtpsFaultDetailType> ) { } finally { try { client.Close(); } catch { client.Abort(); } ((IDisposable)client).Dispose(); } this._cachedMsdnUrls.TryAdd(assetId, endpoint); if (string.IsNullOrEmpty(endpoint)) { return(null); } return(new Uri(string.Format(UrlFormat, this._locale, endpoint))); }