Ejemplo n.º 1
0
 public static Task <bool> CheckIfDialogIsClosedAsync <TDialog>(IClassicDesktopStyleApplicationLifetime app) =>
 WaitService.WaitForConditionAsync(() => CheckIfDialogIsClosed <TDialog>(app));
Ejemplo n.º 2
0
 private static bool CheckIfDialogIsOpened <TDialog>(IClassicDesktopStyleApplicationLifetime app) =>
 app
 .Windows
 .OfType <TDialog>()
 .Any();
Ejemplo n.º 3
0
        private void InitializationClassicDesktopStyle(IClassicDesktopStyleApplicationLifetime desktopLifetime)
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule <AvaloniaModule>();

            var container = builder.Build();

            var serviceProvider = container.Resolve <IServiceProvider>();

            Selector = ThemeSelector.Create("Themes");
            Selector.LoadSelectedTheme("Core2D.theme");

            var log    = serviceProvider.GetService <ILog>();
            var fileIO = serviceProvider.GetService <IFileSystem>();

            log?.Initialize(System.IO.Path.Combine(fileIO?.GetBaseDirectory(), "Core2D.log"));

            var editor = serviceProvider.GetService <IProjectEditor>();

            editor.LayoutPlatform.LoadLayout  = () => editor.Platform.OnLoadLayout();
            editor.LayoutPlatform.SaveLayout  = () => editor.Platform.OnSaveLayout();
            editor.LayoutPlatform.ResetLayout = () => editor.Platform.OnResetLayout();

            var layoutPath = System.IO.Path.Combine(fileIO.GetBaseDirectory(), "Core2D.layout");

            if (fileIO.Exists(layoutPath))
            {
                editor.OnLoadLayout(layoutPath);
            }

            var dockFactory = serviceProvider.GetService <DM.IFactory>();

            editor.Layout ??= dockFactory.CreateLayout();
            dockFactory.InitLayout(editor.Layout);

            var recentPath = System.IO.Path.Combine(fileIO.GetBaseDirectory(), "Core2D.recent");

            if (fileIO.Exists(recentPath))
            {
                editor.OnLoadRecent(recentPath);
            }

            editor.CurrentTool     = editor.Tools.FirstOrDefault(t => t.Title == "Selection");
            editor.CurrentPathTool = editor.PathTools.FirstOrDefault(t => t.Title == "Line");
            editor.IsToolIdle      = true;

            var runtimeInfo             = AvaloniaLocator.Current.GetService <IRuntimePlatform>().GetRuntimeInfo();
            var windowingPlatform       = AvaloniaLocator.Current.GetService <IWindowingPlatform>();
            var platformRenderInterface = AvaloniaLocator.Current.GetService <IPlatformRenderInterface>();
            var windowingSubsystemName  = windowingPlatform.GetType().Assembly.GetName().Name;
            var renderingSubsystemName  = platformRenderInterface.GetType().Assembly.GetName().Name;
            var aboutInfo = CreateAboutInfo(runtimeInfo, windowingSubsystemName, renderingSubsystemName);

            editor.AboutInfo = aboutInfo;

            var mainWindow = serviceProvider.GetService <MainWindow>();

            mainWindow.DataContext = editor;

            mainWindow.Closing += (sender, e) =>
            {
                editor.Layout.Close();
                editor.OnSaveLayout(layoutPath);
                editor.OnSaveRecent(recentPath);
                Selector.SaveSelectedTheme("Core2D.theme");
            };

            desktopLifetime.MainWindow = mainWindow;

            desktopLifetime.Exit += (sennder, e) =>
            {
                log.Dispose();
                container.Dispose();
            };
        }
Ejemplo n.º 4
0
        public override void OnFrameworkInitializationCompleted()
        {
            TabConfigViewModel        tabConfigViewModel   = null;
            TabStatusViewModel        statusViewModel      = null;
            TabHistoryPumpViewModel   historyPumpViewModel = null;
            TabHistoryViewModel       historyViewModel     = null;
            TabGraphicViewModel       graphicViewModel     = null;
            DataService               wateringDataService  = null;
            WateringExecution         wateringExecution;
            WeatherSensorDataProvider sensorDataProvider;

            bool debug = false;

            #if DEBUG
            debug = true;
            #endif

            if (!Design.IsDesignMode)
            {
                Log.Logger = new LoggerConfiguration()
                             .Enrich.WithThreadId()
                             .Enrich.FromLogContext()
                             .Enrich.WithExceptionDetails()
                             .MinimumLevel.Debug()
                             .WriteTo.File("Watering.log",
                                           rollingInterval: RollingInterval.Day,
                                           shared: true,
                                           outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}]<{ThreadId}>{SourceContext} {Message} {Properties} {NewLine}{Exception}")
                             .WriteTo.Console(LogEventLevel.Information, "{NewLine}{Timestamp:yyyy-MM-dd HH:mm:ss} {Message}{NewLine}{Exception}")
                             .CreateLogger();

                Log.Information("Program starting...");
                ConfigController cfgController = new ConfigController();
                tabConfigViewModel   = new TabConfigViewModel(cfgController);
                wateringDataService  = new DataService();
                wateringExecution    = new WateringExecution(cfgController, wateringDataService, debug);
                sensorDataProvider   = new WeatherSensorDataProvider(wateringDataService, cfgController, debug);
                statusViewModel      = new TabStatusViewModel(cfgController, sensorDataProvider, wateringExecution, debug);
                historyPumpViewModel = new TabHistoryPumpViewModel(wateringDataService);
                historyViewModel     = new TabHistoryViewModel(wateringDataService);
                graphicViewModel     = new TabGraphicViewModel(cfgController, wateringDataService, wateringExecution);
            }


            IClassicDesktopStyleApplicationLifetime desktop = null;
            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
            {
                desktop                        = lifetime;
                desktop.MainWindow             = new MainWindow();
                desktop.MainWindow.DataContext = tabConfigViewModel == null ? new MainWindowViewModel()
                    : new MainWindowViewModel(statusViewModel, tabConfigViewModel, historyPumpViewModel, historyViewModel, graphicViewModel, desktop.MainWindow);
            }



            if (desktop != null)
            {
                desktop.Exit += Desktop_Exit;
            }

            base.OnFrameworkInitializationCompleted();
        }
