async void LoadCmdletsForProject(ClosableTabItem tab) { String cmd = Utils.GetCommandTypes(); if (String.IsNullOrEmpty(cmd)) { Utils.MsgBox("Error", Strings.E_EmptyCmds, MessageBoxButton.OK, MessageBoxImage.Error); return; } if (FileProcessor.FindModule(tab.Module.Name)) { tab.Module.ModulePath = null; } tab.ErrorInfo = null; tab.EditorContext.CurrentCmdlet = null; List <CmdletObject> nativeCmdlets = new List <CmdletObject>(); try { IEnumerable <CmdletObject> data = await PowerShellProcessor.EnumCmdlets(tab.Module, cmd, false); nativeCmdlets.AddRange(data); PowerShellProcessor.CompareCmdlets(tab.Module, nativeCmdlets); } catch (Exception e) { String message = e.Message + "\n\nYou still can use the module project in offline mode"; message += "\nHowever certain functionality may not be available."; Utils.MsgBox("Error while loading cmdlets", message, MessageBoxButton.OK, MessageBoxImage.Error); tab.ErrorInfo = e.Message; foreach (CmdletObject cmdlet in tab.Module.Cmdlets) { cmdlet.GeneralHelp.Status = ItemStatus.Missing; } } finally { UIManager.ShowEditor(tab); } }
async void LoadModuleFromFile(Object obj) { // method call from ICommand is allowed only when module selector is active // so skip checks. ClosableTabItem previousTab = _mwvm.SelectedTab; OpenFileDialog dlg = new OpenFileDialog { DefaultExt = ".psm1", Filter = "PowerShell module files (*.psm1, *.psd1)|*.psm1;*.psd1" }; Boolean?result = dlg.ShowDialog(); if (result != true) { return; } UIManager.ShowBusy(previousTab, Strings.InfoModuleLoading); try { ModuleObject module = await PowerShellProcessor.GetModuleFromFile(dlg.FileName); if (module != null && !_mwvm.Modules.Contains(module)) { _mwvm.Modules.Add(module); module.ModulePath = dlg.FileName; } } catch (Exception e) { Utils.MsgBox("Import error", e.Message, MessageBoxButton.OK, MessageBoxImage.Error); previousTab.ErrorInfo = e.Message; } UIManager.ShowModuleList(previousTab); }
public async void LoadCmdlets(Object helpPath, Boolean importCBH) { ClosableTabItem previousTab = _mwvm.SelectedTab; UIElement previousElement = ((Grid)previousTab.Content).Children[0]; String cmd = Utils.GetCommandTypes(); if (String.IsNullOrEmpty(cmd)) { Utils.MsgBox("Error", Strings.E_EmptyCmds, MessageBoxButton.OK, MessageBoxImage.Error); return; } UIManager.ShowBusy(previousTab, Strings.InfoCmdletsLoading); try { IEnumerable <CmdletObject> data = await PowerShellProcessor.EnumCmdlets(_mwvm.SelectedModule, cmd, importCBH); _mwvm.SelectedModule.Cmdlets.Clear(); foreach (CmdletObject item in data) { _mwvm.SelectedModule.Cmdlets.Add(item); } if (helpPath != null) { _mwvm.SelectedModule.ImportedFromHelp = true; XmlProcessor.ImportFromXml((String)helpPath, _mwvm.SelectedModule); } previousTab.Module = _mwvm.SelectedModule; _mwvm.SelectedModule = null; UIManager.ShowEditor(previousTab); } catch (Exception e) { Utils.MsgBox("Error while loading cmdlets", e.Message, MessageBoxButton.OK, MessageBoxImage.Error); _mwvm.SelectedTab.ErrorInfo = e.Message; UIManager.RestoreControl(previousTab, previousElement); } }
public MainViewModel([NotNull] ResourceManager resourceManager, [NotNull] Configuration configuration, [NotNull] ResourceViewModel resourceViewModel, [NotNull] ITracer tracer, [NotNull] SourceFilesProvider sourceFilesProvider) { ResourceManager = resourceManager; _configuration = configuration; _resourceViewModel = resourceViewModel; _tracer = tracer; _powerShell = new PowerShellProcessor(tracer); SourceFilesProvider = sourceFilesProvider; resourceManager.BeginEditing += ResourceManager_BeginEditing; resourceManager.Reloading += ResourceManager_Reloading; resourceManager.ProjectFileSaved += ResourceManager_ProjectFileSaved; try { var folder = Settings.Default.StartupFolder; if (string.IsNullOrEmpty(folder)) { return; } SourceFilesProvider.Folder = folder; if (Directory.Exists(folder)) { Load(); } } catch (Exception ex) { _tracer.TraceError(ex.ToString()); MessageBox.Show(ex.Message); } }
async void LoadModules(Object obj) { // method call from ICommand is allowed only when module selector is active // so skip checks. ClosableTabItem previousTab = _mwvm.SelectedTab; UIManager.ShowBusy(previousTab, Strings.InfoModuleListLoading); _mwvm.Modules.Clear(); try { IEnumerable <ModuleObject> data = obj == null ? await PowerShellProcessor.EnumModules(true) : await PowerShellProcessor.EnumModules(false); foreach (ModuleObject item in data) { _mwvm.Modules.Add(item); } } catch (Exception e) { Utils.MsgBox("Error", e.Message, MessageBoxButton.OK, MessageBoxImage.Error); previousTab.ErrorInfo = e.Message; } UIManager.ShowModuleList(previousTab); }
async void WindowInitialized(Object sender, EventArgs e) { ((MainWindowVM)DataContext).PsVersion = await PowerShellProcessor.GetPsVersion(); Settings.Default.Reload(); }