Inheritance: PackageExplorerViewModel.ViewModelBase
Ejemplo n.º 1
0
        private PackageFile(IPackageFile file, string name, PackageFolder parent, PackageViewModel viewModel)
            : base(name, parent, viewModel)
        {
            if (file == null) {
                throw new ArgumentNullException("file");
            }

            _file = file;
        }
        public PackageMetadataFile(string name, string filePath, PackageViewModel packageViewModel)
        {
            Debug.Assert(name != null);
            Debug.Assert(filePath != null);
            Debug.Assert(packageViewModel != null);

            _filePath = filePath;
            _name = name;
            _packageViewModel = packageViewModel;
        }
Ejemplo n.º 3
0
        protected PackagePart(string name, PackageFolder parent, PackageViewModel viewModel)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            _viewModel = viewModel ?? throw new ArgumentNullException("viewModel");
            _parent    = parent;

            OnNameChange(name);
            RecalculatePath();
        }
Ejemplo n.º 4
0
#pragma warning disable CS8618 // Non-nullable field is uninitialized.
        protected PackagePart(string name, PackageFolder?parent, PackageViewModel viewModel)
#pragma warning restore CS8618 // Non-nullable field is uninitialized.
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            PackageViewModel = viewModel ?? throw new ArgumentNullException("viewModel");
            _parent          = parent;

            OnNameChange(name);
            RecalculatePath();
        }
 public PublishPackageViewModel(
     MruPackageSourceManager mruSourceManager,
     ISettingsManager settingsManager,
     CredentialPublishProvider credentialPublishProvider,
     PackageViewModel viewModel)
 {
     _mruSourceManager          = mruSourceManager;
     _settingsManager           = settingsManager;
     _credentialPublishProvider = credentialPublishProvider;
     _package            = viewModel.PackageMetadata;
     _packageFilePath    = viewModel.GetCurrentPackageTempFile();
     SelectedPublishItem = _mruSourceManager.ActivePackageSource;
     PublishAsUnlisted   = _settingsManager.PublishAsUnlisted;
 }
Ejemplo n.º 6
0
        public void RemoveChild(PackagePart child)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }

            bool removed = Children.Remove(child);

            if (removed)
            {
                PackageViewModel.NotifyChanges();
            }
        }
        internal FileEditorViewModel(PackageViewModel packageViewModel, IEditablePackageFile fileInEdit)
        {
            Debug.Assert(packageViewModel != null);
            Debug.Assert(fileInEdit != null);

            _packageViewModel = packageViewModel;
            _fileInEdit       = fileInEdit;

            // Note: has to preserve the file name here so that the new file "appears" to be the same as old file
            _filePath = fileInEdit.OriginalPath ?? Path.Combine(FileHelper.GetTempFilePath(), fileInEdit.Name);

            _closeCommand = new RelayCommand <IFileEditorService>(CloseExecute);
            _saveCommand  = new RelayCommand <IFileEditorService>(SaveExecute);
        }
        internal FileEditorViewModel(PackageViewModel packageViewModel, IEditablePackageFile fileInEdit)
        {
            Debug.Assert(packageViewModel != null);
            Debug.Assert(fileInEdit != null);

            _packageViewModel = packageViewModel;
            _fileInEdit = fileInEdit;

            // Note: has to preserve the file name here so that the new file "appears" to be the same as old file
            _filePath = fileInEdit.OriginalPath ?? Path.Combine(FileHelper.GetTempFilePath(), fileInEdit.Name);

            _closeCommand = new RelayCommand<IFileEditorService>(CloseExecute);
            _saveCommand = new RelayCommand<IFileEditorService>(SaveExecute);
        }
        public bool Save(string editedFilePath)
        {
            if (!string.Equals(OriginalPath, editedFilePath, StringComparison.OrdinalIgnoreCase))
            {
                ReplaceWith(editedFilePath);
            }
            else if (PackageViewModel.IsShowingFileContent(this))
            {
                // force a refresh to show new content
                PackageViewModel.ShowFileContent(this);
            }

            return(true);
        }
Ejemplo n.º 10
0
        public void RemoveChild(PackagePart child)
        {
            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            var removed = Children.Remove(child);

            if (removed)
            {
                child.Dispose();
                PackageViewModel.NotifyChanges();
            }
        }
