public static IServiceCollection AddEtoFormsHost( this IServiceCollection services, Eto.Forms.Application application) { if (services is null) { throw new ArgumentNullException(nameof(services)); } if (application is null) { throw new ArgumentNullException(nameof(application)); } services.AddSingleton(application.Platform); services.AddSingleton(application); services.AddSingleton <IHostLifetime, EtoFormsApplicationLifetime>(); services.AddOptions <EtoFormsOptions>() .Configure <IServiceProvider>((opts, sp) => { var con = sp.GetService <ConsoleLifetimeOptions>(); opts.SuppressStatusMessages = con?.SuppressStatusMessages ?? false; }) .Validate(opts => { opts.Validate(); return(true); }); return(services); }
public Automation2() { GlobalSettings.Settings.AutomationMode = true; Console.WriteLine("Initializing DWSIM in Automation Mode, please wait..."); app = UI.Desktop.Program.MainApp(null); app.Attach(this); }
/// <summary> /// Enables Eto.Forms support, builds and starts the host and waits for /// the main form of the specified type to close to shut down. /// <para> /// The Form type <typeparamref name="TForm"/> is added as a singleton /// service to the service provider if not already configured. /// </para> /// </summary> /// <typeparam name="TForm">The type of the main form class.</typeparam> /// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param> /// <param name="cancelToken">An optional <see cref="CancellationToken"/> that can be used to close the application.</param> public static void RunEtoForm <TForm>(this IHostBuilder hostBuilder, CancellationToken cancelToken = default) where TForm : Eto.Forms.Form { if (hostBuilder is null) { throw new ArgumentNullException(nameof(hostBuilder)); } var platform = Eto.Platform.Detect; using var application = new Eto.Forms.Application(platform); using var host = hostBuilder .ConfigureServices((_, services) => { services.AddEtoFormsHost(application); services.TryAddSingleton <TForm>(); services.Configure <EtoFormsOptions>(opts => opts.MainForm = typeof(TForm)); }) .Build(); host.Start(); var options = host.Services .GetRequiredService <IOptions <EtoFormsOptions> >().Value; object form = null; if (options.MainForm is Type formType) { form = ActivatorUtilities.GetServiceOrCreateInstance( host.Services, formType); } using var cancelReg = cancelToken.Register(obj => { var app = (Eto.Forms.Application)obj; app.Quit(); }, application); switch (form) { case Eto.Forms.Form mainForm: application.Run(mainForm); break; case Eto.Forms.Dialog dialog: application.Run(dialog); break; case null: application.Run(); break; } var hostLifetime = host.Services.GetRequiredService <IHostApplicationLifetime>(); hostLifetime.StopApplication(); host.WaitForShutdown(); }
public static async Task <int> Main(string[] args) { var platform = Eto.Platform.Detect; using var application = new Eto.Forms.Application(platform); return(await AuthenticationConsole.Program.Main(args) .ConfigureAwait(false)); }
public static void Main() { var platform = Eto.Platform.Detect; using var app = new Eto.Forms.Application(platform); using var form = new MainForm(); app.Run(form); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif // Attach new Eto.Forms application to running app var app = new Eto.Forms.Application(new Eto.WinRT.Platform()).Attach(); app.Run(); Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); //Associate the frame with a SuspensionManager key SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); // Set the default language rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { //Something went wrong restoring state. //Assume there is no state and continue } } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(ItemsPage), "AllGroups"); } // Ensure the current window is active Window.Current.Activate(); }
public Automation2() { GlobalSettings.Settings.AutomationMode = true; Console.WriteLine("Initializing DWSIM Automation Interface..."); app = UI.Desktop.Program.MainApp(null); app.Attach(this); FlowsheetBase.FlowsheetBase.AddPropPacks(); Console.WriteLine("DWSIM Automation Interface initialized successfully."); }
public Automation2() { GlobalSettings.Settings.AutomationMode = true; AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(LoadAssembly); Console.WriteLine("Initializing DWSIM Automation Interface..."); app = UI.Desktop.Program.MainApp(null); app.Attach(this); FlowsheetBase.FlowsheetBase.AddPropPacks(); Console.WriteLine("DWSIM Automation Interface initialized successfully."); }
public static IServiceCollection AddEtoFormsHost <TForm>( this IServiceCollection services, Eto.Forms.Application application) where TForm : Eto.Forms.Form { AddEtoFormsHost(services, application); services.TryAddSingleton <TForm>(); services.AddOptions <EtoFormsOptions>() .Configure(opts => opts.MainForm = typeof(TForm)); return(services); }
public static Eto.Forms.Application Create(string platform) { var app = new Eto.Forms.Application(platform); app.Initialized += delegate { // only create new controls/forms/etc during or after this event app.MainForm = new MainForm(); app.MainForm.Show(); }; return app; }
public static Eto.Forms.Application Create(string platform) { var app = new Eto.Forms.Application(platform); app.Initialized += delegate { // only create new controls/forms/etc during or after this event app.MainForm = new MainForm(); app.MainForm.Show(); }; return(app); }
public GuiEto(IDiContainer di) { eventRoutingService = di.Get <IEventRoutingService>(); var platform = di.Get <Platform>(); platform.Add(di.Get <Eto.Forms.Application.IHandler>); platform.Add(di.Get <RenderControl.IHandler>); etoApplication = new Eto.Forms.Application(platform); var handler = (ILoopAppHandler)etoApplication.Handler; renderLoopDispatcher = di.Get <IRenderLoopDispatcher>(); frameTimeMeasurer = di.Get <IFrameTimeMeasurer>(); mainForm = di.Get <IMainForm>(); handler.NewFrame += NewFrame; }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="args">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; // Attach new Eto.Forms application to running app var app = new Eto.Forms.Application(new Eto.WinRT.Platform()).Attach(); app.Run(); // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); //Associate the frame with a SuspensionManager key SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate try { await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException) { //Something went wrong restoring state. //Assume there is no state and continue } } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!rootFrame.Navigate(typeof(ItemsPage), "AllGroups")) { throw new Exception("Failed to create initial page"); } } // Ensure the current window is active Window.Current.Activate(); }
public EtoFormsApplicationLifetime( IOptions <EtoFormsOptions> options, Eto.Forms.Application application, IHostApplicationLifetime hostapplifetime, IHostEnvironment environment, ILoggerFactory loggerFactory ) : base() { this.options = options?.Value ?? throw new ArgumentNullException(nameof(options)); this.application = application ?? throw new ArgumentNullException(nameof(application)); ApplicationLifetime = hostapplifetime ?? throw new ArgumentNullException(nameof(hostapplifetime)); Environment = environment ?? throw new ArgumentNullException(nameof(environment)); Logger = loggerFactory?.CreateLogger("THNETII.EtoForms.Hosting.Lifetime") ?? Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance; }
public static int Main(string[] args) { using var application = new Eto.Forms.Application(Eto.Platform.Detect); var rootCommand = new RootCommand() { Handler = Handler }; var cmdParser = new CommandLineBuilder(rootCommand) .UseDefaults() .UseHost(Host.CreateDefaultBuilder, hostBuilder => { hostBuilder.ConfigureServices(services => { services.AddEtoFormsHost(application); services.TryAddSingleton <MainForm>(); services.Configure <EtoFormsOptions>(opts => opts.MainForm = typeof(MainForm)); }); }) .Build(); return(cmdParser.InvokeAsync(args).ConfigureAwait(true) .GetAwaiter().GetResult()); }
internal static void Initialize() { _etoApplication = new Eto.Forms.Application(Platform.Detect); }
private static void Main() { using Application app = new Application(); Console.WriteLine("Initializing"); #if NO_TIMED_BAN || NO_NSFW Console.WriteLine("Build config:"); #if NO_TIMED_BAN Console.WriteLine("- NO_TIMED_BAN"); #endif #if NO_NSFW Console.WriteLine("- NO_NSFW"); #endif #endif Github = new GitHubClient(new ProductHeaderValue("DiscHax")); Perspective = new Perspective(TokenManager.PerspectiveToken); DiscordConfiguration cfg = new DiscordConfiguration { Token = TokenManager.DiscordToken, TokenType = TokenType.Bot, AutoReconnect = true, #if DEBUG LogLevel = LogLevel.Debug, #else LogLevel = LogLevel.Info, #endif UseInternalLogHandler = false }; client = new DiscordClient(cfg); Commands = client.UseCommandsNext(new CommandsNextConfiguration { StringPrefixes = new string[0], EnableDms = false, PrefixResolver = async msg => { if (msg.Author.IsBot) { return(-1); } string prefix = msg.Channel.Get(ConfigManager.Prefix, Common.Prefix); string content = msg.Content.TrimStart(' '); if (content.StartsWith(prefix)) { if (content.StartsWith($"{prefix} ")) { return(prefix.Length + 1); } return(prefix.Length); } if (!content.StartsWith(client.CurrentUser.Mention)) { return(-1); } if (content.StartsWith($"{client.CurrentUser.Mention} ")) { return(client.CurrentUser.Mention.Length + 1); } return(client.CurrentUser.Mention.Length); } }); Commands.CommandExecuted += Commands_CommandExecuted; Commands.CommandErrored += Commands_CommandErrored; client.UseInteractivity(new InteractivityConfiguration { PaginationBehaviour = PaginationBehaviour.Ignore, Timeout = TimeSpan.FromMinutes(2) }); Commands.RegisterAll(); client.DebugLogger.LogMessageReceived += DebugLogger_LogMessageReceived; client.Ready += ClientReady; client.MessageCreated += AddMessage; client.ClientErrored += ClientClientErrored; client.ConnectAsync().ConfigureAwait(false).GetAwaiter().GetResult(); while (!Exit) { Exit = ProcessLoop.RunIteration(client); } client?.DisconnectAsync().GetAwaiter().GetResult(); client?.Dispose(); client = null; }
public SampleCsEtoPlugIn() { Application = new Eto.Forms.Application(Eto.Platforms.Wpf); Instance = this; }
public static void Main(string[] args) { //Do our command line parsing first CommandLine.ParseArguments(args); //Create our Eto.Forms app, so we can show message boxes //We shut this down before we run the engine Platform.AllowReinitialize = true; Application app = new Application(); //Now to get the game's entry point IEntryPoint entryPoint = null; string dllPath = Path.GetFullPath($"{CommandLine.GameName}/bin/{CommandLine.GameName}.dll"); try { //Load the game assembly AssemblyLoad assemblyLoad = new AssemblyLoad(); Assembly gameDll = assemblyLoad.LoadAssembly(Path.GetFullPath($"{CommandLine.GameName}/bin"), $"{CommandLine.GameName}.dll"); //Find a class the inherits from IEntryPoint so that we can create the game foreach (Type type in gameDll.GetTypes().Where(x => x.IsPublic && x.IsClass)) //Needs to be public { if (!typeof(IEntryPoint).IsAssignableFrom(type)) { continue; } if (!(Activator.CreateInstance(type) is IEntryPoint point)) { continue; } entryPoint = point; break; } } catch (FileNotFoundException ex) //The DLL wasn't found { Debug.Assert(false, $"The game DLL for '{CommandLine.GameName}' wasn't found in '{dllPath}'!\n{ex}"); #if !DEBUG Eto.Forms.MessageBox.Show($"The game DLL for '{CommandLine.GameName}' wasn't found in '{dllPath}'!", "Engine Error", Eto.Forms.MessageBoxButtons.OK, Eto.Forms.MessageBoxType.Error); app.Dispose(); Environment.Exit(0); #endif } catch (Exception ex) //Some other error { Debug.Assert(false, $"An unknown error occured while preparing the game for launching!\n{ex}"); #if !DEBUG Eto.Forms.MessageBox.Show($"An unknown error occured while preparing the game for launching!", "Engine Error", Eto.Forms.MessageBoxButtons.OK, Eto.Forms.MessageBoxType.Error); app.Dispose(); Environment.Exit(0); #endif } //The entry point wasn't found Debug.Assert(entryPoint != null, "The game DLL doesn't contain an entry point!"); #if !DEBUG if (entryPoint == null) { Eto.Forms.MessageBox.Show("The game DLL didn't contain an entry point!", "Engine Error", Eto.Forms.MessageBoxButtons.OK, Eto.Forms.MessageBoxType.Error); app.Dispose(); Environment.Exit(0); return; } #endif //Dispose of the Eto.Forms app app.Quit(); app.Dispose(); //Tell the engine to init, and use the game entry point. //This is were we actually start to render and run the game. try { Engine.Init(entryPoint); } catch (Exception ex) { if (Logger.IsLoggerInitialized) { Logger.Error("An error occured: {@Exception}", ex); } //If the logger isn't initialized, then the only option we got to log the error is to dump it into console, as we disposed of Eto.Forms Application earlier //and can't create message boxes with out it else { Console.WriteLine(ex.ToString()); } } }
public static void EtoStartup() { if (etoThread != null) { return; } // run Eto UI in separate thread etoThread = new Thread(new ThreadStart(() => { try { Eto.Platform etoPlatform = null; if (Environment.OSVersion.Platform == PlatformID.Win32NT && Type.GetType("Mono.Runtime") != null) { // Mono under Windows does not support WPF, which causes the // automatic platform detection to fail loading it. Skip the // detection and attempt to load the other platform assemblies // manually. string[] platformWinForms = Eto.Platforms.WinForms.Split(new char[] { ',' }); string[] platformGtk3 = Eto.Platforms.Gtk3.Split(new char[] { ',' }); string[] platformGtk2 = Eto.Platforms.Gtk2.Split(new char[] { ',' }); Tuple <string, string>[] platforms = new Tuple <string, string>[] { Tuple.Create(platformWinForms[0].Trim(), platformWinForms[1].Trim()), Tuple.Create(platformGtk3[0].Trim(), platformGtk3[1].Trim()), Tuple.Create(platformGtk2[0].Trim(), platformGtk2[1].Trim()) }; for (int i = 0; i < platforms.Length; i++) { try { string assemblyPath = Path.Combine(basePath, platforms[i].Item2 + ".dll"); Assembly assemblyWinForms = Assembly.LoadFile(assemblyPath); Type platformType = assemblyWinForms.GetType(platforms[i].Item1); etoPlatform = (Eto.Platform)Activator.CreateInstance(platformType); break; } catch (Exception e) { Log.Error("Eto: Failed to load platform " + platforms[i].Item1 + ": " + e.Message); } } } if (etoPlatform == null) { etoPlatform = Eto.Platform.Detect; } using (etoApplication = new Eto.Forms.Application(etoPlatform)) { etoApplication.Initialized += (s, e) => etoWaitHandle.Set(); etoApplication.Run(); } } catch { etoWaitHandle.Set(); throw; } })); etoThread.SetApartmentState(ApartmentState.STA); etoThread.Name = "EtoThread"; etoThread.IsBackground = true; etoThread.Start(); }