static TranslatorHelper() { _TranslatorSleepTime = Math.Max(TypeParseHelper.StrToInt32(ConfigHelper.GetAppSettingValue("_TranslatorSleepTime")), 1); TranslatorUserMethod = Math.Max(TypeParseHelper.StrToInt32(ConfigHelper.GetAppSettingValue("TranslatorUserMethod")), 1); //每个站单独配置Bing的秘钥接口 add by Yang 2016-8-29 11:16:22 BingClientId = ConfigHelper.GetAppSettingValue("BING_CLIENT_ID"); BingClientSecret = ConfigHelper.GetAppSettingValue("BING_CLIENT_SECRET"); if (string.IsNullOrWhiteSpace(BingClientId)) { BingClientId = "TBWEBSITE";//YangHw个人账号(づ。◕‿‿◕。)づ } if (string.IsNullOrWhiteSpace(BingClientSecret)) { BingClientSecret = "0MpRNAZCz09CIFmcO9hSe8NY+nYpHyIznSz2DneD1tA="; } GoogleApiKey = ConfigHelper.GetAppSettingValue("GOOGLE_API_KEY"); if (_TranslatorSleepTime < 1) { _TranslatorSleepTime = 1; } if (TranslatorUserMethod < 1) { TranslatorUserMethod = 1; } }
/// <summary> /// 将一种类型的对象向另一种类型的对象通过相同属性名称的所有属性进行赋值操作 /// 只有SQLServer里面的实体类可以使用,因为SQLServer中有Boolean类型,需要将Int32专成Boolean /// </summary> /// <typeparam name="S">源类型</typeparam> /// <typeparam name="D">目标类型</typeparam> /// <param name="source">源对象</param> /// <param name="desc">目标对象</param> public static void SetPropertyInfoSQLServer <S, D>(S source, D desc) { PropertyInfo[] propertyInfoSources = typeof(S).GetProperties(); PropertyInfo[] propertyInfoDescs = typeof(D).GetProperties(); if (propertyInfoSources != null && propertyInfoSources.Length > 0) { foreach (PropertyInfo propertyInfoSource in propertyInfoSources) { foreach (PropertyInfo propertyInfoDesc in propertyInfoDescs) { if (string.Compare(propertyInfoSource.Name, propertyInfoDesc.Name, true) == 0) { object sourceValue = propertyInfoSource.GetValue(source, null); object descValue = propertyInfoDesc.GetValue(desc, null); if ((sourceValue == null && descValue != null) || (sourceValue != null && descValue == null)) { try { if (sourceValue.GetType() == typeof(Boolean)) { propertyInfoDesc.SetValue(desc, TypeParseHelper.StrToInt32(sourceValue) == 1 ? true : false, null); } else { propertyInfoDesc.SetValue(desc, sourceValue, null); } } catch (Exception) { } } else if (sourceValue != null && descValue != null && !sourceValue.Equals(descValue)) { try { if (sourceValue.GetType() == typeof(Boolean)) { propertyInfoDesc.SetValue(desc, TypeParseHelper.StrToInt32(sourceValue) == 1 ? true : false, null); } else { propertyInfoDesc.SetValue(desc, sourceValue, null); } } catch (Exception) { } } break; } } } Array.Clear(propertyInfoSources, 0, propertyInfoSources.Length); propertyInfoSources = null; Array.Clear(propertyInfoDescs, 0, propertyInfoDescs.Length); propertyInfoDescs = null; } }
/// <summary> /// string数组转int32数组 /// </summary> /// <param name="strings"></param> /// <returns></returns> public static int[] StrsToInt32s(string[] strings) { int[] ints = null; if (strings != null) { int length = strings.Length; ints = new int[length]; for (int i = 0; i < length; i++) { ints[i] = TypeParseHelper.StrToInt32(strings[i]); } } return(ints); }
/// <summary> /// tidebuy所有网站图片水印统一从这里出(婚纱离婚站除外) /// </summary> /// <param name="originalUrl"></param> /// <param name="watermark"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public static string GetImageUrl(string originalUrl, string watermark, string width, string height) { string url = null; if (!string.IsNullOrEmpty(originalUrl) && RegexHelper.IsUrl(originalUrl)) { //wangyunpeng 增加webp,暂时不能使用,主要是多数浏览器还不支持 + 图片的CDN缓存webp格式会有问题。 //if (originalUrl.LastIndexOf(".jpg", StringComparison.CurrentCultureIgnoreCase) > 0) //{ // originalUrl += ".page.webp"; //} Uri uri = new Uri(originalUrl); List <string> segmentList = uri.Segments.ToList(); if (segmentList.Count > 1) { if (!string.IsNullOrWhiteSpace(watermark)) { segmentList.Insert(segmentList.Count - 1, watermark + "/"); } List <string> parameterList = new List <string>(2); int w = TypeParseHelper.StrToInt32(width); int h = TypeParseHelper.StrToInt32(height); if (w > 0 || h > 0) { parameterList.Add(w.ToString()); parameterList.Add(h.ToString()); } if (string.IsNullOrWhiteSpace(watermark) && parameterList.Count > 0) { segmentList.Insert(segmentList.Count - 1, string.Join("-", parameterList) + "/"); } parameterList.Clear(); parameterList = null; UriBuilder uriBuilder = new UriBuilder(uri.Scheme, uri.Host, uri.Port); uriBuilder.Path = string.Join("", segmentList); url = uriBuilder.Uri.ToString(); segmentList.Clear(); } segmentList = null; } else { url = string.Empty; } return(url); }
/// <summary> /// 根据服务名称获取服务状态。 /// </summary> /// <param name="serviceName">服务名</param> /// <returns>状态</returns> public static int GetServiceStatus(string serviceName) { int result = 0; try { using (ServiceController sc = new ServiceController(serviceName)) { result = TypeParseHelper.StrToInt32(sc.Status); } } catch (Exception ex) { result = 0; throw ex; } return(result); }
/// <summary> /// 包含婚纱礼服类目的站点需要加水印和尺寸 /// </summary> /// <param name="originalUrl"></param> /// <param name="watermark"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public static string GetImageUrlByWedding(string originalUrl, string watermark, string width, string height) { string url = null; if (!string.IsNullOrEmpty(originalUrl) && RegexHelper.IsUrl(originalUrl)) { Uri uri = new Uri(originalUrl); List <string> segmentList = uri.Segments.ToList(); if (segmentList.Count > 1) { if (!string.IsNullOrWhiteSpace(watermark)) { segmentList.Insert(segmentList.Count - 1, watermark + "/"); } List <string> parameterList = new List <string>(2); int w = TypeParseHelper.StrToInt32(width); int h = TypeParseHelper.StrToInt32(height); if (w > 0 || h > 0) { parameterList.Add(w.ToString()); parameterList.Add(h.ToString()); } if (parameterList.Count > 0) //eric加上图片水印和尺寸同时截图。wangyunpeng.2016-10-22。2017-3-30,取消使用。 { segmentList.Insert(segmentList.Count - 1, string.Join("-", parameterList) + "/"); } parameterList.Clear(); parameterList = null; UriBuilder uriBuilder = new UriBuilder(uri.Scheme, uri.Host, uri.Port); uriBuilder.Path = string.Join("", segmentList); url = uriBuilder.Uri.ToString(); segmentList.Clear(); } segmentList = null; } else { url = string.Empty; } return(url); }