Ejemplo n.º 11
0
        public static PackageFolder Convert(List<IPackageFile> paths, PackageViewModel viewModel)
        {
            if (paths == null) {
                throw new ArgumentNullException("paths");
            }

            paths.Sort((p1, p2) => String.Compare(p1.Path, p2.Path, StringComparison.OrdinalIgnoreCase));

            PackageFolder root = new PackageFolder("", viewModel);

            List<Tuple<IPackageFile, string[]>> parsedPaths = paths.Select(p => Tuple.Create(p, p.Path.Split('\\'))).ToList();
            Parse(root, parsedPaths, 0, 0, parsedPaths.Count);

            return root;
        }
Ejemplo n.º 12
0
        public PackageFolder AddFolder(string folderName)
        {
            if (ContainsFolder(folderName) || ContainsFile(folderName))
            {
                PackageViewModel.UIServices.Show(Resources.RenameCausesNameCollison, Types.MessageLevel.Error);
                return(null);
            }
            var newFolder = new PackageFolder(folderName, this);

            Children.Add(newFolder);
            newFolder.IsSelected = true;
            this.IsExpanded      = true;
            PackageViewModel.NotifyChanges();
            return(newFolder);
        }
Ejemplo n.º 13
0
        public void AddFile(PackageFile file, bool makeCopy = false)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (Contains(file))
            {
                return;
            }

            PackagePart newFile;

            if (makeCopy)
            {
                string fileCopyPath;
                using (Stream originalFileStream = file.GetStream())
                {
                    fileCopyPath = FileHelper.CreateTempFile(file.Name, originalFileStream);
                }

                string newTargetPath = this.Path + "\\" + file.Name;
                var    physicalFile  = new PhysicalPackageFile
                {
                    SourcePath = fileCopyPath,
                    TargetPath = newTargetPath
                };

                newFile = new PackageFile(physicalFile, file.Name, this);
            }
            else
            {
                // detach from current parent
                if (file.Parent != null)
                {
                    file.Parent.Detach(file);
                }

                newFile = file;
            }

            Attach(newFile);
            newFile.IsSelected = true;
            IsExpanded         = true;
            PackageViewModel.NotifyChanges();
        }
Ejemplo n.º 14
0
        private PackageFile(IPackageFile file, string name, PackageFolder parent, PackageViewModel viewModel)
            : base(name, parent, viewModel)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            _file = file;

            var physicalFile = file as PhysicalPackageFile;
            if (physicalFile != null)
            {
                WatchPhysicalFile(physicalFile);
            }
            ReplaceCommand = new RelayCommand(Replace, () => !viewModel.IsInEditFileMode);
        }
Ejemplo n.º 15
0
        public static PackageFolder Convert(List <IPackageFile> paths, PackageViewModel viewModel)
        {
            if (paths == null)
            {
                throw new ArgumentNullException("paths");
            }

            paths.Sort((p1, p2) => String.Compare(p1.Path, p2.Path, StringComparison.OrdinalIgnoreCase));

            PackageFolder root = new PackageFolder("", viewModel);

            List <Tuple <IPackageFile, string[]> > parsedPaths = paths.Select(p => Tuple.Create(p, p.Path.Split('\\'))).ToList();

            Parse(root, parsedPaths, 0, 0, parsedPaths.Count);

            return(root);
        }
Ejemplo n.º 16
0
        public void Delete()
        {
            bool confirm = PackageViewModel.UIServices.Confirm(
                String.Format(CultureInfo.CurrentCulture, Resources.ConfirmToDeleteContent, Name),
                isWarning: true);

            if (!confirm)
            {
                return;
            }

            if (Parent != null)
            {
                Parent.Children.Remove(this);
                PackageViewModel.NotifyContentDeleted(this);
            }
        }
Ejemplo n.º 17
0
        public void Rename(string newName)
        {
            if (Name != newName)
            {
                if (Parent != null)
                {
                    if (Parent.ContainsFile(newName) || Parent.ContainsFolder(newName))
                    {
                        PackageViewModel.UIServices.Show(Resources.RenameCausesNameCollison, Types.MessageLevel.Error);
                        return;
                    }
                }

                Name = newName;
                PackageViewModel.NotifyChanges();
            }
        }
Ejemplo n.º 18
0
        protected PackagePart(string name, PackageFolder parent, PackageViewModel viewModel)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }

            _viewModel = viewModel;
            _parent    = parent;
            _name      = name;
            RecalculatePath();
        }
