/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) hashCode = hashCode * 59 + Status.GetHashCode(); if (Type != null) { hashCode = hashCode * 59 + Type.GetHashCode(); } if (Title != null) { hashCode = hashCode * 59 + Title.GetHashCode(); } if (MissingParams != null) { hashCode = hashCode * 59 + MissingParams.GetHashCode(); } if (InvalidParams != null) { hashCode = hashCode * 59 + InvalidParams.GetHashCode(); } return(hashCode); } }
/// <summary>Performs static members initialization / clean-up.</summary> private static void PreParsingLogic() { // If ArgumentValueData is not initialized then initialize it // else clear it. if (ArgumentValueData == null) { ArgumentValueData = new Dictionary <string, string>(); } else { ArgumentValueData.Clear(); } // Add default packing type value as Vertical ArgumentValueData.Add(PackingScheme, Vertical); // Add default sprite name ArgumentValueData.Add(SpriteName, DefaultSpriteName); // Add default dedup as False ArgumentValueData.Add(Dedup, "False"); // Add default value for Padding ArgumentValueData.Add(Padding, DefaultPadding.ToString(CultureInfo.InvariantCulture)); // Clear InputImageList if it is not null if (inputImageList != null && inputImageList.Count > 0) { inputImageList.Clear(); } // Arraylist that will hold the missing parameters. First all mandatory parameters // are added to it and as they are parsed removed from the list so the remaining // members in arraylist at the end of parsing are missing. if (MissingParams == null) { MissingParams = new ArrayList(); } else { MissingParams.Clear(); } MissingParams.Add(DirectoryOrFileName); MissingParams.Add(OutputDirectory); MissingParams.Add(XmlMapName); MissingParams.Add(ArgumentParser.Padding); }
/// <summary> /// Returns true if BadRequestError instances are equal /// </summary> /// <param name="other">Instance of BadRequestError to be compared</param> /// <returns>Boolean</returns> public bool Equals(BadRequestError other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Status == other.Status || Status.Equals(other.Status) ) && ( Type == other.Type || Type != null && Type.Equals(other.Type) ) && ( Title == other.Title || Title != null && Title.Equals(other.Title) ) && ( MissingParams == other.MissingParams || MissingParams != null && other.MissingParams != null && MissingParams.SequenceEqual(other.MissingParams) ) && ( InvalidParams == other.InvalidParams || InvalidParams != null && other.InvalidParams != null && InvalidParams.SequenceEqual(other.InvalidParams) )); }
/// <summary>Parses command line parameters and generates a list of image paths from it.</summary> /// <remarks>/inputdirectory and /inputfilepaths overrides inputImages parameter. /// i.e. When inputImages parameters is provided, its value will be used only when /// /inputdirectory and /inputfilepaths are not present in input parameters.</remarks> /// <param name="input">string array of input parameters.</param> /// <param name="inputImages">InputImage List that will be passed by ImageAssembleTask. For all other callers (Console App), this value will be NULL.</param> internal static void ParseArguments(string[] input, IList <InputImage_Accessor> inputImages) { var usage = string.Format(CultureInfo.CurrentCulture, ImageAssembleStrings.ToolUsageMessage, ArgumentParser.DefaultPadding.ToString(CultureInfo.CurrentCulture), ArgumentParser.MinPadding.ToString(CultureInfo.CurrentCulture), ArgumentParser.MaxPadding.ToString(CultureInfo.CurrentCulture)); // Check if arguments are provided if (input == null || input.Length == 0) { throw new ImageAssembleException(string.Format(CultureInfo.CurrentCulture, ImageAssembleStrings.NoInputParametersMessage, usage)); } else { // Check if duplicate input image parameters are present CheckImageFilesDuplicateParameter(input); // Perform some clean-up and/or initialization PreParsingLogic(); // Set InputImageList if it is passed as parameter to this method if (inputImages != null) { inputImageList = inputImages; } foreach (var ar in input) { if (ar.StartsWith(DirectoryName, StringComparison.OrdinalIgnoreCase) || ar.StartsWith(ShorthandInputDirectory, StringComparison.OrdinalIgnoreCase)) { // Directory name parsing var dirName = ParseParameterValueFromArg(ar, DirectoryName, ShorthandInputDirectory); ParseDirectoryValue(dirName, DirectoryName); MissingParams.Remove(DirectoryOrFileName); } else if (ar.StartsWith(Paths, StringComparison.OrdinalIgnoreCase) || ar.StartsWith(ShorthandInputFilePaths, StringComparison.OrdinalIgnoreCase)) { // Input string is semicolon separated file paths // e.g. /i:C:\Users\v-niravd\Documents\Test\Images\Input\pic_karate.gif;C:\Users\v-niravd\Documents\Test\Images\Input\vaio.gif var filePaths = ParseParameterValueFromArg(ar, Paths, ShorthandInputFilePaths); ParseInputFilePaths(filePaths); MissingParams.Remove(DirectoryOrFileName); } else if (ar.StartsWith(OutputDirectory, StringComparison.OrdinalIgnoreCase)) { // Directory name parsing var outputDir = string.Empty; outputDir = ar.Substring(OutputDirectory.Length).Trim(); ParseDirectoryValue(outputDir, OutputDirectory); MissingParams.Remove(OutputDirectory); } else if (ar.StartsWith(PackingScheme, StringComparison.OrdinalIgnoreCase) || ar.StartsWith(ShorthandPackingScheme, StringComparison.OrdinalIgnoreCase)) { // Packing type parsing var packing = ParseParameterValueFromArg(ar, PackingScheme, ShorthandPackingScheme); if (!string.IsNullOrEmpty(packing)) { if (packing.Equals(Horizontal, StringComparison.OrdinalIgnoreCase) || packing.Equals(Vertical, StringComparison.OrdinalIgnoreCase)) { ArgumentValueData[PackingScheme] = packing; } else { ArgumentValueData.Remove(PackingScheme); throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, ImageAssembleStrings.InvalidInputParameterValueMessage, PackingScheme)); } } else { ArgumentValueData.Remove(PackingScheme); throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, ImageAssembleStrings.ValueMissingForInputParameterMessage, PackingScheme)); } } else if (ar.StartsWith(SpriteName, StringComparison.OrdinalIgnoreCase) || ar.StartsWith(ShorthandSpriteImage, StringComparison.OrdinalIgnoreCase)) { // Sprite name parsing var spriteName = ParseParameterValueFromArg(ar, SpriteName, ShorthandSpriteImage); if (!string.IsNullOrEmpty(spriteName)) { ArgumentValueData[SpriteName] = spriteName; } else { ArgumentValueData.Remove(SpriteName); throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, ImageAssembleStrings.ValueMissingForInputParameterMessage, SpriteName)); } } else if (ar.StartsWith(XmlMapName, StringComparison.OrdinalIgnoreCase) || ar.StartsWith(ShorthandLogFile, StringComparison.OrdinalIgnoreCase)) { // Xml map file name parsing var mapFileName = ParseParameterValueFromArg(ar, XmlMapName, ShorthandLogFile); MissingParams.Remove(XmlMapName); ParseLogFile(mapFileName); } else if (ar.StartsWith(ArgumentParser.Padding, StringComparison.OrdinalIgnoreCase) || ar.StartsWith(ShorthandPadding, StringComparison.OrdinalIgnoreCase)) { // Padding parsing var padding = ParseParameterValueFromArg(ar, ArgumentParser.Padding, ShorthandPadding); MissingParams.Remove(ArgumentParser.Padding); ParsePaddingValue(padding); } else if (ar.StartsWith(Dedup, StringComparison.OrdinalIgnoreCase) || ar.StartsWith(ShorthandDedup, StringComparison.OrdinalIgnoreCase)) { // Dedup parsing var dedup = ParseParameterValueFromArg(ar, ArgumentParser.Dedup, ShorthandDedup); MissingParams.Remove(ArgumentParser.Dedup); ParseDedupValue(dedup); } else if (ar.StartsWith(Question, StringComparison.OrdinalIgnoreCase) || ar.StartsWith(Help, StringComparison.OrdinalIgnoreCase)) { continue; } else { // unknown input parameter var paramName = ar.Substring(0, ar.IndexOf(":", StringComparison.OrdinalIgnoreCase) + 1); throw new ImageAssembleException(string.Format(CultureInfo.CurrentUICulture, ImageAssembleStrings.InvalidInputParameterMessage, paramName)); } } // Check missing parameters CheckMissingParameters(usage); } }