Example #1
0
        private void View_Consolidated(ApplicationView sender, ApplicationViewConsolidatedEventArgs args)
        {
            var windowID = ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread());

            PlatformBase.CurrentCore.Logger.Log(LogLevels.Debug, $"Closed secondary window with ID {windowID}");
            AppWindows.Remove(windowID);
            ApplicationView.GetForCurrentView().Consolidated -= View_Consolidated;
            Window.Current.Close();
        }
Example #2
0
        private void BtnStocksView_Click2(object sender, RibbonControlEventArgs e)
        {
            semaphoreSlim1.Wait();
            var dd = Dispatcher.CurrentDispatcher;

            Excel.Sheets ss = Globals.ThisAddIn.Application.ActiveWorkbook?.Worksheets;
            if (ss == null)
            {
                return;
            }
            int count = AppWindows.GetWindowCount <StocksWindow>();

            if (count >= 1)
            {
                return;
            }
            var thread = new Thread((obj) =>
            {
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));
                var vv = new ViewDataWindow(ss);
                AppWindows.AddWindow(vv);
                var ownerWindowHandle = (IntPtr)Globals.ThisAddIn.Application.Hwnd;
                var helper            = new WindowInteropHelper(vv)
                {
                    Owner = ownerWindowHandle // COMMENT THAT AND IT WORKS PROPERLY
                };
                vv.Show();
                vv.Closed += (sender2, e2) =>
                {
                    AppWindows.RemoveWindow(vv);
                    vv.Dispatcher.InvokeShutdown();
                    ((SemaphoreSlim)obj).Release();
                };
                Dispatcher.Run();
            })
            {
                IsBackground = true
            };

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start(semaphoreSlim0);
            //var thread = new Thread(() =>
            //{
            //    ViewDataWindow tempWindow = new ViewDataWindow(ss);
            //    // When the window closes, shut down the dispatcher
            //    tempWindow.Closed += (s, e2) =>
            //       Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

            //    tempWindow.Show();
            //    // Start the Dispatcher Processing
            //    Dispatcher.Run();
            //});
            //thread.IsBackground = true;
            //thread.SetApartmentState(ApartmentState.STA);
            //thread.Start(semaphoreSlim0);
        }
Example #3
0
        /// <summary>
        /// Launches another window with the specified page type.
        /// </summary>
        /// <param name="viewType">Type of the page requested in the secondary window.</param>
        /// <param name="parameter">Page parameter to pass to the new page instance.</param>
        /// <returns>Awaitable task is returned.</returns>
        public virtual async Task NewWindow(Type viewType, object parameter)
        {
            try
            {
                // Create a new window
                var view     = CoreApplication.CreateNewView();
                int windowID = 0;
                await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    windowID = ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread());

                    // Register the new window
                    this.RegisterCoreWindow();

                    // Create a frame for the new window
                    var frame = new ApplicationFrame(true);
                    Window.Current.Content = frame;

                    // Navigate to a page within the new window based on the parameters of this method
                    this.SecondaryWindow(new NavigationRequest(viewType, this.SerializeParameter(parameter)));

                    // Show the new window
                    Window.Current.Activate();
                    ApplicationView.GetForCurrentView().Consolidated += View_Consolidated;

                    PlatformBase.CurrentCore.Logger.Log(LogLevels.Warning, $"Launched new window");
                });

                // Run this on the last dispatcher so the windows get positioned correctly
                bool  viewShown;
                await AppWindows[AppWindows.Keys.First()].Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(windowID);
                });

                // Track the new window
                AppWindows.Add(windowID, view);
            }
            catch (Exception ex)
            {
                PlatformBase.CurrentCore.Logger.LogError(ex, "Could not create new window for view type {0}.", viewType.Name);
                throw ex;
            }
        }
        // Obtain from MS docs
        // https://docs.microsoft.com/en-us/windows/uwp/design/layout/app-window
        private async void NewWindow(String Title, Type Page)
        {
            appWindow = await AppWindow.TryCreateAsync();

            appWindow.Title = Title;
            Frame appWindowContentFrame = new Frame();

            appWindowContentFrame.Navigate(Page);

            ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);

            AppWindows.Add(appWindowContentFrame.UIContext, appWindow);

            appWindow.Closed += delegate
            {
                MainPage.AppWindows.Remove(appWindowContentFrame.UIContext);
                appWindowContentFrame.Content = null;
                appWindow = null;
            };

            await appWindow.TryShowAsync();
        }
