コード例 #1
0
        private void AddBuildFileCommandExecute(string extension)
        {
            var fileName   = PackageMetadata.Id + extension;
            var sourcePath = FileHelper.CreateTempFile(fileName, Constants.ContentForBuildFile);

            if (SelectedItem is PackageFolder selectedFolder)
            {
                var file = selectedFolder.AddFile(sourcePath);
                // file can be null if it collides with other files in the same directory
                if (file != null)
                {
                    EditFileCommandExecute(file);
                }
            }
        }
コード例 #2
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();
        }
コード例 #3
0
        private void AddScriptCommandExecute(string scriptName)
        {
            var content = scriptName.Equals("init.ps1", StringComparison.OrdinalIgnoreCase)
                                 ? Constants.ContentForInit
                                 : Constants.ContentForInstall;
            var sourcePath = FileHelper.CreateTempFile(scriptName, content);

            if (SelectedItem is PackageFolder selectedFolder)
            {
                var file = selectedFolder.AddFile(sourcePath);
                // file can be null if it collides with other files in the same directory
                if (file != null)
                {
                    EditFileCommandExecute(file);
                }
            }
        }
コード例 #4
0
        private void AddNewFileToFolder(PackageFolder folder)
        {
            var result = UIServices.OpenRenameDialog(
                "NewFile.txt",
                "Provide name for the new file.",
                out var newName);

            if (result)
            {
                var sourcePath = FileHelper.CreateTempFile(newName);
                var file       = folder.AddFile(sourcePath);
                // file can be null if it collides with other files in the same directory
                if (file != null)
                {
                    EditFileCommandExecute(file);
                }
            }
        }
コード例 #5
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();
        }