示例#1
0
    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("StartList");
            XElement floder = xdoc.Element("IP_Lab").Element("Floder");
            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)
            {
                StartDevice sd = new StartDevice(file, shell, si.sysname);
                if (sd.Start())
                    continue;
                else
                    return sd.GetFileName() + " 启动失败!";
            }

            return "启动设备成功!";
        }
        catch (System.Exception ex)
        {
            return ex.Message;
        }
    }
示例#2
0
        /*
         *  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;
            }
        }