示例#1
0
        protected string DeleteFiles(IPM pm, RArgs files, RArgs except = null)
        {
            if (files.Any(p => p.type != ArgumentType.StringDouble))
            {
                throw new PMArgException(files, "Input files. Define as {\"f1\", \"f2\", ...}");
            }

            if (except != null && except.Any(p => p.type != ArgumentType.StringDouble))
            {
                throw new PMArgException(except, "'except' argument. Define as {\"f1\", \"f2\", ...}");
            }

            string exs(string file, int idx)
            {
                if (!string.IsNullOrWhiteSpace(file))
                {
                    return(GetLocation(file));
                }
                throw new ArgumentException($"File name is empty. Fail in '{idx}' position.");
            }

            string[] input = files.Select((f, i) => exs((string)f.data, i)).ToArray().ExtractFiles(Exer.BasePath);
#if DEBUG
            LSender.Send(this, $"DeleteFiles: Found files `{string.Join(", ", input)}`", MsgLevel.Trace);
#endif
            if (except != null)
            {
                input = input.Except
                        (
                    except
                    .Where(f => !string.IsNullOrWhiteSpace((string)f.data))
                    .Select(f => GetLocation((string)f.data))
                    .ToArray()
                    .ExtractFiles(Exer.BasePath)
                        )
                        .ToArray();
            }

            if (input.Length < 1)
            {
                throw new PMArgException(files, "Input files was not found. Check your mask and the exception list if used.");
            }

            DeleteFiles(input);
            return(Value.Empty);
        }
示例#2
0
        protected string CopyFile(IPM pm, string src, string dest, bool overwrite, RArgs except = null)
        {
            if (string.IsNullOrWhiteSpace(src) || string.IsNullOrWhiteSpace(dest))
            {
                throw new ArgumentException("The source file or the destination path argument is empty.");
            }

            if (except != null && except.Any(p => p.type != ArgumentType.StringDouble))
            {
                throw new PMArgException(except, "'except' argument. Define as {\"f1\", \"f2\", ...}");
            }

            dest = GetLocation(dest.TrimEnd());
            string destDir  = Path.GetDirectoryName(dest);
            string destFile = Path.GetFileName(dest);

            src = GetLocation(src);
            string[] input = new[] { src }.ExtractFiles(Exer.BasePath);
#if DEBUG
            LSender.Send(this, $"Found files to copy `{string.Join(", ", input)}`", MsgLevel.Trace);
#endif
            if (except != null)
            {
                string path = Path.GetDirectoryName(src);
                input = input.Except
                        (
                    except
                    .Where(f => !string.IsNullOrWhiteSpace((string)f.data))
                    .Select(f => GetLocation((string)f.data, path))
                    .ToArray()
                    .ExtractFiles(Exer.BasePath)
                        )
                        .ToArray();
            }

            if (input.Length < 1)
            {
                throw new ArgumentException("The input files was not found. Check your mask and the exception list if used.");
            }

            CopyFile(destDir, destFile, overwrite, input);
            return(Value.Empty);
        }