Example #1
0
 public override void Deactivate()
 {
     AutomationContext.DeactivateAction();
     AutomationContext.DeactivateView();
     App.HeaderControl.RemoveAll();
     base.Deactivate();
 }
Example #2
0
        public override void Execute()
        {
            try
            {
                object state = AutomationContext.Read(memoryServiceName, memoryItemName);
                if (state == null || state.ToString() != "ScanCodeFaultReset")
                {
                    return;
                }

                state = AutomationContext.Read(scanServiceName2, scanItemName2);
                if (state == null || state.ToString() == string.Empty)
                {
                    return;
                }
                string barcode = state.ToString();

                state = AutomationContext.Read(plcServiceName, O_Stockin_Scan_Alarm);
                state = ObjectUtil.GetObject(state);
                if (state == null || state.ToString() != "1")
                {
                    return;
                }

                AutomationContext.Write(scanServiceName1, scanItemName1, barcode);
            }
            catch (Exception ex)
            {
                Logger.Error("ScanCodeFaultResetProcess 出错,原因:" + ex.Message + "/n" + ex.StackTrace);
            }
        }
Example #3
0
        public async Task <ApiResult> Run(AutomationContext context, CancellationToken cancellationToken)
        {
            var automations = await _repository.Search(new AutomationSearchRequest
            {
                EntityTypeCode = context.EntityTypeCode,
                EntityTypeUid  = context.EntityTypeUid,
                IsActive       = true,
                IncludeRules   = true,
                PageSize       = 100
            }, cancellationToken);

            var affected = 0;

            foreach (var automation in automations.Rows)
            {
                if (await MeetAll(automation.Conditions, context, cancellationToken))
                {
                    await Execute(automation.Actions, context, cancellationToken);

                    affected++;
                }
            }

            return(new ApiResult {
                AffectedRows = affected
            });
        }
