public static PerformerCriteriaFunction ReadFromXml(XmlElement node) { var func = node.InnerText; if (string.IsNullOrEmpty(func)) { return(null); } var desc = node.GetAttributeString("Description"); if (string.IsNullOrEmpty(desc)) { return(null); } var function = new PerformerCriteriaFunction { Function = func, Description = desc }; var order = node.GetAttributeInt("PreferredSortOrder"); try { function.PreferredSortOrder = order.HasValue ? (SortOrder)order.Value : SortOrder.Descending; } catch { } function.MarginValue = node.GetAttributeFloat("MarginValue"); return(function); }
public PerformerCriteriaFunction(PerformerCriteriaFunction funct) { function = funct.function; Description = funct.Description; PreferredSortOrder = funct.PreferredSortOrder; MarginValue = funct.MarginValue; filters = new List <Cortege3 <PerformerStatField, ExpressionOperator, double> >(funct.filters); SortField = funct.SortField; IsExpressionParsed = funct.IsExpressionParsed; }
/// <summary> /// прочитать формулы - описания из строки /// </summary> public void ReadFromFile() { criterias = new List <PerformerCriteriaFunction>(); if (File.Exists(fileName)) { try { var doc = new XmlDocument(); using (var sr = new StreamReader(fileName, Encoding.UTF8)) doc.Load(sr); if (doc.DocumentElement != null) { selectedFunctionIndex = doc.DocumentElement.GetAttributeInt("selected") ?? 0; foreach (XmlElement child in doc.DocumentElement.ChildNodes) { var crit = PerformerCriteriaFunction.ReadFromXml(child); if (crit == null) { continue; } // проверка на дубль и валидность и добавление if (criterias.Any(c => c.AreEqual(crit))) { continue; } string error; if (!ExpressionResolver.CheckFunction(crit.Function, out error, enabledParametersNames)) { continue; } criterias.Add(crit); } } } catch (Exception ex) { Logger.Error("Ошибка в PerformerCriteriaFunction - ReadFromFile", ex); } } // добавить обязательные функции foreach (var fun in obligatoryFunctions) { var formula = fun.Function; if (criterias.Any(c => c.Function.Equals(formula, StringComparison.OrdinalIgnoreCase))) { continue; } criterias.Add(fun); } }
public bool AreEqual(PerformerCriteriaFunction crit) { if (!Function.Equals(crit.Function, StringComparison.OrdinalIgnoreCase)) { return(false); } var descA = Description ?? ""; var descB = crit.Description ?? ""; return(descA.Trim().Equals(descB.Trim(), StringComparison.OrdinalIgnoreCase)); }