Example #1
0
        public void Execute()
        {
            LoadStatus currentStatus = LoadStatus.None;

            try
            {
                if (!File.Exists("elementaryParticles.txt"))
                {
                    currentStatus = LoadStatus.FileNotExists;
                    throw new FileNotFoundException(@"[elementaryParticles.txt not in the directory]");
                }

                if (_dataFileName == null)
                {
                    currentStatus = LoadStatus.FileNotExists;
                    throw new FileNotFoundException(@"[name is empty]");
                }
                _elementaryParticleList = new List <elementaryParticle>();
                // LoadStatus currentStatus = status;

                StreamReader sr = null;
                using (sr = new StreamReader(_dataFileName))
                {
                    while (!sr.EndOfStream)
                    {
                        //Прочитать очередную строку
                        string str = sr.ReadLine();
                        try
                        {
                            string[]           arr = str.Split('|');
                            elementaryParticle elementaryParticle1 = new elementaryParticle()
                            {
                                name   = arr[0],
                                group  = arr[1],
                                charge = arr[2],
                                weight = float.Parse(arr[3])
                            };
                            _elementaryParticleList.Add(elementaryParticle1);
                        }
                        catch (Exception e)
                        {
                            LogUtility.ErrorLog(e.Message);
                            currentStatus = LoadStatus.GeneralError;
                        }
                    }
                }
                currentStatus = LoadStatus.Success;
            }


            catch (Exception ex)
            {
                LogUtility.ErrorLog(ex.Message + Environment.NewLine);
            }
        }
        public void Execute()
        {
            try
            {
                //Фигурная скобка для ограничения области видимости переменной elementaryParticle
                {
                    elementaryParticle elementaryParticle1 = new elementaryParticle()
                                                             //данная констуркция позволяет инициализировать объект при его создании
                    {
                        name   = "Нейтрон",
                        group  = "Н",
                        charge = "0",
                        weight = 940
                    };
                    _elementaryParticleList.Add(elementaryParticle1);
                }

                {
                    elementaryParticle elementaryParticle = new elementaryParticle()
                    {
                        name   = "Ка-плюс",
                        group  = "М",
                        charge = "1",
                        weight = 494
                    };
                    _elementaryParticleList.Add(elementaryParticle);
                }
                {
                    elementaryParticle elementaryParticle = new elementaryParticle()
                    {
                        name   = "Электрон",
                        group  = "Л",
                        charge = "+1",
                        weight = 0.511f
                    };
                    _elementaryParticleList.Add(elementaryParticle);
                }
            }
            catch (NotImplementedException ex)
            {
                DateTime localDate = DateTime.Now;
                //MessageBox.Show("Ошибка №1: " + ex.Message);
                LogUtility.ErrorLog(localDate.ToString() + ex.Message + Environment.NewLine);
            }
            //обработка остальных исключений
            // catch (Exception ex)
            {
                // DateTime localDate = DateTime.Now;
                //  MessageBox.Show("Ошибка №2: " + ex.Message);
                // LogUtility.ErrorLog(localDate.ToString() + ex.Message + Environment.NewLine);
            }
        }