Пример #1
0
        Setting setting = new Setting(); //загружениые настройки программы

        #endregion Fields

        #region Constructors

        public LogForm()
        {
            InitializeComponent();
            filterSplitContainer.Panel1Collapsed = true;

            //Загружаеются настройки из файла конфига
            setting = Setting.LoadSetting();
            //На момент тестирования включал системный лог, сейчас не нужен
            setting.SystemLog = String.Empty;

            bool isAccess = false;
            //Проверка на существование папки, в которой лежат файлы с логами
            if (Directory.Exists(setting.LogPath))
            {
                isAccess = CheckAccessToFolder(setting.LogPath);
            }

            string path = setting.LogPath + @"\" + setting.LogFileName;
            setting.SystemLog += "File path: " + path;

            //если возможно прочитать файлы логов - читаем
            if (isAccess)
            {
                setting.SystemLog += "\r\nisAccess = true";
                //Читаем файлы логов
                LoadFileContent(path, false);
                setting.SystemLog += "\r\nLoadFileContent ends";
                setting.SystemLog += "\r\nLogItemCount = " + datas.Items.Count;
                //Заполняем данными с логов табличку
                FillListView(datas.Items);

                statusLabel_FilePath.Text = path;
                statusLabel_FilePath.ForeColor = Color.Black;
            }
            else
            {
                setting.SystemLog += "\r\nisAccess = false";
                statusLabel_FilePath.Text = string.Format("Помилка доступу до файлу або даного файлу не існує: {0}", path);
                statusLabel_FilePath.ForeColor = Color.Red;
            }
            //File.WriteAllText("\\Logs.txt", setting.SystemLog);
        }
Пример #2
0
        public static Setting LoadSetting()
        {
            string path = Directory.GetCurrentDirectory() + @"\setting.xml";

            Setting setParam = new Setting();

            Stream stream = null;
            XmlDictionaryReader xmlTextReader = null;

            try
            {
                if (File.Exists(path))
                {
                    stream = new FileStream(path, FileMode.Open, FileAccess.Read);
                    DataContractSerializer serializer = new DataContractSerializer(typeof(Setting));

                    xmlTextReader = XmlDictionaryReader.CreateTextReader(stream, new XmlDictionaryReaderQuotas());
                    setParam = (Setting)serializer.ReadObject(xmlTextReader, true);

                    xmlTextReader.Close();
                    stream.Close();
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (xmlTextReader != null)
                {
                    xmlTextReader.Close();
                }
                if (stream != null)
                {
                    stream.Close();
                }
            }
            return setParam;
        }
Пример #3
0
        public static bool SaveSetting(Setting setParam)
        {
            setParam.SystemLog = String.Empty;
            string filepath = Directory.GetCurrentDirectory() + @"\setting.xml";
            Stream stream = null;
            XmlTextWriter xmlTextWriter = null;
            bool successfull = false;
            try
            {
                stream = new FileStream(filepath, FileMode.Create, FileAccess.Write);
                DataContractSerializer serializer = new DataContractSerializer(typeof(Setting));

                xmlTextWriter = new XmlTextWriter(stream, null) { Formatting = Formatting.Indented, Indentation = 4 };

                serializer.WriteObject(xmlTextWriter, setParam);

                xmlTextWriter.Close();
                stream.Close();

                successfull = true;
            }
            catch (Exception ex)
            {
                successfull = false;
            }
            finally
            {
                if (xmlTextWriter != null)
                {
                    xmlTextWriter.Close();
                }
                if (stream != null)
                {
                    stream.Close();
                }
            }
            return successfull;
        }
Пример #4
0
        private void btSetting_Click(object sender, EventArgs e)
        {
            SettingForm sf = new SettingForm();
            sf.SetParams = setting;

            if (sf.ShowDialog() == DialogResult.OK)
            {
                setting = sf.SetParams;
            }
        }