Exemple #1
0
        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();
        }
Exemple #2
0
        /// <summary>
        /// this function return file version
        /// </summary>
        /// <param name="version"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetFileVersion(string version, string fileName)
        {
            string fileVersion = string.Empty;

            //check file version format exists
            bool validSizeFormat = listVersion.Any(s => s.Equals(version));

            if (validSizeFormat && fileName.Trim().Length > 0)
            {
                FileDetails fileDetails;
                try
                {
                    fileDetails = new FileDetails();
                    fileVersion = fileDetails.Version(fileName);
                    return(fileVersion);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message.ToString());
                }
                finally
                {
                    fileDetails = null;
                }
            }

            return(fileVersion);
        }
Exemple #3
0
        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();
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        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());
            }
        }
Exemple #6
0
 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");
     }
 }
Exemple #7
0
        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;
            }
        }
Exemple #8
0
 public FileDataUtility(IParser parser, IRepository repository)
 {
     CommandLineParser = parser;
     Repository        = repository;
     CommandsActions   = new Dictionary <string[], Func <string[], string> >();
     FileDetails       = new FileDetails();
 }
Exemple #9
0
        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);
        }
Exemple #10
0
 public bool ProcessFile(string[] args)
 {
     Log.Debug("File Processing Started..");
     if (args.Length != 2)
     {
         return(false);
     }
     if (_fileVersions.Exists(x => x == args[0]))
     {
         Log.Debug("Argument is of type 'Version'");
         var versionDetails = new FileDetails().Version(args[1]);
         Log.Debug($"Version {versionDetails} retrived");
         return(true);
     }
     if (!_fileSizes.Exists(x => x == args[0]))
     {
         return(false);
     }
     {
         Log.Debug("Argument is of type 'Size'");
         var sizeDetails = new FileDetails().Size(args[1]);
         Log.Debug($"Size {sizeDetails} retrived");
         return(true);
     }
 }
        public static void Main(string[] args)
        {
            var fileDetails = new FileDetails();

            try
            {
                if (args != null)
                {
                    if (args.Length == 2)
                    {
                        FileAction fileAction = new FileAction(
                            new VersionProperty(fileDetails),
                            new SizeProperty(fileDetails),
                            new DataGenerator()
                            );

                        var response = fileAction.PerformAction(args[0], args[1]);
                        Console.WriteLine(response);
                    }
                    else
                    {
                        throw new ArgumentNullException($"{args} is not found");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }
        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;
            }
        }
Exemple #13
0
        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)}");
        }
Exemple #14
0
        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);
        }
Exemple #15
0
        public static void Main(string[] args)
        {
            // Would prefer doing Dependency injection
            FileDetails     fileDetails     = new FileDetails();
            FileDataManager fileDataManager = new FileDataManager(fileDetails);
            var             result          = fileDataManager.GetFileData(args);

            Console.WriteLine(result);
            Console.ReadLine();
        }
Exemple #16
0
        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());
            });
        }
Exemple #17
0
        /// <summary>
        /// Get file version.
        /// </summary>
        /// <param name="functionality">Funtionality to perform.</param>
        /// <param name="filename">Filename under test.</param>
        /// <returns>The version of the file.</returns>
        private static string GetVersion(string functionality, string filename)
        {
            var result = string.Empty;

            if (functionality == "-v" || functionality == "--v" ||
                functionality == "/v" || functionality == "--version")
            {
                FileDetails fd = new FileDetails();
                result = fd.Version(filename);
            }

            return(result);
        }
