CP-32101: Allow the application to seek help relevant to its release instead of always pointing to help for the latest CR.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2019-09-25 09:40:03 +01:00 committed by Mihaela Stoica
parent 5244c91658
commit 91e2ec3bbe
6 changed files with 64 additions and 24 deletions

View File

@ -30,7 +30,9 @@
*/
using System;
using System.Net;
using System.Resources;
using System.Threading;
using XenAdmin.Core;
@ -41,10 +43,55 @@ namespace XenAdmin.Help
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static readonly ResourceManager resources;
private static readonly string HelpUrl = Registry.CustomHelpUrl;
private static readonly string HelpQuery = string.Empty;
private static volatile string _helpVersion;
private static readonly object _helpLock = new object();
static HelpManager()
{
resources = new ResourceManager("XenAdmin.Help.HelpManager", typeof(HelpManager).Assembly);
if (string.IsNullOrEmpty(HelpUrl))
{
HelpUrl = InvisibleMessages.HELP_URL;
HelpQuery = string.Format(InvisibleMessages.HELP_URL_QUERY,
$"{Branding.XENCENTER_VERSION}.{Program.Version.Revision}".Replace('.', '_'),
Messages.XENCENTER);
}
}
internal static void SetHelpVersion()
{
ThreadPool.QueueUserWorkItem(obj =>
{
try
{
var version = Program.Version;
var helpVersion = $"{version.Major}-{version.Minor}/";
var request = WebRequest.Create(HelpUrl + helpVersion + "index.html");
request.Method = "HEAD";
using (var response = request.GetResponse() as HttpWebResponse)
{
if (response != null && response.StatusCode == HttpStatusCode.OK)
_helpVersion = helpVersion;
else
_helpVersion = "current-release/";
}
}
catch
{
_helpVersion = "current-release/";
}
finally
{
lock (_helpLock)
Monitor.PulseAll(_helpLock);
}
});
}
internal static bool TryGetTopicId(string pageRef, out string topicId)
@ -68,30 +115,17 @@ namespace XenAdmin.Help
else
log.DebugFormat("Found help topic ID {0} for {1}", topicId, pageRef);
var helpTopicUrl = GetHelpUrl(topicId);
Program.OpenURL(helpTopicUrl);
if (string.IsNullOrEmpty(_helpVersion))
lock (_helpLock)
Monitor.Wait(_helpLock);
var helpTopicUrl = HelpUrl + _helpVersion + $"{topicId ?? "index"}.html" + HelpQuery;
Program.OpenURL(helpTopicUrl.ToLowerInvariant());
// record help usage
Properties.Settings.Default.HelpLastUsed = DateTime.UtcNow.ToString("u");
Settings.TrySaveSettings();
}
private static string GetHelpUrl(string topicId)
{
var helpQuery = string.Empty;
var helpUrl = Registry.CustomHelpUrl;
if (string.IsNullOrEmpty(helpUrl))
{
helpUrl = InvisibleMessages.HELP_URL;
helpQuery = string.Format(InvisibleMessages.HELP_URL_QUERY,
$"{Branding.XENCENTER_VERSION}.{Program.Version.Revision}".Replace('.', '_'),
Messages.XENCENTER);
}
return (helpUrl + $"{topicId ?? "index"}.html" + helpQuery).ToLowerInvariant();
}
}
internal interface IFormWithHelp

View File

@ -44,6 +44,7 @@ using System.Drawing;
using XenAdmin.Core;
using XenAdmin.Network;
using XenAdmin.Dialogs;
using XenAdmin.Help;
using XenAdmin.XenSearch;
using XenAPI;
using XenCenterLib;
@ -350,8 +351,13 @@ namespace XenAdmin
Application.ApplicationExit -= Application_ApplicationExit;
Application.ApplicationExit += Application_ApplicationExit;
MainWindow mainWindow = new MainWindow(argType, args);
//set the help version before launching the main window;
//the call starts a different thread so it won't delay the main window launch;
//in most cases it is expected to have returned by the time the users request help;
//if they do before it has returned, the thread requesting help will wait for it
HelpManager.SetHelpVersion();
MainWindow mainWindow = new MainWindow(argType, args);
Application.Run(mainWindow);
log.Info("Application main thread exited");

View File

@ -97,7 +97,7 @@ namespace XenAdmin {
}
/// <summary>
/// Looks up a localized string similar to http://docs.citrix.com/en-us/xencenter/current-release/.
/// Looks up a localized string similar to http://docs.citrix.com/en-us/xencenter/.
/// </summary>
public static string HELP_URL {
get {

View File

@ -193,7 +193,7 @@
<value>https://www.citrix.com/products/citrix-hypervisor/get-started.html</value>
</data>
<data name="HELP_URL" xml:space="preserve">
<value>http://docs.citrix.com/ja-jp/xencenter/current-release/</value>
<value>http://docs.citrix.com/ja-jp/xencenter/</value>
</data>
<data name="HELP_URL_QUERY" xml:space="preserve">
<value>?utm_campaign={0}&amp;utm_medium=ui_link&amp;utm_source={1}</value>

View File

@ -193,7 +193,7 @@
<value>https://www.citrix.com/products/citrix-hypervisor/get-started.html</value>
</data>
<data name="HELP_URL" xml:space="preserve">
<value>http://docs.citrix.com/en-us/xencenter/current-release/</value>
<value>http://docs.citrix.com/en-us/xencenter/</value>
</data>
<data name="HELP_URL_QUERY" xml:space="preserve">
<value>?utm_campaign={0}&amp;utm_medium=ui_link&amp;utm_source={1}</value>

View File

@ -193,7 +193,7 @@
<value>https://www.citrix.com/products/citrix-hypervisor/get-started.html</value>
</data>
<data name="HELP_URL" xml:space="preserve">
<value>http://docs.citrix.com/zh-cn/xencenter/current-release/</value>
<value>http://docs.citrix.com/zh-cn/xencenter/</value>
</data>
<data name="HELP_URL_QUERY" xml:space="preserve">
<value>?utm_campaign={0}&amp;utm_medium=ui_link&amp;utm_source={1}</value>