// Use the standard root node to get a list of locales available. public static SortedDictionary<string, string> GetLocales() { SortedDictionary<string, string> locales = new SortedDictionary<string, string>(); getContentRequest request = new getContentRequest(); ContentService proxy = new ContentService(); getContentResponse response; request.contentIdentifier = rootContentItem.contentId; request.locale = "en-US"; // Now required otherwise an exception. try { response = proxy.GetContent(request); } catch { locales.Add("English (United States)", "en-us"); return locales; } foreach (availableVersionAndLocale av in response.availableVersionsAndLocales) { // Use the DisplayName as the key instead of the locale because // that's how we want the collection sorted. string displayName = new CultureInfo(av.locale).DisplayName; if (locales.ContainsKey(displayName) == false) locales.Add(displayName, av.locale.ToLower()); } return locales; }
public getContentResponse GetContent([System.Xml.Serialization.XmlElementAttribute(Namespace = "urn:msdn-com:public-content-syndication")] getContentRequest getContentRequest) { object[] results = this.Invoke("GetContent", new object[] { getContentRequest }); return((getContentResponse)(results[0])); }
/// <remarks/> public void GetContentAsync(getContentRequest getContentRequest, object userState) { if ((this.GetContentOperationCompleted == null)) { this.GetContentOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetContentOperationCompleted); } this.InvokeAsync("GetContent", new object[] { getContentRequest }, this.GetContentOperationCompleted, userState); }
/// <remarks/> public void GetContentAsync(getContentRequest getContentRequest) { this.GetContentAsync(getContentRequest, null); }
/// <remarks/> public void GetContentAsync(getContentRequest getContentRequest, object userState) { if ((this.GetContentOperationCompleted == null)) { this.GetContentOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetContentOperationCompleted); } this.InvokeAsync("GetContent", new object[] { getContentRequest}, this.GetContentOperationCompleted, userState); }
// Added the loadFailSafe optimization public void Load(bool loadImages, bool loadFailSafe) { getContentRequest request = new getContentRequest(); request.contentIdentifier = contentIdentifier; request.locale = locale; request.version = collection + "." + version; List<requestedDocument> documents = new List<requestedDocument>(); requestedDocument document = new requestedDocument(); document.selector = "Mtps.Links"; document.type = documentTypes.common; documents.Add(document); document = new requestedDocument(); document.type = documentTypes.primary; document.selector = "Mtps.Toc"; documents.Add(document); document = new requestedDocument(); document.type = documentTypes.common; document.selector = "Mtps.Search"; documents.Add(document); // Mtps.Annotations removed because it caused many bugs /*document = new requestedDocument(); document.type = documentTypes.feature; document.selector = "Mtps.Annotations"; documents.Add(document);*/ if (loadFailSafe == true) { document = new requestedDocument(); document.type = documentTypes.primary; document.selector = "Mtps.Failsafe"; documents.Add(document); } request.requestedDocuments = documents.ToArray(); ContentService proxy = new ContentService(); proxy.appIdValue = new appId(); proxy.appIdValue.value = application; getContentResponse response; try { response = proxy.GetContent(request); } catch { return; } if (validateAsFilename.Match(response.contentId).Success == true) { contentId = response.contentId; } else { throw (new BadContentIdException("ContentId contains illegal characters: [" + contentId + "]")); } numImages = response.imageDocuments.Length; foreach (common commonDoc in response.commonDocuments) { if (commonDoc.Any != null) { switch (commonDoc.commonFormat.ToLower()) { case "mtps.search": metadata = commonDoc.Any[0].OuterXml; break; case "mtps.links": links = commonDoc.Any[0].OuterXml; break; } } } foreach (primary primaryDoc in response.primaryDocuments) { if (primaryDoc.Any != null) { switch (primaryDoc.primaryFormat.ToLower()) { case "mtps.failsafe": RemoveDuplicateSentences(primaryDoc.Any); xml = primaryDoc.Any.OuterXml; break; case "mtps.toc": toc = primaryDoc.Any.OuterXml; break; } } } /*foreach (feature featureDoc in response.featureDocuments) { if (featureDoc.Any != null) { if (featureDoc.featureFormat.ToLower() == "mtps.annotations") { 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) == true) metadata = "<se:search xmlns:se=\"urn:mtpg-com:mtps/2004/1/search\" />"; //if (string.IsNullOrEmpty(annotations) == true) annotations = "<an:annotations xmlns:an=\"urn:mtpg-com:mtps/2007/1/annotations\" />"; sizeImages = 0; if (loadImages == true) { requestedDocument[] imageDocs = new requestedDocument[response.imageDocuments.Length]; // Now that we know their names, we run a request with each image. for (int i = 0; i < response.imageDocuments.Length; i++) { imageDocs[i] = new requestedDocument(); imageDocs[i].type = documentTypes.image; imageDocs[i].selector = response.imageDocuments[i].name + "." + response.imageDocuments[i].imageFormat; } request.requestedDocuments = imageDocs; response = proxy.GetContent(request); foreach (image imageDoc in response.imageDocuments) { string imageFilename = imageDoc.name + "." + imageDoc.imageFormat; if (validateAsFilename.Match(imageFilename).Success == true) { images.Add(new Image(imageDoc.name, imageDoc.imageFormat, imageDoc.Value)); sizeImages = sizeImages + imageDoc.Value.Length; } else { throw (new BadImageNameExeception( "Image filename contains illegal characters: [" + imageFilename + "]")); } } } }