Esempio n. 1
0
    public static Window InitializationClassicDesktopStyle(IClassicDesktopStyleApplicationLifetime?desktopLifetime, out ProjectEditorViewModel editor)
    {
        var jsonSettings = new JsonSerializerSettings()
        {
            Formatting                 = Formatting.Indented,
            TypeNameHandling           = TypeNameHandling.Objects,
            PreserveReferencesHandling = PreserveReferencesHandling.Objects,
            ReferenceLoopHandling      = ReferenceLoopHandling.Serialize,
            ContractResolver           = new ListContractResolver(typeof(ObservableCollection <>)),
            NullValueHandling          = NullValueHandling.Ignore,
            Converters                 =
            {
                new KeyValuePairConverter()
            }
        };

        var builder = new ContainerBuilder();

        builder.RegisterModule <AppModule>();

        var container = builder.Build();

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

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

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

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

        if (fileSystem.Exists(windowSettingsPath))
        {
            var jsonWindowSettings = fileSystem?.ReadUtf8Text(windowSettingsPath);
            if (!string.IsNullOrEmpty(jsonWindowSettings))
            {
                windowSettings = JsonConvert.DeserializeObject <WindowConfiguration>(jsonWindowSettings, jsonSettings);
            }
        }

        editor = serviceProvider.GetService <ProjectEditorViewModel>();

        editor.DockFactory = new DockFactory(editor);

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

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

        var rootDock     = default(RootDock);
        var rootDockPath = System.IO.Path.Combine(fileSystem?.GetBaseDirectory(), "Core2D.layout");

        if (fileSystem.Exists(rootDockPath))
        {
            var jsonRootDock = fileSystem?.ReadUtf8Text(rootDockPath);
            if (!string.IsNullOrEmpty(jsonRootDock))
            {
                rootDock = JsonConvert.DeserializeObject <RootDock>(jsonRootDock, jsonSettings);
                if (rootDock is { })