Ejemplo n.º 19
0
        private PackageFile(IPackageFile file, string name, PackageFolder parent, PackageViewModel viewModel)
            : base(name, parent, viewModel)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            _file = file;

            var physicalFile = file as PhysicalPackageFile;

            if (physicalFile != null)
            {
                WatchPhysicalFile(physicalFile);
            }
            ReplaceCommand = new RelayCommand(Replace, () => !viewModel.IsReadOnly && !viewModel.IsInEditFileMode);
        }
        public SymbolValidator(PackageViewModel packageViewModel, IPackage package)
        {
            _packageViewModel = packageViewModel ?? throw new ArgumentNullException(nameof(packageViewModel));
            _package          = package;
            _packageViewModel.PropertyChanged += _packageViewModel_PropertyChanged;

            SourceLinkResult    = SymbolValidationResult.Pending;
            DeterministicResult = DeterministicResult.Pending;

            // NuGet signs all its packages and stamps on the service index. Look for that.
            if (package is ISignaturePackage sigPackage)
            {
                if (sigPackage.RepositorySignature?.V3ServiceIndexUrl?.AbsoluteUri.Contains(".nuget.org/", StringComparison.OrdinalIgnoreCase) == true)
                {
                    _publishedOnNuGetOrg = true;
                }
            }
        }
        public SignPackageViewModel(PackageViewModel viewModel, IUIServices uiServices, ISettingsManager settingsManager)
        {
            _uiServices       = uiServices;
            _settingsManager  = settingsManager;
            _packageViewModel = viewModel;

            SelectCertificateFileCommand  = new RelayCommand(SelectCertificateFileCommandExecute);
            SelectCertificateStoreCommand = new RelayCommand(SelectCertificateStoreCommandExecute);
            ShowCertificateCommand        = new RelayCommand(ShowCertificateCommandExecute);

            if (!string.IsNullOrEmpty(settingsManager.SigningCertificate))
            {
                if (File.Exists(settingsManager.SigningCertificate))
                {
                    CertificateFileName = settingsManager.SigningCertificate;
                }
                else
                {
                    try
                    {
                        using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
                        {
                            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

                            var certificates = store.Certificates.Find(X509FindType.FindByThumbprint, settingsManager.SigningCertificate, validOnly: true);

                            if (certificates.Count > 0)
                            {
                                Certificate         = certificates[0];
                                CertificateFileName = null;
                            }
                        }
                    }
                    catch { }
                }
            }

            TimestampServer = settingsManager.TimestampServer;

            if (Enum.TryParse(settingsManager.SigningHashAlgorithmName, out HashAlgorithmName hashAlgorithmName))
            {
                _hashAlgorithmName = hashAlgorithmName;
            }
        }
Ejemplo n.º 22
0
        public void Rename(string newName)
        {
            if (!Name.Equals(newName, StringComparison.Ordinal))
            {
                if (Parent != null)
                {
                    if (!Name.Equals(newName, StringComparison.OrdinalIgnoreCase) &&
                        (Parent.ContainsFile(newName) || Parent.ContainsFolder(newName)))
                    {
                        PackageViewModel.UIServices.Show(
                            string.Format(CultureInfo.CurrentCulture, Resources.RenameCausesNameCollison, newName),
                            MessageLevel.Error);
                        return;
                    }
                }

                Name = newName;
                PackageViewModel.NotifyContentRenamed(this);
            }
        }
Ejemplo n.º 23
0
 public PublishPackageViewModel(
     MruPackageSourceManager mruSourceManager,
     ISettingsManager settingsManager,
     IUIServices uiServices,
     CredentialPublishProvider credentialPublishProvider,
     PackageViewModel viewModel)
 {
     if (viewModel is null)
     {
         throw new ArgumentNullException(nameof(viewModel));
     }
     _mruSourceManager          = mruSourceManager ?? throw new ArgumentNullException(nameof(mruSourceManager));
     _settingsManager           = settingsManager ?? throw new ArgumentNullException(nameof(settingsManager));
     _uiServices                = uiServices ?? throw new ArgumentNullException(nameof(uiServices));
     _credentialPublishProvider = credentialPublishProvider ?? throw new ArgumentNullException(nameof(credentialPublishProvider));
     _package            = viewModel.PackageMetadata;
     _packageFilePath    = viewModel.GetCurrentPackageTempFile();
     SelectedPublishItem = _mruSourceManager.ActivePackageSource;
     PublishAsUnlisted   = _settingsManager.PublishAsUnlisted;
 }
