Artemis.ViewModels.Profiles.ProfileEditorViewModel.ImportProfile C# (CSharp) Метод

ImportProfile() публичный Метод

public ImportProfile ( ) : void
Результат void
        public async void ImportProfile()
        {
            if (_mainManager.DeviceManager.ActiveKeyboard == null)
            {
                DialogService.ShowMessageBox("Cannot import profile.",
                    "To import a profile, please select a keyboard in the options menu first.");
                return;
            }
            var dialog = new OpenFileDialog {Filter = "Artemis profile (*.json)|*.json"};
            var result = dialog.ShowDialog();
            if (result != DialogResult.OK)
                return;

            var profile = ProfileProvider.LoadProfileIfValid(dialog.FileName);
            if (profile == null)
            {
                DialogService.ShowErrorMessageBox("Oh noes, the profile you provided is invalid. " +
                                                  "If this keeps happening, please make an issue on GitHub and provide the profile.");
                return;
            }

            // Verify the game
            if (profile.GameName != _gameModel.Name)
            {
                DialogService.ShowErrorMessageBox(
                    $"Oh oops! This profile is ment for {profile.GameName}, not {_gameModel.Name} :c");
                return;
            }

            // Verify the keyboard
            var deviceManager = _mainManager.DeviceManager;
            if (profile.KeyboardSlug != deviceManager.ActiveKeyboard.Slug)
            {
                var adjustKeyboard = await DialogService.ShowQuestionMessageBox("Profile not inteded for this keyboard",
                    $"Watch out, this profile wasn't ment for this keyboard, but for the {profile.KeyboardSlug}. " +
                    "You can still import it but you'll probably have to do some adjusting\n\n" +
                    "Continue?");
                if (!adjustKeyboard.Value)
                    return;

                // Resize layers that are on the full keyboard width
                profile.ResizeLayers(deviceManager.ActiveKeyboard);
                // Put layers back into the canvas if they fell outside it
                profile.FixBoundaries(deviceManager.ActiveKeyboard.KeyboardRectangle(1));

                // Setup profile metadata to match the new keyboard
                profile.KeyboardSlug = deviceManager.ActiveKeyboard.Slug;
                profile.Width = deviceManager.ActiveKeyboard.Width;
                profile.Height = deviceManager.ActiveKeyboard.Height;
            }

            profile.IsDefault = false;

            // Verify the name
            while (ProfileProvider.GetAll().Contains(profile))
            {
                profile.Name = await DialogService.ShowInputDialog("Rename imported profile",
                    "A profile with this name already exists for this game. Please enter a new name");

                // Null when the user cancelled
                if (string.IsNullOrEmpty(profile.Name))
                    return;
            }

            ProfileProvider.AddOrUpdate(profile);
            LoadProfiles();

            SelectedProfile = Profiles.FirstOrDefault(p => p.Name == profile.Name);
        }