Example #5
0
        private void BtnStocksView_Click(object sender, RibbonControlEventArgs e)
        {
            semaphoreSlim1.Wait();
            Excel.Sheets ss = Globals.ThisAddIn.Application.ActiveWorkbook?.Worksheets;
            if (ss == null)
            {
                return;
            }
            int count = AppWindows.GetWindowCount <StocksWindow>();

            if (count >= 1)
            {
                return;
            }
            var thread = new Thread((obj) =>
            {
                var sw = new StocksWindow(ss);
                AppWindows.AddWindow(sw);
                var ownerWindowHandle = (IntPtr)Globals.ThisAddIn.Application.Hwnd;
                var helper            = new WindowInteropHelper(sw)
                {
                    Owner = ownerWindowHandle // COMMENT THAT AND IT WORKS PROPERLY
                };
                sw.Show();
                sw.Closed += (sender2, e2) =>
                {
                    AppWindows.RemoveWindow(sw);
                    sw.Dispatcher.InvokeShutdown();
                    ((SemaphoreSlim)obj).Release();
                };
                Dispatcher.Run();
            });

            thread.IsBackground = true;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start(semaphoreSlim1);
        }
Example #6
0
        public static Gtk.Window Create(AppWindows type)
        {
            string title = string.Empty;
            Gtk.Window window = null;
            switch (type) {
                default:
                    Program.ExitProgram(ExitCodes.EXIT_INT_NOT_FOUND, "CreateWindow: Unknown window type {0}", type);
                    break;
                case AppWindows.WINDOW_MAIN:
                    if (Variables.Window.main == null) {
                        Variables.Window.main = MainWindow.Create ();
                        window = Variables.Window.main;
                        MainWindow.LoadGeometry ();
                        GameGUI.PrintMessage (Catalog.GetString ("Welcome to Bygfoot %s"), Bygfoot.VERS);
                        title = string.Format ("Bygfoot Football Manager {0}", Bygfoot.VERS);
                    }
                    else
                        window = Variables.Window.main;
                    if (Option.OptInt ("int_opt_maximize_main_window") == 1)
                        window.Maximize ();
                    break;
                case AppWindows.WINDOW_STARTUP:
                    if (Variables.Window.startup != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.startup = StartupWindow.Create();
                    window = Variables.Window.startup;
                    break;
                case AppWindows.WINDOW_LIVE:
                    if (Variables.Window.live != null)
                        Debug.PrintMessage ("Window.Create: called on already existing window\n");
                    else
                        Variables.Window.live = LiveWindow.Instance.Create ();
                    /*
                if(((LiveGame*)statp)->fix != NULL)
                    strcpy(buf, league_cup_get_name_string(((LiveGame*)statp)->fix->clid));
                window = Variables.Window.live;
                window_live_set_up();
                */
                    break;
                case AppWindows.WINDOW_WARNING:
                    if (Variables.Window.warning != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.warning = WarningWindow.Create();
                    window = Variables.Window.warning;
                    break;
                case AppWindows.WINDOW_PROGRESS:
                    if (Variables.Window.progress != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.progress = ProgressWindow.Create();
                    window = Variables.Window.progress;
                    break;
                case AppWindows.WINDOW_DIGITS:
                    if(Variables.Window.digits != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.digits = DigitsWindow.Create();

                    window = Variables.Window.digits;
                    title = Catalog.GetString("Numbers...");
                    break;
                case AppWindows.WINDOW_STADIUM:
                    if(Variables.Window.stadium != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.stadium = StadiumWindow.Create();
                    window = Variables.Window.stadium;
                    title = Catalog.GetString("Your stadium");
                    break;
                case AppWindows.WINDOW_JOB_OFFER:
                    if(Variables.Window.job_offer != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.job_offer = JobOfferWindow.Create();
                    window = Variables.Window.job_offer;
                    title = Catalog.GetString("Job offer");
                    break;
                case AppWindows.WINDOW_YESNO:
                    if(Variables.Window.yesno != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.yesno = YesNoWindow.Create();
                    window = Variables.Window.yesno;
                    title = "???";
                    break;
                case AppWindows.WINDOW_OPTIONS:
                    if(Variables.Window.options != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.options = OptionsWindow.Create();
                    window = Variables.Window.options;
                    title = Catalog.GetString("Options");
                    break;
                case AppWindows.WINDOW_FONT_SEL:
                    if(Variables.Window.font_sel != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.font_sel = FontSelWindow.Create();
                    window = Variables.Window.font_sel;
                    title = Catalog.GetString("Select font");
                    break;
                case AppWindows.WINDOW_FILE_CHOOSER:
                    if(Variables.Window.file_chooser != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.file_chooser = FileChooserWindow.Create();
                    window = Variables.Window.file_chooser;
                    break;
                case AppWindows.WINDOW_CONTRACT:
                    if(Variables.Window.contract != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.contract = ContractWindow.Create();
                    window = Variables.Window.contract;
                    title = Catalog.GetString("Contract offer");
                    break;
                case AppWindows.WINDOW_USER_MANAGEMENT:
                    if(Variables.Window.user_management != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.user_management = UserManagementWindow.Create();
                    window = Variables.Window.user_management;
                    title = Catalog.GetString("User management");
                    break;
                case AppWindows.WINDOW_DEBUG:
                    if(Variables.Window.wdebug != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.wdebug = DebugWindow.Create();
                    window = Variables.Window.wdebug;
                    title = "Bygfoot debug window";
                    break;
                case AppWindows.WINDOW_HELP:
                    if(Variables.Window.help != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.help = HelpWindow.Create();
                    window = Variables.Window.help;
                    break;
                case AppWindows.WINDOW_TRANSFER_DIALOG:
                    if(Variables.Window.transfer_dialog != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.transfer_dialog = TransferDialogWindow.Create();
                    window = Variables.Window.transfer_dialog;
                    title = Catalog.GetString("Transfer offer");
                    break;
                case AppWindows.WINDOW_SPONSORS:
                    if(Variables.Window.sponsors != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.sponsors = SponsorsWindow.Create();
                    window = Variables.Window.sponsors;
                    title = Catalog.GetString("Sponsorship offers");
                    break;
                case AppWindows.WINDOW_MMATCHES:
                    if(Variables.Window.mmatches != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.mmatches = MMatchesWindow.Create();
                    window = Variables.Window.mmatches;
                    title = Catalog.GetString("Memorable matches");
                    break;
                case AppWindows.WINDOW_BETS:
                    if(Variables.Window.bets != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.bets = BetsWindow.Create();
                    window = Variables.Window.bets;
                    title = Catalog.GetString("Betting");
                    break;
                case AppWindows.WINDOW_SPLASH:
                    if (Variables.Window.splash != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.splash = SplashWindow.Create();
                    window = Variables.Window.splash;
                    break;
                case AppWindows.WINDOW_TRAINING_CAMP:
                    if(Variables.Window.training_camp != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.training_camp = TrainingCampWindow.Create();
                    window = Variables.Window.training_camp;
                    title = Catalog.GetString("Training camp");
                    break;
                case AppWindows.WINDOW_ALR:
                    if(Variables.Window.alr != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.alr = AlrWindow.Create();
                    window = Variables.Window.alr;
                    title = Catalog.GetString("Automatic loan repayment");
                    break;
                case AppWindows.WINDOW_NEWS:
                    if(Variables.Window.news != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.news = NewsWindow.Create();
                    window = Variables.Window.news;
                    title = Catalog.GetString("Bygfoot News");
                    break;
                case AppWindows.WINDOW_CONSTANTS:
                    if(Variables.Window.constants != null)
                        Debug.PrintMessage("CreateWindow: called on already existing window");
                    else
                        Variables.Window.constants = ConstantsWindow.Create();
                    window = Variables.Window.constants;
                    title = Catalog.GetString("Bygfoot constants");
                    break;
            }

            if (type != AppWindows.WINDOW_FILE_CHOOSER)
                window.Title = title;

            if (type != AppWindows.WINDOW_PROGRESS && type != AppWindows.WINDOW_STARTUP)
                GLib.Timeout.Add (20, () => {
                    return ShowWindow(window);
                });
            else
                window.Show ();

            return window;
        }
Example #7
0
        private static void FullExample(string[] args)
        {
            Debugger.Break();

            // Konfiguration vorbereiten
            IConfigurationBuilder configBuilder = new ConfigurationBuilder()
                                                  // NuGet: Microsoft.Extensions.Configuration.CommandLine
                                                  .AddCommandLine(args);

            // Build() liest die Werte aller Quellen ein
            IConfigurationRoot config = configBuilder.Build();

            configBuilder
            .SetBasePath(Directory.GetCurrentDirectory())
            // NuGet: Microsoft.Extensions.Configuration.Json
            .AddJsonFile($"appsettings.{config.GetValue("Env", "Production")}.json");
            config = configBuilder.Build();

            // Connectionstring abrufen...
            config = configBuilder.Build();
            string connectionString = config["ConnectionStrings:Main"];

            // ...damit Konfiguration aus Datenbank aktivieren
            config = configBuilder
                     .AddSqlDatabase(connectionString)
                     .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "App:Window:Height", "740" },
                { "App:Window:Width", "900" },
                { "App:Window:Top", "10" },
                { "App:Window:Left", "10" },
                { "App:Window:Title:Color", "Green" }
            })
                     // NuGet: Microsoft.Extensions.Configuration.EnvironmentVariables
                     .AddEnvironmentVariables()
                     // NuGet: Microsoft.Extensions.Configuration.CommandLine
                     .AddCommandLine(args)
                     // NuGet: Microsoft.Extensions.Configuration.Ini
                     .AddIniFile("Config.ini")
                     // NuGet: Microsoft.Extensions.Configuration.Xml
                     .AddXmlFile("Config.xml")
                     // NuGet: Microsoft.Extensions.Configuration.AzureKeyVault
                     //.AddAzureKeyVault($"https://{config["Vault"]}.vault.azure.net/",
                     //                  config["ClientId"],
                     //                  config["ClientSecret"])
                     .Build();

            // Nicht definierter Wert
            int smptPort = config.GetValue("Smtp:Port", 25);

            // Einfacher Zugriff (ohne Binder)
            string conString = config["ConnectionStrings:Main"];

            // JSON-File
            int c = config.GetValue("App:MainWindow:Top", 0);
            // Aus Ini-Datei
            string wetter = config.GetValue <string>("IniSection:Wetter");
            // Aus XML-Datei
            // Konfiguration auf Enum mappen
            PaperOrientation paperOrientation = config.GetValue("setting:Orientation:value", PaperOrientation.Portrait);
            // Umgebungsvariabel
            string systemdrive = config.GetValue("SystemDrive", "X:");
            // Programm-Argumente
            string enviroment = config.GetValue("Env", "Production");
            // Aus der Datebank (Custom)
            string color = config.GetValue <string>("Color");

            // Konfiguration auf POCOs mappen
            var appWindow = new AppWindows();

            config.GetSection("App:Window").Bind(appWindow);

            // Aus Private-Setter-Eigenschaften binden
            appWindow = config.GetSection("App:Window").Get <AppWindows>(
                o => o.BindNonPublicProperties = true
                );
        }