Example #1
0
 /// <inheritdoc/>
 public override string GetDefaultExtension(MediaType?mediaType) => Converters.Extension(mediaType);
Example #2
0
        /// <inheritdoc/>
        protected override bool ValidateAndSetParameters(string parameters)
        {
            // The string has to be valid by itself first
            if (string.IsNullOrWhiteSpace(parameters))
            {
                return(false);
            }

            // Now split the string into parts for easier validation
            // https://stackoverflow.com/questions/14655023/split-a-string-that-has-white-spaces-unless-they-are-enclosed-within-quotes
            parameters = parameters.Trim();
            List <string> parts = Regex.Matches(parameters, @"[\""].+?[\""]|[^ ]+")
                                  .Cast <Match>()
                                  .Select(m => m.Value)
                                  .ToList();

            // Determine what the commandline should look like given the first item
            int start = 0;

            BaseCommand = Converters.StringToCommand(parts[0]);
            if (BaseCommand != Command.NONE)
            {
                start = 1;
            }

            // Loop through all auxilary flags, if necessary
            int i = 0;

            for (i = start; i < parts.Count; i++)
            {
                // Flag read-out values
                long?  longValue   = null;
                string stringValue = null;

                // Keep a count of keys to determine if we should break out to filename handling or not
                int keyCount = Keys.Count();

                #region Boolean flags

                // Progress
                ProcessBooleanParameter(parts, FlagStrings.Progress, Flag.Progress, ref i);

                // Size
                ProcessBooleanParameter(parts, FlagStrings.Size, Flag.Size, ref i);

                #endregion

                #region Int64 flags

                // Block Size
                longValue = ProcessInt64Parameter(parts, FlagStrings.BlockSize, Flag.BlockSize, ref i);
                if (longValue == Int64.MinValue)
                {
                    return(false);
                }
                else if (longValue != null)
                {
                    BlockSizeValue = longValue;
                }

                // Count
                longValue = ProcessInt64Parameter(parts, FlagStrings.Count, Flag.Count, ref i);
                if (longValue == Int64.MinValue)
                {
                    return(false);
                }
                else if (longValue != null)
                {
                    CountValue = longValue;
                }

                // Seek
                longValue = ProcessInt64Parameter(parts, FlagStrings.Seek, Flag.Seek, ref i);
                if (longValue == Int64.MinValue)
                {
                    return(false);
                }
                else if (longValue != null)
                {
                    SeekValue = longValue;
                }

                // Skip
                longValue = ProcessInt64Parameter(parts, FlagStrings.Skip, Flag.Skip, ref i);
                if (longValue == Int64.MinValue)
                {
                    return(false);
                }
                else if (longValue != null)
                {
                    SkipValue = longValue;
                }

                #endregion

                #region String flags

                // Filter (fixed, removable, disk, partition)
                stringValue = ProcessStringParameter(parts, FlagStrings.Filter, Flag.Filter, ref i);
                if (!string.IsNullOrEmpty(stringValue))
                {
                    FilterValue = stringValue;
                }

                // Input File
                stringValue = ProcessStringParameter(parts, FlagStrings.InputFile, Flag.InputFile, ref i);
                if (string.Equals(stringValue, string.Empty))
                {
                    return(false);
                }
                else if (stringValue != null)
                {
                    InputFileValue = stringValue;
                }

                // Output File
                stringValue = ProcessStringParameter(parts, FlagStrings.OutputFile, Flag.OutputFile, ref i);
                if (string.Equals(stringValue, string.Empty))
                {
                    return(false);
                }
                else if (stringValue != null)
                {
                    OutputFileValue = stringValue;
                }

                #endregion
            }

            return(true);
        }
Example #3
0
        /// <inheritdoc/>
        public override string GenerateParameters()
        {
            List <string> parameters = new List <string>();

            if (BaseCommand != Command.NONE)
            {
                parameters.Add(Converters.LongName(BaseCommand));
            }

            #region Boolean flags

            // Progress
            if (GetSupportedCommands(Flag.Progress).Contains(BaseCommand))
            {
                if (this[Flag.Progress] == true)
                {
                    parameters.Add($"{this[Flag.Progress]}");
                }
            }

            // Size
            if (GetSupportedCommands(Flag.Size).Contains(BaseCommand))
            {
                if (this[Flag.Size] == true)
                {
                    parameters.Add($"{this[Flag.Size]}");
                }
            }

            #endregion

            #region Int64 flags

            // Block Size
            if (GetSupportedCommands(Flag.BlockSize).Contains(BaseCommand))
            {
                if (this[Flag.BlockSize] == true && BlockSizeValue != null)
                {
                    parameters.Add($"{Converters.LongName(Flag.BlockSize)}={BlockSizeValue}");
                }
            }

            // Count
            if (GetSupportedCommands(Flag.Count).Contains(BaseCommand))
            {
                if (this[Flag.Count] == true && CountValue != null)
                {
                    parameters.Add($"{Converters.LongName(Flag.Count)}={CountValue}");
                }
            }

            // Seek
            if (GetSupportedCommands(Flag.Seek).Contains(BaseCommand))
            {
                if (this[Flag.Seek] == true && SeekValue != null)
                {
                    parameters.Add($"{Converters.LongName(Flag.Seek)}={SeekValue}");
                }
            }

            // Skip
            if (GetSupportedCommands(Flag.Skip).Contains(BaseCommand))
            {
                if (this[Flag.Skip] == true && SkipValue != null)
                {
                    parameters.Add($"{Converters.LongName(Flag.Skip)}={SkipValue}");
                }
            }

            #endregion

            #region String flags

            // Filter
            if (GetSupportedCommands(Flag.Filter).Contains(BaseCommand))
            {
                if (this[Flag.Filter] == true && FilterValue != null)
                {
                    parameters.Add($"{Converters.LongName(Flag.Filter)}={FilterValue}");
                }
            }

            // Input File
            if (GetSupportedCommands(Flag.InputFile).Contains(BaseCommand))
            {
                if (this[Flag.InputFile] == true && InputFileValue != null)
                {
                    parameters.Add($"{Converters.LongName(Flag.InputFile)}={InputFileValue}");
                }
                else
                {
                    return(null);
                }
            }

            // Output File
            if (GetSupportedCommands(Flag.OutputFile).Contains(BaseCommand))
            {
                if (this[Flag.OutputFile] == true && OutputFileValue != null)
                {
                    parameters.Add($"{Converters.LongName(Flag.OutputFile)}={OutputFileValue}");
                }
                else
                {
                    return(null);
                }
            }

            #endregion

            return(string.Empty);
        }