private static RiserNode CreateRiserNode(string channelName, string name, int n, int nodeOffset, ChannelNode channelNode, RiserAddress addr) { var riserNode = new RiserNode { Active = Data.Config.ReadBool(channelName, name, true), NodeType = Data.Config.ReadInteger(channelName, name + "_NodeType", 0), Index = n, Name = name, Node = addr.Riser + nodeOffset, NextFetching = DateTime.Now + new TimeSpan(channelNode.FetchTime * TimeSpan.TicksPerSecond), Channel = channelNode.Index, Overpass = addr.Overpass, Way = addr.Way, Product = addr.Product, Riser = addr.Riser, TotalRequests = 0, TotalErrors = 0, BarometerValue = 30, MarginalLimit = 15, FailLimit = 30, TimeMarginal = new TimeSpan(0, 0, 15), TimeFail = new TimeSpan(0, 1, 0), }; return(riserNode); }
private static void AddFetchLine(string config) { var vals = config.Split(new[] { ';' }); if (vals.Length != 12) { return; } var comvals = vals[11].Split(new[] { ',' }); if (comvals.Length != 3) { return; } int overpass, way, first, last, step, offset, comport, baudrate; var parity = comvals[2]; if (!int.TryParse(vals[0], out overpass) || !int.TryParse(vals[1], out way) || !int.TryParse(vals[5], out first) || !int.TryParse(vals[6], out last) || !int.TryParse(vals[7], out step) || !int.TryParse(vals[10], out offset) || !int.TryParse(comvals[0], out comport) || !int.TryParse(comvals[1], out baudrate) || !(new [] { "N", "O", "E" }).Contains(parity)) { return; } var arg = new FetchArg { Channel = 0, Overpass = overpass, Way = way, WayFine = vals[2], Product = vals[3], ProductFine = vals[4], RiserFirst = first, RiserLast = last, RiserStep = step, MoxaName = vals[8], MoxaIp = vals[9], NodeOffset = offset, Comport = comport, Baudrate = baudrate, Parity = parity }; var list = new List <RiserNode>(); var channelNode = Data.ChannelNodes.FirstOrDefault( item => item.Name.Equals(arg.MoxaName) && item.IpAddr.Equals(arg.MoxaIp)); var newChannel = false; const int fetchTime = 1; if (channelNode == null) { var risersList = new List <int>(); for (var i = arg.RiserFirst; i <= arg.RiserLast; i = i + arg.RiserStep) { risersList.Add(i); } risersList.Sort(); var index = Data.ChannelNodes.Count; var channelName = String.Format("Channel{0}", index + 1); channelNode = new ChannelNode { Active = Data.Config.ReadBool("FetchChannels", channelName, true), Index = index, Name = arg.MoxaName, IpAddr = arg.MoxaIp, LinkType = Data.Config.ReadInteger("FetchChannels", channelName + "_LinkType", 0), Comport = arg.Comport, Baudrate = arg.Baudrate, Parity = arg.Parity, FetchTime = fetchTime, NextFetching = DateTime.Now + new TimeSpan(fetchTime * TimeSpan.TicksPerSecond), TotalRequests = 0, TotalErrors = 0, BarometerValue = 30, MarginalLimit = 15, FailLimit = 30, TimeMarginal = new TimeSpan(0, 0, 15), TimeFail = new TimeSpan(0, 1, 0), SendTimeout = 3, ReceiveTimeout = 3, Risers = new List <RiserNode>(), Overpass = arg.Overpass, Way = arg.Way, WayFine = arg.WayFine, Product = arg.Product, ProductFine = arg.ProductFine, RisersRange = risersList.ToArray(), RisersRangeFine = arg.RiserStep > 1 ? String.Format("{0},{1} ... {2}", arg.RiserFirst, arg.RiserFirst + 2, arg.RiserLast) : String.Format("{0} ... {1}", arg.RiserFirst, arg.RiserLast) }; channelNode.Descriptor = arg.Overpass == 0 ? channelNode.ProductFine : String.Format("Эстакада {0}. Путь {1}. {2}. Стояки {3}", channelNode.Overpass, channelNode.WayFine, channelNode.ProductFine, channelNode.RisersRangeFine); newChannel = true; } arg.Channel = channelNode.Index; var npp = channelNode.Risers.Count; for (var riserNumber = arg.RiserFirst; riserNumber <= arg.RiserLast; riserNumber = riserNumber + arg.RiserStep) { var addr = new RiserAddress { Channel = channelNode.Index, Overpass = arg.Overpass, Way = arg.Way, Product = arg.Product, Riser = riserNumber }; var channelName = String.Format("Channel{0}", channelNode.Index + 1); var name = String.Format("N{0}{1}{2}{3:D3}", arg.Overpass, arg.Way, arg.Product, riserNumber); var riser = CreateRiserNode(channelName, name, npp, arg.NodeOffset, channelNode, addr); list.Add(riser); Data.RiserNodes.Add(addr, riser); // загрузка записанных заданий налива var riserKey = String.Format("N{0}{1}{2}{3}", addr.Overpass, addr.Way, addr.Product, addr.Riser.ToString("000")); riser.Number = Data.Tasks.ReadString(riserKey, "Number", ""); riser.Ntype = Data.Tasks.ReadString(riserKey, "NType", ""); riser.FactHeight = Data.Tasks.ReadInteger(riserKey, "FactHeight", 0); riser.Setpoint = Data.Tasks.ReadInteger(riserKey, "Setpoint", 0); npp++; } channelNode.Risers.AddRange(list); if (newChannel) { Data.ChannelNodes.Add(channelNode); } else { var risersList = new List <int>(channelNode.RisersRange); for (var i = arg.RiserFirst; i <= arg.RiserLast; i = i + arg.RiserStep) { risersList.Add(i); } risersList.Sort(); channelNode.RisersRange = risersList.ToArray(); var addition = arg.RiserStep > 1 ? String.Format(", {0},{1} ... {2}", arg.RiserFirst, arg.RiserFirst + 2, arg.RiserLast) : String.Format(", {0} ... {1}", arg.RiserFirst, arg.RiserLast); channelNode.RisersRangeFine += addition; channelNode.Descriptor += addition; } var worker = new BackgroundWorker(); Workers.Add(worker); worker.DoWork += WorkerDoWork; worker.ProgressChanged += WorkerProgressChanged; worker.WorkerSupportsCancellation = true; worker.RunWorkerAsync(arg); }