示例#1
0
        static void Main(string[] args)
        {
            AppParams appParams = new AppParams();

            if (handleAppArgs(ref args, ref appParams))
            {
                Program p = new Program(appParams);
                p.execute();
            }
        }
示例#2
0
        static bool handleAppArgs(ref string[] args, ref AppParams appParams)
        {
            //Кол-во аргументов
            if (args != null && args.Length != 3)
            {
                Console.WriteLine("app.exe path_to_file start_time end_time");
                return(false);
            }

            //Проверяем время начала и конца
            try
            {
                appParams.startTime = DateTime.Parse(args[1]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Wrong start time");
                return(false);
            }

            try
            {
                appParams.stopTime = DateTime.Parse(args[2]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Wrong stop time");
                return(false);
            }

            if (appParams.stopTime < appParams.startTime)
            {
                Console.WriteLine("Stop time should be more that start time");
                return(false);
            }

            //Проверка сущ файла и возможности его чтения
            string filePath = args[0];

            if (File.Exists(filePath))
            {
                try
                {
                    appParams.inputStream = File.OpenRead(filePath);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Can't open file, " + ex.Message);
                    return(false);
                }

                if (!appParams.inputStream.CanRead)
                {
                    appParams.inputStream.Close();
                    Console.WriteLine("Can't read file");
                    return(false);
                }
            }
            else
            {
                Console.WriteLine("File don't exists");
                return(false);
            }

            return(true);
        }
示例#3
0
 public Program(AppParams Params)
 {
     m_params  = Params;
     m_readBuf = new byte[KReadBufSize];
 }