in src/MICore/LaunchOptions.cs [1241:1421]
public static LaunchOptions GetInstance(HostConfigurationStore configStore, string exePath, string args, string dir, string options, bool noDebug, IDeviceAppLauncherEventCallback eventCallback, TargetEngine targetEngine, Logger logger)
{
if (string.IsNullOrWhiteSpace(exePath))
throw new ArgumentNullException(nameof(exePath));
options = options?.Trim();
if (string.IsNullOrEmpty(options))
throw new InvalidLaunchOptionsException(MICoreResources.Error_StringIsNullOrEmpty);
logger?.WriteTextBlock("LaunchOptions", options);
LaunchOptions launchOptions = null;
Guid clsidLauncher = Guid.Empty;
object launcher = null;
object launcherXmlOptions = null;
if (options[0] == '{')
{
try
{
JObject parsedOptions = JObject.Parse(options);
// if the customLauncher element is present then try using the custom launcher implementation from the config store
if (parsedOptions["customLauncher"] != null && !string.IsNullOrWhiteSpace(parsedOptions["customLauncher"].Value<string>()))
{
string customLauncherName = parsedOptions["customLauncher"].Value<string>();
var jsonLauncher = configStore?.GetCustomLauncher(customLauncherName);
if (jsonLauncher == null)
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_UnknownCustomLauncher, customLauncherName));
}
if (jsonLauncher as IPlatformAppLauncher == null)
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_LauncherNotFound, customLauncherName));
}
launchOptions = ExecuteLauncher(configStore, (IPlatformAppLauncher)jsonLauncher, exePath, args, dir, parsedOptions, eventCallback, targetEngine, logger);
}
else if (parsedOptions["pipeTransport"] != null && parsedOptions["pipeTransport"].HasValues)
{
launchOptions = PipeLaunchOptions.CreateFromJson(parsedOptions);
}
else
{
launchOptions = LocalLaunchOptions.CreateFromJson(parsedOptions);
}
}
catch (JsonReaderException e)
{
throw new InvalidLaunchOptionsException(e.Message);
}
}
else if (options[0] == '<')
{
//xml
try
{
XmlSerializer serializer;
using (XmlReader reader = OpenXml(options))
{
switch (reader.LocalName)
{
case "LocalLaunchOptions":
{
serializer = GetXmlSerializer(typeof(Xml.LaunchOptions.LocalLaunchOptions));
var xmlLaunchOptions = (Xml.LaunchOptions.LocalLaunchOptions)Deserialize(serializer, reader);
launchOptions = LocalLaunchOptions.CreateFromXml(xmlLaunchOptions);
launchOptions.BaseOptions = xmlLaunchOptions;
}
break;
case "PipeLaunchOptions":
{
serializer = GetXmlSerializer(typeof(Xml.LaunchOptions.PipeLaunchOptions));
var xmlLaunchOptions = (Xml.LaunchOptions.PipeLaunchOptions)Deserialize(serializer, reader);
launchOptions = PipeLaunchOptions.CreateFromXml(xmlLaunchOptions);
launchOptions.BaseOptions = xmlLaunchOptions;
}
break;
case "TcpLaunchOptions":
{
serializer = GetXmlSerializer(typeof(Xml.LaunchOptions.TcpLaunchOptions));
var xmlLaunchOptions = (Xml.LaunchOptions.TcpLaunchOptions)Deserialize(serializer, reader);
launchOptions = TcpLaunchOptions.CreateFromXml(xmlLaunchOptions);
launchOptions.BaseOptions = xmlLaunchOptions;
}
break;
case "IOSLaunchOptions":
{
serializer = GetXmlSerializer(typeof(IOSLaunchOptions));
launcherXmlOptions = Deserialize(serializer, reader);
clsidLauncher = new Guid("316783D1-1824-4847-B3D3-FB048960EDCF");
}
break;
case "AndroidLaunchOptions":
{
serializer = GetXmlSerializer(typeof(AndroidLaunchOptions));
launcherXmlOptions = Deserialize(serializer, reader);
clsidLauncher = new Guid("C9A403DA-D3AA-4632-A572-E81FF6301E9B");
}
break;
case "SSHLaunchOptions":
{
serializer = GetXmlSerializer(typeof(SSHLaunchOptions));
launcherXmlOptions = Deserialize(serializer, reader);
clsidLauncher = new Guid("7E3052B2-FB42-4E38-B22C-1FD281BD4413");
}
break;
default:
{
launcher = configStore?.GetCustomLauncher(reader.LocalName);
if (launcher == null)
{
throw new XmlException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_UnknownXmlElement, reader.LocalName));
}
if (launcher as IPlatformAppLauncher == null)
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_LauncherNotFound, reader.LocalName));
}
var deviceAppLauncher = (IPlatformAppLauncherSerializer)launcher;
if (deviceAppLauncher == null)
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_LauncherSerializerNotFound, clsidLauncher.ToString("B")));
}
serializer = deviceAppLauncher.GetXmlSerializer(reader.LocalName);
launcherXmlOptions = Deserialize(serializer, reader);
}
break;
}
// Read any remaining bits of XML to catch other errors
while (reader.NodeType != XmlNodeType.None)
reader.Read();
}
}
catch (XmlException e)
{
throw new InvalidLaunchOptionsException(e.Message);
}
}
else
{
throw new InvalidLaunchOptionsException(MICoreResources.Error_UnknownLaunchOptions);
}
if (clsidLauncher != Guid.Empty)
{
launchOptions = ExecuteLauncher(configStore, clsidLauncher, exePath, args, dir, launcherXmlOptions, eventCallback, targetEngine, logger);
}
else if (launcher != null)
{
launchOptions = ExecuteLauncher(configStore, (IPlatformAppLauncher)launcher, exePath, args, dir, launcherXmlOptions, eventCallback, targetEngine, logger);
}
if (targetEngine == TargetEngine.Native)
{
if (launchOptions.ExePath == null)
launchOptions.ExePath = exePath;
}
if (string.IsNullOrEmpty(launchOptions.ExeArguments))
launchOptions.ExeArguments = args;
if (string.IsNullOrEmpty(launchOptions.WorkingDirectory))
launchOptions.WorkingDirectory = dir;
launchOptions.NoDebug = noDebug;
if (launchOptions._setupCommands == null)
launchOptions._setupCommands = new List<LaunchCommand>(capacity: 0).AsReadOnly();
// load supplemental options
launchOptions.LoadSupplementalOptions(logger);
launchOptions.SetInitializationComplete();
return launchOptions;
}