public void LoadSetting() { //ЗАГРУЗКА НАСТРОЕК---------------------------------------------------------------- XmlListenerSettings xmlListener; XmlSerialSettings xmlSerial; XmlLogSettings xmlLog; List <XmlCashierSettings> xmlCashier; try { var xmlFile = XmlWorker.LoadXmlFile("Settings", "Setting.xml"); //все настройки в одном файле if (xmlFile == null) { return; } xmlListener = XmlListenerSettings.LoadXmlSetting(xmlFile); xmlSerial = XmlSerialSettings.LoadXmlSetting(xmlFile); xmlLog = XmlLogSettings.LoadXmlSetting(xmlFile); xmlCashier = XmlCashierSettings.LoadXmlSetting(xmlFile); } catch (FileNotFoundException ex) { ErrorString = ex.ToString(); return; } catch (Exception ex) { ErrorString = "ОШИБКА в узлах дерева XML файла настроек: " + ex; return; } //СОЗДАНИЕ ЛОГА-------------------------------------------------------------------------- LogTicket = new Log("TicketLog.txt", xmlLog); //СОЗДАНИЕ СЛУШАТЕЛЯ ДЛЯ ТЕРМИНАЛОВ------------------------------------------------------- Listener = new ListenerTcpIp(xmlListener); ProviderTerminal = new Server2TerminalExchangeDataProvider(); ProviderTerminal.PropertyChanged += (o, e) => { var provider = o as Server2TerminalExchangeDataProvider; if (provider != null) { if (e.PropertyName == "InputData") { TicketItem ticket; provider.OutputData = provider.OutputData ?? new TerminalOutData(); switch (provider.InputData.NumberQueue) { //ПРИГОРОДНЫЕ КАСС case 1: switch (provider.InputData.Action) { //ИНФОРМАЦИЯ ОБ ОЧЕРЕДИ case TerminalAction.Info: provider.OutputData.NumberQueue = provider.InputData.NumberQueue; provider.OutputData.CountElement = (ushort)QueueVilage.Count; provider.OutputData.NumberElement = (ushort)(TicketFactoryVilage.GetCurrentTicketNumber + 1); provider.OutputData.AddedTime = DateTime.Now; break; //ДОБАВИТЬ БИЛЕТ В ОЧЕРЕДЬ case TerminalAction.Add: ticket = TicketFactoryVilage.Create((ushort)QueueVilage.Count); provider.OutputData.NumberQueue = provider.InputData.NumberQueue; provider.OutputData.CountElement = ticket.CountElement; provider.OutputData.NumberElement = (ushort)ticket.NumberElement; provider.OutputData.AddedTime = ticket.AddedTime; QueueVilage.Enqueue(ticket); break; } break; //ДАЛЬНЕГО СЛЕДОВАНИЯ КАССЫ case 2: switch (provider.InputData.Action) { //ИНФОРМАЦИЯ ОБ ОЧЕРЕДИ case TerminalAction.Info: provider.OutputData.NumberQueue = provider.InputData.NumberQueue; provider.OutputData.CountElement = (ushort)QueueLong.Count; provider.OutputData.NumberElement = (ushort)(TicketFactoryLong.GetCurrentTicketNumber + 1); provider.OutputData.AddedTime = DateTime.Now; break; //ДОБАВИТЬ БИЛЕТ В ОЧЕРЕДЬ case TerminalAction.Add: ticket = TicketFactoryLong.Create((ushort)QueueLong.Count); provider.OutputData.NumberQueue = provider.InputData.NumberQueue; provider.OutputData.CountElement = ticket.CountElement; provider.OutputData.NumberElement = (ushort)ticket.NumberElement; provider.OutputData.AddedTime = ticket.AddedTime; QueueLong.Enqueue(ticket); break; } break; } } } }; //СОЗДАНИЕ КАССИРОВ------------------------------------------------------------------------------------------------ foreach (var xmlCash in xmlCashier) { var casher = new Сashier(xmlCash.Id, (xmlCash.Prefix == "A") ? QueueVilage : QueueLong, xmlCash.MaxCountTryHanding); DeviceCashiers.Add(new DeviceCashier(casher)); } //СОЗДАНИЕ ПОСЛЕД. ПОРТА ДЛЯ ОПРОСА КАССИРОВ----------------------------------------------------------------------- MasterSerialPort = new MasterSerialPort(xmlSerial); CashierExchangeService = new CashierExchangeService(DeviceCashiers, xmlSerial.TimeRespoune); MasterSerialPort.AddFunc(CashierExchangeService.ExchangeService); MasterSerialPort.PropertyChanged += (o, e) => { var port = o as MasterSerialPort; if (port != null) { if (e.PropertyName == "StatusString") { ErrorString = port.StatusString; } } }; }
public void LoadSetting() { //ЗАГРУЗКА НАСТРОЕК---------------------------------------------------------------- XmlListenerSettings xmlListener; IList <XmlSerialSettings> xmlSerials; List <XmlCashierSettings> xmlCashier; List <XmlQueuesSettings> xmlQueues; try { var xmlFile = XmlWorker.LoadXmlFile("Settings", "Setting.xml"); //все настройки в одном файле if (xmlFile == null) { return; } xmlListener = XmlListenerSettings.LoadXmlSetting(xmlFile); xmlSerials = XmlSerialSettings.LoadXmlSetting(xmlFile).ToList(); xmlCashier = XmlCashierSettings.LoadXmlSetting(xmlFile); xmlQueues = XmlQueuesSettings.LoadXmlSetting(xmlFile); } catch (FileNotFoundException ex) { ErrorString = ex.ToString(); return; } catch (Exception ex) { ErrorString = "ОШИБКА в узлах дерева XML файла настроек: " + ex; return; } //РАЗРЕШИТЬ ЛОГГИРОВАНИЕ----------------------------------------------------------- Log.EnableLogging(true); //СОЗДАНИЕ ОЧЕРЕДИ----------------------------------------------------------------------- foreach (var xmlQueue in xmlQueues) { var queue = new QueuePriority(xmlQueue.Name, xmlQueue.Prefixes); QueuePriorities.Add(queue); } //СОЗДАНИЕ СЛУШАТЕЛЯ ДЛЯ ТЕРМИНАЛОВ------------------------------------------------------- Listener = new ListenerTcpIp(xmlListener); ProviderTerminal = new Server2TerminalExchangeDataProvider(isSynchronized: true); ProviderTerminal.PropertyChanged += (o, e) => { var provider = o as Server2TerminalExchangeDataProvider; if (provider != null) { if (e.PropertyName == "InputData") { try { provider.OutputData = provider.OutputData ?? new TerminalOutData(); //Найдем очередь к которой обращен запрос var prefixQueue = provider.InputData.PrefixQueue; var nameQueue = provider.InputData.NameQueue; var queue = QueuePriorities.FirstOrDefault(q => string.Equals(q.Name, nameQueue, StringComparison.InvariantCultureIgnoreCase)); if (queue == null) { return; } switch (provider.InputData.Action) { //ИНФОРМАЦИЯ ОБ ОЧЕРЕДИ case TerminalAction.Info: provider.OutputData.PrefixQueue = provider.InputData.PrefixQueue; provider.OutputData.CountElement = (ushort)queue.GetInseartPlace(prefixQueue); provider.OutputData.NumberElement = (ushort)(queue.GetCurrentTicketNumber + 1); provider.OutputData.AddedTime = DateTime.Now; break; //ДОБАВИТЬ БИЛЕТ В ОЧЕРЕДЬ case TerminalAction.Add: var ticket = queue.CreateTicket(prefixQueue); provider.OutputData.PrefixQueue = provider.InputData.PrefixQueue; provider.OutputData.CountElement = ticket.CountElement; provider.OutputData.NumberElement = (ushort)ticket.NumberElement; provider.OutputData.AddedTime = ticket.AddedTime; queue.Enqueue(ticket); var logMessage = $"ДОБАВИТЬ БИЛЕТ В ОЧЕРЕДЬ (команда от терминала): {ticket.ToString()} "; _logQueueInput.Info(logMessage); break; } } catch (Exception ex) { _logQueueInput.Error($"Server2TerminalExchangeDataProvider: {ex.ToString()}"); } } } }; //DEBUG------ИНИЦИАЛИЗАЦИЯ ОЧЕРЕДИ--------------------- //Обязательно коментировать _model.LoadStates(); иначе состояние очереди затрется //var queueTemp = QueuePriorities.FirstOrDefault(q => string.Equals(q.Name, "Main", StringComparison.InvariantCultureIgnoreCase)); //var queueAdmin = QueuePriorities.FirstOrDefault(q => string.Equals(q.Name, "Admin", StringComparison.InvariantCultureIgnoreCase)); //for (int i = 0; i < 200; i++) //{ // var ticketAdmin = queueTemp.CreateTicket("А"); // queueAdmin.Enqueue(ticketAdmin); // var ticket = queueTemp.CreateTicket("К"); // queueTemp.Enqueue(ticket); // ticket = queueTemp.CreateTicket("К"); // queueTemp.Enqueue(ticket); // ticket = queueTemp.CreateTicket("Г"); // queueTemp.Enqueue(ticket); // ticket = queueTemp.CreateTicket("И"); // queueTemp.Enqueue(ticket); // ticket = queueTemp.CreateTicket("С"); // queueTemp.Enqueue(ticket); //} //DEBUG---------------------------------------------- //СОЗДАНИЕ КАССИРОВ------------------------------------------------------------------------------------------------ foreach (var xmlCash in xmlCashier) { var queue = QueuePriorities.FirstOrDefault(q => q.Name == xmlCash.NameQueue); if (queue != null) { var logName = "Server.CashierInfo_" + xmlCash.Port; var casher = new Сashier(xmlCash.Id, xmlCash.Prefixs, queue, xmlCash.MaxCountTryHanding, logName); DeviceCashiers.Add(new DeviceCashier(xmlCash.AddressDevice, casher, xmlCash.Port)); } } AdminCasher = DeviceCashiers.FirstOrDefault(d => d.Cashier.Prefixes.Contains("А")); //СОЗДАНИЕ ПОСЛЕД. ПОРТА ДЛЯ ОПРОСА КАССИРОВ----------------------------------------------------------------------- var cashersGroup = DeviceCashiers.GroupBy(d => d.Port).ToDictionary(group => group.Key, group => group.ToList()); //принадлежность кассира к порту foreach (var xmlSerial in xmlSerials) { var logName = "Server.CashierInfo_" + xmlSerial.Port; var sp = new MasterSerialPort(xmlSerial, logName); var cashiers = cashersGroup[xmlSerial.Port]; var cashierExch = new CashierExchangeService(cashiers, AdminCasher, xmlSerial.TimeRespoune, logName); sp.AddFunc(cashierExch.ExchangeService); //sp.PropertyChanged += (o, e) => // { // var port = o as MasterSerialPort; // if (port != null) // { // if (e.PropertyName == "StatusString") // { // ErrorString = port.StatusString; //TODO: РАЗДЕЛЯЕМЫЙ РЕСУРС возможно нужна блокировка // } // } // }; MasterSerialPorts.Add(sp); CashierExchangeServices.Add(cashierExch); } }