public static void BuildBlind() // Построение состояний лампочек { // вычислим примерные размеры массива SortedList <string, int> sl = null; sl = new SortedList <string, int>(Server.Count); Context con = null; con = Server.getContext(Server.PointVariables); for (int i = 0; i < con.Count; i++) { int index = con.getChaild(i); Context var = Server.getContext(index); sl.Add(var.Name, index); } con = Server.getContext(Server.PointModels); for (int i = 0; i < con.Count; i++) { int index = con.getChaild(i); Context var = Server.getContext(index); sl.Add(var.Name, index); } con = Server.getContext(Server.PointConstants); for (int i = 0; i < con.Count; i++) { int index = con.getChaild(i); Context var = Server.getContext(index); sl.Add(var.Name, index); } DateTime tm = DateTime.Now; long bazatime = tm.Ticks; for (int i = 0; i < defBlind.Count; i++) { int numFunction; SmallBlind sBl = defBlind[i]; string name = "Blind" + string.Format("{0:0000}", i); string description = sBl.nameFunction + "( "; for (int j = 0; j < sBl.nameParamIn.Count; j++) { description += j == 0 ? "" : ","; description += sBl.nameParamIn[j] + " in"; if (sBl.ups[j]) { description += " up"; } } for (int j = 0; j < sBl.nameParamOut.Count; j++) { description += "," + sBl.nameParamOut[j] + " out"; } description += " )"; numFunction = Function.NameToInt(sBl.nameFunction); if (numFunction < 0) { Util.errorMessage("Отсутствует функция ", description); Util.work = false; } Blind BL = new Blind(numFunction, sBl.onstart); if (sBl.steptimer > 0) { BL.setOnTimer(bazatime, sBl.steptimer); } for (int j = 0; j < sBl.nameParamIn.Count; j++) { int ip = sl.IndexOfKey(sBl.nameParamIn[j]); if (ip < 0) { Util.errorMessage("Нет " + sBl.nameParamIn[j], description); Util.work = false; ip = 1; } else { ip = sl[sBl.nameParamIn[j]]; if (sBl.ups[j]) { Context cont = Server.getContext(ip); Variable var = (Variable)cont.defContext; if (var != null) { var.appendReference(Server.Count); var.blinds.Add(Server.Count); Server.setContext(ip, cont); } } else { Context cont = Server.getContext(ip); Variable var = (Variable)cont.defContext; var.blinds.Add(Server.Count); Server.setContext(ip, cont); } BL.listParamIn.Add(ip); } } for (int j = 0; j < sBl.nameParamOut.Count; j++) { int ip = sl.IndexOfKey(sBl.nameParamOut[j]); if (ip < 0) { Util.errorMessage("Нет " + sBl.nameParamIn[j], description); Util.work = false; ip = 1; } else { ip = sl[sBl.nameParamOut[j]]; Context cont = Server.getContext(ip); Variable var = (Variable)cont.defContext; var.blinds.Add(Server.Count); Server.setContext(ip, cont); BL.listParamOut.Add(ip); } } if (!Function.isCorrect(numFunction, BL.listParamIn, BL.listParamOut)) { Util.errorMessage("Ошибки в параметрах вызова ", description); Util.work = false; } ; Blind.appendBlind(name, description, BL); Util.message(name + " " + description + " добавлено "); } sl = null; }
public static bool LoadBlind(XmlDocument xml) { string onstart, time; foreach (XmlNode k in xml.SelectNodes("/Apax/Blinds")) { string loadfile; //string pathBlinds; //loadfile = XmlExt.GetAttrValue(k,"load"); //try { loadfile = XmlExt.GetAttrValue(k,"load"); } catch (Exception) { loadfile = @"c:/OPU/blindR.xml"; Util.errorMessage("Предупреждение: отсутствуют настройки вывода на лампочки Blinds ..... Присвоено по умолчанию: ", loadfile); } loadfile = XmlExt.GetAttrValue(k, "load"); if (loadfile == "") { loadfile = @"c:/OPU/blindR.xml"; } XmlDocument xmlload = new XmlDocument(); xmlload.Load(loadfile); foreach (XmlNode n in xmlload.SelectNodes("/Blinds/blind")) // считывание состояния вывода состояния на лампочки из конфигурационного файла { SmallBlind sBl = new SmallBlind(); sBl.nameParamIn = new List <string>(); sBl.nameParamOut = new List <string>(); sBl.ups = new List <bool>(); sBl.nameFunction = XmlExt.GetAttrValue(n, "name"); //try{ onstart = XmlExt.GetAttrValue(n,"start"); } catch (Exception) { onstart = "true"; } //try { time = XmlExt.GetAttrValue(n,"time"); } catch (Exception) { time = 0; } onstart = XmlExt.GetAttrValue(n, "start"); if (onstart == "") { onstart = "true"; // ????? } time = XmlExt.GetAttrValue(n, "time"); if (time == "") { time = "0"; } if (onstart == null) { onstart = "false"; } if (time == null) { time = "0"; } try { sBl.onstart = bool.Parse(onstart); sBl.steptimer = int.Parse(time); } catch (Exception) { Util.errorMessage("Ошибка дополнительных параметров ", sBl.nameFunction); } foreach (XmlNode par in n.ChildNodes) { string name, type; name = XmlExt.GetAttrValue(par, "name"); type = XmlExt.GetAttrValue(par, "type"); if (type == null) { type = "in"; } if (type.Equals("in")) { sBl.nameParamIn.Add(name); sBl.ups.Add(false); } else { if (type.Equals("up")) { sBl.nameParamIn.Add(name); sBl.ups.Add(true); } else { sBl.nameParamOut.Add(name); } } } defBlind.Add(sBl); } } return(true); }