/// <summary>
        /// Find the ICodeCounterLogic implementation that can work with the file type we
        /// have found.
        /// </summary>
        /// <exception cref="FileTypeNotSupportedException">Thrown if no logic is found for the given file type</exception>
        /// <exception cref="ConfigurationFileException">Thrown if no logic is defined in the config file</exception>
        /// <returns>ICodeCounterLogic</returns>
        private ICodeCounterLogic GetFileProcessor(FileInfo info)
        {
            if (null == _implementerList)
            {
                _implementerList = CodeCounterLogicImplementerList.LoadFromConfigFile();
                if (0 == _implementerList.Count)
                {
                    throw new ConfigurationFileException("No code counter logic found.");
                }
            }

            ICodeCounterLogic handler = null;

            foreach (CodeCounterLogicImplementer implementer in _implementerList)
            {
                ICodeCounterLogic potentialHandler = implementer.Implementer;

                if (true == potentialHandler.CanProcessFile(info.Name))
                {
                    handler = potentialHandler;
                    break;
                }
            }

            if (null == handler)
            {
                throw FileTypeNotSupportedException.CreateException(info);
            }

            return(handler);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prints help to console
        /// </summary>
        private void PrintHelp()
        {
            Console.WriteLine("");
            Console.WriteLine("\t-verbose");
            Console.WriteLine("\t-recurse");
            Console.WriteLine("\t-supportedTypes");
            Console.WriteLine("\t-help");
            Console.WriteLine("\t-about (opens www.mattraffel.com)");
            Console.WriteLine("\t{filename}");
            Console.WriteLine("");
            Console.WriteLine("FileName can be full filename or partial with wild card");

            // _detailedHelp is set to true when -supportedTypes is found in the command line
            // this means we show information from each of the code counter implmentations
            if (true == _detailedHelp)
            {
                Console.WriteLine("");
                CodeCounterLogicImplementerList list = CodeCounterLogicImplementerList.LoadFromConfigFile();
                if (0 == list.Count)
                {
                    Console.WriteLine("No code types supported.  Check the config file.");
                    return;
                }

                Console.WriteLine("File formats supported:");

                foreach (CodeCounterLogicImplementer implementor in list)
                {
                    string[] fileTypeList = implementor.Implementer.FileTypesHandled();
                    foreach (string fileType in fileTypeList)
                    {
                        // most file types are short so we will make a fair assumption
                        // that it is ok to right justify fileType by 10 chars....
                        string details = string.Format("{0,10} by {1}", fileType, implementor.ImplementerType.Name);
                        Console.WriteLine(details);
                    }
                }
            }
        }
        /// <summary>
        /// Find the ICodeCounterLogic implementation that can work with the file type we 
        /// have found.
        /// </summary>
        /// <exception cref="FileTypeNotSupportedException">Thrown if no logic is found for the given file type</exception>
        /// <exception cref="ConfigurationFileException">Thrown if no logic is defined in the config file</exception>
        /// <returns>ICodeCounterLogic</returns>
        private ICodeCounterLogic GetFileProcessor(FileInfo info)
        {
            if (null == _implementerList)
            {
                _implementerList = CodeCounterLogicImplementerList.LoadFromConfigFile();
                if (0 == _implementerList.Count)
                    throw new ConfigurationFileException("No code counter logic found.");
            }

            ICodeCounterLogic handler = null;

            foreach (CodeCounterLogicImplementer implementer in _implementerList)
            {
                ICodeCounterLogic potentialHandler = implementer.Implementer;

                if (true == potentialHandler.CanProcessFile(info.Name))
                {
                    handler = potentialHandler;
                    break;
                }
            }

            if (null == handler)
                throw FileTypeNotSupportedException.CreateException(info);

            return handler;
        }