public string GetFileDetailsUsingCommandLine(string[] arguments) { string strVersionOrSize = string.Empty; try { if (arguments != null) { string[] version = new string[] { "–v", "--v", "/v", "--version" }; string[] size = new string[] { "–s", "--s", "/s", "--size" }; if (version.Contains(arguments[0])) { Console.WriteLine("Version of the file is :" + _fileDetails.Version(arguments[1])); strVersionOrSize = _fileDetails.Version(arguments[1]); } if (size.Contains(arguments[0])) { Console.WriteLine("Size of the file is: " + _fileDetails.Size(arguments[1])); strVersionOrSize = _fileDetails.Size(arguments[1]).ToString(); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(strVersionOrSize); }
public static void Main(string[] args) { #region initialzation string sizeOrVersion = string.Empty; FileDetails fileDetails = new FileDetails(); //this can be injected if DI is implemented to follow SINGLE RESPONSIBILITY PRINCIPLE #endregion if (args.Length != 2) { Console.WriteLine("Please enter correct number of arguments. i.e. 2"); Console.ReadKey(); return; } //Format values are configured in app.config for flexibility in modifications wihout building code if (!validateArgSizeOrVersionFormat(args[0], out sizeOrVersion)) { Console.WriteLine("Please enter first argument from any of these values –v, --v, /v, --version or –s, --s, /s, --size"); Console.ReadKey(); return; } string filePath = args[1];//not validating this argument on purpose as mentioned in requirements Console.WriteLine(sizeOrVersion == SIZE ? "Size of file : " + fileDetails.Size(filePath).ToString() : "Version of file : " + fileDetails.Version(filePath)); //wait until key is pressed Console.ReadKey(); }
public static void Main(string[] args) { // string FilePath = @"D:\Backup"; string FilePath = ConfigurationSettings.AppSettings["FilePath"].ToString(); string version = string.Empty; int size = 0; FetchDetails fetchdetails = new FetchDetails(); FileDetails filedetails = new FileDetails(); DataTable dt = fetchdetails.PopulateFilesDetails(FilePath); var filenameversion = from row in dt.AsEnumerable() where row.Field <string>("File_Name").Contains(args[1]) select row.Field <string>("Version"); if (args[0].ToUpper().Contains("V") && filenameversion.Count() != 0) { version = filedetails.Version(FilePath + "\\" + args[1]); Console.WriteLine("The File is " + args[1] + " Version is " + version); } var filesize = from row in dt.AsEnumerable() where row.Field <string>("File_Name").Contains(args[1]) select row.Field <int>("Size"); if (args[0].ToUpper().Contains("S") && filesize.Count() != 0) { size = filedetails.Size(FilePath + "\\" + args[1]); Console.WriteLine("The File is " + args[1] + " Size is " + size); } Console.Read(); }
public static void Test(string Version, string Size) { try { String FilePath = @"C:\test.txt"; FileDetails FD = new FileDetails(); if (Version == "-v" || Version == "--v" || Version == "/v" || Version == "--Version") { Console.WriteLine("Version : " + FD.Version(FilePath)); } else { Console.WriteLine("Version cannot find"); } if (Size == "-s" || Size == "--s" || Size == "/s" || Size == "--size") { Console.WriteLine("File Size : " + FD.Size(FilePath)); } else { Console.WriteLine("File Size cannot find"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void Main(string[] args) { if (args.Length > 0 && args.Length == 2) { FileDetails objFileDetails = new FileDetails(); string[] arrVersion = new string[] { "-v", "--v", "/v", "--version" }; string[] arrSize = new string[] { "-s", "--s", "/s", "--size" }; if (Array.Exists(arrVersion, element => element.Equals(args[0].ToString()))) { Console.WriteLine("Version is : " + objFileDetails.Version(args[1]).ToString()); } else if (Array.Exists(arrSize, element => element.Equals(args[0].ToString()))) { Console.WriteLine("Size is : " + objFileDetails.Size(args[1])); } else { Console.WriteLine("Invalid input."); } } else { Console.WriteLine("Invalid number of arguments"); } }
public static string GetFileDetails(string strFunctionality, string strFilename) { try { //Getting Version and Size string[] arrVersion = Convert.ToString(ConfigurationManager.AppSettings["version"]).Split(','); string[] arrSize = Convert.ToString(ConfigurationManager.AppSettings["size"]).Split(','); string strFileDetails = string.Empty; FileDetails fileDetails = new FileDetails(); //Getting file version if (!string.IsNullOrEmpty(Array.Find(arrVersion, s => s.Equals(strFunctionality)))) { strFileDetails = "File Version: " + fileDetails.Version(strFilename); } //Getting file size else if (!string.IsNullOrEmpty(Array.Find(arrSize, s => s.Equals(strFunctionality)))) { strFileDetails = "File Size: " + fileDetails.Size(strFilename).ToString(); } else { throw new Exception("Invalid Functionality."); } return(strFileDetails); } catch (Exception Ex) { throw Ex; } }
/// <summary> /// Performs the required action; Version or Size. /// </summary> /// <param name="actionParameter">Parameter will dictate which action to perform</param> /// <param name="filename">dummy filename</param> /// <returns></returns> public T Action <T>(string actionParameter, string filename) { T actionResult; switch (actionParameter) { //Version action case "-v": case "--v": case "/v": case "--version": actionResult = (T)Convert.ChangeType(_fileDetails.Version(filename), typeof(T)); break; //Size action case "-s": case "--s": case "/s": case "--size": actionResult = (T)Convert.ChangeType(_fileDetails.Size(filename), typeof(T)); break; default: actionResult = default(T); //explicitally set the action to error state break; } return(actionResult); }
public static void Main(string[] args) { String [] versionSwitch = { "-v", "--v", "/v", "--version" }; String [] sizeSwitch = { "-s", "--s", "/s", "--size" }; FileDetails fileDets = new FileDetails(); if (args.Length != 2) { Console.WriteLine("Incorrect number of arguments"); return; } if (versionSwitch.Contains(args[0].ToString())) { Console.WriteLine(fileDets.Version(args[1].ToString())); return; } if (sizeSwitch.Contains(args[0].ToString())) { Console.WriteLine(fileDets.Size(args[1].ToString())); return; } }
public static void Main(string[] args) { Console.WriteLine("\nWhat is the functionality you would like to perform? "); string func = Console.ReadLine(); Console.WriteLine("\nWhat is the file name? "); string name = Console.ReadLine(); if (func == "–v" || func == "--v" || func == "/v" || func == "--version") { string version; FileDetails obj = new FileDetails(); version = obj.Version(name); Console.WriteLine($"The version of the file {name} is {version}"); } else if (func == "–s" || func == "--s" || func == "/s" || func == "--size") { int size; FileDetails obj = new FileDetails(); size = obj.Size(name); Console.WriteLine($"The size of the file {name} is {size}"); } Console.Write("\nPress any key to exit..."); Console.ReadKey(true); }
/// <summary> /// This function return file size /// </summary> /// <param name="size"></param> /// <param name="fileName"></param> /// <returns></returns> public static int GetFileSize(string size, string fileName) { //check file size format exists bool validSizeFormat = listSize.Any(s => s.Equals(size)); int fileSize = 0; FileDetails fileDetails; if (validSizeFormat && fileName.Trim().Length > 0) { try { fileDetails = new FileDetails(); fileSize = fileDetails.Size(fileName); return(fileSize); } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } finally { fileDetails = null; } } return(fileSize); }
public string PopulateFileData() { string Message = string.Empty; string versionorSize = string.Empty; try { Message = _objFileData.ValidateArgs(); //validate arguments... if (String.IsNullOrEmpty(Message)) { versionorSize = _objFileData.CheckForfunctionalityCall(); if (versionorSize == "v") { Message = "Version" + _objFileDetails.Version(FileName); } else { Message = "Size" + _objFileDetails.Size(FileName); } } } catch (Exception ex) { Message = ex.Message; } return(Message); }
public static string ProcessFile(CheckType checkType, string path) { var fileDetails = new FileDetails(); return(checkType == CheckType.version ? $"File Version: {fileDetails.Version(path)}" : $"File Size: {fileDetails.Size(path)}"); }
public string funcexecution(string ftype, string filename) { string returnValue; FileDetails obj = new FileDetails(); switch (ftype) { case "-v": returnValue = String.Format("File Version: {0}", obj.Version(filename)); break; case "--v": returnValue = String.Format("File Version: {0}", obj.Version(filename)); break; case "/v": returnValue = String.Format("File Version: {0}", obj.Version(filename)); break; case "--version": returnValue = String.Format("File Version: {0}", obj.Version(filename)); break; case "-s": returnValue = String.Format("File Size: {0}", obj.Size(filename)); break; case "--s": returnValue = String.Format("File Size: {0}", obj.Size(filename)); break; case "/s": returnValue = String.Format("File Size: {0}", obj.Size(filename)); break; case "--size": returnValue = String.Format("File Size: {0}", obj.Size(filename)); break; default: returnValue = string.Format("Please enter correct values {0}", ftype); break; } return(returnValue); }
public static string GetOutput(string identifier, string filepath) { string output = String.Empty; //Checking this condition if GetOutput method to be tested alone and throwing exception if (identifier == "" || filepath == "") { throw new Exception("identifier and filepath are mandatory"); //return output; } List <string> list1 = new List <string>(); List <string> list2 = new List <string>(); try { //Adding the items which will be used to get Version info list1.Add("-v"); list1.Add("--v"); list1.Add("/v"); list1.Add("--version"); //Adding the items which will be used ot get size info list2.Add("-s"); list2.Add("--s"); list2.Add("/s"); list2.Add("--size"); FileDetails filedetails = new FileDetails(); //Condition and call Version(filepath) method from FileDetails class to get Version info if (list1.Contains(identifier)) { output = filedetails.Version(filepath); } //Condition and call Version(filepath) method from FileDetails class to get Size info else if (list2.Contains(identifier)) { output = Convert.ToString(filedetails.Size(filepath)); } //Returning the output if correct identifier not passed else { output = "Incorrect identifier; Please check"; } } catch (Exception ex) { output = "Exception occurred: " + ex.Message + ".Please pass proper identifier"; } list1 = null; list2 = null; return(output); }
public static void Main(string[] args) { if (args.Length == 0) { System.Console.WriteLine("Please enter argument."); Console.ReadLine(); return; } if (args.Length > 2) { System.Console.WriteLine("Please enter a valid argument."); Console.ReadLine(); return; } string strArg1 = args[0]; string strArg2 = args[1]; if (!Utility.Utility.IsValidPath(strArg2)) { System.Console.WriteLine("Please enter a valid file Path."); Console.ReadLine(); return; } FileDetails fd = new FileDetails(); switch (strArg1.ToUpper()) { case "-V": System.Console.WriteLine(fd.Version(strArg2)); break; case "--V": System.Console.WriteLine(fd.Version(strArg2)); break; case "/V": System.Console.WriteLine(fd.Version(strArg2)); break; case "-S": System.Console.WriteLine(fd.Size(strArg2)); break; case "--S": System.Console.WriteLine(fd.Size(strArg2)); break; case "/S": System.Console.WriteLine(fd.Size(strArg2)); break; default: Console.WriteLine("Invalid selection."); break; } Console.ReadLine(); }
public static void Main(string[] args) { //args[0] = functionality to perform //args[1] = filename/filepath switch (Convert.ToString(args[0])) { case "-v": Console.WriteLine(Constant.Fileversion + _fileDetails.Version(args[1])); break; case "--v": Console.WriteLine(Constant.Fileversion + _fileDetails.Version(args[1])); break; case "v": Console.WriteLine(Constant.Fileversion + _fileDetails.Version(args[1])); break; case "--version": Console.WriteLine(Constant.Fileversion + _fileDetails.Version(args[1])); break; case "-s": Console.WriteLine(Constant.FileSize + _fileDetails.Size(args[1])); break; case "--s": Console.WriteLine(Constant.FileSize + _fileDetails.Size(args[1])); break; case "s": Console.WriteLine(Constant.FileSize + _fileDetails.Size(args[1])); break; case "--size": Console.WriteLine(Constant.FileSize + _fileDetails.Size(args[1])); break; default: break; } Console.WriteLine(Constant.EnterKey); Console.ReadKey(); }
public void LoadCommandsActions() { CommandsActions.Add(Repository.GetAllCommandOptionsByCommandName("Version").ToArray(), (options) => { return(FileDetails.Version(options[options.Length - 1])); }); CommandsActions.Add(Repository.GetAllCommandOptionsByCommandName("Size").ToArray(), (options) => { return(FileDetails.Size(options[options.Length - 1]).ToString()); }); }
/// <summary> /// Writes the output based on the parameters passed. /// </summary> /// <param name="args">Contains two arguments</param> /// <returns>Returns the result value</returns> /// public static string WriteOutPut(string[] args) { string returnValue = ""; //Checks arguments are passed if (args.Length > 0) { string[] version = { "-v", "--v", "/v", "--version" }; string[] fileSize = { "-s", "--s", "/s", "--size" }; FileDetails fileDetails = new FileDetails(); //Checks if version is looking for. if (version.Any(x => x == args[0])) { if (!string.IsNullOrEmpty(args[1])) { returnValue = fileDetails.Version(args[1]); } else { returnValue = fileDetails.Version(fileName); } } // checks if size is looking for. else if (fileSize.Any(x => x == args[0])) { if (!string.IsNullOrEmpty(args[1])) { returnValue = fileDetails.Size(args[1]).ToString(); } else { returnValue = fileDetails.Size(fileName).ToString(); } } Console.WriteLine(returnValue); // Console.ReadKey(); } return(returnValue); }
/// <summary> /// /// </summary> /// <param name="para"></param> /// <param name="filePath"></param> /// <returns></returns> public string GetFileSize(string para, string filePath) { if (_validSizePara.Contains(para + ",")) { //Could format the display to Gb, Mb return(ConvertFileSize(_fileDetail.Size(filePath))); } else { return("Invalid parameter. Paramemter shoul be one from the list " + _validSizePara.Substring(0, _validSizePara.Length - 1)); } }
/// <summary> /// Get file size. /// </summary> /// <param name="functionality">Funtionality to perform.</param> /// <param name="filename">Filename under test.</param> /// <returns>The size of the file.</returns> private static string GetSize(string functionality, string filename) { var result = string.Empty; if (functionality == "-s" || functionality == "--s" || functionality == "/s" || functionality == "--size") { FileDetails fd = new FileDetails(); int iSize = fd.Size(filename); result = iSize.ToString() + "B"; } return(result); }
public static void Main(string[] args) { _getFileVersion = false; _getFileSize = false; _filename = ""; bool suceessful = true; try { if (ParseArgs(args)) { FileDetails fd = new FileDetails(); if (_getFileSize) { int filesize = fd.Size(_filename); Console.WriteLine(String.Format("The file {0} has a size of {1}", _filename, filesize.ToString())); } else if (_getFileVersion) { string version = fd.Version(_filename); Console.WriteLine(String.Format("The file {0} has the version {1}", _filename, version.ToString())); } } else { Console.WriteLine("Error parsing parameters"); suceessful = false; } } catch (ArgumentException exarg) { Console.WriteLine(String.Format("Error passing parametsr due to {0}", exarg.Message)); suceessful = false; } catch (Exception ex) { Console.WriteLine(String.Format("Unhandled exeption due to {0}", ex.Message)); suceessful = false; } if (suceessful) { Console.WriteLine("Program completed successfully"); } Console.WriteLine("Press any ley to exit the program"); Console.Read(); }
public string GetAppropriateAction(string command, string fileName) { if (IsSizeTask(command)) { return(fileDetails.Size(fileName).ToString()); } else if (IsVersonTask(command)) { return(fileDetails.Version(fileName)); } else { throw new Exception("Command not recognised"); } }
/// <summary> /// calling appropriate filedetils class methods based on argument /// Check inputval exist in version and size array and call appropriate method /// </summary> /// <param name="inputVal"></param> /// <param name="fileName"></param> public static void FuncSizeVersion(string inputVal, string fileName) { if (Array.IndexOf(strVersion, inputVal) != -1) { Console.WriteLine(fd.Version(fileName)); } else if (Array.IndexOf(strSize, inputVal) != -1) { Console.WriteLine(fd.Size(fileName)); } else { Console.WriteLine("value not found"); } }
//function returns the values of size and version number based upon the input from filename public String GetFileData(Func <string> TestValue, String Filename) { FileDetails fileDetails = new FileDetails(); String returnvalue = null; if (TestValue.Equals("v")) { returnvalue = fileDetails.Version(Filename); } else if (TestValue.Equals("s")) { returnvalue = fileDetails.Size(Filename).ToString(); } return(returnvalue); }
/// <summary> /// Interperets the detailTypeString argument to provide the selected detail for the file at the given filePath /// </summary> /// <param name="detailTypeString"></param> /// <param name="filePath"></param> /// <returns></returns> public string GetDetail(string detailTypeString, string filePath) { var detailType = ParseDetailTypeString(detailTypeString); switch (detailType) { case DetailType.version: return(_fileDetails.Version(filePath)); case DetailType.size: return(_fileDetails.Size(filePath).ToString()); default: throw GetInvalidDetailTypeException(detailTypeString); } }
/// <summary> /// Get File Size Information /// </summary> public string GetFileSize() { string[] versionKeyWords = new string[] { "-s", "–s", "--s", "/s", "--size" }; try { if (ValidateData(versionKeyWords)) { return(string.Format("File Size: {0}", _fileDetails.Size(_args[1].Replace("’", "")))); } } catch (Exception ex) { return(string.Format("Error:{0}", ex.Message)); } return(string.Empty); }
public string Execute() { if (WrongNumberOfArguments) { return(""); } if (_versionArgs.Contains(Functionality)) { return(_fileDetails.Version(Filename)); } if (_sizeArgs.Contains(Functionality)) { return(_fileDetails.Size(Filename).ToString()); } return(""); }
public static void Main(string[] args) { String filePath = null; String requiresVersion = null; String requiresSize = null; //Check there is 3 arguments, else output below string to help user. if (args.Length < 3) { Console.WriteLine("Please enter a file name and at least 2 argument"); Console.WriteLine("–v, --v, /v, --version for file version | –s, --s, /s, --size for file size"); } else { //By using the for method, it doesnt matter what order the user inputs the arguments. foreach (var a in args) { //Assign File Path if (a.Contains(":\\")) { filePath = a; continue; } //Write File version if –v, --v, /v, --version is passed as an argument if (a.Contains("v") || a.Contains("version")) { requiresVersion = a; var fd = new FileDetails(); Console.WriteLine("File Version: " + fd.Version(filePath)); continue; } //Write file size if –s, --s, /s, --size is passed as an argument if (a.Contains("s") || a.Contains("size")) { requiresSize = a; var fd = new FileDetails(); Console.WriteLine("File Size: " + fd.Size(filePath)); } } } // Keep the console open. Console.ReadLine(); }
public static string ConvertInput(string[] args) { FileDetails fd = new FileDetails(); string str = args[0].Replace("-", "").Replace("/", "").ToLower(); if (str.StartsWith("v")) { Console.WriteLine("Version: " + fd.Version(args[1])); } else if (str.StartsWith("s")) { Console.WriteLine("Size: " + fd.Size(args[1])); } Console.ReadKey(); return(fd.Version(args[1]).ToString()); }
private string GetDetailsByArguments(IEnumerable <string> arguments, string filePath) { StringBuilder resultBuilder = new StringBuilder(); var sizeArgument = arguments.GetValidArguments(StaticPatterns.SizePatterns); var versionArgument = arguments.GetValidArguments(StaticPatterns.VersionPatterns); if (sizeArgument != null && sizeArgument.Count() != 0) { resultBuilder.AppendLine($"File size: {_fileDetailsManager.Size(filePath)}"); } if (versionArgument != null && versionArgument.Count() != 0) { resultBuilder.AppendLine($"File version: {_fileDetailsManager.Version(filePath)}"); } return(resultBuilder.ToString()); }