private static void DisplayError(string error, NLog.Logger logger = null) { if (null != logger) { logger.Error(error); } else { Console.Error.WriteLine(error); } }
private void TimeGo() { while (true) { TalePlayer.Oneloop(); timeTick++; if (timeTick > 1000) { timeTick -= 1000; } if (page == 0) { var logWid = tabPageLogin.Width / 4; var logHeight = tabPageLogin.Height / 5; var logX = (tabPageLogin.Width - logWid) / 2; var logY = (tabPageLogin.Height - logHeight) / 2 + Math.Sin((double)timeTick / 12) * 6; tabPageLogin.Invalidate(new Rectangle(logX, (int)logY - 6, logWid, logHeight + 12)); //logo区域 } else if (page == 1) { try { foreach (var control in tabPageGame.Controls) { if (control is BasePanel) { (control as BasePanel).OnFrame(timeTick, 0.05f); } } if (SystemMenuManager.IsHotkeyEnabled && (timeTick % 5) == 0) { SystemMenuManager.UpdateAll(tabPageGame); if (MainTipManager.OnFrame()) { tabPageGame.Invalidate(); } } if (SystemMenuManager.GMMode) { GMCodeZone.OnFrame(); } if (flowController != null) { flowController.CheckTick(); } } catch (Exception e) { NLog.Error(e); throw; } } Thread.Sleep(50); } }
private static void PlayInThread(byte[] file, bool isBGM) {//子线程中的处理 if (isBGM) { if (_channelBGM != null) { bool isPlaying; _channelBGM.isPlaying(out isPlaying); if (isPlaying) { _channelBGM.stop(); } } } var info = new CREATESOUNDEXINFO(); info.length = (uint)file.Length; Sound s; if (isBGM) { var result2 = _fmod.createSound(file, MODE.OPENMEMORY | MODE.LOOP_NORMAL, ref info, out s); if (result2 != RESULT.OK) { NLog.Error("fmod createSound " + result2); } } else { var result2 = _fmod.createSound(file, MODE.OPENMEMORY, ref info, out s); if (result2 != RESULT.OK) { NLog.Error("fmod createSound " + result2); } } Channel channel; var result = _fmod.playSound(s, null, false, out channel); _fmod.update(); int index; channel.getIndex(out index); if (result != RESULT.OK) { NLog.Error("fmod playSound " + result); } if (isBGM) { channel.setVolume(BGMVolume * WorldInfoManager.BGVolumn); _channelBGM = channel; } else { channel.setVolume(EffectVolume * WorldInfoManager.SoundVolumn); } }
/// <summary> /// Writes to NLog file for basic application wide logging /// </summary> /// <param name="logger"></param> /// <param name="mode"></param> /// <param name="message"></param> public void NLog(NLog.Logger logger, Enums.NLogType mode, string message) { switch (mode) { case Enums.NLogType.Error: logger.Error(string.Format("Error Message: {0}",message)); break; case Enums.NLogType.Info: logger.Info(message); break; case Enums.NLogType.Warn: logger.Warn( message); break; case Enums.NLogType.Stacktrace: logger.Error(string.Format("Error Stacktrace: {0}", message)); break; default: logger.Info(message); break; } }
public void RecostSelectCard() { var selectCard = CardManager.GetDeckCardAt(SelectId); if (selectCard == null) { NLog.Error(string.Format("RecostSelectCard id={0} not Found", SelectId)); return; } AddMp(-selectCard.Mp); AddLp(-selectCard.Lp); AddPp(-selectCard.Pp); }
/// <summary> /// 给定连接的数据库用假设参数执行一个sql命令(不返回数据集) /// </summary> /// <param name="cmdText">存储过程名称或者sql命令语句</param> /// <param name="commandParameters">执行命令所用参数的集合</param> /// <param name="cmdType">命令类型(存储过程, 文本, 等等)</param> /// <returns>执行命令所影响的行数</returns> internal static int ExecuteNonQuery(string cmdText, MySqlParameter[] commandParameters, CommandType cmdType = CommandType.Text) { try { MySqlCommand cmd = new MySqlCommand(); PrepareCommand(cmd, cmdType, cmdText, commandParameters); int val = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return(val); } catch (Exception ex) { NLog.Error("执行非查询语句失败", ex); return(0); } }
/// <summary> /// 用指定的数据库连接字符串执行一个命令并返回一个数据集的第一列 /// </summary> /// <param name="cmdText">存储过程名称或者sql命令语句</param> /// <param name="commandParameters">执行命令所用参数的集合</param> /// <param name="cmdType">命令类型(存储过程, 文本, 等等)</param> internal static object ExecuteScalar(string cmdText, MySqlParameter[] commandParameters, CommandType cmdType = CommandType.Text) { try { MySqlCommand cmd = new MySqlCommand(); PrepareCommand(cmd, cmdType, cmdText, commandParameters); object val = cmd.ExecuteScalar(); cmd.Parameters.Clear(); return(val); } catch (Exception ex) { NLog.Error("执行Scalar查询失败", ex); return(null); } }
public static void Init() { NLVFS.NLVFS.LoadVfsFile("./SoundResource.vfs"); Factory.System_Create(out _fmod); _fmod.setDSPBufferSize(4096, 2); var result = _fmod.init(16, FMOD.INITFLAGS.NORMAL, (IntPtr)null);//16个频道 if (result != RESULT.OK) { NLog.Error("fmod SoundManager " + result); } bgmHistory = new Stack <string>(); soundThread = new Thread(SoundWork); soundThread.Start(); soundThread.IsBackground = true; }
private void tabPageGame_Paint(object sender, PaintEventArgs e) { try { SystemMenuManager.DrawAll(e.Graphics); MainTipManager.DrawAll(e.Graphics); flowController.DrawAll(e.Graphics); if (SystemMenuManager.GMMode) //希望在最上层,所以必须最后绘制 { GMCodeZone.Paint(e.Graphics, tabPageGame.Width, tabPageGame.Height); } } catch (Exception err) { NLog.Error(err); } }
protected internal override void Execute() { var functionList = new List <string> { "CLRCreateInstance" }; foreach (var functionName in functionList) { var functionAddress = NativeImports.GetProcAddress(NativeImports.GetModuleHandle("mscoree"), functionName); if (!this.ProtectNative(functionAddress)) { NLog.Error("Failed to protect CLRCreateInstance. FunctionAddress: {0:X}", functionAddress); } } }
internal static MySqlConnection GetConnection() { try { string connectionString = ConfigurationManager.ConnectionStrings["MySQLConnection"].ConnectionString; if (connection == null) { connection = new MySqlConnection(connectionString); connection.Open(); } return(connection); } catch (Exception ex) { NLog.Error("打开数据库连接失败", ex); connection = null; return(null); } }
/// <summary> /// 用执行的数据库连接执行一个返回数据集的sql命令 /// </summary> /// <param name="cmdType">命令类型(存储过程, 文本, 等等)</param> /// <param name="cmdText">存储过程名称或者sql命令语句</param> /// <param name="commandParameters">执行命令所用参数的集合</param> /// <returns>包含结果的读取器</returns> internal static MySqlDataReader ExecuteReader(string cmdText, MySqlParameter[] commandParameters, CommandType cmdType = CommandType.Text) { MySqlCommand cmd = new MySqlCommand(); MySqlConnection conn = GetConnection(); try { PrepareCommand(cmd, cmdType, cmdText, commandParameters, conn); MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); cmd.Parameters.Clear(); return(reader); } catch (Exception ex) { NLog.Error("执行Reader查询失败", ex); conn.Close(); return(null); } }
private static void PlayInThread(byte[] file, bool isBGM) {//子线程中的处理 if (isBGM) { if (_channelBGM != null) { bool isPlaying; _channelBGM.isPlaying(out isPlaying); if (isPlaying) { _channelBGM.stop(); } } } var info = new CREATESOUNDEXINFO(); info.length = (uint)file.Length; Sound s; var result = _fmod.createSound(file, MODE.OPENMEMORY, ref info, out s); if (result != RESULT.OK) { NLog.Error("fmod createSound " + result); } Channel channel; result = _fmod.playSound(s, null, false, out channel); _fmod.update(); int index; channel.getIndex(out index); if (result != RESULT.OK) { NLog.Error("fmod playSound " + result); } if (isBGM) { _channelBGM = channel; } }
private bool Send(string cmd, ref string response) { try { using (var client = new RequestSocket()) { client.Connect(server); client.TrySendFrame(new TimeSpan(0, 0, 3), Encoding.UTF8.GetBytes(cmd)); bool result = client.TryReceiveFrameString(new TimeSpan(0, 0, 3), Encoding.UTF8, out response); client.Close(); client.Dispose(); return(result); } } catch (Exception ex) { NLog.Error("交易指令异常" + cmd, ex); } return(false); }
public static async void RefreshBlockList() { await Task.Run(() => { try { List <StockInfo> list = new List <StockInfo>(); FillSZList(ref list, ConfigurationManager.AppSettings["SZListUrl"], HostingEnvironment.MapPath("~") + "\\file\\SZList.xlsx"); FillSHList(ref list, ConfigurationManager.AppSettings["SHMbmListUrl"], HostingEnvironment.MapPath("~") + "\\file\\SHMbmList.txt"); FillSHList(ref list, ConfigurationManager.AppSettings["SHStartListUrl"], HostingEnvironment.MapPath("~") + "\\file\\SHStartList.txt"); if (list.Count > 4000) { StockInfoDA.Add(list); } } catch (Exception ex) { NLog.Error("刷新股票列表失败", ex); } }); }
/// <summary> /// 返回DataTable /// </summary> /// <param name="cmdText">存储过程名称或者sql命令语句</param> /// <param name="commandParameters">执行命令所用参数的集合</param> /// <param name="cmdType">命令类型(存储过程, 文本, 等等)</param> /// <returns></returns> internal static DataTable GetDataTable(string cmdText, MySqlParameter[] commandParameters, CommandType cmdType = CommandType.Text) { MySqlCommand cmd = new MySqlCommand(); MySqlConnection conn = GetConnection(); try { PrepareCommand(cmd, cmdType, cmdText, commandParameters, conn); MySqlDataAdapter adapter = new MySqlDataAdapter(); adapter.SelectCommand = cmd; DataTable dt = new DataTable(); adapter.Fill(dt); cmd.Parameters.Clear(); return(dt); } catch (Exception ex) { NLog.Error("执行Table查询失败", ex); conn.Close(); return(null); } }
private void DeckViewForm_Paint(object sender, PaintEventArgs e) { BorderPainter.Draw(e.Graphics, "", Width, Height); Font font = new Font("黑体", 12 * 1.33f, FontStyle.Bold, GraphicsUnit.Pixel); e.Graphics.DrawString("我的卡片", font, Brushes.White, Width / 2 - 40, 8); font.Dispose(); try { if (show) { if (!isShowStatistic) { cardDetail.Draw(e.Graphics); } else { deckStatistic.Draw(e.Graphics); } cardRegion.Draw(e.Graphics); selectRegion.Draw(e.Graphics); virtualRegion.Draw(e.Graphics); font = new Font("黑体", 12 * 1.33f, FontStyle.Bold, GraphicsUnit.Pixel); e.Graphics.DrawString(UserProfile.InfoCard.SelectedDeck.Name, font, Brushes.White, 5, 580); font.Dispose(); } } catch (Exception ex) { NLog.Error("DeckViewForm_Paint" + ex); } }
public static bool UploadConfig(string configZipPath, string AzureAccountName, string AzureAccountKey, string orgID, string studyID, string homeID, string desiredConfigFilename, NLog.Logger logger = null) { Microsoft.WindowsAzure.CloudStorageAccount storageAccount = null; Microsoft.WindowsAzure.StorageClient.CloudBlobClient blobClient = null; Microsoft.WindowsAzure.StorageClient.CloudBlobContainer container = null; Microsoft.WindowsAzure.StorageClient.CloudBlockBlob blockBlob = null; string leaseId = null; try { storageAccount = new Microsoft.WindowsAzure.CloudStorageAccount(new Microsoft.WindowsAzure.StorageCredentialsAccountAndKey(AzureAccountName, AzureAccountKey), true); blobClient = storageAccount.CreateCloudBlobClient(); container = blobClient.GetContainerReference(AzureConfigContainerName); container.CreateIfNotExist(); blockBlob = container.GetBlockBlobReference(DesiredConfigBlobName(orgID, studyID, homeID, desiredConfigFilename)); bool blobExists = BlockBlobExists(blockBlob); if (blobExists) leaseId = AcquireLease(blockBlob, logger); // Acquire Lease on Blob else blockBlob.Container.CreateIfNotExist(); if (blobExists && leaseId == null) { if (null != logger) { logger.Error("AcquireLease on Blob: " + DesiredConfigBlobName(orgID, studyID, homeID, desiredConfigFilename) + " Failed"); } return false; } string url = blockBlob.Uri.ToString(); if (blockBlob.ServiceClient.Credentials.NeedsTransformUri) { url = blockBlob.ServiceClient.Credentials.TransformUri(url); } var req = BlobRequest.Put(new Uri(url), AzureBlobLeaseTimeout, new Microsoft.WindowsAzure.StorageClient.BlobProperties(), Microsoft.WindowsAzure.StorageClient.BlobType.BlockBlob, leaseId, 0); using (var writer = new BinaryWriter(req.GetRequestStream())) { writer.Write(File.ReadAllBytes(configZipPath)); writer.Close(); } blockBlob.ServiceClient.Credentials.SignRequest(req); req.GetResponse().Close(); ReleaseLease(blockBlob, leaseId); // Release Lease on Blob return true; } catch (Exception e) { if (null != logger) { logger.ErrorException("UploadConfig_Azure, configZipPath: " + configZipPath, e); } ReleaseLease(blockBlob, leaseId); return false; } }
public void Error(string message, params object[] placeholders) { NLog.Error(message, placeholders); }
public static bool DownloadConfig(string downloadedZipPath, string AzureAccountName, string AzureAccountKey, string orgID, string studyID, string homeID, string configFilename, NLog.Logger logger=null) { Microsoft.WindowsAzure.CloudStorageAccount storageAccount = null; Microsoft.WindowsAzure.StorageClient.CloudBlobClient blobClient = null; Microsoft.WindowsAzure.StorageClient.CloudBlobContainer container = null; Microsoft.WindowsAzure.StorageClient.CloudBlockBlob blockBlob = null; string leaseId = null; try { storageAccount = new Microsoft.WindowsAzure.CloudStorageAccount(new Microsoft.WindowsAzure.StorageCredentialsAccountAndKey(AzureAccountName, AzureAccountKey), true); blobClient = storageAccount.CreateCloudBlobClient(); container = blobClient.GetContainerReference(AzureConfigContainerName); if (configFilename == PackagerHelper.ConfigPackagerHelper.actualConfigFileName) { blockBlob = container.GetBlockBlobReference(ActualConfigBlobName(orgID, studyID, homeID, configFilename)); } else if (configFilename == PackagerHelper.ConfigPackagerHelper.desiredConfigFileName) { blockBlob = container.GetBlockBlobReference(DesiredConfigBlobName(orgID, studyID, homeID, configFilename)); } bool blobExists = BlockBlobExists(blockBlob); if (blobExists) leaseId = AcquireLease(blockBlob, logger); // Acquire Lease on Blob else return false; if (blobExists && leaseId == null) { if (null != logger) { logger.Error("AcquireLease on Blob: " + ActualConfigBlobName(orgID, studyID, homeID, configFilename) + " Failed"); } return false; } string url = blockBlob.Uri.ToString(); if (blockBlob.ServiceClient.Credentials.NeedsTransformUri) { url = blockBlob.ServiceClient.Credentials.TransformUri(url); } var req = BlobRequest.Get(new Uri(url), AzureBlobLeaseTimeout, null, leaseId); blockBlob.ServiceClient.Credentials.SignRequest(req); using (var reader = new BinaryReader(req.GetResponse().GetResponseStream())) { FileStream zipFile = new FileStream(downloadedZipPath, FileMode.OpenOrCreate); reader.BaseStream.CopyTo(zipFile); zipFile.Close(); } req.GetResponse().GetResponseStream().Close(); ReleaseLease(blockBlob, leaseId); // Release Lease on Blob return true; } catch (Exception e) { if (null != logger) { logger.ErrorException("DownloadConfig_Azure, downloadZipPath: " + downloadedZipPath, e); } ReleaseLease(blockBlob, leaseId); return false; } }