BitrixAQA.General.Options.GetOption C# (CSharp) Method

GetOption() public static method

Метод получает значение опции из файла options.xml
public static GetOption ( string Node, bool NoSignal = false ) : string
Node string Путь к опции в формате XPath
NoSignal bool Оключение логирования об ошибке
return string
        public static string GetOption(string Node, bool NoSignal = false)
        {
            XmlDocument reader = new XmlDocument();
            reader.Load("options.xml");
            //Мало ли кто укажет лишнюю / в конце пути до ноды
            if (Node.Substring(Node.Length - 1, 1) == "/")
                Node = Node.Substring(0, Node.Length - 1);

            XmlNode node = reader.DocumentElement.SelectSingleNode(Node);
            if (node == null)
            {
                if(!NoSignal)
                    Log.MesError("Такой опции не существует " + Node);
                return "";
            }

            return node.InnerText;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Метод реализует выполнение запросов к базе mysql
        /// </summary>
        /// <param name="edition">Редакция</param>
        /// <param name="DBType">Тип базы</param>
        /// <param name="query">SQL запрос</param>
        /// <returns>Результат выполнения запроса</returns>
        public static string mysqlQuery(string edition, string DBType, string query)
        {
            string result           = null;
            string ConnectionString = null;

            ConnectionString = "SERVER=" + Options.GetOption("/Options/ConnectionString/mysql") + ";" +
                               "port=" + Options.GetOption("/Options/ConnectionString/mysql_port") + ";" +
                               "DATABASE=" + GetDBname(edition, DBType) + ";" +
                               "UID=root;" +
                               "PASSWORD=;";
            using (MySqlConnection connection = new MySqlConnection(ConnectionString))
            {
                using (MySqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = query;
                    connection.Open();

                    var results = new List <string>();
                    using (MySqlDataReader Reader = command.ExecuteReader())
                    {
                        bool first = true;

                        while (Reader.Read())
                        {
                            var sb = new StringBuilder();
                            for (int i = 0; i < Reader.FieldCount; i++)
                            {
                                sb.AppendLine(Reader.GetValue(i).ToString());
                            }
                            results.Add(sb.ToString());

                            if (first)
                            {
                                result = Reader.GetValue(0).ToString();
                                first  = false;
                            }
                        }
                    }

                    if (results.Count > 1)
                    {
                        string Return = null;
                        foreach (var r in results)
                        {
                            Return = Return + r + " ";
                        }
                        string spanID = DateTime.Now.Ticks.ToString();
                        Log.MesQuestion("<div style=\"margin: 0px 0px 0px 50px;\"><font size=\"2\" face=\"Verdana\"><a class=\"plus\"" +
                                        " href=\"\" onclick=\"return collapse('" + spanID + "', this)\">" + "Результат выполнения запроса " + query + " содержит больше чем одно поле. Все поля: " +
                                        " </a></font></div><br><span style=\"display:none;\" id=\"" + spanID + "\">" + Return);
                    }
                }
                connection.Close();
            }
            return(result);
        }
All Usage Examples Of BitrixAQA.General.Options::GetOption