public static async Task Main(string[] args) { try { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; BuildServices(); Conductor = Services.GetRequiredService <Conductor>(); CasterSocket = Services.GetRequiredService <CasterSocket>(); Conductor.ProcessArgs(args); SystemEvents.SessionEnding += async(s, e) => { if (e.Reason == SessionEndReasons.SystemShutdown) { await CasterSocket.DisconnectAllViewers(); } }; if (Conductor.Mode == Core.Enums.AppMode.Chat) { StartUiThreads(null); await Task.Run(async() => { var chatService = Services.GetRequiredService <IChatHostService>(); await chatService.StartChat(Conductor.RequesterID, Conductor.OrganizationName); }); } else if (Conductor.Mode == Core.Enums.AppMode.Unattended) { StartUiThreads(null); App.Current.Dispatcher.Invoke(() => { App.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; }); await Task.Run(StartScreenCasting); } else { StartUiThreads(() => new MainWindow()); } TaskHelper.DelayUntil(() => App.Current.Dispatcher?.HasShutdownStarted != false, TimeSpan.MaxValue, 1000); } catch (Exception ex) { Logger.Write(ex); throw; } }
public static void Main(string[] args) { try { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; BuildServices(); Conductor = Services.GetRequiredService <Conductor>(); CasterSocket = Services.GetRequiredService <ICasterSocket>(); Conductor.ProcessArgs(args); SystemEvents.SessionEnding += async(s, e) => { if (e.Reason == SessionEndReasons.SystemShutdown) { await CasterSocket.DisconnectAllViewers(); } }; if (Conductor.Mode == Core.Enums.AppMode.Chat) { StartUiThreads(false); _ = Task.Run(async() => { var chatService = Services.GetRequiredService <IChatHostService>(); await chatService.StartChat(Conductor.RequesterID, Conductor.OrganizationName); }); } else if (Conductor.Mode == Core.Enums.AppMode.Unattended) { StartUiThreads(false); App.Current.Dispatcher.Invoke(() => { App.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; }); _ = Task.Run(StartScreenCasting); } else { StartUiThreads(true); } WaitForAppExit(); } catch (Exception ex) { Logger.Write(ex); throw; } }
public static async Task Main(string[] args) { try { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; BuildServices(); Conductor = Services.GetRequiredService <Conductor>(); CasterSocket = Services.GetRequiredService <ICasterSocket>(); Conductor.ProcessArgs(args); SystemEvents.SessionEnding += async(s, e) => { if (e.Reason == SessionEndReasons.SystemShutdown) { await CasterSocket.DisconnectAllViewers(); } }; var deviceInitService = Services.GetRequiredService <IDeviceInitService>(); var activationUri = Services.GetRequiredService <IClickOnceService>().GetActivationUri(); if (Uri.TryCreate(activationUri, UriKind.Absolute, out var result)) { var host = $"{result.Scheme}://{result.Authority}"; if (!string.IsNullOrWhiteSpace(host)) { Conductor.UpdateHost(host); using var httpClient = new HttpClient(); try { var url = $"{host.TrimEnd('/')}/api/branding"; var query = HttpUtility.ParseQueryString(result.Query); if (query?.AllKeys?.Contains("organizationid") == true) { url += $"?organizationId={query["organizationid"]}"; Conductor.UpdateOrganizationId(query["organizationid"]); } var branding = await httpClient.GetFromJsonAsync <BrandingInfo>(url).ConfigureAwait(false); if (branding != null) { deviceInitService.SetBrandingInfo(branding); } } catch { } } } await deviceInitService.GetInitParams().ConfigureAwait(false); if (Conductor.Mode == Core.Enums.AppMode.Chat) { StartUiThreads(false); _ = Task.Run(async() => { var chatService = Services.GetRequiredService <IChatClientService>(); await chatService.StartChat(Conductor.RequesterID, Conductor.OrganizationName); }); } else if (Conductor.Mode == Core.Enums.AppMode.Unattended) { StartUiThreads(false); App.Current.Dispatcher.Invoke(() => { App.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; }); _ = Task.Run(StartScreenCasting); } else { StartUiThreads(true); } WaitForAppExit(); } catch (Exception ex) { Logger.Write(ex); throw; } }