Пример #1
0
        public void Deserializate()
        {
            try
            {
                using (FileStream fileStream = new FileStream(ConfigurationManager.AppSettings["PathToSerialize"].ToString(), FileMode.Open))
                {
                    BinaryFormatter binaryFormatter = new BinaryFormatter();

                    listOfCars = (List <Car>)binaryFormatter.Deserialize(fileStream);

                    foreach (var item in listOfCars)
                    {
                        Print(item.ToString());
                    }
                }
            }
            catch (UnauthorizedAccessException exception)
            {
                logger.writeMessageLog(exception);
            }
            catch (Exception e)
            {
                logger.writeMessageLog(e);
            }
        }
 public void Input()
 {
     if (!File.Exists(ConfigurationManager.AppSettings["PathToCalculationFile"].ToString()))
     {
         File.Create(ConfigurationManager.AppSettings["PathToCalculationFile"].ToString());
     }
     try
     {
         using (StreamWriter streamWriter = File.AppendText(ConfigurationManager.AppSettings["PathToLog"].ToString()))
         {
             FirstNumeric = Convert.ToDouble(Console.ReadLine());
             streamWriter.WriteLine(FirstNumeric);
             SecondNumeric = Convert.ToDouble(Console.ReadLine());
             streamWriter.WriteLine(SecondNumeric);
         }
     }
     catch (UnauthorizedAccessException e)
     {
         Print("File could not be written");
         Print(e.Message);
         logger.writeMessageLog(e);
     }catch (Exception e)
     {
         Print(e.Message);
         logger.writeMessageLog(e);
     }
 }
 public void Input()
 {
     try
     {
         firstNumeric  = Convert.ToDouble(Console.ReadLine());
         secondNumeric = Convert.ToDouble(Console.ReadLine());
     }catch (FormatException e)
     {
         logger.writeMessageLog(e);
     }catch (Exception e)
     {
         logger.writeMessageLog(e);
     }
 }
        public void Run()
        {
            ExceptionGenerator exceptionGenerator = new ExceptionGenerator();

            Log.Logger log = new Log.Logger();
            try
            {
                exceptionGenerator.StackOverflow();
                exceptionGenerator.IndexOutOfRange(new int[4] {
                    31, 4, 11, 8
                });                                                              // Will never happen
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine(e.Message);
                log.writeMessageLog(e);
            }
            catch (StackOverflowException e)
            {
                Console.WriteLine(e.Message);
                log.writeMessageLog(e);
            }
            try
            {
                exceptionGenerator.IndexOutOfRange(new int[4] {
                    31, 4, 11, 8
                });
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine(e.Message);
                log.writeMessageLog(e);
            }
            try
            {
                exceptionGenerator.DoSomeMath(-1, 3);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                log.writeMessageLog(e);
            }
            Console.ReadKey();
        }
 public void FindSubDirecotories(string path, string partialName)
 {
     try
     {
         string[] subDirectories = Directory.GetDirectories(path);
         foreach (string item in subDirectories)
         {
             DirectoryInfo directoryInfo = new DirectoryInfo(item);
             FindFileByPartialName(item, partialName);
             FindSubDirecotories(item, partialName);
         }
     }
     catch (UnauthorizedAccessException e)
     {
         Print(e.Message);
         logger.writeMessageLog(e);
         throw new UnauthorizedAccessException();
     }
     catch (ArgumentNullException e)
     {
         Print(e.Message);
         logger.writeMessageLog(e);
         throw new ArgumentException();
     }
     catch (DirectoryNotFoundException e)
     {
         Print(e.Message);
         logger.writeMessageLog(e);
         throw new DirectoryNotFoundException();
     }
 }
Пример #6
0
 public void Deserializate()
 {
     try
     {
         using (FileStream fileStream = new FileStream(ConfigurationManager.AppSettings["PathToSerialize"].ToString(), FileMode.Open))
         {
             DataContractJsonSerializer deserealizer = new DataContractJsonSerializer(typeof(List <Car>));
             List <Car> list = (List <Car>)deserealizer.ReadObject(fileStream);
             foreach (var item in list)
             {
                 Print(item.ToString());
             }
         }
     }
     catch (UnauthorizedAccessException exception)
     {
         logger.writeMessageLog(exception);
     }
     catch (Exception e)
     {
         logger.writeMessageLog(e);
     }
 }