Beispiel #1
0
        public static string SAVE_TO_JSON(TargetManagerDataModel targets, ToolsNavigationDataModel <LayoutDocument> navigation, ToolLayout dockingLayout, IReadOnlyList <LayoutDocument> floatingLayout, string file)
        {
            using var ms     = new MemoryStream();
            using var writer = new Utf8JsonWriter(ms, new JsonWriterOptions()
            {
                Indented = true
            });

            writer.WriteStartObject();

            writer.WritePropertyName("Targets");
            TargetManagerDataModel.SAVE_TO_JSON(writer, targets);

            writer.WritePropertyName("Docking");
            navigation.ExportDockingToolboxToJSON(writer, dockingLayout);

            writer.WritePropertyName("Floating");
            navigation.ExportFloatingToolboxToJSON(writer, floatingLayout);

            writer.WriteEndObject();
            writer.Flush();

            using var fs = new FileStream(file, FileMode.Create, FileAccess.Write);
            ms.Seek(0, SeekOrigin.Begin);
            ms.CopyTo(fs);
            fs.Flush();

            return(Encoding.UTF8.GetString(ms.ToArray()));
        }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();
            __main_wnd_data_model = new MainDataModel();
            DataContext           = __main_wnd_data_model;
            try
            {
                __cabinets_navigation_data_model = new ToolsNavigationDataModel <LayoutDocument>(null, null, Plugin_PropertyChanged);
                _CabinetContainer.Content        = new ToolsNavigationControl(__cabinets_navigation_data_model);
                __docking_documents_layout       = __save_documents_docking_layout(_ToolboxContainer);
                __docking_documents_layout_null  = __docking_documents_layout;

                __data_synchronizer           = new DataSynchronizer(__cabinets_navigation_data_model.ToolDataCollection);
                __user_interface_synchronizer = new UserInterfaceSynchronizer(this, __ui_data_refresh_handler);
            }
            catch (Exception ex)
            {
                HandyControl.Controls.MessageBox.Show(this, $"At least one unexpected error occured during the boot process.\n{ex.Message}", "Error Message", MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
            }
        }
Beispiel #3
0
        public static void RESTORE_FROM_JSON(string file, out TargetManagerDataModel targets, ToolsNavigationDataModel <LayoutDocument> navigation, out ToolLayout dockingLayout, out List <LayoutDocument> floatingLayout)
        {
            targets        = null;
            dockingLayout  = null;
            floatingLayout = null;
            ReadOnlySpan <byte> fs = File.ReadAllBytes(file);

            if (fs.StartsWith(__utf8_bom))
            {
                fs = fs.Slice(__utf8_bom.Length);
            }

            var reader = new Utf8JsonReader(fs, new JsonReaderOptions()
            {
                CommentHandling = JsonCommentHandling.Skip
            });

            try
            {
                while (reader.Read())
                {
                    switch (reader.TokenType, reader.CurrentDepth)
                    {
                    case (JsonTokenType.PropertyName, 1):
                        switch (reader.GetString())
                        {
                        case "Targets":
                            TargetManagerDataModel.RESTORE_FROM_JSON(ref reader, out targets); break;

                        case "Docking":
                            dockingLayout = navigation.ImportDockingToolboxFromJSON(ref reader, fs); break;

                        case "Floating":
                            floatingLayout = navigation.ImportFloatingToolboxFromJSON(ref reader, fs); break;
                        }
                        break;
Beispiel #4
0
 public ToolsNavigationControl(ToolsNavigationDataModel <LayoutDocument> dataModel)
 {
     InitializeComponent();
     DataContext = dataModel;
 }