Exemple #18
0
        public static void Main(string[] args)
        {
            try
            {
                var verList  = ConfigurationManager.AppSettings["Size"];    // get the size parameter formats
                var sizeList = ConfigurationManager.AppSettings["Version"]; //get the version parameter formats

                List <string> verLst  = verList.Split(',').ToList <string>();
                List <string> sizeLst = sizeList.Split(',').ToList <string>();

                FileDetails objFileDetails = new FileDetails();

                if (args.Length > 0)
                {
                    if (args[0] != string.Empty)
                    {
                        if (verLst.Contains(args[0]))
                        {
                            // call version
                            Console.WriteLine(ConfigurationManager.AppSettings["FileVerMsg"].ToString());
                            Console.WriteLine(ConfigurationManager.AppSettings["FileNameMsg"].ToString(), args[1]);
                            Console.WriteLine(ConfigurationManager.AppSettings["FileVersionMsg"].ToString(), objFileDetails.Version(args[1]));
                        }

                        else if (sizeLst.Contains(args[0]))
                        {
                            // call size
                            Console.WriteLine(ConfigurationManager.AppSettings["FileSizeHeadMsg"].ToString());
                            Console.WriteLine(ConfigurationManager.AppSettings["FileNameMsg"].ToString(), args[1]);
                            Console.WriteLine(ConfigurationManager.AppSettings["FileSizeMsg"].ToString(), objFileDetails.Size(args[1]));
                        }
                        else
                        {
                            // alert please enter corrrect values
                            Console.WriteLine(ConfigurationManager.AppSettings["AlertMsgHdr1"].ToString());
                            Console.WriteLine(ConfigurationManager.AppSettings["AlertMsgHdr2"].ToString(), verList);
                            Console.WriteLine(ConfigurationManager.AppSettings["AlertMsgHdr3"].ToString(), sizeList);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //throw ex;  e.mesages
                Console.WriteLine(ConfigurationManager.AppSettings["AlertErrMsg"].ToString(), ex.ToString());
            }


            Console.WriteLine(ConfigurationManager.AppSettings["AlertExitMsg"].ToString());
            Console.ReadKey();
        }
Exemple #19
0
        /// <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);
        }
Exemple #20
0
        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();
        }
Exemple #21
0
        //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);
        }
Exemple #22
0
        public static void Main(string[] args)
        {
            string          strResult        = string.Empty;
            FileDetails     fileDetails      = new FileDetails();
            FileInfoDetails _fileInfoDetails = new FileInfoDetails(fileDetails);

            if (args != null && args.Length > 0)
            {
                strResult = _fileInfoDetails.GetFileDetailsUsingCommandLine(args);
            }
            else
            {
                _fileInfoDetails.GetFileDetailsUsingConsole();
            }
        }
        public bool ProcessFile(string[] args)
        {
            if (args.Length != 2)
            {
                return(false);
            }
            if (args[0] != "-v")
            {
                return(false);
            }
            var fileDetails = new FileDetails().Version(args[1]);

            Console.WriteLine(fileDetails);
            Console.ReadLine();
            return(true);
        }
Exemple #24
0
        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());
        }
Exemple #25
0
        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 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);
        }
Exemple #27
0
        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();
        }
Exemple #28
0
        private ClientResponse GetFileSize(string FilePath)
        {
            ClientResponse clientResposne = new ClientResponse();
            FileDetails    fileDetails    = new FileDetails();

            try
            {
                clientResposne.FileSize = fileDetails.Size(FilePath);
                clientResposne.Success  = true;
                clientResposne.Message  = clientResposne.FileSize.ToString() + " bytes";
            }

            catch
            {
                //for error handling
            }
            return(clientResposne);
        }
        public static void Main(string[] args)
        {
            FileDetails obj = new FileDetails();

            if (args[0] == "-v" || args[0] == "--v" || args[0] == "/v" || args[0] == "--version")
            {
                System.Console.WriteLine("File version is--" + obj.Version(args[0]));
            }
            else if (args[0] == "-s" || args[0] == "--s" || args[0] == "/s" || args[0] == "--size")

            {
                System.Console.WriteLine("File Size is--" + obj.Size(args[0]));
            }
            else
            {
                System.Console.WriteLine("Invalid input please check");
            }
        }
Exemple #30
0
        private ClientResponse GetFileVersion(string FilePath)
        {
            ClientResponse clientResposne = new ClientResponse();
            FileDetails    fileDetails    = new FileDetails();

            try
            {
                clientResposne.FileVersion = fileDetails.Version(FilePath);
                clientResposne.Success     = true;
                clientResposne.Message     = "version:" + clientResposne.FileVersion;
            }

            catch
            {
                //for error handling
            }
            return(clientResposne);
        }