public override string ExecuteCommand(string command, string data) { try { // 获取服务器信息 XDocument xser = XDocument.Parse(command); string lab_ip = xser.Element("IPLab").Element("LabIP").Value; si = Util.GetServerInfoFromIP(lab_ip); XDocument xdoc = XDocument.Parse(data); XElement filelist = xdoc.Element("IP_Lab").Element("StopList"); ParseXMLtoList(filelist); SshShell shell = new SshShell(si.serverip, si.usrname, si.pwd); shell.Connect(); if (shell.Expect(new Regex(si.sysname), 5) == null) throw new Exception("连接服务器出错!"); if (CiscoSwitchList.Count > 0) { // 登录到设备上 Util.SshWriteAndExpect(shell, "cd ~", si.sysname); Util.SshWriteAndExpect(shell, "ssh " + si.innerusrname + "@" + si.innerservip, "Password:"******" 停止失败!"; } Util.SshWriteAndExpect(shell, "cd ~", si.innersysname); Util.SshWriteAndExpect(shell, "exit", si.sysname); } Util.SshWriteAndExpect(shell, "cd ~", si.sysname); foreach (FileBase file in FileList) { StopDevice sd = new StopDevice(file, shell, si.sysname); if (sd.Stop()) continue; else return sd.GetFileName() + " 停止失败!"; } return "停止设备成功!"; } catch (System.Exception ex) { return ex.Message; } }
/// <summary> /// 初始化挡停 /// </summary> private void InitStopDevice() { string strPath = AppDomain.CurrentDomain.BaseDirectory + "Data\\Stop.txt"; List <string[]> lstStop = GetCSVData(strPath); if (lstStop.Count == 0) { return; } foreach (var stop in lstStop) { StopDevice stopDevice = new StopDevice(Convert.ToInt32(stop[0]), stop[1], stop[2], stop[3], stop[4], stop[5]); StopDevices.Add(stopDevice); } }
/* * HandlePosEvent is called from _ui_Notify event listener (above). * * Most messages are simply turned into .NET events. A few do more, * especially: * ADD_TO_BASKET : Updates our own Basket object with new items * REMOVE_FROM_BASKET : Removes item from our own Basket * BASKET_COMMITTED : Updates the Basket state; and fetches all the vouchers */ private void HandlePosEvent(PosEvent posEvent) { if (posEvent == null) { // Debug.Assert(false); return; } if (_timeoutTimer != null) { _timeoutTimer.Enabled = false; _timeoutTimer = null; } switch (posEvent.EventName) { case PosEventType.READY: Ready?.Invoke(this, null); _rollbackHandler.ProcessPendingRollbacks(_config.Url); break; case PosEventType.SHOW_GUI: _ui.Show(); ShowGUI?.Invoke(this, null); break; case PosEventType.HIDE_GUI: _ui.Hide(); HideGUI?.Invoke(this, null); break; case PosEventType.ADD_TO_BASKET: var addedItem = (AddToBasketEvent)posEvent; _basket.Id = addedItem.BasketId; _basket.Items.Add(addedItem.BasketItem); ItemAdded?.Invoke(this, addedItem.BasketItem); break; case PosEventType.BASKET_COMMITTED: var basketCommittedEvent = (BasketCommittedEvent)posEvent; // Check: // (1) Incoming .BasketId is what we expect. This is just a sanity check, and should never fail. // (2) basketCommittedEvent.Basket.Committed = TRUE // (3) this.FailOnCommit = FALSE. This may be set to TRUE to test correct processing of a Commit failure. if (_basket.Id == basketCommittedEvent.BasketId && basketCommittedEvent.Basket.Committed && !FailOnCommit) { _basket.Clear(); _basket.Id = basketCommittedEvent.BasketId; foreach (var basketItem in basketCommittedEvent.Basket.basketItems) { _basket.Items.Add(basketItem); // Now with Touch ID, and Vouchers (we trust!) if (basketItem is PurchaseBasketItem) { var purchase = (PurchaseBasketItem)basketItem; if (purchase.Vouchers?.Count > 0) { GetVoucher(purchase.Vouchers[0].Link); } } else if (basketItem is RefundBasketItem) { var refund = (RefundBasketItem)basketItem; if (refund.RefundVoucher != null) { GetVoucher(refund.RefundVoucher.Link); } } } _basket.Committed = true; BasketCommitted?.Invoke(this, _basket); } else { ProcessFailedCommit(); } // _basket.Clear(); break; case PosEventType.REMOVE_FROM_BASKET: var removeFromBasketEvent = (RemoveFromBasketEvent)posEvent; foreach (var basketItem in _basket.Items) { if (basketItem.Id == removeFromBasketEvent.BasketItemId) { _basket.Items.Remove(basketItem); ItemRemoved?.Invoke(this, basketItem); break; } } break; case PosEventType.PRINT_VOUCHER: // This is an "unexpected" ad hoc voucher... var PrintVoucherEvent = (PrintVoucherEvent)posEvent; VoucherAvailable?.Invoke(this, PrintVoucherEvent.Data); break; case PosEventType.VOUCHER_HTML: //...whereas this is the response to the BasketGetVoucherEvent message var voucherHtmlEvent = (VoucherHtmlEvent)posEvent; if (!string.IsNullOrEmpty(voucherHtmlEvent.VoucherHtml)) { VoucherAvailable?.Invoke(this, voucherHtmlEvent.VoucherHtml); } break; case PosEventType.START_DEVICE: var startDeviceEvent = (StartDeviceEvent)posEvent; StartDevice?.Invoke(this, startDeviceEvent.Device); break; case PosEventType.STOP_DEVICE: var stopDeviceEvent = (StopDeviceEvent)posEvent; StopDevice?.Invoke(this, stopDeviceEvent.Device); break; case PosEventType.DISPLAY_MESSAGE: var displayMessageEvent = (DisplayMessageEvent)posEvent; DisplayMessage?.Invoke(this, displayMessageEvent.Message); break; case PosEventType.SIMPLE_PRODUCT: var simpleProductEvent = (SimpleProductEvent)posEvent; SimpleProduct?.Invoke(this, new SimpleProductInfo(simpleProductEvent)); break; case PosEventType.SYNC_BASKET: var synBasketEvent = (SyncBasketEvent)posEvent; SyncBasket?.Invoke(this, null); break; case PosEventType.ERROR: var errorEvent = (ErrorEvent)posEvent; if (errorEvent.Method == "BasketCommitBasket") { ProcessFailedCommit(); } Error?.Invoke(this, errorEvent.Reason); break; default: Debug.Assert(false); // Unknown PosEventType break; } }
private void MiReSendMsg_Click(object sender, RoutedEventArgs e) { MenuItem mi = sender as MenuItem; ContextMenu ctxMenu = mi.Parent as ContextMenu; DataGrid dataGrid = ctxMenu.PlacementTarget as DataGrid; if (dataGrid.SelectedItems != null && dataGrid.SelectedItems.Count > 0) { foreach (var item in dataGrid.SelectedItems) { DeviceBase device = item as DeviceBase; if (device is StopDevice) { try { StopDevice stop = device as StopDevice; PLCMsg msg = new PLCMsg() { NO = stop.NO, DEVICE_TYPE = stop.DEVICE_TYPE, PALLET_COUNT = stop.PALLET_COUNT, STATUS = stop.STATUS, MESSAGE_TYPE = "plc", time_stamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") }; string strMsg = JsonConvert.SerializeObject(msg); viewModel?.mqClient?.SentMessage(strMsg); MessageBox.Show("发送挡停信息完毕!"); } catch (Exception ex) { MyLogLib.MyLog.WriteLog("手动发送挡停信息失败!", ex); MessageBox.Show("发送挡停信息失败!"); } } else if (device is MachineDevice) { try { MachineDevice machine = device as MachineDevice; PLCMsg msg = new PLCMsg() { NO = machine.NO, DEVICE_TYPE = machine.DEVICE_TYPE, PALLET_COUNT = machine.PALLET_COUNT, STATUS = machine.STATUS, MESSAGE_TYPE = "plc", time_stamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") }; string strMsg = JsonConvert.SerializeObject(msg); viewModel?.mqClient?.SentMessage(strMsg); MessageBox.Show("发送挡停信息完毕!"); } catch (Exception ex) { MyLogLib.MyLog.WriteLog("手动发送专机信息失败!", ex); MessageBox.Show("发送专机信息失败!"); } } else if (device is ScanDevice) { try { StopDevice stop = (device as ScanDevice).Stop; if (stop == null) { return; } PLCMsg msg = new PLCMsg() { NO = stop.NO, DEVICE_TYPE = stop.DEVICE_TYPE, PALLET_COUNT = stop.PALLET_COUNT, STATUS = stop.STATUS, MESSAGE_TYPE = "plc", time_stamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") }; string strMsg = JsonConvert.SerializeObject(msg); viewModel?.mqClient?.SentMessage(strMsg); MessageBox.Show("上传档停状态完毕!"); } catch (Exception ex) { MyLogLib.MyLog.WriteLog("手动发送挡停信息失败!", ex); MessageBox.Show("发送挡停信息失败!"); } } } } }