Example #4
0
        internal void UpdateBarcode(string text, string productCode, string barcode)
        {
            if (!ScanManagerView.InitCigaretteScanInfoStack())
            {
                return;
            }
            ProductDal productDal = new ProductDal();

            if (barcode != string.Empty && productDal.Exist(barcode))
            {
                return;
            }
            DataTable table = productDal.FindProduct(productCode);

            if (table.Rows.Count > 0)
            {
                UpdateBarcodeDialog updateBarcodeDialog = new UpdateBarcodeDialog(CigaretteScanInfoStack.Values.ToArray());
                updateBarcodeDialog.setInformation(text, barcode);
                if (updateBarcodeDialog.ShowDialog() == DialogResult.OK)
                {
                    if (updateBarcodeDialog.IsPass && updateBarcodeDialog.Barcode.Length == 6)
                    {
                        productCode = updateBarcodeDialog.SelectedCigaretteCode;
                        barcode     = updateBarcodeDialog.Barcode;
                        productDal.UpdateBarcode(productCode, barcode);
                        CigaretteScanInfoStack[productCode].Barcode = barcode;
                        AutomationContext.Write(memoryServiceName, memoryItemName, CigaretteScanInfoStack);
                    }
                    else
                    {
                        XtraMessageBox.Show("验证码错误,或者条码格式不对!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
        private void btnHandScan_Click(object sender, EventArgs e)
        {
            try
            {
                object state = AutomationContext.Read(memoryServiceName1, memoryItemName1);
                if (state == null || state.ToString() != "WholePalletScan")
                {
                    XtraMessageBox.Show("当手持扫码模式不是 [手持扫码整托盘入库]!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                state = AutomationContext.Read(plcServiceName, I_Whole_Pallet_StockIn_Scan_Request);
                state = ObjectUtil.GetObject(state);
                if (state == null || !Convert.ToBoolean(state))
                {
                    XtraMessageBox.Show("当前PLC未请求扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                ScanDialog scanDialog = new ScanDialog();
                scanDialog.Text = "整盘入库手工扫码!";
                if (scanDialog.ShowDialog() == DialogResult.OK)
                {
                    int[] data = new int[] { scanDialog.ProductNo, scanDialog.Quantity };
                    AutomationContext.Write(memoryServiceName2, memoryItemName2, data);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(string.Format("手工扫码失败,详情原因 : {0}", ex.Message), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #6
0
 public override void Activate()
 {
     AddHeaderRootItems();
     AutomationContext.ActivateAction();
     AutomationContext.ActivateView();
     base.Activate();
 }
Example #7
0
        internal void Complete()
        {
            if (!ScanManagerView.InitCigaretteScanInfoStack())
            {
                return;
            }
            string            productCode = gridView.GetSelectedRows().Count() > 0 ? gridView.GetRowCellValue(gridView.GetSelectedRows()[0], "ProductCode").ToString() : "";
            CigaretteScanInfo info        = CigaretteScanInfoStack.Keys.Contains(productCode)
                                        ? CigaretteScanInfoStack[productCode] : null;

            if (info == null)
            {
                XtraMessageBox.Show("请选择要完成扫码的品牌!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (info.State != "3")
            {
                XtraMessageBox.Show("请选择正在扫码的品牌!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string productName = gridView.GetSelectedRows().Count() > 0 ? gridView.GetRowCellValue(gridView.GetSelectedRows()[0], "ProductName").ToString() : "";

            if (XtraMessageBox.Show("确认完成扫码吗?当前[" + productName + "]码盘是否确实已完成!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                info.Index = 0; info.State = "4";
                lock (CigaretteScanInfoStack)
                {
                    CigaretteScanInfoStack.Remove(info.ProductCode);
                }
                AutomationContext.Write(memoryServiceName, memoryItemName, CigaretteScanInfoStack);
            }
            Refresh();
        }
Example #8
0
        internal void Pause()
        {
            if (!ScanManagerView.InitCigaretteScanInfoStack())
            {
                return;
            }
            string            productCode = gridView.GetSelectedRows().Count() > 0 ? gridView.GetRowCellValue(gridView.GetSelectedRows()[0], "ProductCode").ToString() : "";
            CigaretteScanInfo info        = CigaretteScanInfoStack.Keys.Contains(productCode)
                                        ? CigaretteScanInfoStack[productCode] : null;

            if (info == null)
            {
                XtraMessageBox.Show("请选择要停止扫码的品牌!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (info.State == "0" || info.State == "1" || info.State == "4")
            {
                XtraMessageBox.Show("请选择等待扫码或正在扫码的品牌!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string productName = gridView.GetSelectedRows().Count() > 0 ? gridView.GetRowCellValue(gridView.GetSelectedRows()[0], "ProductName").ToString() : "";

            if (XtraMessageBox.Show("确认暂停扫码?当前[" + productName + "]码盘会清空!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                info.Index = 0; info.State = "1";
                AutomationContext.Write(plcServiceName, O_StockIn_Scan_Cancel, info.ProductNo);
                lock (CigaretteScanInfoStack)
                {
                    CigaretteScanInfoStack.Remove(info.ProductCode);
                }
                AutomationContext.Write(memoryServiceName, memoryItemName, CigaretteScanInfoStack);
            }
            Refresh();
        }
        private void DockManager_PanelClosed(object sender, DockablePanelEventArgs e)
        {
            switch (e.ActivePanelKey)
            {
            case "kStockChannelQuery":
                stockChannelQueryIsOpen = false;
                App.DockManager.Remove("kStockChannelQuery");
                App.HeaderControl.Remove(actionItem[0].Key);
                return;

            case "kScanQuery":
                stateManagerViewIsOpen = false;
                App.HeaderControl.Remove(actionItem[5].Key);
                App.HeaderControl.Remove(actionItem[6].Key);
                App.DockManager.Remove("kScanQuery");
                return;

            case "kSortChannelQuery":
                sortChannelQueryIsOpen = false;
                App.HeaderControl.Remove(actionItem[1].Key);
                App.HeaderControl.Remove(actionItem[2].Key);
                App.DockManager.Remove("kSortChannelQuery");
                return;

            case "kOrderStateQuery":
                orderQueryViewIsOpen = false;
                App.HeaderControl.Remove(actionItem[3].Key);
                App.HeaderControl.Remove(actionItem[4].Key);
                App.DockManager.Remove(AutomationContext.GetView <OrderStateQueryView>().Key);
                return;
            }
        }
 private void OrderQuery_Click(object sender, EventArgs e)
 {
     if (!orderQueryViewIsOpen)
     {
         AddDockablePanel(AutomationContext.GetView <OrderStateQueryView>());
         orderQueryViewIsOpen = true;
     }
     App.DockManager.SelectPanel(AutomationContext.GetView <OrderStateQueryView>().Key);
 }
 private void SortChannelQuery_Click(object sender, EventArgs e)
 {
     if (!sortChannelQueryIsOpen)
     {
         AddDockablePanel(AutomationContext.GetView <SortChannelQueryView>());
         sortChannelQueryIsOpen = true;
     }
     App.DockManager.SelectPanel("kSortChannelQuery");
 }
        private void btnStopRefresh_Click(object sender, EventArgs e)
        {
            var view = AutomationContext.GetView <ScanManagerView>();

            if (view != null)
            {
                view.Focus = false;
            }
        }
Example #13
0
        public async Task <bool> Meet(AutomationCondition automationCondition, AutomationContext context, CancellationToken cancellationToken)
        {
            var condition = (FieldAutomationCondition)automationCondition;

            var entity = await _automationContextProvider.GetEntity(context, cancellationToken);

            var props = condition.Props;

            var result = false;

            // todo: move to automation context provider (?)
            var property = entity.GetType().GetProperty(props.Field);

            if (property != null)
            {
                var getMethod = property.GetGetMethod();

                if (getMethod != null)
                {
                    var value = Convert.ToString(getMethod.Invoke(entity, null));

                    var compareResult = string.Compare(value, props.Value, StringComparison.OrdinalIgnoreCase);

                    switch (props.Operator)
                    {
                    case AutomationConditionOperator.Equal:
                        result = compareResult == 0;
                        break;

                    case AutomationConditionOperator.NotEqual:
                        result = compareResult != 0;
                        break;

                    case AutomationConditionOperator.LessThan:
                        result = compareResult < 0;
                        break;

                    case AutomationConditionOperator.LessThanEqual:
                        result = compareResult <= 0;
                        break;

                    case AutomationConditionOperator.GreaterThan:
                        result = compareResult > 0;
                        break;

                    case AutomationConditionOperator.GreaterThanEqual:
                        result = compareResult >= 0;
                        break;

                    default:
                        throw new InvalidOperationException($"Operator {props.Operator} is not supported.");
                    }
                }
            }

            return(result);
        }
Example #14
0
        public async Task <object> GetEntity(AutomationContext context, CancellationToken cancellationToken)
        {
            var result = await _repository.Search(new DocumentSearchRequest
            {
                Uid           = context.EntityUid,
                IncludeFields = true
            }, cancellationToken);

            return(result.Rows.Single());
        }
        private void ScanRefresh_Click(object sender, EventArgs e)
        {
            string index = ((DropDownActionItem)actionItem[5]).SelectedItem == null ? "" : ((DropDownActionItem)actionItem[5]).SelectedItem.ToString().Split('-')[0];

            if (index == "")
            {
                return;
            }
            AutomationContext.GetView <ScanQueryView>().Refresh(index);
        }
Example #16
0
        public async Task <object> GetEntity(AutomationContext context, CancellationToken cancellationToken)
        {
            if (context.Values.TryGetValue(EntityKey, out var entity) == false)
            {
                var contextProvider = _serviceFactory.GetRequiredService(context.EntityTypeCode);

                entity = context.Values[EntityKey] = await contextProvider.GetEntity(context, cancellationToken);
            }

            return(entity);
        }
Example #17
0
        private async Task Execute(IEnumerable <AutomationAction> actions, AutomationContext context, CancellationToken cancellationToken)
        {
            if (actions != null)
            {
                foreach (var action in actions)
                {
                    var provider = _providerRegistry.GetActionProvider(action.Type);

                    await provider.Execute(action, context, cancellationToken);
                }
            }
        }
 public List <SelectListItem> GetDepartmentsListItems()
 {
     using (AutomationContext context = new AutomationContext())
     {
         var result = from d in context.Departments.Where(x => x.IsActive == true)
                      select new SelectListItem
         {
             Text  = d.DepartmentName,
             Value = d.DepartmentId.ToString()
         };
         return(result.ToList());
     }
 }
Example #19
0
        public async Task <bool> Meet(AutomationCondition automationCondition, AutomationContext context, CancellationToken cancellationToken)
        {
            var condition = (GroupAutomationCondition)automationCondition;

            var props = condition.Props;

            if (props.Meet == AutomationConditionMeet.All)
            {
                return(await MeetAll(props.Conditions, context, cancellationToken));
            }

            return(await MeetAny(props.Conditions, context, cancellationToken));
        }
Example #20
0
 public List <SelectListItem> GetRoles()
 {
     using (AutomationContext context = new AutomationContext())
     {
         var result = from r in context.Roles
                      select new SelectListItem
         {
             Text  = r.RoleName,
             Value = r.RoleId.ToString()
         };
         return(result.ToList());
     }
 }
Example #21
0
 public List <SelectListItem> GetBrandListItems()
 {
     using (AutomationContext context = new AutomationContext())
     {
         var result = from p in context.Products.Where(p => p.IsActive == true)
                      select new SelectListItem
         {
             Text  = p.Brand,
             Value = p.ProductId.ToString()
         };
         return(result.ToList());
     }
 }
 public List <SelectListItem> GetCustomerListItems()
 {
     using (AutomationContext context = new AutomationContext())
     {
         var result = from c in context.Customers.Where(c => c.IsActive == true)
                      select new SelectListItem
         {
             Text  = c.CustomerName,
             Value = c.CustomerId.ToString()
         };
         return(result.ToList());
     }
 }
Example #23
0
 public List <SelectListItem> GetEmployeeListItems()
 {
     using (AutomationContext context = new AutomationContext())
     {
         var result = from e in context.Employees.Where(e => e.IsActive == true)
                      select new SelectListItem
         {
             Text  = e.EmployeeName,
             Value = e.EmployeeId.ToString()
         };
         return(result.ToList());
     }
 }
        public InteractiveVM()
        {
            var scriptingContext  = new IronPythonScriptingContext();
            var automationContext = new AutomationContext(scriptingContext);

            AutomationContext.Current = automationContext;

            scriptingContext.InjectGlobalVariable("automation_context", automationContext);
            scriptingContext.LoadEmbeddedScript(Assembly.GetExecutingAssembly(), "Automation/Scripts/(Initialize).py");
            scriptingContext.LoadEmbeddedScript(Assembly.GetExecutingAssembly(), "Automation/Scripts/Globals.py");
            scriptingContext.ExternalScriptPaths.Add(Path.GetDirectoryName("Scripts"));
            this.Context = scriptingContext;
        }
Example #25
0
 internal void UploadSize()
 {
     foreach (var cigaretteScanInfo in CigaretteScanInfoStack.Values)
     {
         ProductDal        productDal = new ProductDal();
         CigaretteScanInfo info       = productDal.FindProductForScan(cigaretteScanInfo.ProductCode);
         cigaretteScanInfo.ProductNo = info.ProductNo;
         cigaretteScanInfo.Length    = info.Length;
         cigaretteScanInfo.Width     = info.Width;
         cigaretteScanInfo.Height    = info.Height;
         cigaretteScanInfo.Barcode   = info.Barcode;
     }
     AutomationContext.Write(memoryServiceName, memoryItemName, CigaretteScanInfoStack);
 }
Example #26
0
        internal void Scan()
        {
            if (!ScanManagerView.InitCigaretteScanInfoStack())
            {
                return;
            }
            string            productCode = gridView.GetSelectedRows().Count() > 0 ? gridView.GetRowCellValue(gridView.GetSelectedRows()[0], "ProductCode").ToString() : "";
            CigaretteScanInfo info        = CigaretteScanInfoStack.Keys.Contains(productCode)
                                        ? CigaretteScanInfoStack[productCode] : null;

            if (info == null)
            {
                XtraMessageBox.Show("请选择要扫码的品牌!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (info.State == "2" || info.State == "3" || info.State == "4")
            {
                XtraMessageBox.Show("请选择未扫码的品牌!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            int[] data = new int[] { info.ProductNo, info.Quantity - info.ScanQuantity, info.Length, info.Width, info.Height, info.AreaNo, 1 };
            if (AutomationContext.Write(plcServiceName, O_StockIn_Scan_Info, data))
            {
                Thread.Sleep(1000);
                object obj = AutomationContext.Read(plcServiceName, I_StockIn_Scan_Info);
                if (obj is Array)
                {
                    Array arrayObj = (Array)obj;
                    if (arrayObj.Length == 7 &&
                        data[0] == Convert.ToInt32(arrayObj.GetValue(0)) &&
                        data[1] == Convert.ToInt32(arrayObj.GetValue(1)) &&
                        data[2] == Convert.ToInt32(arrayObj.GetValue(2)) &&
                        data[3] == Convert.ToInt32(arrayObj.GetValue(3)) &&
                        data[4] == Convert.ToInt32(arrayObj.GetValue(4)) &&
                        data[5] == Convert.ToInt32(arrayObj.GetValue(5)) &&
                        data[6] == Convert.ToInt32(arrayObj.GetValue(6)))
                    {
                        if (AutomationContext.Write(plcServiceName, O_StockIn_Scan_Complete, 1))
                        {
                            info.Index = CigaretteScanInfoStack.Values.Max(c => c.Index) + 1;
                            info.State = "2";
                            AutomationContext.Write(memoryServiceName, memoryItemName, CigaretteScanInfoStack);
                        }
                    }
                }
            }
            Refresh();
        }
Example #27
0
        /// <summary>
        /// 更新游戏
        /// </summary>
        /// <param name="patchName">更新包的名字</param>
        bool UpdateGame(int userId, string patchName)
        {
            bool result = false;

            if (_server.IsConnected)
            {
                //TODO 这里要确保游戏进程不存在才能允许更新

                string cmdScript = ShellScriptManager.TheInstance.GetScript("UpdateGame", _server.SystemName);
                if (cmdScript != null)
                {
                    string cmdText = string.Format(
                        cmdScript,
                        _server.GuardDir + GameServer.FilePathDelimiter + GameServer.UploadFileDir,
                        patchName,
                        _server.GameInstallDir);
                    if (cmdText != null)
                    {
                        _stackTrace.Length = 0;
                        if (ExecuteSystemCommand(userId, cmdText, string.Empty, GuardTask.UpdateGameServer, true))
                        {
                            _updateGameResult.Length = 0;

                            _server.AppendMessage(string.Format("UpdateGameBegin\nPatchName:\"{0}\"", patchName), GameServer.MessageInfo.Type.Alert);

                            //触发UpdateGameBegin事件
                            AutomationContext context = new AutomationContext();
                            context.Message = string.Format("{0} UpdateGameBegin\nPatchName:\"{1}\"", _server.ToString(), patchName);;
                            context.Server  = _server;
                            AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.UpdateGameBegin, context);

                            result = true;
                        }
                    }
                }
            }

            User user = AdminServer.TheInstance.SecurityManager.GetUser(userId);

            Security.LogSystem.TheInstance.WriteLog(userId,
                                                    Security.OpType.EXECUTE,
                                                    _server.Id,
                                                    string.Format(StringDef.LogMessageUpdateGame,
                                                                  user == null ? userId.ToString() : user.UserName,
                                                                  _server.Name,
                                                                  result ? StringDef.Success : StringDef.Fail)
                                                    );
            return(result);
        }
Example #28
0
        private bool InitSRMS(string srmName)
        {
            if (!SRMS.ContainsKey(srmName))
            {
                var srm = AutomationContext.Read(memoryServiceName, srmName) as Device.SRM;

                if (srm != null)
                {
                    SRMS.Add(srmName, srm);
                    return(true);
                }
                return(false);
            }
            return(true);
        }
Example #29
0
        public async Task <IList <FieldMetadata> > GetFields(AutomationContext context, CancellationToken cancellationToken)
        {
            // todo: combine document fields + fields from document questionaire
            var entityType = typeof(Document);

            var fields = entityType
                         .GetProperties()
                         .Select(x => new TextField {
                Key = x.Name, Name = x.Name
            })
                         .Cast <FieldMetadata>()
                         .ToList();

            return(await Task.FromResult(fields));
        }
 private void btnUploadSize_Click(object sender, EventArgs e)
 {
     try
     {
         var view = AutomationContext.GetView <ScanManagerView>();
         if (view != null)
         {
             view.UploadSize();
         }
     }
     catch (Exception ex)
     {
         XtraMessageBox.Show(string.Format("更新尺寸信息失败,详情原因 : {0}", ex.Message), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #31
0
		private void MessageReceived(GameServer server, IProtocol message)
		{
			switch ((ProtocolDef)message.ProtocolId)
			{
				case ProtocolDef.g2e_exesyscmd_def:
					{
						g2e_exesyscmd protocol = message as g2e_exesyscmd;
						FSEyeResult returnCode = (FSEyeResult)protocol.ReturnCode;

						switch (_guardTask)
						{
							case GuardTask.Unknown:
							case GuardTask.Idle:
                                //设置时间服务器断连后的回包处理
                                //if (returnCode == FSEyeResult.g2e_ExeSysCmd_done) break;
								//throw new Exception("State Exception");
							case GuardTask.StartGameServer:
								switch (returnCode)
								{
									case FSEyeResult.g2e_ExeSysCmd_done:
										_guardTask = GuardTask.Idle;
										break;
									case FSEyeResult.g2e_ExeSysCmd_busy:
										break;
									case FSEyeResult.g2e_ExeSysCmd_result:
										AppendSysCmdOutput(protocol.OutputBuff);
										break;
								}
								break;
							case GuardTask.DoNormalSysCmd:
								switch (returnCode)
								{
									case FSEyeResult.g2e_ExeSysCmd_done:
										_guardTask = GuardTask.Idle;                                                                        
										break;
									case FSEyeResult.g2e_ExeSysCmd_busy:
										break;
									case FSEyeResult.g2e_ExeSysCmd_result:
										AppendSysCmdOutput(protocol.OutputBuff);
										break;
								}
								break;
							case GuardTask.UpdateGameServer:
								switch (returnCode)
								{
									case FSEyeResult.g2e_ExeSysCmd_done:
										{
											_guardTask = GuardTask.Idle;
											if (_updateGameResult.ToString().Contains("fail"))
											{
												server.AppendMessage(string.Format("UpdateGameFail\nFailureMessage:\"{0}\"", _updateGameResult.ToString()), GameServer.MessageInfo.Type.Failure);

												//触发UpdateGameFail事件
												AutomationContext context = new AutomationContext();
												context.Message = string.Format("{0} UpdateGameFail\nFailureMessage:\"{1}\"", server.ToString(), _updateGameResult.ToString()); ;
												context.Server = server;
												AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.UpdateGameFail, context);
											}
											else
											{
												server.AppendMessage("UpdateGameSucceed", GameServer.MessageInfo.Type.Success);

												//触发UpdateGameSucceed事件
												AutomationContext context = new AutomationContext();
												context.Message = string.Format("{0} UpdateGameSucceed", server.ToString());
												context.Server = server;
												AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.UpdateGameSucceed, context);
											}
										}
										break;
									case FSEyeResult.g2e_ExeSysCmd_busy:
										break;
									case FSEyeResult.g2e_ExeSysCmd_result:
										_updateGameResult.Append(protocol.OutputBuff);
										break;
								}
								break;
							case GuardTask.RefreshUploadDirFileInfo:
								switch (returnCode)
								{
									case FSEyeResult.g2e_ExeSysCmd_done:
										_guardTask = GuardTask.Idle;
                                        break;
									case FSEyeResult.g2e_ExeSysCmd_busy:
										break;
									case FSEyeResult.g2e_ExeSysCmd_result:
                                        _uploadDirInfo += protocol.OutputBuff;
										break;
								}
								break;
							case GuardTask.CheckGame:
								switch (returnCode)
								{
									case FSEyeResult.g2e_ExeSysCmd_done:
										_guardTask = GuardTask.Idle;
										_GameProcessState = (protocol.OutputBuff.Length > 0) ? GameProcessState.Exist : GameProcessState.NotExist;
										break;
									case FSEyeResult.g2e_ExeSysCmd_busy:
										break;
									case FSEyeResult.g2e_ExeSysCmd_result:
										break;
								}
								break;
							case GuardTask.GetStatckStrace:
								switch (returnCode)
								{
									case FSEyeResult.g2e_ExeSysCmd_done:
										_guardTask = GuardTask.Idle;
										_getStackTraceState = GetStackTraceState.Done;
										break;
									case FSEyeResult.g2e_ExeSysCmd_busy:
										break;
									case FSEyeResult.g2e_ExeSysCmd_result:
										_stackTrace.Append(protocol.OutputBuff);
										break;
								}
								break;

                            ////2008-03 huangbiao 去掉getTime任务
                            case GuardTask.GetServerTime:
                            ////    switch (returnCode)
                            ////    {
                            ////        case FSEyeResult.g2e_ExeSysCmd_done:
                            ////            _guardTask = GuardTask.Idle;
                            ////            break;
                            ////        case FSEyeResult.g2e_ExeSysCmd_busy:
                            ////            GetServerTime(1);
                            ////            break;
                            ////        case FSEyeResult.g2e_ExeSysCmd_result:
                            ////            try
                            ////            {
                            ////                string dateText = protocol.OutputBuff.TrimEnd('\n').Replace('_', ' ');
                            ////                _serverTimeSpan = DateTime.Now.Subtract(DateTime.Parse(dateText));
                            ////            }
                            ////            catch (Exception ex)
                            ////            {
                            ////                throw (ex);
                            ////            }
                            ////            break;
                            ////    }
                                break;
							default:
								throw new Exception("State Exception");
						}

						switch (returnCode)
						{
							case FSEyeResult.g2e_ExeSysCmd_done:
								if (_exeSysCmdComplete != null)
								{
									_exeSysCmdComplete(_server, true, _sysCmdOutput.ToString());
									_exeSysCmdComplete = null;
								}
								break;
							case FSEyeResult.g2e_ExeSysCmd_busy:
								if (_exeSysCmdComplete != null)
								{
									_exeSysCmdComplete(_server, false, "busy");
									_exeSysCmdComplete = null;
								}
								break;
							case FSEyeResult.g2e_ExeSysCmd_result:
								break;
						}
					}
					break;
				case ProtocolDef.g2e_GetGuardDir_def:
					{
						g2e_GetGuardDir protocol = message as g2e_GetGuardDir;
						server.GuardDir = protocol.GuardDir;
					}
					break;
				case ProtocolDef.g2e_switchmode_def:
					{

						server.AppendMessage(StringDef.StopConfigGuard, GameServer.MessageInfo.Type.Normal);

                        AdminServer.TheInstance.GameServerManager.SendServerConfigFile(server);
                        
                        foreach (GameServer svr in AdminServer.TheInstance.GameServerManager._gameServerList)
                        {
                            if (svr.IpAddress == server.IpAddress)
                            {
                                svr.ConfigState = GameServer.ConfigGuardState.Configured;
                                AdminServer.TheInstance.GameServerManager.ModifyGameServer(svr, svr.Name, svr.Comment, svr.IpAddress, svr.GameDir, svr.Group, svr.LordConfig, svr.ConfigState, svr.ConfigContent, svr.Type, svr.FtpServer);

                            }
                        }
					}
					break;
				case ProtocolDef.g2e_config_def:
					{
						//TODO 提示重新配置Guard成功
						UpdateGuard(0);
					}
					break;
				default:
					break;
			}
		}
Example #32
0
		/// <summary>
		/// 更新游戏
		/// </summary>
		/// <param name="patchName">更新包的名字</param>
		bool UpdateGame(int userId,string patchName)
		{
            bool result = false;
			if (_server.IsConnected)
			{
				//TODO 这里要确保游戏进程不存在才能允许更新

                string cmdScript = ShellScriptManager.TheInstance.GetScript("UpdateGame", _server.SystemName);
				if (cmdScript != null)
				{                    
					string cmdText = string.Format(
						cmdScript,
						_server.GuardDir + GameServer.FilePathDelimiter + GameServer.UploadFileDir,
						patchName,
						_server.GameInstallDir);
					if (cmdText != null)
					{
						_stackTrace.Length = 0;
						if (ExecuteSystemCommand(userId,cmdText, string.Empty, GuardTask.UpdateGameServer, true))
						{
							_updateGameResult.Length = 0;

							_server.AppendMessage(string.Format("UpdateGameBegin\nPatchName:\"{0}\"", patchName), GameServer.MessageInfo.Type.Alert);

							//触发UpdateGameBegin事件
							AutomationContext context = new AutomationContext();
							context.Message = string.Format("{0} UpdateGameBegin\nPatchName:\"{1}\"", _server.ToString(), patchName); ;
							context.Server = _server;
							AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.UpdateGameBegin, context);

                            result = true;
						}
					}
				}
            }

            User user = AdminServer.TheInstance.SecurityManager.GetUser(userId);
            Security.LogSystem.TheInstance.WriteLog(userId,
                Security.OpType.EXECUTE,
                _server.Id,
                string.Format(StringDef.LogMessageUpdateGame,
                    user == null ? userId.ToString() : user.UserName,
                    _server.Name,
                    result ? StringDef.Success : StringDef.Fail)
            );
			return result;
		}
Example #33
0
		/// <summary>
		/// 设置模块状态码
		/// </summary>
		void SetModuleStateCode(int moduleIndex, int newStateCode)
		{
			if (moduleIndex >= 0 && moduleIndex < MaxModuleCount)
			{
				if (_moduleErrorCodes[moduleIndex] != newStateCode)
				{
					int originalStateCode = _moduleErrorCodes[moduleIndex];
					_moduleErrorCodes[moduleIndex] = newStateCode;

					if (ModuleStateChanged != null)
					{
						ModuleStateChanged(moduleIndex, originalStateCode, newStateCode);
					}

					if (newStateCode == -1 || newStateCode > 0)
					{
						AutomationContext context = new AutomationContext();						
						context.Server = _server;

						switch (moduleIndex)
						{
							case 0:
								{
									context.Message = string.Format(StringDef.GameModuleError, _server.ToString(), "Paysys", newStateCode);
									AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.ModulePaysysError, context);									
								}
								break;
							case 1:
								{
									context.Message = string.Format(StringDef.GameModuleError, _server.ToString(), "Database", newStateCode);
									AdminServer.TheInstance.StrategyManager.OnEvent(FSEyeEvent.ModuleDatabaseError, context);
								}
								break;
						}
					}
				}
			}
		}