private void AddContentFileExecute(object parameter) { DiagnosticsClient.TrackEvent("PackageViewModel_AddContentFileExecute"); try { var folder = (parameter ?? SelectedItem) as PackageFolder; AddExistingFileToFolder(folder ?? RootFolder); } catch (Exception e) { UIServices.Show(e.Message, MessageLevel.Error); } }
private void EditFileCommandExecute(PackagePart file) { // before editing file, try to commit metadata pending changes to avoid data loss if (IsInEditMetadataMode) { var isMetadataValid = ApplyEditExecute(); if (!isMetadataValid) { UIServices.Show(Resources.EditFormHasInvalidInput, MessageLevel.Error); return; } } FileEditorViewModel = new FileEditorViewModel(this, file as PackageFile); }
private void OpenContentFileExecute(object parameter) { try { parameter = parameter ?? SelectedItem; if (parameter is PackageFile file) { FileHelper.OpenFileInShell(file, UIServices); } } catch (Exception e) { UIServices.Show(e.Message, MessageLevel.Error); } }
private void PackageCommandExecute(LazyPackageCommand packageCommand) { var package = PackageHelper.BuildPackage(PackageMetadata, GetFiles()); try { packageCommand.Value.Execute(package, PackageSource); } catch (Exception ex) { UIServices.Show("The command failed with this error message:" + Environment.NewLine + Environment.NewLine + ex.Message, MessageLevel.Error); } }
private void ExportExecute() { if (_uiServices.OpenFolderDialog("Choose a folder to export package to:", _folderPath, out var rootPath)) { try { Export(rootPath); UIServices.Show(Resources.ExportPackageSuccess, MessageLevel.Information); } catch (Exception ex) { UIServices.Show(ex.Message, MessageLevel.Error); } _folderPath = rootPath; } }
private void OpenContentFileExecute(object?parameter) { DiagnosticsClient.TrackEvent("PackageViewModel_OpenContentFileExecute"); try { parameter ??= SelectedItem; if (parameter is PackageFile file) { FileHelper.OpenFileInShell(file, UIServices); } } catch (Exception e) { UIServices.Show(e.Message, MessageLevel.Error); } }
internal void ExportManifest(string fullpath, bool askForConfirmation = true, bool includeFilesSection = true) { if (File.Exists(fullpath) && askForConfirmation) { var confirmed = UIServices.Confirm( Resources.ConfirmToReplaceFile_Title, string.Format(CultureInfo.CurrentCulture, Resources.ConfirmToReplaceFile, fullpath)); if (!confirmed) { return; } } var rootPath = Path.GetDirectoryName(fullpath); using (Stream fileStream = File.Create(fullpath)) { var manifest = Manifest.Create(PackageMetadata); if (includeFilesSection) { var tempPath = Path.GetTempPath(); manifest.Files.AddRange(RootFolder.GetFiles().Select( f => new ManifestFile { Source = string.IsNullOrEmpty(f.OriginalPath()) || f.OriginalPath().StartsWith(tempPath, StringComparison.OrdinalIgnoreCase) ? f.Path : PathUtility.RelativePathTo(rootPath, f.OriginalPath()), Target = f.Path }) ); } using (var ms = new MemoryStream()) { try { manifest.Save(ms); ms.Position = 0; ManifestUtility.SaveToStream(ms, fileStream); } catch (Exception e) { UIServices.Show(e.Message, MessageLevel.Error); } } } }
private void PublishExecute() { if (!NetworkInterface.GetIsNetworkAvailable()) { UIServices.Show(Resources.NoNetworkConnection, MessageLevel.Warning); return; } // validate the package to see if there is any error before actually creating the package. var firstIssue = Validate().FirstOrDefault(p => p.Level == PackageIssueLevel.Error); if (firstIssue != null) { UIServices.Show( Resources.PackageCreationFailed + Environment.NewLine + Environment.NewLine + firstIssue.Description, MessageLevel.Warning); return; } try { using (var mruSourceManager = new MruPackageSourceManager( new PublishSourceSettings(SettingsManager))) { var publishPackageViewModel = new PublishPackageViewModel( mruSourceManager, SettingsManager, UIServices, _credentialPublishProvider, this); UIServices.OpenPublishDialog(publishPackageViewModel); } } catch (Exception e) { UIServices.Show(e.Message, MessageLevel.Error); } }
private void ExportExecute() { if (UIServices.OpenFolderDialog("Choose a folder to export package to:", _folderPath, out var rootPath)) { try { Export(rootPath); UIServices.Show(Resources.ExportPackageSuccess, MessageLevel.Information); } catch (Exception ex) { if (!(ex is IOException) && !(ex is ArgumentException) && !(ex is UnauthorizedAccessException)) { DiagnosticsClient.Notify(ex); } UIServices.Show(ex.Message, MessageLevel.Error); } _folderPath = rootPath; } }
private void SaveContentExecute(PackageFile file) { try { var title = "Save " + file.Name; const string filter = "All files (*.*)|*.*"; if (UIServices.OpenSaveFileDialog(title, file.Name, /* initial directory */ null, filter, /* overwritePrompt */ true, out var selectedFileName, out var filterIndex)) { using (var fileStream = File.Open(selectedFileName, FileMode.Create, FileAccess.Write, FileShare.Read)) using (var packageStream = file.GetStream()) { packageStream.CopyTo(fileStream); } } } catch (Exception e) { UIServices.Show(e.Message, MessageLevel.Error); } }
private void EditFileCommandExecute(PackagePart file) { DiagnosticsClient.TrackEvent("PackageViewModel_EditFileCommandExecute"); // before editing file, try to commit metadata pending changes to avoid data loss if (IsInEditMetadataMode) { var isMetadataValid = ApplyEditExecute(); if (!isMetadataValid) { UIServices.Show(Resources.EditFormHasInvalidInput, MessageLevel.Error); return; } } if (file is PackageFile f) { FileEditorViewModel = new FileEditorViewModel(this, f, UIServices); } else { FileEditorViewModel = null; } }