public string ToItemStats(Boolean forsave = false) { if (Item != null && Item.Template.Type == 113) { var SpeakingItem = Item.SpeakingItem; if (SpeakingItem != null) { return(SpeakingItem.convertirAString()); } else { return("3cc#0#0#" + IntHelper.toHexString(1) + "," + "3cb#0#0#1," + "3cd#0#0#" + Item.GetObjiType() + "," + "3ca#0#0#0," + "3ce#0#0#0"); } } if (!forsave && Item != null && Item.SpeakingItem != null) { var NormalStat = new StringBuilder(string.Join(",", this.myWeaponStats.Select(x => x.Value.ToItemString())) + (this.myStats.Count > 0 ? "," : "") + string.Join(",", this.myStats.Select(x => x.Value.ToItemString())) + (this.mySpecialEffects.Count > 0 ? "," : "") + string.Join(",", this.mySpecialEffects.Select(x => SpecialEffectToString(x)))); if (NormalStat.Length > 0) { NormalStat.Append(","); } NormalStat.Append(Item.SpeakingItem.convertirAString()); return(NormalStat.ToString()); } return(string.Join(",", this.myWeaponStats.Select(x => x.Value.ToItemString())) + (this.myStats.Count > 0 ? "," : "") + string.Join(",", this.myStats.Select(x => x.Value.ToItemString())) + (this.mySpecialEffects.Count > 0 ? "," : "") + string.Join(",", this.mySpecialEffects.Select(x => SpecialEffectToString(x)))); }
private static object FormatValueAsExpectedString(object value) { var valueType = value.GetType(); if (valueType == typeof(DateTime)) { return(DateTimeHelper.Serialize((DateTime)value)); } if (valueType == typeof(bool)) { return(BooleanHelper.Serialize((bool)value)); } if (valueType == typeof(double?)) { return(DoubleHelper.Serialize((double?)value)); } if (valueType == typeof(int?)) { return(IntHelper.Serialize((int?)value)); } return(value.ToString()); }
public static Expression <Func <TModel, bool> > GetCelestialObjectTypeExpression <TModel>(FilterModel filter) where TModel : class, ICelestialObjectTypeReferenceModel { for (var index = filter.FilterItems.Count - 1; index >= 0; index--) { var filterItem = filter.FilterItems[index]; if (filterItem.Column.Equals(nameof(CelestialObjectType))) { if (filterItem.Filter != FilterType.Equal) { throw new ArgumentException($"{nameof(CelestialObjectType)}-filter only supports {nameof(FilterType)} {FilterType.Equal}."); } if (IntHelper.IntIsNullOrEmpty(filterItem.Value)) { throw new ArgumentException($"{filterItem.Value} is not a valid value."); } var celestialObjectType = (CelestialObjectType)IntHelper.ToInt(filterItem.Value); var model = CelestialObjectTypeFactory.Instance.GetSingleByEnum(celestialObjectType); filter.FilterItems.RemoveAt(index); return(x => x.CelestialObjectTypeId == model.Id); } } return(null); }
private async Task PreloadDays(DateTime referenceDate, int days) { if (days < 0) { MinimumDateLoaded = referenceDate.AddDays(days); } if (days > 0) { MaximumDateLoaded = referenceDate.AddDays(days); } var start = IntHelper.GetMin(0, days); var end = IntHelper.GetMax(0, days); for (var i = start; i <= end; i++) { if (i != 0) { var loadDate = referenceDate.AddDays(i).GetClosestUtcZeroTime(); var model = SolarSystem.Helpers.Seeder.CelestialObjectSeedHelper.GetSunPosition(loadDate); await DataLoader.LoadAsync(DataLoading.Preload, model).ConfigureAwait(false); } } }
public Task ProfileAsync(SocketGuildUser User = null) { User = User ?? Context.User as SocketGuildUser; var Servers = Context.Session.Query <GuildModel>().Customize(x => x.WaitForNonStaleResults()).ToList(); var Profiles = Servers.Select(x => x.Profiles.Where(y => y.Key == User.Id)); var Starboard = Servers.Select(x => x.Starboard.StarboardMessages.Where(y => y.AuthorId == User.Id)); var GuildProfile = Context.GuildHelper.GetProfile(Context.Guild.Id, User.Id); var Commands = GuildProfile.Commands.OrderByDescending(x => x.Value); string FavCommand = !GuildProfile.Commands.Any() ? $"None {Emotes.Squint}" : $"{Commands.FirstOrDefault().Key} ({Commands.FirstOrDefault().Value} times)"; var Blacklisted = GuildProfile.IsBlacklisted ? Emotes.ThumbUp : Emotes.ThumbDown; int TotalXp = Profiles.Sum(x => x.Sum(y => y.Value.ChatXP)); var Embed = GetEmbed(Paint.Magenta) .WithAuthor($"👾 {User.Username} Profile", User.GetAvatarUrl()) .WithThumbnailUrl(User.GetAvatarUrl()) .AddField("Server Stats", $"**Level:** {IntHelper.GetLevel(GuildProfile.ChatXP)}\n" + $"**Stars:** {Context.Server.Starboard.StarboardMessages.Where(x => x.AuthorId == User.Id).Sum(x => x.Stars)}\n" + $"**Crystals:** {GuildProfile.Crystals}\n", true) .AddField("Global Stats", $"**XP:** {TotalXp}\n" + $"**Stars:** {Starboard.Sum(x => x.Sum(y => y.Stars))}\n" + $"**Crystals:** {Profiles.Sum(x => x.Sum(y => y.Value.Crystals))}\n", true) .AddField("\u200B", "\u200B", true) .AddField("\u200B", "\u200B", true) .AddField("Blacklisted?", Blacklisted, true) .AddField("Favorite Command", FavCommand, true); return(ReplyAsync(string.Empty, Embed.Build())); }
private bool IsConditionSatisfied(ProfileCondition condition, int?currentValue) { if (!currentValue.HasValue) { // If the value is unknown, it satisfies if not marked as required return(!condition.IsRequired); } int expected; if (IntHelper.TryParseCultureInvariant(condition.Value, out expected)) { switch (condition.Condition) { case ProfileConditionType.Equals: return(currentValue.Value.Equals(expected)); case ProfileConditionType.GreaterThanEqual: return(currentValue.Value >= expected); case ProfileConditionType.LessThanEqual: return(currentValue.Value <= expected); case ProfileConditionType.NotEquals: return(!currentValue.Value.Equals(expected)); default: throw new InvalidOperationException("Unexpected ProfileConditionType"); } } return(false); }
public static String PrismDefenders(long id, Fight fight) { StringBuilder str = new StringBuilder("+").Append(id); StringBuilder stra = new StringBuilder(); if (fight != null) { foreach (Fighter f in fight.Team2.GetFighters()) { if (f == null || f.ActorType != GameActorTypeEnum.TYPE_CHARACTER) { continue; } str.Append("|" + IntHelper.toString((int)(f as CharacterFighter).Character.ActorId, 36) + ";"); str.Append(f.Name + ";"); str.Append(f.Skin + ";"); str.Append(f.Level + ";"); str.Append(IntHelper.toString((f as CharacterFighter).Character.Color1, 36)).Append(";"); str.Append(IntHelper.toString((f as CharacterFighter).Character.Color2, 36)).Append(";"); str.Append(IntHelper.toString((f as CharacterFighter).Character.Color3, 36)).Append(";"); if (fight.Team2.GetFighters().Count > 7) { str.Append("1;"); } else { str.Append("0;"); } } stra.Append(str.ToString().Substring(1)); (fight as PrismFight).DefenderList = (stra.ToString()); //Todo other form to serialize } return(str.ToString()); }
/// <summary> /// 异步PostMessage /// </summary> /// <param name="hwnd"></param> /// <param name="msg"></param> /// <param name="wparam"></param> /// <param name="lparam"></param> /// <returns></returns> public async static Task <int> PostMessageAsync(IntPtrHelper hwnd, IntHelper msg, IntHelper wparam, IntPtrHelper lparam) { return(await Task.Factory.StartNew <int>(() => { return PostMessage(hwnd, msg, wparam, lparam); })); }
private static Expression <Func <TModel, bool> > ToIntValueExpression <TModel>(FilterItemModel filterItem, bool isNullable) where TModel : class { var type = ReflectionHelper.GetPropertyType <TModel>(filterItem.Column); if (type.IsEnum || type.IsNullableEnum()) { if (filterItem.Filter == FilterType.Equal) { return(EnumToExpression <TModel>(filterItem, type)); } throw new ArgumentException($"Filter {filterItem.Filter} not supported for type Enum. Only {FilterType.Equal} kan be evaluated.", nameof(filterItem)); } var nullableFilterValue = IntHelper.ToIntOrNull(filterItem.Value); if (!nullableFilterValue.HasValue) { throw new ArgumentException($"{filterItem.Value} is not of type {typeof(int)}."); } var filterValue = nullableFilterValue.Value; if (isNullable) { var entityParamSelector = ReflectionHelper.MemberSelector <TModel, int?>(filterItem.Column); if (filterItem.Filter == FilterType.In) { var result = filterItem.CollectionExpression(entityParamSelector, IntHelper.ToIntOrNull); if (result != null) { return(result); } } var expression = FilterExpressionHelper.GetNullableExpression(filterItem.Filter, filterValue); return(entityParamSelector.CombineSelectorParamExpression(expression)); } else { var entityParamSelector = ReflectionHelper.MemberSelector <TModel, int>(filterItem.Column); if (filterItem.Filter == FilterType.In) { var result = filterItem.CollectionExpression(entityParamSelector, IntHelper.ToInt); if (result != null) { return(result); } } var expression = FilterExpressionHelper.GetExpression(filterItem.Filter, filterValue); return(entityParamSelector.CombineSelectorParamExpression(expression)); } }
public CheckPosition FindStartCheck() { var rnd = new Random(); return(new CheckPosition { Position = IntHelper.FindPositionFromRandomNumber(rnd.Next(1, 101)) }); }
protected virtual void _handleMaxBans(string value) { IntHelper.TryParse(value, _ => { foreach (var key in ServerInformation.ChannelModes.TypeA) { ServerInformation.Limit.TypeAModeListEntries[key] = _; } }); }
public void Serialize_IntHasValue_ReturnsExpectedString(Tuple <string, int> testCases) { var value = testCases.Item2; var expected = testCases.Item1; var result = IntHelper.Serialize(value); Assert.That(result, Is.EqualTo(expected)); }
public void Parse_ValidIntString_ReturnsExpectedValue(Tuple <string, int> testCases) { var value = testCases.Item1; var expected = testCases.Item2; var result = IntHelper.Parse(value); Assert.That(result, Is.EqualTo(expected)); }
protected virtual void _handleMaxChannels(string value) { IntHelper.TryParse(value, _ => { foreach (var key in ServerInformation.ChannelTypes) { ServerInformation.Limit.Channels[key] = _; } ServerInformation.Limit.TotalChannels = _; }); }
public void UpdatePacmanWeight(int generation) { var oneGenerationPacman = _sqLiteConnection.GetOneGenerationPacmans(generation); foreach (var p in oneGenerationPacman) { p.Points = IntHelper.GetPointsArr(p.PointsString); var weight = p.Points.Sum() > 1000 ? p.Points.Sum() + p.AveragePoints + p.MaxPoints + p.PositivePointsCount : p.AveragePoints + p.MaxPoints + p.PositivePointsCount; p.Weight = weight <= 0 ? 1 : weight; _sqLiteConnection.UpdateWeight(p); } }
public void UpdatePacman(int generation) { var oneGenerationPacman = _sqLiteConnection.GetOneGenerationPacmans(generation); foreach (var pacman in oneGenerationPacman) { var pointsArr = IntHelper.GetPointsArr(pacman.PointsString); // pacman.MaxPoints= pointsArr.OrderByDescending(x => x).First(); pacman.PositivePointsCount = pointsArr.Where(x => x > 0).Count(); _sqLiteConnection.UpdatePacmansMaxPoints(pacman); } }
/// <summary> /// 获取Long高位1的位置(左侧1的位置) /// </summary> /// <param name="i"></param> /// <returns></returns> public static int NumberOfTrailingZeros(long p_value) { /* * //Java原始代码 * // HD, Figure 5-14 * int x, y; * if (i == 0) return 64; * int n = 63; * y = (int)i; if (y != 0) { n = n -32; x = y; } else x = (int)(i>>>32); * y = x <<16; if (y != 0) { n = n -16; x = y; } * y = x << 8; if (y != 0) { n = n - 8; x = y; } * y = x << 4; if (y != 0) { n = n - 4; x = y; } * y = x << 2; if (y != 0) { n = n - 2; x = y; } * return n - ((x << 1) >>> 31); */ long i = p_value; // HD, Figure 5-14 int x, y; if (i == 0) { return(64); } int n = 63; y = (int)i; if (y != 0) { n = n - 32; x = y; } else { x = (int)LongHelper.UnsignedRightBitMove(i, 32); } y = x << 16; if (y != 0) { n = n - 16; x = y; } y = x << 8; if (y != 0) { n = n - 8; x = y; } y = x << 4; if (y != 0) { n = n - 4; x = y; } y = x << 2; if (y != 0) { n = n - 2; x = y; } return(n - IntHelper.UnsignedRightBitMove((x << 1), 31)); }
public Task RankAsync(SocketGuildUser User = null) { User = User ?? Context.User as SocketGuildUser; var Profile = Context.GuildHelper.GetProfile(Context.Guild.Id, User.Id); return(ReplyAsync(string.Empty, GetEmbed(Paint.Yellow) .WithAuthor($"{User.Username}'s Server Rank", User.GetAvatarUrl()) .WithThumbnailUrl(User.GetAvatarUrl()) .AddField("Rank", $" {IntHelper.GetGuildRank(Context, User.Id)} / {Context.Server.Profiles.Count}", true) .AddField("Level", IntHelper.GetLevel(Profile.ChatXP), true) .AddField("Current XP", $"{Profile.ChatXP} XP", true) .AddField("Next Level XP", IntHelper.NextLevelXP(IntHelper.GetLevel(Profile.ChatXP)), true).Build())); }
public void ToIntTestOrNullTest(object value, bool expected) { var actual = IntHelper.ToIntOrNull(value); var isDefaultResult = actual == null; if (!isDefaultResult) { actual = IntHelper.ToIntOrNull(value); isDefaultResult = actual == null; } Assert.Equal(expected, isDefaultResult); }
/// <summary> /// 获取描述信息(无HTML) /// </summary> /// <param name="content"></param> /// <param name="length"></param> /// <param name="startIndex"></param> /// <returns></returns> public static string GetDescript(string content, int length = 0, int startIndex = 0) { if (VerifyHelper.IsEmpty(content)) { return(""); } if (length == 0) { length = IntHelper.Get(SettingConfig.GetValue(KeyModel.Config.Setting.KeyDescriptLength)); } content = HtmlsHelper.Remove(HtmlsHelper.Decode(content)); return(StringHelper.ToCutString(content, length, startIndex: startIndex)); }
/// <summary> /// 获取使用次数 /// </summary> /// <returns></returns> public static int GetUseTimes() { if (!WpfHelper.RegistryIsExist(Registry.LocalMachine, REGISTRYPATH, USETIMES)) { WpfHelper.RegistrySet(Registry.LocalMachine, REGISTRYPATH, USETIMES, "0"); } var userTimes = IntHelper.Get(WpfHelper.RegistryGet(Registry.LocalMachine, REGISTRYPATH, USETIMES), -1); if (userTimes < 0) { throw new DbxException(EnumCode.注册表异常); } return(userTimes); }
public static Expression <Func <TModel, bool> > EnumToExpression <TModel>(this FilterItemModel filterItem, Type typeEnum) where TModel : class { var isNullable = ReflectionHelper.IsNullable <TModel>(filterItem.Column); var propertyType = isNullable ? typeof(int?) : typeof(int); var paramExpression = Expression.Parameter(typeof(TModel)); var propertySelector = filterItem.Column.Split('.').Aggregate <string, Expression>(paramExpression, Expression.Property); var castedPropertySelector = Expression.Convert(propertySelector, propertyType); var compareExpression = Expression.Constant(IntHelper.ToIntOrNull(filterItem.Value)); var convertedCompareExpression = Expression.Convert(compareExpression, propertyType); var bodyExpression = Expression.Equal(castedPropertySelector, convertedCompareExpression); var expression = Expression.Lambda <Func <TModel, bool> >(bodyExpression, paramExpression); return(expression); }
/// <summary> /// 增加使用次数 /// </summary> /// <returns></returns> public static void AddUseTimes() { if (!WpfHelper.RegistryIsExist(Registry.LocalMachine, REGISTRYPATH, USETIMES)) { throw new DbxException(EnumCode.注册表异常); } var userTimes = IntHelper.Get(WpfHelper.RegistryGet(Registry.LocalMachine, REGISTRYPATH, USETIMES), -1); if (userTimes < 0) { throw new DbxException(EnumCode.注册表异常); } WpfHelper.RegistrySet(Registry.LocalMachine, REGISTRYPATH, USETIMES, (userTimes + 1).ToString()); }
/// <summary> /// 该方法的作用是返回无符号整型i的最高非零位前面的0的个数,包括符号位在内; ///如果i为负数,这个方法将会返回0,符号位为1. ///比如说,10的二进制表示为 0000 0000 0000 0000 0000 0000 0000 1010 ///java的整型长度为32位。那么这个方法返回的就是28 /// </summary> /// <param name="i"></param> /// <returns></returns> public static int NumberOfLeadingZeros(long i) { /* * // HD, Figure 5-6 * if (i == 0) * return 64; * int n = 1; * int x = (int)(i >>> 32); * if (x == 0) { n += 32; x = (int)i; } * if (x >>> 16 == 0) { n += 16; x <<= 16; } * if (x >>> 24 == 0) { n += 8; x <<= 8; } * if (x >>> 28 == 0) { n += 4; x <<= 4; } * if (x >>> 30 == 0) { n += 2; x <<= 2; } * n -= x >>> 31; * return n; */ // HD, Figure 5-6 if (i == 0) { return(64); } int n = 1; int x = (int)LongHelper.UnsignedRightBitMove(i, 32); if (x == 0) { n += 32; x = (int)i; } if (LongHelper.UnsignedRightBitMove(x, 16) == 0) { n += 16; x <<= 16; } if (LongHelper.UnsignedRightBitMove(x, 24) == 0) { n += 8; x <<= 8; } if (LongHelper.UnsignedRightBitMove(x, 28) == 0) { n += 4; x <<= 4; } if (LongHelper.UnsignedRightBitMove(x, 30) == 0) { n += 2; x <<= 2; } n -= IntHelper.UnsignedRightBitMove(x, 31); return(n); }
private static int?GetInt32(XmlElement element, string property) { string value = GetString(element, property); if (string.IsNullOrEmpty(value)) { return(null); } value = value.Replace(" ", ""); int result = 0; if (IntHelper.TryParse(value, out result)) { return(result); } return(null); }
public static String parsetoGuild(int GuildID) { StringBuilder sb = new StringBuilder("+"); Boolean isFirst = true; foreach (var perco in TaxCollectorTable.Cache.Values.Where(x => x.GuildID == GuildID)) { if (!isFirst) { sb.Append("|"); } sb.Append(perco.ActorId).Append(";").Append(perco.N1).Append(perco.N2).Append(";"); sb.Append(IntHelper.toString(perco.Map.Id, 36)).Append(",").Append(perco.Map.X).Append(",").Append(perco.Map.Y).Append(";"); //Integer.toString(map.get_id(), 36) sb.Append(perco.inFight).Append(";"); if (perco.inFight == 1) { if (perco.Map.GetFight(perco.inFight) == null) { sb.Append("45000;"); } else { sb.Append(perco.TimeTurn).Append(";"); } sb.Append("45000;"); sb.Append("7;"); sb.Append("?,?,"); } else { sb.Append("0;"); sb.Append("45000;"); sb.Append("7;"); sb.Append("?,?,"); } sb.Append("1,2,3,4,5"); isFirst = false; } if (sb.Length == 1) { return(null); } return(sb.ToString()); }
private void Run(string[] args) { #if DEBUG Debug.Listeners.Add(new CustomTraceListener( )); #endif var ports = new Collection <int>( ); foreach (var arg in args[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { if ('+' == arg[0]) { IntHelper.TryParse(arg.Substring(1), _ => ports.Add(-_)); } else { IntHelper.TryParse(arg, ports.Add); } } Console.CancelKeyPress += ConsoleCancelKeyPress; _identServer = new IdentServer( ); _identServer.Start( ); _serverConnector = new ServerConnector(new ConnectionConfiguration { NickName = "ZiveIrcTest", UserName = "******", RealName = "Testing instance of ZiveIrc. Contact: IceKarma", NickServPassword = "******", ServerHostName = args[0], Ports = ports, }); _serverConnector.ConnectionEstablished += ConnectionEstablished; _serverConnector.ConnectionAttemptStarted += ConnectionAttemptStarted; _serverConnector.ConnectionAttemptFailed += ConnectionAttemptFailed; _serverConnector.ConnectionFailed += ConnectionFailed; Console.WriteLine("Starting connection attempt."); _serverConnector.BeginConnect( ); _doneEvent.WaitOne( ); _doneEvent.Dispose( ); _doneEvent = null; }
/// <summary> /// 技術リストビューの項目を作成する /// </summary> /// <param name="tech">技術データ</param> /// <returns>技術リストビューの項目</returns> private static ListViewItem CreateTechListViewItem(TechItem tech) { if (tech == null) { return(null); } ListViewItem item = new ListViewItem { Text = Config.GetText(tech.Name), Tag = tech }; item.SubItems.Add(IntHelper.ToString(tech.Id)); item.SubItems.Add(IntHelper.ToString(tech.Year)); item.SubItems.Add(""); return(item); }
public static String PrismAttackers(long id, Fight fight) { StringBuilder str = new StringBuilder("+").Append(id); //StringBuilder str = new StringBuilder("+" + IntHelper.ToString(id, 36)); if (fight != null) { foreach (Fighter f in fight.Team1.GetFighters()) { if (f == null || f.ActorType != GameActorTypeEnum.TYPE_CHARACTER) { continue; } str.Append("|" + IntHelper.toString((int)(f as CharacterFighter).Character.ActorId, 36) + ";"); str.Append(f.Name + ";"); str.Append(f.Name + ";"); } } return(str.ToString()); }
/** * 生成直接支付url,支付url有效期为2小时,模式二 * @param productId 商品ID * @return 模式二URL */ public static string GetPayUrl(string rechargeRecordId, string tags, string descript, decimal moneyValue, out string tradeNo) { tradeNo = RandHelper.GenerateNonceStr(); WxPayData data = new WxPayData(); data.SetValue("body", descript); //商品描述 data.SetValue("attach", ""); //附加数据 data.SetValue("out_trade_no", tradeNo); //随机字符串 data.SetValue("total_fee", StringHelper.Get(IntHelper.Get(moneyValue * 100))); //总金额 data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")); //交易起始时间 data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间 data.SetValue("goods_tag", tags); //商品标记 data.SetValue("trade_type", "NATIVE"); //交易类型 data.SetValue("product_id", rechargeRecordId); //商品ID WxPayData result = UnifiedOrder(data); //调用统一下单接口 string url = result.GetValue("code_url").ToString(); //获得统一下单接口返回的二维码链接 return(url); }