Пример #1
0
        //Main Constructor
        static void Main(string[] args)
        {
            StartTime = DateTime.Now;

            Log.LogWrite("//////////////////////////PROJECT COMMENCED!\\\\\\\\\\\\\\\\\\\\\\\\\\");

            HandlerRoutine handlerRoutine = new HandlerRoutine(ConsoleCtrlCheck);

            GC.KeepAlive(handlerRoutine);
            SetConsoleCtrlHandler(handlerRoutine, true);

            //Check for arguments
            if (args.Count() > 0 && args[0] == "-?") ErrorMsg(3);

            //Instatiate required objects
            Initialization initialization = new Initialization();

            List<SimpleFileInfo> files = new List<SimpleFileInfo>();

            List<string> filteredFiles = new List<string>();

            List<string> rawFiles = new List<string>();

            //Read config file and set Initialization properties
            if (File.Exists(initialization.IniFilePath))
            {
                //Get all lines in config file
                string[] iniData = File.ReadAllLines(initialization.IniFilePath);

                //Iterate through lines and retreive data, if data is present, ensure it is valid.
                foreach (string s in iniData)
                {
                    if (s.Contains(initialization.SourceHeader))
                    {
                        initialization.DataSource = s.Remove(0, initialization.SourceHeader.Count());
                        if (!initialization.CheckSourceDestination(initialization.DataSource)) ErrorMsg(2);
                    }
                    if (s.Contains(initialization.DestinationHeader))
                    {
                        initialization.DataDestination = s.Remove(0, initialization.DestinationHeader.Count());
                        if (!initialization.CheckSourceDestination(initialization.DataDestination)) ErrorMsg(1);
                    }
                    if (s.Contains(initialization.SizeHeader))
                    {
                        initialization.DataSize = Convert.ToDouble(s.Remove(0, initialization.SizeHeader.Count()));
                        if (initialization.DataSize < 210) ErrorMsg(4);
                    }
                    if (s.Contains(initialization.ExceptionsHeader))
                    {
                        string t = s.Remove(0, initialization.ExceptionsHeader.Count());
                        string[] exceptions;

                        if (t.Contains(",")) exceptions = t.Split(',');

                        else if (t.Count() > 0) exceptions = new string[1] { t };

                        else exceptions = new string[1] { "" };

                        initialization.CheckExceptions(exceptions);
                    }
                }
            }

            //No config file
            else ErrorMsg(3);

            //Enumerate files and get file info
            files = GetFileData(initialization.FileExceptions, initialization.CopyDirectories, initialization.WildCardExceptions).ToList();

            //Pack files into bins sorted by file size
            List<Bin> packedBins = PackFiles(files, initialization.DataSize);

            //Create text files for packed bins
            CreateOutputFiles(packedBins, initialization.DataDestination);

            FinishTime = DateTime.Now;

            Log.LogWrite(String.Format("////////////PROJECT COMPLETE! Elapsed Time = {0:hh\\:mm}\\\\\\\\\\\\", ElapsedTime));

            ConsoleCtrlCheck(CtrlTypes.CTRL_CLOSE_EVENT);
        }
Пример #2
0
        //Main Constructor
        static void Main(string[] args)
        {
            StartTime = DateTime.Now;

            Log.LogWrite("//////////////////////////PROJECT COMMENCED!\\\\\\\\\\\\\\\\\\\\\\\\\\");

            HandlerRoutine handlerRoutine = new HandlerRoutine(ConsoleCtrlCheck);

            GC.KeepAlive(handlerRoutine);
            SetConsoleCtrlHandler(handlerRoutine, true);

            //Check for arguments
            if (args.Count() > 0 && args[0] == "-?")
            {
                ErrorMsg(3);
            }

            //Instatiate required objects
            Initialization initialization = new Initialization();

            List <SimpleFileInfo> files = new List <SimpleFileInfo>();

            List <string> filteredFiles = new List <string>();

            List <string> rawFiles = new List <string>();

            //Read config file and set Initialization properties
            if (File.Exists(initialization.IniFilePath))
            {
                //Get all lines in config file
                string[] iniData = File.ReadAllLines(initialization.IniFilePath);

                //Iterate through lines and retreive data, if data is present, ensure it is valid.
                foreach (string s in iniData)
                {
                    if (s.Contains(initialization.SourceHeader))
                    {
                        initialization.DataSource = s.Remove(0, initialization.SourceHeader.Count());
                        if (!initialization.CheckSourceDestination(initialization.DataSource))
                        {
                            ErrorMsg(2);
                        }
                    }
                    if (s.Contains(initialization.DestinationHeader))
                    {
                        initialization.DataDestination = s.Remove(0, initialization.DestinationHeader.Count());
                        if (!initialization.CheckSourceDestination(initialization.DataDestination))
                        {
                            ErrorMsg(1);
                        }
                    }
                    if (s.Contains(initialization.SizeHeader))
                    {
                        initialization.DataSize = Convert.ToDouble(s.Remove(0, initialization.SizeHeader.Count()));
                        if (initialization.DataSize < 210)
                        {
                            ErrorMsg(4);
                        }
                    }
                    if (s.Contains(initialization.ExceptionsHeader))
                    {
                        string   t = s.Remove(0, initialization.ExceptionsHeader.Count());
                        string[] exceptions;

                        if (t.Contains(","))
                        {
                            exceptions = t.Split(',');
                        }

                        else if (t.Count() > 0)
                        {
                            exceptions = new string[1] {
                                t
                            }
                        }
                        ;

                        else
                        {
                            exceptions = new string[1] {
                                ""
                            }
                        };

                        initialization.CheckExceptions(exceptions);
                    }
                }
            }

            //No config file
            else
            {
                ErrorMsg(3);
            }

            //Enumerate files and get file info
            files = GetFileData(initialization.FileExceptions, initialization.CopyDirectories, initialization.WildCardExceptions).ToList();

            //Pack files into bins sorted by file size
            List <Bin> packedBins = PackFiles(files, initialization.DataSize);

            //Create text files for packed bins
            CreateOutputFiles(packedBins, initialization.DataDestination);

            FinishTime = DateTime.Now;

            Log.LogWrite(String.Format("////////////PROJECT COMPLETE! Elapsed Time = {0:hh\\:mm}\\\\\\\\\\\\", ElapsedTime));

            ConsoleCtrlCheck(CtrlTypes.CTRL_CLOSE_EVENT);
        }