public void LoadConfig(TargetConfig config) { CheckUtil.ArgumentNotNull(config, "config"); Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) { throw new ConfigurationErrorsException("DbTarget子元素 " + node.Name + "只能为单值元素"); } switch (node.Name) { case "connectionStringName": ConnectionStringName = node.FirstChild.Value; break; case "commandText": CommandText = node.FirstChild.Value; break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析DbTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
/// <summary> /// 加载配置 /// </summary> /// <param name="config"></param> /// <exception cref="InvalidOperationException">配置已经被加载</exception> /// <exception cref="ArgumentNullException">参数<c>config</c> 不能为空</exception> /// <exception cref="ConfigurationErrorsException">配置无法正确加载</exception> public void LoadConfig(TargetConfig config) { CheckUtil.ArgumentNotNull(config, "config"); this.Name = config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) { throw new ConfigurationErrorsException("RemotingTarget子元素 " + node.Name + "只能为单值元素"); } switch (node.Name) { case "clientName": ClientName = node.FirstChild.Value; break; case "appName": AppName = node.FirstChild.Value; break; default: break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析RemotingTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } }
/// <summary> /// 构造函数,指定数据提供程序工厂实例 /// </summary> /// <param name="connectionString"></param> /// <param name="dbProviderFactory"></param> public Database(string connectionString, DbProviderFactory dbProviderFactory) { CheckUtil.ArgumentNotNullOrEmpty(connectionString, "connectionString"); CheckUtil.ArgumentNotNull(dbProviderFactory, "dbProviderFactory"); this._ConnectionString = connectionString; this._DbProviderFactory = dbProviderFactory; }
int DoUpdateDataSet(UpdateBehavior behavior, DataSet dataSet, string tableName, IDbCommand insertCommand, IDbCommand updateCommand, IDbCommand deleteCommand, int?updateBatchSize) { CheckUtil.ArgumentNotNullOrEmpty(tableName, "tableName"); CheckUtil.ArgumentNotNull(dataSet, "dataSet"); if (insertCommand == null && updateCommand == null && deleteCommand == null) { throw new ArgumentException(Resources.Data.MustInitAtLeastOneCommand); } using (DbDataAdapter adapter = GetDataAdapter(behavior)) { IDbDataAdapter explicitAdapter = adapter; if (insertCommand != null) { explicitAdapter.InsertCommand = insertCommand; } if (updateCommand != null) { explicitAdapter.UpdateCommand = updateCommand; } if (deleteCommand != null) { explicitAdapter.DeleteCommand = deleteCommand; } if (updateBatchSize != null) { adapter.UpdateBatchSize = (int)updateBatchSize; if (insertCommand != null) { adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None; } if (updateCommand != null) { adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None; } if (deleteCommand != null) { adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None; } } try { //DateTime startTime = DateTime.Now; int rows = adapter.Update(dataSet.Tables[tableName]); //instrumentationProvider.FireCommandExecutedEvent(startTime); return(rows); } catch (Exception e) { //instrumentationProvider.FireCommandFailedEvent("DbDataAdapter.Update() " + tableName, ConnectionStringNoCredentials, e); throw; } } }
/// <summary> /// 计算文件流的哈希值并将其转换为使用Base64编码的字符串 /// </summary> /// <param name="fileStream"></param> /// <param name="hashAlgorithmType"></param> /// <returns></returns> public static string GetHash2Base64(FileStream fileStream, HashAlgorithmType hashAlgorithmType) { CheckUtil.ArgumentNotNull(fileStream, "fileStream"); byte[] bytes = GetHash(fileStream, hashAlgorithmType); string result = Convert.ToBase64String(bytes); return(result); }
/// <summary> /// 计算字节数组的哈希值并将其转换为使用Base64编码的字符串 /// </summary> /// <param name="data"></param> /// <param name="hashAlgorithmType"></param> /// <returns></returns> public static string GetHash2Base64(byte[] data, HashAlgorithmType hashAlgorithmType) { CheckUtil.ArgumentNotNull(data, "data"); byte[] bytes = GetHash(data, hashAlgorithmType); string result = Convert.ToBase64String(bytes); return(result); }
/// <summary> /// 计算字节数组的哈希值 /// </summary> /// <param name="data"></param> /// <param name="hashAlgorithmType"></param> /// <returns></returns> public static byte[] GetHash(byte[] data, HashAlgorithmType hashAlgorithmType) { CheckUtil.ArgumentNotNull(data, "data"); HashAlgorithm hashAlgorithm = CreateHashAlgorithmProvider(hashAlgorithmType); byte[] result = hashAlgorithm.ComputeHash(data); hashAlgorithm.Clear(); return(result); }
/// <summary> /// 计算文件流的哈希值 /// </summary> /// <param name="fileStream"></param> /// <param name="hashAlgorithmType"></param> /// <returns></returns> public static byte[] GetHash(FileStream fileStream, HashAlgorithmType hashAlgorithmType) { CheckUtil.ArgumentNotNull(fileStream, "fileStream"); HashAlgorithm hashAlgorithm = CreateHashAlgorithmProvider(hashAlgorithmType); byte[] result = hashAlgorithm.ComputeHash(fileStream); hashAlgorithm.Clear(); fileStream.Close(); return(result); }
/// <summary> /// 计算文件流的哈希值并将其转换为字符串 /// </summary> /// <param name="fileStream"></param> /// <param name="hashAlgorithmType"></param> /// <returns></returns> public static string GetHash2String(FileStream fileStream, HashAlgorithmType hashAlgorithmType) { CheckUtil.ArgumentNotNull(fileStream, "fileStream"); string result = string.Empty; byte[] bytes = GetHash(fileStream, hashAlgorithmType); foreach (byte b in bytes) { result += Convert.ToString(b, 16).ToUpper(CultureInfo.InvariantCulture).PadLeft(2, '0'); } return(result); }
public FileTarget(IFormatter formatter) { CheckUtil.ArgumentNotNull(formatter, "formatter"); Formatter = formatter; DaysToKeepLogs = 0; //路径规则相关 YearInPath = false; MonthInPath = true; DayInPath = false; LoggerNameInPath = false; LogLevelInPath = false; //文件名规则相关,优先级Hour>Day>Month>Year,其他附加在日期时间后面 WritePerYear = false; WritePerMonth = false; WritePerDay = true; WritePerHour = false; LoggerNameInFilename = false; LogLevelInFilename = false; }
/// <summary> /// 加密为字符串 /// </summary> /// <param name="s"></param> /// <returns></returns> public string EncryptString(byte[] inputData) { CheckUtil.ArgumentNotNull(inputData, "inputData"); byte[] outputData = null; using (MemoryStream ms = new System.IO.MemoryStream()) { symmetricAlgorithmProvider.Key = GetLegalKey(); symmetricAlgorithmProvider.IV = GetLegalIV(); ICryptoTransform cryptoTransform = symmetricAlgorithmProvider.CreateEncryptor(); using (CryptoStream cs = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write)) { cs.Write(inputData, 0, inputData.Length); cs.FlushFinalBlock(); outputData = ms.ToArray(); } } return Convert.ToBase64String(outputData, 0, outputData.Length); }
public DbTarget(IFormatter formatter) { CheckUtil.ArgumentNotNull(formatter, "formatter"); Formatter = formatter; }
public RemotingTarget(IFormatter formatter) { CheckUtil.ArgumentNotNull(formatter, "formatter"); this.Formatter = formatter; this.ClientName = string.Empty; }
/// <summary> /// 加载配置 /// </summary> /// <param name="config"></param> /// <exception cref="InvalidOperationException">配置已经被加载</exception> /// <exception cref="ArgumentNullException">参数<c>config</c> 不能为空</exception> /// <exception cref="ConfigurationErrorsException">配置无法正确加载</exception> public void LoadConfig(TargetConfig config) { CheckUtil.ArgumentNotNull(config, "config"); _Config = config; Name = _Config.Name; foreach (XmlNode node in config.ChildConfig) { try { if (node.ChildNodes.Count != 1) { throw new ConfigurationErrorsException("FileTarget子元素 " + node.Name + "只能为单值元素"); } switch (node.Name) { case "daysToKeepLogs": DaysToKeepLogs = int.Parse(node.FirstChild.Value); break; case "writeDirectly": WriteDirectly = node.FirstChild.Value.ToLower() == "true"; break; case "baseDirectory": _BaseDirectory = node.FirstChild.Value; break; case "yearInPath": YearInPath = node.FirstChild.Value.ToLower() == "true"; break; case "monthInPath": MonthInPath = node.FirstChild.Value.ToLower() == "true"; break; case "dayInPath": DayInPath = node.FirstChild.Value.ToLower() == "true"; break; case "loggerNameInPath": LoggerNameInPath = node.FirstChild.Value.ToLower() == "true"; break; case "logLevelInPath": LogLevelInPath = node.FirstChild.Value.ToLower() == "true"; break; case "fileName": FileName = node.FirstChild.Value; break; case "writePerYear": WritePerYear = node.FirstChild.Value.ToLower() == "true"; break; case "writePerMonth": WritePerMonth = node.FirstChild.Value.ToLower() == "true"; break; case "writePerDay": WritePerDay = node.FirstChild.Value.ToLower() == "true"; break; case "writePerHour": WritePerHour = node.FirstChild.Value.ToLower() == "true"; break; case "loggerNameInFilename": LoggerNameInFilename = node.FirstChild.Value.ToLower() == "true"; break; case "logLevelInFilename": LogLevelInFilename = node.FirstChild.Value.ToLower() == "true"; break; default: break; } } catch (FormatException ex) { throw new ConfigurationErrorsException("解析FileTarget子元素值 '" + node.FirstChild.Value + "'失败", ex); } } try { if (string.IsNullOrEmpty(_BaseDirectory) == false && Directory.Exists(_BaseDirectory) == false) { Directory.CreateDirectory(_BaseDirectory); } } catch (Exception ex) { LogManager.TriggerEvent(this, ex); } }