コード例 #1
0
        protected override void ProcessRecord()
        {
            if (Folder == null)
            {
                throw new ArgumentNullException(nameof(Folder));
            }
            if (Path == null)
            {
                throw new ArgumentNullException(nameof(Path));
            }

            if (!OverrideSealedFolder.IsPresent && Folder.IsSealed)
            {
                ThrowTerminatingError(new ErrorRecord(new InvalidOperationException("Target folder is set to sealed and -" + nameof(OverrideSealedFolder) + " is not present."), "ImageStore Remove Directory", ErrorCategory.SecurityError, Folder.Id));
            }

            if (!SkipFile.IsPresent)
            {
                string folderPath;

                if (Path == "")
                {
                    folderPath = Folder.Path;
                }
                else
                {
                    folderPath = Folder.Path + DirectorySeparatorString.Value + Path;
                }
                Directory.Delete(folderPath, true);
                WriteInformation("Directory " + folderPath + " is deleted.", new string[] { "RemoveDirectory" });
            }

            int result = FileHelper.Delete(Folder.Id, Path);

            if (result == 0)
            {
                WriteVerbose("No file is removed from database.");
            }
            else if (result == 1)
            {
                WriteVerbose("One file is removed from database.");
            }
            else
            {
                WriteVerbose(result.ToString() + " files are removed from database.");
            }
        }
コード例 #2
0
        protected override void ProcessRecord()
        {
            if (File != null)
            {
                Id = File.Id;
            }

            var connection = DatabaseConnection.Current;
            var fileName   = FileHelper.GetFileName(Id, out _, out _, out _, out var isFolderSealed, out var folderId);

            if (fileName == null)
            {
                ThrowTerminatingError(new ErrorRecord(new ArgumentException("File cannot be found.", nameof(Id)), "ImageStore Remove File", ErrorCategory.InvalidArgument, null));
            }
            if (!OverrideSealedFolder.IsPresent && isFolderSealed)
            {
                ThrowTerminatingError(new ErrorRecord(new InvalidOperationException("Folder containing this file is set to sealed and -" + nameof(OverrideSealedFolder) + " is not present."), "ImageStore Remove File", ErrorCategory.SecurityError, folderId));
            }

            if (!SkipFile.IsPresent)
            {
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.File.Delete(fileName);
                    WriteInformation("File " + fileName + " is deleted.", new string[] { "RemoveFile" });
                }
                else
                {
                    WriteWarning("File to be removing cannot be found. Path: " + fileName);
                }
            }

            if (!FileHelper.Delete(Id))
            {
                ThrowTerminatingError(new ErrorRecord(
                                          new InvalidOperationException("Cannot remove this file."),
                                          "ImageStore Remove File", ErrorCategory.WriteError, null));
            }
        }