Exemplo n.º 1
0
        /// <summary>
        /// <para>Initialization method, used by constructors, creates folder for tab, inits filenames</para>
        /// <para>Метод инициализации, используемый всеми конструкторами.
        /// Создаёт папку под вкладку, задаёт имена файлов.</para>
        /// </summary>
        /// <param name="type"></param>
        protected void Init(TabTypes type)
        {
            TabType = type;

            if (TabType != TabTypes.CUSTOM)
            {
                TabTypeString = type.ToString();
            }
            else
            {
                TabTypeString = CustomTabType;
            }

            if (IsAllTab())
            {
                _dirname = Log9KCore.Settings.Folder + "/" + Log9KUtil.GetDayMonthYearString() + "/";
            }
            else if (IsInnerLogTab())
            {
                _dirname = Log9KCore.Settings.Folder + "/" + Log9KUtil.GetDayMonthYearString() + "/" + "." + Log9KCore.INNER_LOG_TAB;
            }
            else
            {
                _dirname = Log9KCore.Settings.Folder + "/" + Log9KUtil.GetDayMonthYearString() + "/" + TabTypeString;
            }

            if (IsAllTab())
            {
                Log9KUtil.CreateDirIfNotExists(_dirname);
                _directoryNotCreated = false;
            }

            FilenameLogFile = _dirname + "/" + Log9KUtil.GetDayMonthYearHourMinuteSecondString() + Log9KCore.LOG_EXTENSION;

            try {
                // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                Path.GetFullPath(FilenameLogFile);
            } catch (Exception e) {
                Log9KCore.InnerLog("Ошибка: что-то не так с именем файла — " + e.Message, true);
            }

            FilenameTempFile = FilenameLogFile + Log9KCore.TEMP_LOG_EXTENSION;

            DuplicationsDictionary = new Dictionary <int, DuplicationNode>();

            InitCollection();

            InitTabHeader();
        }
Exemplo n.º 2
0
        /// <summary>
        /// <para>Method for loading settings from xml file.</para>
        /// <para>This file should have this structure: some root element with child elements named 'Setting'</para>
        /// <para>Elements 'Setting' should have attribute 'Id', which corresponds to name of Log9KSetting auto property</para>
        /// <para>and attribute 'Value' with value of the property.</para>
        /// </summary>
        /// <param name="path"></param>
        public bool LoadFromFile(string path)
        {
            XmlTextReader textReader;

            try {
                if (!File.Exists(path))
                {
                    Log9KCore.InnerLog("Не найден файл настроек, будут использованы настройки по умолчанию ", true);
                    return(false);
                }
                textReader = new XmlTextReader(path);
                textReader.Read();
            } catch (Exception e) {
                Log9KCore.InnerLog("При загрузке настроек произошла ошибка: " + e.Message, true);
                return(false);
            }

            Type t = GetType();

            PropertyInfo[] properties = t.GetProperties();

            try {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(textReader);
                XmlNodeList settings = xmlDocument.GetElementsByTagName("Setting");
                foreach (XmlNode setting in settings)
                {
                    if (setting.Attributes != null)
                    {
                        XmlAttribute id = setting.Attributes["Id"];
                        if (id == null)
                        {
                            continue;
                        }
                        string settingName = id.Value;
                        if (setting.Attributes["Value"] == null)
                        {
                            continue;
                        }
                        string settingValueString = setting.Attributes["Value"].Value;
                        foreach (PropertyInfo propertyInfo in properties)
                        {
                            if (settingName == propertyInfo.Name)
                            {
                                object settingValue = settingValueString;
                                if (propertyInfo.PropertyType == typeof(bool))
                                {
                                    settingValue = Convert.ToBoolean(settingValueString);
                                }
                                else if (propertyInfo.PropertyType == typeof(Brush))
                                {
                                    object color = ColorConverter.ConvertFromString(settingValueString);
                                    if (color == null)
                                    {
                                        continue;
                                    }
                                    settingValue = new SolidColorBrush((Color)color);
                                }

                                propertyInfo.SetValue(this, settingValue, null);
                                break;
                            }
                        }
                    }
                }
            } catch (XmlException e) {
                Log9KCore.InnerLog("Ошибка: при загрузке настроек произошла ошибка: " + e.Message, true);
                return(false);
            }

            return(true);
        }