コード例 #1
0
ファイル: AEMGViewModel.cs プロジェクト: xuan2261/EMM
        private void InitializeCommandAndEvents()
        {
            ConvertCommand = new RelayCommand(p =>
            {
                var result = this.scriptGenerator.GenerateScript(macroManager.GetCurrentTemplate(), AEActionListViewModel.AEActionList);

                if (result == null)
                {
                    return;
                }

                if (result == true)
                {
                    this.messageBoxService.ShowMessageBox("Done", "Convert", MessageButton.OK, MessageImage.Information, MessageResult.OK);
                }
                else
                {
                    this.messageBoxService.ShowMessageBox("Error. Check your setting or contact me for help", "Convert", MessageButton.OK, MessageImage.Error, MessageResult.OK);
                }
            });

            TestSelectedCommand = new RelayCommand(p =>
            {
                this.scriptGenerator.GenerateScript(macroManager.GetCurrentTemplate(), aEAction: AEActionListViewModel.GetSelected());
            });

            PreviewInEMMCommand = new RelayCommand(p =>
            {
                //check if EMM exist
                if (!File.Exists(Path.Combine(Environment.CurrentDirectory, AEMGStatic.EMM_NAME)))
                {
                    this.messageBoxService.ShowMessageBox("Cannot find EMM application. Put this application to the same folder as EMM.exe", "ERROR", MessageButton.OK, MessageImage.Error);
                    return;
                }

                var path = this.scriptGenerator.GenerateTempScript(macroManager.GetCurrentTemplate(), AEActionListViewModel.AEActionList);

                AEMGHelpers.StartEMM(path, StaticVariables.NO_SAVE_AGRS);
            });

            macroManager.SelectChanged += (sender, e) =>
            {
                Settings.CustomName = e.NewMacro?.MacroName;
            };
        }
コード例 #2
0
        private void InitializeCommandsAndEvents()
        {
            OpenProfilePopupCommand = new RelayCommand(p =>
            {
                IsCreateNewProfile ^= true;
            }, p => Save != null);

            NewProfileCommand = new RelayCommand(p =>
            {
                var currentTemplate = manager.GetCurrentTemplate();

                if (string.IsNullOrWhiteSpace(NewProfileName) || !AEMGHelpers.IsValidFilename(NewProfileName) || currentTemplate == null)
                {
                    return;
                }

                var newProfile = new SavedAEProfile
                {
                    Id        = Guid.NewGuid().ToString(),
                    IsDefault = true,
                    Name      = NewProfileName,
                    Setups    = GetCurrentSetup(),
                };

                repository.ResetProfileDefault();
                repository.AddProfile(newProfile);
                repository.SaveChange();

                RefreshSave();
                IsCreateNewProfile = false;
            }, p => Save != null);

            RemoveProfileCommand = new RelayCommand(p =>
            {
                if (!(p is SavedAEProfile save))
                {
                    return;
                }

                repository.RemoveProfile(save);
                repository.SaveChange();

                RefreshSave();
            }, p => Save != null);

            LoadProfileCommand = new RelayCommand(p =>
            {
                if (!(p is SavedAEProfile save))
                {
                    return;
                }

                repository.ResetProfileDefault();
                save.IsDefault = true;
                repository.SaveChange();

                manager.InvokeLoadMacroProfile(save);
            }, p => Save != null);

            UpdateCurrentProfileCommand = new RelayCommand(p =>
            {
                if (repository.CurrentSave()?.DefaultProfile == null)
                {
                    return;
                }

                var oldSetups     = repository.CurrentSave().DefaultProfile.Setups;
                var currentSetups = GetCurrentSetup();

                //merge setups
                if (currentSetups.Count >= oldSetups.Count)
                {
                    repository.CurrentSave().DefaultProfile.Setups = currentSetups;
                }
                else
                {
                    for (int i = 0; i < currentSetups.Count; i++)
                    {
                        if (i < oldSetups.Count)
                        {
                            oldSetups[i] = currentSetups[i];
                        }
                    }
                }

                repository.SaveChange();
            }, p => repository.CurrentSave()?.DefaultProfile != null);

            manager.SelectChanged += (sender, test) =>
            {
                if (test.NewMacro == null)
                {
                    Save = null;
                    Profiles?.Clear();
                    return;
                }

                Save     = repository.FindByMacroPath(test.SelectedMacroPath);
                Profiles = new ObservableCollection <SavedAEProfile>(Save.Profiles);

                //Fire event to load default save profile
                if (Profiles.Count > 0)
                {
                    manager.InvokeSaveLoaded(repository.CurrentSave());
                }
            };
        }