// Get Topic by F1 Keyword private void DoGetTopicFromF1(Boolean getDetails) //false to return just the file IStream { if (!Globals.catalog.IsOpen) { MessageBox.Show("Open a catalog first!"); return; } ClearAll(); IHelpFilter filter = null; // no filtering String keyword = TopicFromF1TextBox.Text.Trim(); if (String.IsNullOrEmpty(keyword)) { return; } String[] prioritizedF1Keywords = keyword.Split(new Char[] { '|' }); //arbitarily separate by ; for (int i = 0; i < prioritizedF1Keywords.Length; i++) { prioritizedF1Keywords[i] = prioritizedF1Keywords[i].Trim(); } Cursor.Current = Cursors.WaitCursor; try { if (getDetails) //Returns detail and stream { resultsPanel.SetupView(Panel_HelpTopicResults.HelpTopicResultsView.HelpTopic); //Do It ITopic helpTopic = Globals.catalogRead.GetTopicDetailsForF1Keyword(Globals.catalog, prioritizedF1Keywords, filter); if (helpTopic == null) { MessageBox.Show("No results found! Returned null."); } else //display result { resultsPanel.DisplayHelpTopic(helpTopic); } } else //Returns just the stream { resultsPanel.SetupView(Panel_HelpTopicResults.HelpTopicResultsView.RawContent); //Do It Stream stream = (Stream)Globals.catalogRead.GetTopicForF1Keyword(Globals.catalog, prioritizedF1Keywords, filter); if (stream == null) { MessageBox.Show("No results found! Returned null."); } { resultsPanel.ViewStream(stream); stream.Close(); } } } catch { MessageBox.Show("No results. Exception while calling catalogRead.GetTopic...ForF1Keyword()"); } finally { Cursor.Current = Cursors.Default; //Persistence: Save settings using (UserData userData = new UserData(Globals.DataRegKey)) { userData.WriteStr("Keyword.TopicFromF1TextBox", TopicFromF1TextBox.Text); } } }
// Get Topic by ID private void DoGetTopicFromId(Boolean getDetails) //false to return just the file IStream { if (!Globals.catalog.IsOpen) { MessageBox.Show("Open a catalog first!"); return; } ClearAll(); IHelpFilter filter = null; // no filtering String topicID = TopicFromIdCbo.Text.Trim(); if (String.IsNullOrEmpty(topicID)) { return; } Cursor.Current = Cursors.WaitCursor; try { if (getDetails) //Returns detail object { resultsPanel.SetupView(Panel_HelpTopicResults.HelpTopicResultsView.HelpTopic); ITopic helpTopic = Globals.catalogRead.GetIndexedTopicDetails(Globals.catalog, topicID, filter); if (helpTopic == null) { MessageBox.Show("No results found! Returned null."); } else //display result { resultsPanel.DisplayHelpTopic(helpTopic); } } else //Returns just the stream { resultsPanel.SetupView(Panel_HelpTopicResults.HelpTopicResultsView.RawContent); //Get Stream only Stream stream = (Stream)Globals.catalogRead.GetIndexedTopic(Globals.catalog, topicID, filter); if (stream == null) { MessageBox.Show("No results found! Returned null."); } else { resultsPanel.ViewStream(stream); stream.Close(); } } } catch { MessageBox.Show("No results. Exception while calling catalogRead.GetIndexedTopic...()"); } finally { Cursor.Current = Cursors.Default; //Persistence: Save settings using (UserData userData = new UserData(Globals.DataRegKey)) { userData.WriteStr("Keyword.TopicFromIdCbo", TopicFromIdCbo.Text); } } }
// Get Linked Asset == IStream GetLinkedAsset(ICatalog catalog, string packageName, string path, string locale) private void GetAssetBtn_Click(object sender, EventArgs e) { if (!Globals.catalog.IsOpen) { MessageBox.Show("Open a catalog first!"); return; } ClearAll(); IHelpFilter filter = null; // no filtering String keyword = TopicFromIdCbo.Text.Trim(); if (String.IsNullOrEmpty(keyword)) { return; } Cursor.Current = Cursors.WaitCursor; try { //Returns topic detail ITopic helpTopic = Globals.catalogRead.GetIndexedTopicDetails(Globals.catalog, keyword, filter); if (helpTopic == null) { MessageBox.Show("No results found! GetIndexedTopicDetails returned null."); } else //display result { resultsPanel.SetupView(Panel_HelpTopicResults.HelpTopicResultsView.RawContent); // Now try an Asset call // The call above returns helpTopic.Package == helpTopic.Url = package;\\path (so we need to split this out into Package & internal path //Note: This is test is rather artificial but gives you an idea of how to access the GetLinkedAsset() call. String[] url = helpTopic.Url.Split(new char[] { ';' }); if (url.Length == 2) { Stream stream = (Stream)Globals.catalogRead.GetLinkedAsset(Globals.catalog, url[0], url[1], helpTopic.Locale); if (stream == null) { MessageBox.Show("GetLinkedAsset() returned null."); } else { resultsPanel.ViewStream(stream); stream.Close(); } } else { MessageBox.Show("Could Test. Unable to extract Package name and internal path from \"" + helpTopic.Url + "\""); } } } catch { MessageBox.Show("No results. Exception!"); } finally { Cursor.Current = Cursors.Default; } }