Files
duplicati/Duplicati/GUI/Duplicati.GUI.TrayIcon/HostedInstanceKeeper.cs
T
Tyler Gill 83a1dcfb64 Replace all instances of InvariantCultureIgnoreCase with OrdinalIgnoreCase in string comparisons.
InvariantCulture is useful when comparing / sorting human language strings in a culturely correct way. It handles things like accented letters in a way that makes sense to humans (e.g., 'a' should be sorted next to 'á', rather than after 'z').
Ordinal looks just at the raw code points of the characters. As such, it is recommended for use in cases when comparing system strings (file paths, command line parameters, config settings, etc.). Since it doesn't need to use the culture specific sorting rules, this method can often be faster.

For more information, see https://stackoverflow.com/questions/492799/difference-between-invariantculture-and-ordinal-string-comparison (and other related questions)
2017-09-18 23:55:08 -06:00

76 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Duplicati.GUI.TrayIcon
{
/// <summary>
/// We keep the hosted instance here to allow the TrayIcon executable to load without requiring the Server.exe
/// </summary>
internal class HostedInstanceKeeper : IDisposable
{
private System.Threading.Thread m_runner;
private System.Exception m_runnerException = null;
public event Action InstanceShutdown;
public HostedInstanceKeeper(string[] args)
{
m_runner = new System.Threading.Thread((dummy_arg) => {
try
{
//When running the hosted instance we do not really care what port we are using,
// so we just throw a few out there and try them
if (args == null || !args.Any(x => x.Trim().StartsWith("--" + Duplicati.Server.WebServer.Server.OPTION_PORT + "=", StringComparison.OrdinalIgnoreCase)))
args = (args ?? new string[0]).Union(new string[] { "--" + Duplicati.Server.WebServer.Server.OPTION_PORT + "=8200,8300,8400,8500,8600,8700,8800,8900,8989" }).ToArray();
Duplicati.Server.Program.Main(args);
} catch (Exception ex) {
m_runnerException = ex;
Duplicati.Server.Program.ServerStartedEvent.Set();
} finally {
if (InstanceShutdown != null)
try { InstanceShutdown(); }
catch (Exception shutex)
{
if (m_runnerException != null)
m_runnerException = new AggregateException(m_runnerException, shutex);
else
m_runnerException = shutex;
}
}
});
m_runner.Start();
if (!Duplicati.Server.Program.ServerStartedEvent.WaitOne(TimeSpan.FromSeconds(100), true))
{
if (m_runnerException != null)
throw m_runnerException;
else
throw new Duplicati.Library.Interface.UserInformationException("Hosted server startup timed out");
}
if (m_runnerException != null)
throw m_runnerException;
}
public void Dispose()
{
try
{
Duplicati.Server.Program.ApplicationExitEvent.Set();
if (!m_runner.Join(TimeSpan.FromSeconds(10)))
{
m_runner.Abort();
m_runner.Join(TimeSpan.FromSeconds(10));
}
}
catch
{
}
}
}
}