Ejemplo n.º 24
0
        public void Delete(bool requireConfirmation = true)
        {
            if (requireConfirmation)
            {
                var confirm = PackageViewModel.UIServices.Confirm(
                    Resources.ConfirmToDeleteContent_Title,
                    string.Format(CultureInfo.CurrentCulture, Resources.ConfirmToDeleteContent, Name),
                    isWarning: true);

                if (!confirm)
                {
                    return;
                }
            }

            if (Parent != null)
            {
                Parent.RemoveChild(this);
                PackageViewModel.NotifyContentDeleted(this);
            }
        }
Ejemplo n.º 25
0
        public void AddFile(PackageFile file, bool makeCopy = false)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            if (Contains(file))
            {
                return;
            }

            PackagePart newFile;

            if (makeCopy)
            {
                string fileCopyPath;
                using (var originalFileStream = file.GetStream())
                {
                    fileCopyPath = FileHelper.CreateTempFile(file.Name, originalFileStream);
                }

                var newTargetPath = Path + "\\" + file.Name;
                var physicalFile  = new DiskPackageFile(newTargetPath, fileCopyPath);

                newFile = new PackageFile(physicalFile, file.Name, this);
            }
            else
            {
                ((PackageFolder?)file.Parent)?.Detach(file);

                newFile = file;
            }

            Attach(newFile);
            newFile.IsSelected = true;
            IsExpanded         = true;
            PackageViewModel?.NotifyChanges();
        }
Ejemplo n.º 26
0
        internal void ReplaceFile(PackageFile oldFile, string newFilePath)
        {
            var showingFile = PackageViewModel.IsShowingFileContent(oldFile);

            // temporarily remove the old file in order to add a new file
            Children.Remove(oldFile);

            var newFile = AddFile(newFilePath, isTempFile: false);
            if (newFile != null)
            {
                // new file added successfully, officially delete the old file by disposing it
                oldFile.Dispose();

                if (showingFile)
                {
                    PackageViewModel.ShowFileContent(newFile);
                }
            }
            else
            {
                // otherwise, if the adding failed, restore the old file
                Children.Add(oldFile);
            }
        }
Ejemplo n.º 27
0
        public async Task <PackageViewModel> CreateViewModel(IPackage package, string packagePath, string packageSource)
        {
            // If it's a zip package, we need to load the verification data so it's ready for later
            if (package is ISignaturePackage zip)
            {
                await zip.LoadSignatureDataAsync();
            }

            var pvm = new PackageViewModel(
                package,
                packagePath,
                packageSource,
                MruManager,
                UIServices,
                EditorService.Value,
                SettingsManager,
                CredentialPublishProvider,
                ContentViewerMetadata,
                PackageRules);

            DiagnosticsClient.TrackEvent("PackageViewModelFactory_CreateViewModel", package, pvm.PublishedOnNuGetOrg);

            return(pvm);
        }
Ejemplo n.º 28
0
 public SavePackageCommand(PackageViewModel model)
     : base(model)
 {
 }
Ejemplo n.º 29
0
 public PackageFile(IPackageFile file, string name, PackageViewModel viewModel)
     : this(file, name, null, viewModel)
 {
 }
 public ViewContentCommand(PackageViewModel packageViewModel)
     : base(packageViewModel)
 {
 }
Ejemplo n.º 31
0
 public PackageFolder(string name, PackageViewModel viewModel)
     : base(name, null, viewModel)
 {
     Children = new SortedCollection <PackagePart>();
 }
 public SavePackageCommand(PackageViewModel model)
     : base(model)
 {
 }
Ejemplo n.º 33
0
 public PackageFile(IPackageFile file, string name, PackageViewModel viewModel)
     : this(file, name, null, viewModel)
 {
 }
Ejemplo n.º 34
0
 public ViewContentCommand(PackageViewModel packageViewModel)
     : base(packageViewModel)
 {
 }
 public PackageFolder(string name, PackageViewModel viewModel)
     : base(name, null, viewModel)
 {
     Children = new SortedCollection<PackagePart>();
 }