/// <summary> /// Main entry point for handling a Config operation /// </summary> /// <param name="portal">DevicePortal reference for communicating with the device.</param> /// <param name="parameters">Parsed command line parameters.</param> public static void HandleOperation(DevicePortal portal, ParameterHelper parameters) { if (parameters.HasFlag(ParameterHelper.HelpFlag)) { Console.WriteLine(AppUsageMessage); return; } string operationType = parameters.GetParameterValue("subop"); if (string.IsNullOrWhiteSpace(operationType)) { Console.WriteLine("Missing subop parameter"); Console.WriteLine(); Console.WriteLine(AppUsageMessage); return; } operationType = operationType.ToLowerInvariant(); try { if (operationType.Equals("list")) { Task <AppPackages> packagesTask = portal.GetInstalledAppPackages(); packagesTask.Wait(); Console.WriteLine(packagesTask.Result); } else { string packageFullName = parameters.GetParameterValue("pfn"); if (string.IsNullOrEmpty(packageFullName)) { Console.WriteLine("The Package Full Name is required as the /pfn<packageFullName> parameter for this operation."); Console.WriteLine(); Console.WriteLine(AppUsageMessage); return; } if (operationType.Equals("suspend")) { Console.WriteLine("Suspend isn't currently supported, but will be in the future."); } else if (operationType.Equals("resume")) { Console.WriteLine("Resume isn't currently supported, but will be in the future."); } else if (operationType.Equals("launch")) { string aumid = parameters.GetParameterValue("aumid"); if (string.IsNullOrEmpty(aumid)) { Console.WriteLine("The appId (AUMID) is required as the /aumid:<appId> parameter for the launch operation."); Console.WriteLine(); Console.WriteLine(AppUsageMessage); return; } Task launchTask = portal.LaunchApplication(aumid, packageFullName); launchTask.Wait(); Console.WriteLine("Application launched."); } else if (operationType.Equals("terminate")) { Task terminateTask = portal.TerminateApplication(packageFullName); terminateTask.Wait(); Console.WriteLine("Application terminated."); } else if (operationType.Equals("uninstall")) { Task uninstallTask = portal.UninstallApplication(packageFullName); uninstallTask.Wait(); Console.WriteLine("Application uninstalled."); } } } catch (AggregateException e) { if (e.InnerException is DevicePortalException) { DevicePortalException innerException = e.InnerException as DevicePortalException; Console.WriteLine(string.Format("Exception encountered: 0x{0:X} : {1}", innerException.HResult, innerException.Reason)); } else if (e.InnerException is OperationCanceledException) { Console.WriteLine("The operation was cancelled."); } else { Console.WriteLine(string.Format("Unexpected exception encountered: {0}", e.Message)); } return; } }