Ejemplo n.º 5
0
 public static TDialog GetDialog <TDialog>(IClassicDesktopStyleApplicationLifetime app) =>
 app
 .Windows
 .OfType <TDialog>()
 .SingleOrDefault();
Ejemplo n.º 6
0
        private void InitializationClassicDesktopStyle(IClassicDesktopStyleApplicationLifetime desktopLifetime)
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule <AvaloniaModule>();

            var container = builder.Build();

            var serviceProvider = container.Resolve <IServiceProvider>();

            var log    = serviceProvider.GetService <ILog>();
            var fileIO = serviceProvider.GetService <IFileSystem>();

            log?.Initialize(System.IO.Path.Combine(fileIO?.GetBaseDirectory(), "Core2D.log"));

            var windowSettings     = default(WindowConfiguration);
            var windowSettingsPath = System.IO.Path.Combine(fileIO?.GetBaseDirectory(), "Core2D.window");

            if (fileIO.Exists(windowSettingsPath))
            {
                var jsonWindowSettings = fileIO?.ReadUtf8Text(windowSettingsPath);
                if (!string.IsNullOrEmpty(jsonWindowSettings))
                {
                    windowSettings = JsonSerializer.Deserialize <WindowConfiguration>(jsonWindowSettings);
                }
            }

            var windowLayout     = default(LayoutConfiguration);
            var windowLayoutPath = System.IO.Path.Combine(fileIO?.GetBaseDirectory(), "Core2D.layout");

            if (fileIO.Exists(windowLayoutPath))
            {
                var jsonWindowLayout = fileIO?.ReadUtf8Text(windowLayoutPath);
                if (!string.IsNullOrEmpty(jsonWindowLayout))
                {
                    windowLayout = JsonSerializer.Deserialize <LayoutConfiguration>(jsonWindowLayout);
                }
            }

            var editor = serviceProvider.GetService <IProjectEditor>();

            var recentPath = System.IO.Path.Combine(fileIO.GetBaseDirectory(), "Core2D.recent");

            if (fileIO.Exists(recentPath))
            {
                editor.OnLoadRecent(recentPath);
            }

            editor.CurrentTool     = editor.Tools.FirstOrDefault(t => t.Title == "Selection");
            editor.CurrentPathTool = editor.PathTools.FirstOrDefault(t => t.Title == "Line");
            editor.IsToolIdle      = true;

            var runtimeInfo             = AvaloniaLocator.Current.GetService <IRuntimePlatform>().GetRuntimeInfo();
            var windowingPlatform       = AvaloniaLocator.Current.GetService <IWindowingPlatform>();
            var platformRenderInterface = AvaloniaLocator.Current.GetService <IPlatformRenderInterface>();
            var windowingSubsystemName  = windowingPlatform.GetType().Assembly.GetName().Name;
            var renderingSubsystemName  = platformRenderInterface.GetType().Assembly.GetName().Name;
            var aboutInfo = CreateAboutInfo(runtimeInfo, windowingSubsystemName, renderingSubsystemName);

            editor.AboutInfo = aboutInfo;

            var mainWindow  = serviceProvider.GetService <MainWindow>();
            var mainControl = mainWindow.FindControl <MainControl>("MainControl");

            if (windowSettings != null)
            {
                WindowConfigurationFactory.Load(mainWindow, windowSettings);
            }

            if (mainControl != null && windowLayout != null)
            {
                LayoutConfigurationFactory.Load(mainControl, windowLayout);
            }

            mainWindow.DataContext = editor;

            mainWindow.Closing += (sender, e) =>
            {
                editor.OnSaveRecent(recentPath);

                windowSettings = WindowConfigurationFactory.Save(mainWindow);
                var jsonWindowSettings = JsonSerializer.Serialize(windowSettings, new JsonSerializerOptions()
                {
                    WriteIndented = true
                });
                if (!string.IsNullOrEmpty(jsonWindowSettings))
                {
                    fileIO?.WriteUtf8Text(windowSettingsPath, jsonWindowSettings);
                }

                windowLayout = LayoutConfigurationFactory.Save(mainControl);
                var jsonWindowLayout = JsonSerializer.Serialize(windowLayout, new JsonSerializerOptions()
                {
                    WriteIndented = true
                });
                if (!string.IsNullOrEmpty(jsonWindowLayout))
                {
                    fileIO?.WriteUtf8Text(windowLayoutPath, jsonWindowLayout);
                }
            };

            desktopLifetime.MainWindow = mainWindow;

            desktopLifetime.Exit += (sennder, e) =>
            {
                log.Dispose();
                container.Dispose();
            };
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initilize main window
 /// </summary>
 /// <param name="desktop"></param>
 private void InitializeMainWindow(IClassicDesktopStyleApplicationLifetime desktop) => desktop.MainWindow = LookupMainWindow();