public RedialResult Redial(Action action = null) { if (CheckIsRedialing()) { while (true) { Thread.Sleep(50); if (!CheckIsRedialing()) { //ReleaseRedialLocker(); return(RedialResult.OtherRedialed); } } } else { try { LogCenter.Log(null, "Wait all atomic action...", LogLevel.Warn); // 等待数据库等操作完成 WaitAll(); LogCenter.Log(null, "Start redial...", LogLevel.Warn); Redialer.Redial(); InternetDetector.Detect(); Thread.Sleep(2000); LogCenter.Log(null, "Redial finished.", LogLevel.Warn); action?.Invoke(); return(RedialResult.Sucess); } catch (IOException) { // 有极小可能同时调用File.Open时抛出异常 return(Redial(action)); } catch (Exception) { return(RedialResult.Failed); } finally { ReleaseRedialLocker(); if (AfterRedialWaitTime > 0) { Console.WriteLine($"Going to sleep for {AfterRedialWaitTime} after redial."); Thread.Sleep(AfterRedialWaitTime); } } } }
public static void Speak(string content) { try { speecher.Speak(content); } catch (Exception e) { LogCenter.Error(e.Message); } }
/// <summary> /// 更新FAI,檢驗完成回壓FAICount,第一次首件回壓FAIDevice /// </summary> /// <param name="equipmentName"></param> /// <param name="lot"></param> public static void UpdateFAI(string equipmentName, string lot, bool initFlag, TransactionStamp txs) { //取得批號資料 var lotData = LotInfo.GetLotByLot(lot); var faiData = CSTEquipmentFAIInfo.GetDataByEquipmentAndDevice(equipmentName, lotData.DeviceName); if (faiData == null) { return; } if (faiData.INSPTYPE == FAIType.CN.ToCimesString()) { #region 連N測試,只要一支NG,就要reset檢驗次數,重新送件 //判定NG的時候回壓初始化FAICount,判定OK則WAITFAICOUNT減1 if (initFlag) //NG { //取得料號版本的資料 var deviceVerExData = DeviceVersionInfo.GetDeviceVersion(lotData.DeviceName, lotData.DeviceVersion).ChangeTo <DeviceVersionInfoEx>(); //檢查料號的FAICount有無設定 if (deviceVerExData.FAICount.ToString().IsNullOrTrimEmpty()) { //T00541 //料號:xxx的系統屬性:xxx 未設定,請洽IT人員!) error code:T00031 throw new Exception(TextMessage.Error.T00541(deviceVerExData.DeviceName, "FAICount")); } faiData.WAITFAICOUNT = deviceVerExData.FAICount; } else //OK { faiData.WAITFAICOUNT = faiData.WAITFAICOUNT - 1; } #endregion } else { //首N測試,判定OK將WAITFAICOUNT減1就好,判定NG不須動作 if (!initFlag) { faiData.WAITFAICOUNT = faiData.WAITFAICOUNT - 1; } } faiData.UpdateToDB(txs.UserID, txs.RecordTime); LogCenter.LogToDB(faiData, LogCenter.LogIndicator.Create(ActionType.Set, txs.UserID, txs.RecordTime)); }
// Use this for initialization void Start() { DontDestroyOnLoad(this.gameObject); AppFacade.Instance.StartUp(); AppFacade.Instance.GetManager <GameManager>(ManagerName.Game).StartGame(); Application.logMessageReceived += LogHandler; LogCenter.Instance().OpenTrace(LogTraceType.File); Screen.sleepTimeout = SleepTimeout.NeverSleep; if (Application.isMobilePlatform) { Application.targetFrameRate = AppConst.GameFrameRate; } OnInitialize(); }
/// <summary> /// 儲存刀壽 /// </summary> /// <param name="userID"></param> /// <param name="recordTime"></param> private void SaveToolLife(string toolType, string userID, string recordTime) { //例外處理資料刪除的部份 _SourceToolTypeLifes.ForEach(toolTypeLife => { toolTypeLife.DeleteFromDB(); LogCenter.LogToDB(toolTypeLife, LogCenter.LogIndicator.Create(ActionType.Remove, userID, recordTime)); }); //新增刀壽設定清單 _ModifyToolTypeLifes.ForEach(toolTypeLife => { //註記刀壽設定LOG的狀態 ActionType actionType = new ActionType(); if (toolTypeLife.InfoState == InfoState.NewCreate) { //新增資料 toolTypeLife.ToolType = toolType; toolTypeLife.InsertToDB(userID, recordTime); actionType = ActionType.Add; //更新刀具已設定的刀壽次數 UpdateToolLifes(toolTypeLife, userID, recordTime); } else if (toolTypeLife.InfoState == InfoState.Modified) { //更改資料 toolTypeLife.ToolType = toolType; toolTypeLife.UpdateToDB(userID, recordTime); actionType = ActionType.Set; _SourceToolTypeLifes.Remove(toolTypeLife); //更新刀具已設定的刀壽次數 UpdateToolLifes(toolTypeLife, userID, recordTime); } else if (toolTypeLife.InfoState == InfoState.Unchanged) { _SourceToolTypeLifes.Remove(toolTypeLife); } //紀錄歷史紀錄[CST_TOOL_TYPE_LIFE_LOG] if (actionType != ActionType.None) { LogCenter.LogToDB(toolTypeLife, LogCenter.LogIndicator.Create(actionType, userID, recordTime)); } }); }
private void buttonEnable_Click(object sender, EventArgs e) { try { int temp = checkedListBoxModules.SelectedIndex; moduleOrder[checkedListBoxModules.SelectedIndex] = new KeyValuePair <bool, string>(!moduleOrder[checkedListBoxModules.SelectedIndex].Key, moduleOrder[checkedListBoxModules.SelectedIndex].Value); na.modules.UpdateModuleOrder(moduleOrder); moduleOrder = na.modules.GetModuleOrder(); UpdateView(); checkedListBoxModules.SelectedIndex = temp; } catch (Exception ne) { LogCenter.WriteErrorLog(ne); } }
private void DoArbiOrder() { if (!this.VerifyLogin()) { return; } LogCenter.Log("套利单发送,价差:" + this.Spread); string groupID = Guid.NewGuid().ToString(); foreach (var item in this.InstrumentModels) { var order = this.GenerateOrder(item, groupID); TradeAdapter.Instance.InsertOrder(order); } SpeechHelper.Speak("Order"); }
public override void OnRspQryInvestorPositionDetail(ThostFtdcInvestorPositionDetailField pInvestorPositionDetail, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (pRspInfo != null && pRspInfo.ErrorID != 0) { LogCenter.Error("查询投资者持仓明细错误:" + pRspInfo.ErrorMsg); return; } if (pInvestorPositionDetail == null) { return; } var detial = new InvestorPositionDetail { InstrumentID = pInvestorPositionDetail.InstrumentID, BrokerID = pInvestorPositionDetail.BrokerID, InvestorID = pInvestorPositionDetail.InvestorID, HedgeFlag = (HedgeFlag)pInvestorPositionDetail.HedgeFlag, Direction = (DirectionType)pInvestorPositionDetail.Direction, OpenDate = pInvestorPositionDetail.OpenDate, TradeID = pInvestorPositionDetail.TradeID, Volume = pInvestorPositionDetail.Volume, OpenPrice = pInvestorPositionDetail.OpenPrice, TradingDay = pInvestorPositionDetail.TradingDay, SettlementID = pInvestorPositionDetail.SettlementID, TradeType = (TradeType)pInvestorPositionDetail.TradeType, CombInstrumentID = pInvestorPositionDetail.CombInstrumentID, ExchangeID = pInvestorPositionDetail.ExchangeID, CloseProfitByDate = pInvestorPositionDetail.CloseProfitByDate, CloseProfitByTrade = pInvestorPositionDetail.CloseProfitByTrade, PositionProfitByDate = pInvestorPositionDetail.PositionProfitByDate, PositionProfitByTrade = pInvestorPositionDetail.PositionProfitByTrade, Margin = pInvestorPositionDetail.Margin, ExchMargin = pInvestorPositionDetail.ExchMargin, MarginRateByMoney = pInvestorPositionDetail.MarginRateByMoney, MarginRateByVolume = pInvestorPositionDetail.MarginRateByVolume, LastSettlementPrice = pInvestorPositionDetail.LastSettlementPrice, SettlementPrice = pInvestorPositionDetail.SettlementPrice, CloseVolume = pInvestorPositionDetail.CloseVolume, CloseAmount = pInvestorPositionDetail.CloseAmount, }; this.positionDetails.Add(detial); if (bIsLast) { PositionViewModel.Instance.Update(this.positionDetails); } }
public void WithoutNlogConfig() { var nlogConfig = LogCenter.GetDefaultConfigString(); XmlDocument document = new XmlDocument(); document.Load(new StringReader(nlogConfig)); Assert.Equal("nlog", document.DocumentElement.Name); Assert.Equal(2, document.DocumentElement.ChildNodes.Count); Assert.Equal(2, document.DocumentElement.ChildNodes[0].ChildNodes.Count); Assert.Equal("target", document.DocumentElement.ChildNodes[0].ChildNodes[0].Name); Assert.Equal("console", document.DocumentElement.ChildNodes[0].ChildNodes[0].Attributes["name"].Value); Assert.Equal("file", document.DocumentElement.ChildNodes[0].ChildNodes[1].Attributes["name"].Value); Assert.Equal(2, document.DocumentElement.ChildNodes[1].ChildNodes.Count); Assert.Equal("logger", document.DocumentElement.ChildNodes[1].ChildNodes[0].Name); Assert.Equal("console", document.DocumentElement.ChildNodes[1].ChildNodes[0].Attributes["writeTo"].Value); Assert.Equal("file", document.DocumentElement.ChildNodes[1].ChildNodes[1].Attributes["writeTo"].Value); }
public override void OnRspQryInstrument(ThostFtdcInstrumentField pInstrument, ThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast) { if (pRspInfo != null && pRspInfo.ErrorID != 0) { LogCenter.Error("请求查询合约错误:" + pRspInfo.ErrorMsg); return; } if (pInstrument.ProductClass == EnumProductClassType.Futures) { this.instruments.Add(new Instrument(pInstrument)); } if (bIsLast) { LogCenter.Log("收到期货合约数量:" + this.instruments.Count); InstrumentCenter.Instance.SetInstruments(this.instruments.OrderBy(p => p.InstrumentID).ToArray()); } }
public RedialResult Redial() { if (CheckIsRedialing()) { while (true) { Thread.Sleep(50); if (!CheckIsRedialing()) { return(RedialResult.OtherRedialed); } } } else { try { LogCenter.Log(null, "Wait all atomic action...", LogLevel.Warn); // 等待数据库等操作完成 WaitAll(); LogCenter.Log(null, "Start redial...", LogLevel.Warn); Redialer.Redial(); InternetDetector.Detect(); Thread.Sleep(2000); LogCenter.Log(null, "Redial finished.", LogLevel.Warn); return(RedialResult.Sucess); } catch (IOException) { // 有极小可能同时调用File.Open时抛出异常 return(Redial()); } catch (Exception) { return(RedialResult.Failed); } finally { ReleaseRedialLocker(); } } }
/// <summary> /// Builds the module Help window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonHelp_Click(object sender, EventArgs e) { try { ThemedForm f = new ThemedForm(); f.Size = new System.Drawing.Size(640, 480); System.Reflection.Assembly target = System.Reflection.Assembly.GetExecutingAssembly(); f.Icon = new System.Drawing.Icon(target.GetManifestResourceStream("PassThru.Resources.newIcon.ico")); f.Text = "Help"; Help uc = new Help(checkedListBoxModules.SelectedItem); uc.Dock = DockStyle.Fill; f.Controls.Add(uc); ColorScheme.SetColorScheme(f); f.Show(); } catch (Exception ne) { LogCenter.WriteErrorLog(ne); } }
public MainWindowBak() { LogCenter logCenter = new LogCenter(); this.Language = System.Windows.Markup.XmlLanguage.GetLanguage(System.Threading.Thread.CurrentThread.CurrentUICulture.IetfLanguageTag); mSSqlRep = new MSSqlRep(); mSSqlRep.newLogMessage += logCenter.AddMessage; mSSqlRep.newLogMessage += scrollLogView; InitializeComponent(); lst_log.ItemsSource = logCenter.records; logCenter.AddMessage("Репозитарий создан"); cbx_ClientType.DataContext = mSSqlRep.DtClientsTypes.DefaultView; dtg_Clients.DataContext = mSSqlRep.dt_clients.DefaultView; dtg_Accaunts.DataContext = mSSqlRep.dt_Accaunts.DefaultView; //repository.Generate(15); }
private void buttonMoveDown_Click(object sender, EventArgs e) { try { if (checkedListBoxModules.SelectedIndex != moduleOrder.Count - 1) { KeyValuePair <bool, string> temp = moduleOrder[checkedListBoxModules.SelectedIndex]; moduleOrder.RemoveAt(checkedListBoxModules.SelectedIndex); moduleOrder.Insert(checkedListBoxModules.SelectedIndex + 1, temp); na.modules.UpdateModuleOrder(moduleOrder); moduleOrder = na.modules.GetModuleOrder(); int newIndex = checkedListBoxModules.SelectedIndex + 1; UpdateView(); checkedListBoxModules.SelectedIndex = newIndex; } } catch (Exception ne) { LogCenter.WriteErrorLog(ne); } }
private void buttonOpenConfiguration_Click(object sender, EventArgs e) { try { UserControl uc = na.modules.GetModule(checkedListBoxModules.SelectedIndex).GetControl(); if (uc != null) { ThemedForm f = new ThemedForm(); f.Size = new System.Drawing.Size(640, 480); System.Reflection.Assembly target = System.Reflection.Assembly.GetExecutingAssembly(); f.Icon = new System.Drawing.Icon(target.GetManifestResourceStream("PassThru.Resources.newIcon.ico")); f.Text = na.InterfaceInformation.Name + ": " + na.modules.GetModule(checkedListBoxModules.SelectedIndex).MetaData.Name + " - " + na.modules.GetModule(checkedListBoxModules.SelectedIndex).MetaData.Version; f.Controls.Add(uc); ColorScheme.SetColorScheme(f); f.Show(); } } catch (Exception ne) { LogCenter.WriteErrorLog(ne); } }
public static bool ValidateProxy(string ip, int port) { bool isReachable = false; try { TcpClient tcp = new TcpClient(); IPAddress ipAddr = IPAddress.Parse(ip); tcp.ReceiveTimeout = 5000; Stopwatch watch = new Stopwatch(); watch.Start(); tcp.ConnectAsync(ipAddr, port).Wait(); watch.Stop(); LogCenter.Log(null, $"Detect one usefull proxy: {ip}:{port}, cost {watch.ElapsedMilliseconds}ms.", LogLevel.Debug); isReachable = true; } catch (Exception e) { LogCenter.Log(null, $"FAILRE - CAN not connect! Proxy: {ip}:{port}.", LogLevel.Error, e); } return(isReachable); }
protected void gvQuery_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { int dataIndex = gvQuery.Rows[e.RowIndex].DataItemIndex; //取得登入者資訊 var recordTime = DBCenter.GetSystemTime(); var userID = User.Identity.Name; using (CimesTransactionScope cts = CimesTransactionScope.Create()) { //刪除主檔資料 _ToolDevices[dataIndex].DeleteFromDB(); LogCenter.LogToDB(_ToolDevices[dataIndex], LogCenter.LogIndicator.Create(ActionType.Remove, userID, recordTime)); //取得明細資料 var toolDeviceDetails = CSTToolDeviceDetailInfo.GetDataListByToolDeviceSID(_ToolDevices[dataIndex].ToolDeviceSID); toolDeviceDetails.ForEach(toolDeviceDetail => { //刪除明細資料 toolDeviceDetail.DeleteFromDB(); LogCenter.LogToDB(toolDeviceDetail, LogCenter.LogIndicator.Create(ActionType.Remove, userID, recordTime)); }); cts.Complete(); } QueryData(); } catch (Exception E) { HandleError(E); } }