private void GetAllMyFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_MYKAIXIN; SetMessageLn("刷新[我在开心网上的所有好友]..."); //login if (!this.ValidationLogin()) { if (AllMyFriendsFetched != null) { AllMyFriendsFetched(_allMyFriendsList); } return; } string content = RequestAllMyFriends(); ReadAllMyFriends(content, true); SetMessageLn("[我在开心网上的所有好友]信息刷新成功!"); //invoke event if (AllMyFriendsFetched != null) { AllMyFriendsFetched(_allMyFriendsList); } }); ExecuteTryCatchBlock(th, "[我在开心网上的所有好友]信息刷新失败!"); }
private void GetBitableFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_BITING; SetMessageLn("刷新[我可以去咬的人]..."); if (!this.ValidationLogin(true)) { if (BitableFriendsFetched != null) { BitableFriendsFetched(_bitableFriendsList); } return; } string content = RequestBiteHomePage(); content = RequestBitableFriends(); ReadBitableFriends(content, true); SetMessageLn("[我可以去咬的人]信息刷新成功!"); //invoke event if (BitableFriendsFetched != null) { BitableFriendsFetched(_bitableFriendsList); } }); base.ExecuteTryCatchBlock(th, "[我可以去咬的人]信息刷新失败!"); }
private void GetBuyableSlaves() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_SLAVE; SetMessageLn("刷新[我能买的奴隶]..."); if (!this.ValidationLogin(true)) { if (BuyableSlavesFetched != null) { BuyableSlavesFetched(_buyableSlaveList); } return; } string content = RequestSlaveHomePage(); content = RequestBuyableSlaves(); ReadBuyableSlaves(content, true); SetMessageLn("[我能买的奴隶]信息刷新成功!"); //invoke event if (BuyableSlavesFetched != null) { BuyableSlavesFetched(_buyableSlaveList); } }); base.ExecuteTryCatchBlock(th, "[我能买的奴隶]信息刷新失败!"); }
private void GetMySlaves() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_MYKAIXIN; SetMessageLn("刷新[我的奴隶]..."); //login if (!this.ValidationLogin(true)) { if (MySlaveFetched != null) { MySlaveFetched(_mySlaveList); } return; } //read cars string content = RequestSlaveHomePage(); ReadSlaves(content, true); SetMessageLn("[我的奴隶]信息刷新成功!"); //invoke event if (MySlaveFetched != null) { MySlaveFetched(_mySlaveList); } }); base.ExecuteTryCatchBlock(th, "[我的奴隶]信息刷新失败!"); }
public void RunRich() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_RICH; SetMessageLn("开始超级大亨..."); //rich string contentHome = RequestRichHomePage(false); //我的财富等级 GetMyFuntuneRank(contentHome, true); //我的现金 GetMyCash(contentHome, true); //我的资产 GetMyAssets(false); if (Task.SellAsset) { SellAsset(); } if (Task.BuyAsset) { BuyAsset(); } SetMessageLn("超级大亨完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,超级大亨失败!"); }
protected void ExecuteTryCatchBlock(TryCatchBlock method, string ErrorMsg) { try { method(); } catch (ThreadAbortException) { SetMessageLn("Execution Aborted!"); if (OperationFailed != null) { OperationFailed(); } } catch (ThreadInterruptedException) { SetMessageLn("Execution Aborted!"); if (OperationFailed != null) { OperationFailed(); } } catch (Exception ex) { Log4Helper.Write(ErrorMsg + this.Caption, ex); SetMessageLn(ErrorMsg + "Error:" + ex.Message); if (OperationFailed != null) { OperationFailed(); } } }
private void SingleTaskStart() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_TASK; SetMessage("\r\n" + "============================== 开始 =============================="); SingleTaskRun(); SetMessage("\r\n" + "============================== 完成 =============================="); }); base.ExecuteTryCatchBlock(th, "发生异常,测试失败!"); }
public void RunSlave() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_SLAVE; SetMessageLn("开始朋友买卖..."); //slave string content = RequestSlaveHomePage(); ReadSlaves(content, false); if (Task.BuySlave) { this.BuySlaveFromBuyList(); } if (Task.BuyLowPriceSlave) { this.BuyLowPriceSlave(); } if (Task.FawnMaster || Task.PropitiateSlave || Task.AfflictSlave || Task.ReleaseSlave) { if (Task.FawnMaster) { this.FawnMaster(); } if (Task.BuySlave || Task.BuyLowPriceSlave) { content = RequestSlaveHomePage(); ReadSlaves(content, false); this.DisplayMySlaves(); } if (Task.PropitiateSlave) { this.PropitiateSlaves(); } if (Task.AfflictSlave) { this.AfflictSlaves(); } if (Task.ReleaseSlave) { this.ReleaseSlaves(); } } SetMessageLn("朋友买卖完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,朋友买卖失败!"); }
/// <summary> /// 获取服务状态 /// </summary> /// <param name="serviceName">服务名</param> /// <returns>返回服务状态</returns> public static ServiceControllerStatus GetServiceStatus(string serviceName) { ServiceControllerStatus status = ServiceControllerStatus.ContinuePending; TryCatchBlock.TrycatchAndLog(() => { var sc = new ServiceController(serviceName, MachineName); status = sc.Status; }); return(status); }
public void RunBite() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_BITING; SetMessageLn("开始咬人..."); RunBiteWithReturn(); SetMessageLn("咬人完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,咬人失败!"); }
protected TryCatchBlock(TryCatchBlock antecedent) { if (antecedent == null) { throw new ArgumentNullException("antecedent"); } if (antecedent.finalized) { throw new InvalidOperationException("This block has been finalized with a call to 'Finally()'"); } this.First = antecedent.First; this.Antecedent = antecedent; antecedent.Subsequent = this; }
/// <summary> /// 启动服务 /// </summary> /// <param name="serviceName">服务名</param> /// <returns>存在返回 true,否则返回 false;</returns> public static bool Run(string serviceName) { bool ret = false; TryCatchBlock.TrycatchAndLog(() => { var sc = new ServiceController(serviceName, MachineName); if (sc.Status.Equals(ServiceControllerStatus.Stopped) || sc.Status.Equals(ServiceControllerStatus.StopPending)) { sc.Start(); ret = true; } }); return(ret); }
/// <summary> /// 获取服务安装路径 /// </summary> /// <param name="serviceName"></param> /// <returns></returns> public static string GetWindowsServiceInstallPath(string serviceName) { string path = ""; TryCatchBlock.TrycatchAndLog(() => { string key = @"SYSTEM\CurrentControlSet\Services\" + serviceName; path = Registry.LocalMachine.OpenSubKey(key).GetValue("ImagePath").ToString(); path = path.Replace("\"", string.Empty);//替换掉双引号 FileInfo fi = new FileInfo(path); path = fi.Directory.ToString(); }); return(path); }
/// <summary> /// 获取指定服务的版本号 /// </summary> /// <param name="serviceName">服务名称</param> /// <returns></returns> public static string GetServiceVersion(string serviceName) { if (string.IsNullOrEmpty(serviceName)) { return(string.Empty); } TryCatchBlock.TrycatchAndLog(() => { string path = GetWindowsServiceInstallPath(serviceName) + "\\" + serviceName + ".exe"; Assembly assembly = Assembly.LoadFile(path); AssemblyName assemblyName = assembly.GetName(); Version version = assemblyName.Version; return(version.ToString()); }); return(string.Empty); }
private JsArray CompileHandlers(TryCatchBlock block) { return(new JsArray( block.Handlers .Cast <HandlerBlock>() .OrderBy(x => x.EntryPoint.Index) .Select( x => { var obj = new JsObject { { "type", ToJs(x.Type) }, { "entry", x.EntryIndex }, { "exception", CompileExceptionType(x.ExceptionType) } }; return (object)obj; } ), "\n")); }
private void ValidateUser() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MODULE_VALIDATION; SetMessage("开始用户验证...", true); bool result = false; //string content = HH.Get("http://bbs.77sx.com/verify.asp"); //if (content == "1") result = true; SetMessage("用户验证完成!", true); if (ValidationFinished != null) ValidationFinished(result); }); base.ExecuteTryCatchBlock(th, "发生异常,验证用户失败!"); }
private void SendRequest() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_MAINTAINCONTACT; SetMessageLn("开始发送添加好友请求..."); if (!this.ValidationLogin(_account)) { if (SendRequestFinished != null) { SendRequestFinished(); } return; } int num = 0; foreach (FriendInfo friend in _friends) { num++; SetMessageLn(string.Format("向#{0} {1}({2})发送请求:", num, friend.Name, friend.Id)); if (this.SendFriendRequest(friend.Id, _requestcontent)) { SetMessage("成功!"); } else { SetMessage("失败!"); } } SetMessageLn("发送添加好友请求完成!"); if (SendRequestFinished != null) { SendRequestFinished(); } }); base.ExecuteTryCatchBlock(th, "发生异常,发送添加好友请求失败!"); }
/// <summary> /// Executes the chain of 'try-catch' wrappers. /// </summary> //[DebuggerStepThrough] public void Execute() { TryCatchBlock current = this.First; try { if (current.Action != null) { current.Action(); } } catch (Exception exception) { while (current.Subsequent != null) { current = current.Subsequent; if (current.CanHandle(exception)) { current.Handle(exception); break; } if (current.Subsequent == null) { throw; } } } finally { while (current.Subsequent != null) { current = current.Subsequent; if (current.finalized && current.Action != null) { current.Action(); } } } }
public void RunHouse() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_HOUSE; SetMessageLn("开始买房子..."); //house string contentHome = RequestHouseHomePage(false); //same village friends ReadSameVillageFriends(contentHome, false); //all house friends string content = RequestAllHouseFriends(); ReadAllHouseFriends(content, false); //free friends content = RequestFreeFriends(); ReadFreeFriends(content, false); if (Task.DoJob) DoJob(); if (Task.StayHouse) StayHouse(contentHome); if (Task.RobFriends || Task.RobFreeFriends) { _robbedFriendsList.Clear(); SetMessageLn("抢人:"); SetMessageLn("#1"); RobFriends(this._myHouses[0], true); for (int ix = 1; ix < this._myHouses.Count; ix++) { SetMessageLn("#" + (ix + 1).ToString()); RobFriends(this._myHouses[ix], false); } } SetMessageLn("买房子完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,买房子失败!"); }
private void GetNovelList() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MODULE_NOVELLIST; SetMessage("刷新小说列表...", true); Collection<NovelInfo> novels = new Collection<NovelInfo>(); string originaltext = HH.Get(_categoryurl); if (string.IsNullOrEmpty(originaltext)) { LogHelper.Write("GetNovelListByCategory()" + _categoryurl, "Empty http response!!!", LogSeverity.Warn); return; } string content = originaltext; content = StringHelper.GetMid(content, "<table width=950px>", "<div align=\"center\">"); if (content != null) { int num; for (string info = StringHelper.GetMid(content, "<tr>", "</tr>", out num); info != null; info = StringHelper.GetMid(content, "<tr>", "</tr>", out num)) { content = content.Substring(num); NovelInfo novel = new NovelInfo(); novel.Name = StringHelper.GetMid(info, "style=\"font-size:14px\">", "</font>"); novel.ChapterUrl = StringHelper.GetMid(info, "<A href=\"", "\" target=_blank"); novel.Id = ParseNovelId(novel.ChapterUrl); if (info.Contains(" 待续")) novel.State = PublishStatus.ToBeContinued; else if (info.Contains(" 全文完")) novel.State = PublishStatus.Finished; novel.Author = StringHelper.GetMid(info, "<td width=20% class=Hot><A title=", " href=\"search.asp?"); if (!String.IsNullOrEmpty(novel.Name) && !String.IsNullOrEmpty(novel.ChapterUrl)) novels.Add(novel); } } PagingInfo paging = new PagingInfo(); content = StringHelper.GetMid(originaltext, "<tr><td colspan=4 align=right", "页</td></tr>"); if (!String.IsNullOrEmpty(content)) { paging.Required = true; paging.Total = StringHelper.GetMidInteger(originaltext, " / ", " 页 "); paging.Current = StringHelper.GetMidInteger(originaltext, "第 ", " / "); paging.Category = StringHelper.GetMidInteger(originaltext, "window.location='", "_'+this.value+'"); } SetMessage("小说列表获取成功!", true); if (NovelListFetched != null) NovelListFetched(novels, paging); }); base.ExecuteTryCatchBlock(th, "发生异常,获取小说列表失败!"); }
private void GetFreeFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_HOUSE; SetMessageLn("刷新[露宿街头的好友]..."); if (!this.ValidationLogin(true)) { if (FreeFriendsFetched != null) FreeFriendsFetched(_freeFriendsList); return; } string content = RequestHouseHomePage(false); content = RequestFreeFriends(); ReadFreeFriends(content, true); SetMessageLn("[露宿街头的好友]信息刷新成功!"); //invoke event if (FreeFriendsFetched != null) FreeFriendsFetched(_freeFriendsList); }); base.ExecuteTryCatchBlock(th, "[露宿街头的好友]信息刷新失败!"); }
private void GetSeedsInShop() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_UPDATEDATA; SetMessageLn("刷新[商店中种子列表]..."); if (!this.ValidationLogin()) { if (SeedsInShopFetched != null) SeedsInShopFetched(null); return; } string content = RequestHouseHomePage(false); content = RequestSeedsList(); Collection<SeedInfo> seeds = ConfigCtrl.GetOriginalSeedsList(content); if (seeds == null || seeds.Count == 0) SetMessageLn("[商店中种子列表]信息刷新失败!"); else SetMessageLn("[商店中种子列表]信息刷新成功!"); //invoke event if (SeedsInShopFetched != null) SeedsInShopFetched(seeds); }); base.ExecuteTryCatchBlock(th, "[商店中种子列表]信息刷新失败!"); }
public void RunRich() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_RICH; SetMessageLn("开始超级大亨..."); //rich string contentHome = RequestRichHomePage(false); //我的财富等级 GetMyFuntuneRank(contentHome, true); //我的现金 GetMyCash(contentHome, true); //我的资产 GetMyAssets(false); if (Task.SellAsset) SellAsset(); if (Task.BuyAsset) BuyAsset(); SetMessageLn("超级大亨完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,超级大亨失败!"); }
private void RunAddFriend() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_ADDFRIENDS; SetMessageLn("开始互加好友..."); if (_addFriends.DeleteAllMessages) { SetMessageLn("清空所有账号的系统消息"); int num = 0; foreach (AccountInfo account in _addFriends.Accounts) { num++; SetMessageLn("正在清空#" + num + ":" + account.UserName + "(" + account.Email + ")" + "的所有系统消息..."); if (!this.ValidationLogin(account, false)) { //SetMessageLn(account.UserName + "(" + account.Email + ")" + "登录失败!"); continue; } HH.Post("http://www.kaixin001.com/msg/clear_sys_msg.php", ""); SetMessageLn(account.UserName + "(" + account.Email + ")" + "的所有系统消息已被删除!"); } } if (!_addFriends.ExecuteSendRequest && !_addFriends.ExecuteConfirmRequest) { return; } if (_addFriends.AddMode) { int num; if (_addFriends.ExecuteSendRequest) { SetMessageLn("发送添加好友请求:"); num = 0; for (int ix = 0; ix < _addFriends.Accounts.Count; ix++) { num++; SetMessageLn("账号#" + num + ":" + _addFriends.Accounts[ix].UserName + "(" + _addFriends.Accounts[ix].Email + ")" + "开始发送请求..."); if (!this.ValidationLogin(_addFriends.Accounts[ix], true)) { continue; } string content = RequestAllMyFriends(); ReadAllMyFriends(content, false); int newcount = 0; for (int iy = ix + 1; iy < _addFriends.Accounts.Count; iy++) { if (!IsAlreadyMyFriend(_addFriends.Accounts[iy].UserId)) { newcount++; SetMessageLn(string.Format("添加好友请求#{0} {1}({2}) :", newcount.ToString(), _addFriends.Accounts[iy].UserName, _addFriends.Accounts[iy].UserId)); if (this.SendFriendRequest(_addFriends.Accounts[iy].UserId)) { SetMessage("成功!"); } else { SetMessage("失败!"); } } } } } if (_addFriends.ExecuteConfirmRequest) { SetMessageLn("确认好友请求:"); num = 0; foreach (AccountInfo account in _addFriends.Accounts) { num++; SetMessageLn("账号#" + num + ":" + account.UserName + "(" + account.Email + ")" + "开始确认请求..."); if (!this.ValidationLogin(account, true)) { continue; } this.ConfirmFriend(); } } } else { int num; if (_addFriends.ExecuteSendRequest) { SetMessageLn("发送添加好友请求:"); num = 0; foreach (AccountInfo account in _addFriends.NewAccountsList) { num++; SetMessageLn("新账号#" + num + ":" + account.UserName + "(" + account.Email + ")" + "开始发送请求..."); if (!this.ValidationLogin(account, true)) { continue; } this.AddAllList(account, _addFriends.NewAccountsList, true); this.AddAllList(account, _addFriends.OldAccountsList, false); } } if (_addFriends.ExecuteConfirmRequest) { SetMessageLn("确认好友请求:"); num = 0; foreach (AccountInfo account in _addFriends.NewAccountsList) { num++; SetMessageLn("新账号#" + num + ":" + account.UserName + "(" + account.Email + ")" + "开始确认请求..."); if (!this.ValidationLogin(account, true)) { continue; } this.ConfirmFriend(); } num = 0; foreach (AccountInfo account in _addFriends.OldAccountsList) { num++; SetMessageLn("旧账号#" + num + ":" + account.UserName + "(" + account.Email + ")" + "开始确认请求..."); if (!this.ValidationLogin(account, true)) { continue; } this.ConfirmFriend(); } } } SetMessageLn("互加好友完成!"); if (AddFriendsFinished != null) { AddFriendsFinished(); } }); base.ExecuteTryCatchBlock(th, "发生异常,互加好友失败!"); }
private void GetFishTackleInShop() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_UPDATEDATA; SetMessageLn("刷新[商店中鱼竿列表]..."); if (!this.ValidationLogin()) { if (FishTacklesFetched != null) FishTacklesFetched(null); return; } string content = RequestFishHomePage(false); content = RequestFishTacklesList(); Collection<FishTackleInfo> fishtackles = ConfigCtrl.GetOriginalFishTackles(content); if (fishtackles == null || fishtackles.Count == 0) SetMessageLn("[商店中鱼竿列表]信息刷新失败!"); else SetMessageLn("[商店中鱼竿列表]信息刷新成功!"); //invoke event if (FishTacklesFetched != null) FishTacklesFetched(fishtackles); }); base.ExecuteTryCatchBlock(th, "[商店中鱼竿列表]信息刷新失败!"); }
private void GetAllCafeFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_CAFE; SetMessageLn("刷新[所有开心餐厅的好友]..."); if (!this.ValidationLogin(true)) { if (AllCafeFriendsFetched != null) AllCafeFriendsFetched(_allCafeFriendsList); return; } string content = RequestCafeHomePage(false); content = RequestAllCafeFriends(); ReadAllCafeFriends(content, true); SetMessageLn("[所有开心餐厅的好友]信息刷新成功!"); //invoke event if (AllCafeFriendsFetched != null) AllCafeFriendsFetched(_allCafeFriendsList); }); base.ExecuteTryCatchBlock(th, "[所有开心餐厅的好友]信息刷新失败!"); }
private void GetHirableFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_CAFE; SetMessageLn("刷新[可以雇佣的好友列表]..."); if (!this.ValidationLogin()) { if (HirableFriendsFetched != null) HirableFriendsFetched(null); return; } string content = RequestCafeHomePage(false); CafeInfo cafe = ReadCafe(this._verifyCode, CurrentAccount.UserId, false); ReadHirableFriends(cafe, true); if (this._hirableFriendsList == null || this._hirableFriendsList.Count == 0) SetMessageLn("[可以雇佣的好友列表]信息刷新失败!"); else SetMessageLn("[可以雇佣的好友列表]信息刷新成功!"); //invoke event if (HirableFriendsFetched != null) HirableFriendsFetched(this._hirableFriendsList); }); base.ExecuteTryCatchBlock(th, "[可以雇佣的好友列表]信息刷新失败!"); }
private void GetTransactionDishesInMarket() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_UPDATEDATA; SetMessageLn("刷新[菜肴交易价格表]..."); if (!this.ValidationLogin()) { if (TransactionDishesFetched != null) TransactionDishesFetched(null); return; } string content = RequestCafeHomePage(false); CafeInfo cafe = ReadCafe(this._verifyCode, CurrentAccount.UserId, false); if (cafe == null) { return; } Collection<DishInfo> dishes = ConfigCtrl.GetDishesInMenu(); int num = 0; foreach (DishInfo dish in dishes) { SetMessageLn(string.Format("#{0} {1} ", ++num, dish.Title)); HH.DelayedTime = Constants.DELAY_1SECONDS; //http://www.kaixin001.com/cafe/api_tradeinfo.php?verify=2588258_1136_2588258_1266372458_f84ac5d57a67249f7b4068ead5dc8dfc&cafeid=185596&uid=2588258&dishid=22&type=21&r=0.3238336769863963 //http://www.kaixin001.com/cafe/api_tradeinfo.php?verify=2588258_1136_2588258_1267272898_fd382ccf4b137ed2ae8f6e20f3d12811&cafeid=185596&uid=2588258&dishid=18&type=21&r=0.35850675450637937 content = HH.Get(string.Format("http://www.kaixin001.com/cafe/api_tradeinfo.php?verify={0}&cafeid={1}&uid={2}&dishid={3}&type=21&r=0.3238336769863963", DataConvert.GetEncodeData(this._verifyCode), cafe.CafeId, CurrentAccount.UserId, dish.DishId)); dish.MaxPrice = DataConvert.GetDecimal(JsonHelper.GetMid(content, "<maxprice>", "</maxprice>")); dish.MinPrice = DataConvert.GetDecimal(JsonHelper.GetMid(content, "<minprice>", "</minprice>")); SetMessage(string.Format("最高价:{0},最低价:{1}", dish.MaxPrice, dish.MinPrice)); } //invoke event if (TransactionDishesFetched != null) TransactionDishesFetched(dishes); }); base.ExecuteTryCatchBlock(th, "[菜肴交易价格表]信息刷新失败!"); }
private void SaveFriendsToFile() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_MAINTAINCONTACT; SetMessageLn("开始导出所有好友列表..."); //start SetMessage("\r\n" + "============================== 开始 =============================="); int num = 0; foreach (AccountInfo account in _accounts) { try { num++; SetMessageLn("------ 共" + _accounts.Count + "个帐户,第" + num + "个帐户:" + account.UserName + "(" + account.Email + ") ------"); if (!this.ValidationLogin(account)) { continue; } SetMessageLn("取得[我在开心网上的所有好友]..."); string content = RequestAllMyFriends(); ReadAllMyFriends(content, false); SetMessageLn("[我在开心网上的所有好友]信息取得成功!"); this.LogOut(true); SetMessageLn("保存所有好友信息至文件..."); string result = ConfigCtrl.SaveContactToFile(_path, account, base.AllMyFriendsList); if (result == Constants.STATUS_SUCCESS) { SetMessageLn("成功!"); } else { SetMessageLn("失败:" + result); } } catch (ThreadAbortException) { LogHelper.Write("ToolMaintainContact.SaveFriendsToFile", account.UserName, LogSeverity.Info); } catch (ThreadInterruptedException) { LogHelper.Write("ToolMaintainContact.SaveFriendsToFile", account.UserName, LogSeverity.Info); } catch (Exception ex) { LogHelper.Write("ToolMaintainContact.SaveFriendsToFile", account.UserName, ex, LogSeverity.Error); SetMessageLn("发生异常,此账户操作失败!错误:" + ex.Message); continue; } } SetMessage("\r\n" + "============================== 完成 =============================="); if (AllFetchFinished != null) { AllFetchFinished(); } }); base.ExecuteTryCatchBlock(th, "发生异常,导出所有好友列表失败!"); }
private void GetCalvesInShop() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_UPDATEDATA; SetMessageLn("刷新[商店中动物幼仔列表]..."); if (!this.ValidationLogin()) { if (CalvesInShopFetched != null) CalvesInShopFetched(null); return; } string content = RequestHouseHomePage(false); content = RequestCalvesList(); Collection<CalfInfo> calves = ConfigCtrl.GetOriginalCalves(content); calves = SortCalvesListByPrice(calves); if (calves == null || calves.Count == 0) SetMessageLn("[商店中动物幼仔列表]信息刷新失败!"); else SetMessageLn("[商店中动物幼仔列表]信息刷新成功!"); //invoke event if (CalvesInShopFetched != null) CalvesInShopFetched(calves); }); base.ExecuteTryCatchBlock(th, "[商店中动物幼仔列表]信息刷新失败!"); }
public void RunGarden() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_GARDEN; SetMessageLn("开始花园..."); //house string contentHome = RequestHouseHomePage(false); GardenInfo garden = ReadGarden(this._verifyCode, CurrentAccount.UserId); if (garden == null) { SetMessageLn("无法读取我的花园信息!"); return; } ReadMySeeds(garden); if (_myseedsList.Count == 0) { SetMessage("没有种子了!"); } if (Task.FarmSelf) FarmGarden(garden); string content = ""; //偷窃果实 if (Task.StealFruit && Operation.StealAll || Task.FarmShared && Operation.FarmAll) { content = RequestMatureFriends(); ReadMatureFriends(content, false); } if (Task.StealFruit) StealGardens(); if (Task.HelpOthers || Task.FarmShared && Operation.FarmAll) { content = RequestAllGardenFriends(); ReadAllGardenFriends(content, false); } //播种爱心地块 if (Task.HelpOthers || Task.FarmShared) HelpOthersGardens(); //赠送果实 if (Task.PresentFruit) PresentFruit(); //出售果实 if (Task.SellFruit) SellFruit(garden); SetMessageLn("花园完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,花园失败!"); }
private void GetSameVillageFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_HOUSE; SetMessageLn("刷新[住在同小区里的好友]..."); if (!this.ValidationLogin(true)) { if (SameVillageFriendsFetched != null) SameVillageFriendsFetched(_sameVillageFriendsList); return; } string content = RequestHouseHomePage(false); string content2 = RequestAllHouseFriends(); ReadAllHouseFriends(content2, false); ReadSameVillageFriends(content, true); SetMessageLn("[住在同小区里的好友]信息刷新成功!"); //invoke event if (SameVillageFriendsFetched != null) SameVillageFriendsFetched(_sameVillageFriendsList); }); base.ExecuteTryCatchBlock(th, "[住在同小区里的好友]信息刷新失败!"); }
protected void ExecuteTryCatchBlock(TryCatchBlock method, string ErrorMsg) { try { method(); } catch (ThreadAbortException) { SetMessage("中止执行!"); if (OperationFailed != null) OperationFailed(); } catch (ThreadInterruptedException) { SetMessage("中止执行!"); if (OperationFailed != null) OperationFailed(); } catch (Exception ex) { LogHelper.Write(ErrorMsg, ex); SetMessage(ErrorMsg + "错误:" + ex.Message); if (OperationFailed != null) OperationFailed(); } TraceLog.WriteLogToFile(this._logfile, this._sblog.ToString()); _sblog.Length = 0; _logtimes = 0; }
private void GetAgriculturalProductFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_RANCH; SetMessageLn("刷新[牧场中有可偷的农副产品的好友]..."); if (!this.ValidationLogin(true)) { if (AgriculturalProductFriendsFetched != null) AgriculturalProductFriendsFetched(_ranchFriendsList); return; } string content = RequestHouseHomePage(false); content = RequestAgriculturalProductFriends(); ReadAgriculturalProductFriends(content, true); SetMessageLn("[牧场中有可偷的农副产品的好友]信息刷新成功!"); //invoke event if (AgriculturalProductFriendsFetched != null) AgriculturalProductFriendsFetched(_ranchFriendsList); }); base.ExecuteTryCatchBlock(th, "[牧场中有可偷的农副产品的好友]信息刷新失败!"); }
public void RunFish() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_FISH; SetMessageLn("开始钓鱼..."); //fish string contentHome = RequestFishHomePage(false); PondInfo pond = ReadPond(this._verifyCode, CurrentAccount.UserId, true); if (pond == null) { SetMessageLn("无法读取我的鱼塘信息!"); return; } //我的鱼竿 SetMessageLn("我的鱼竿:"); string content = RequestMyTacklesList(); Collection<FishTackleInfo> myTackcles = ConfigCtrl.GetMyTackles(content); for (int ix = 0; ix < myTackcles.Count; ix++) { if (myTackcles[ix].Status == 1) { SetMessageLn(string.Format("#{0} 已有 {1}", ix + 1, myTackcles[ix].Title)); if (myTackcles[ix].Status == 1 && myTackcles[ix].BUse == 1) SetMessage("(正在使用)"); } } if (Task.Shake) Shake(pond); if (Task.TreatFish) TreatFish(pond); if (Task.UpdateFishPond) UpdateFishPond(); if (Task.BangKeJing) BangKeJing(pond); if (Task.NetSelfFish) { NetSelfFish(pond); pond = ReadPond(this._verifyCode, CurrentAccount.UserId, false); if (pond == null) { SetMessageLn("无法读取我的鱼塘信息!"); return; } } if (Task.BuyFish) BuyFish(pond); if (Task.BuyUpdateTackle) BuyFishTackles(pond); if (Task.HarvestFish) { content = RequestAllFishFriends(); ReadAllFishFriends(content, false); HarvestFish(); } if (Task.Fishing) { content = RequestAllFishFriends(); ReadAllFishFriends(content, false); FishingPonds(pond); } if (Task.HelpFish) HelpFish(); if (Task.PresentFish) PresentFish(); if (Task.SellFish) SellFish(pond); SetMessageLn("钓鱼完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,钓鱼失败!"); }
public void RunRanch() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_RANCH; SetMessageLn("开始牧场..."); //ranch string contentHome = RequestHouseHomePage(false); //task manager中不会为null,在测试黑白配置时为null if (this._calfsList == null) { this._calfsList = ConfigCtrl.GetCalvesInShop(); } //RequestRanchConf(this._verifyCode, CurrentAccount.UserId); //return; RanchInfo ranch = ReadRanch(this._verifyCode, CurrentAccount.UserId, true); if (ranch == null) { SetMessageLn("无法读取我的牧场信息!"); return; } ReadMyFoods(ranch); if (_myfoodList.Count == 0) { SetMessage("没有饲料了!"); } string content = ""; //添水 if (Task.AddWater) AddWater(CurrentAccount.UserId, ranch); //添牧草 if (Task.AddGrass) AddGrass(CurrentAccount.UserId, ranch); //添胡萝卜 if (Task.AddCarrot) AddCarrot(CurrentAccount.UserId, ranch); //添竹子 if (Task.AddBamboo) AddBamboo(CurrentAccount.UserId, ranch); //收获农副产品 if (Task.HarvestProduct) HarvestProduct(ranch); //生产/收获动物 if (Task.MakeProduct || Task.HarvestAnimal) HarvestAndProductAnimal(ranch); //配种 if (Task.BreedAnimal) BreedAnimal(); //购买幼仔 if (Task.BuyCalf) { BuyCalf(ranch); //ranch = ReadRanch(this._verifyCode, CurrentAccount.UserId, false); } if (Task.HelpAddWater || Task.HelpAddGrass || Task.HelpAddCarrot || Task.HelpAddBamboo || Task.HelpMakeProduct) { content = RequestAllRanchFriends(); ReadAllRanchFriends(content, false); } //偷窃农副产品 //if (Task.StealProduct && Operation.StealProductAll || Task.HelpMakeProduct && Operation.HelpRanchAll) //{ //} content = RequestAgriculturalProductFriends(); ReadAgriculturalProductFriends(content, false); if (Task.StealProduct) StealRanchs(); //帮忙生产 if (Task.HelpMakeProduct) HelpMakeProduct(); //去其他牧场帮忙 if (Task.HelpAddWater || Task.HelpAddGrass || Task.HelpAddCarrot || Task.HelpAddBamboo) HelpOthersRanchs(); //赠送农副产品 if (Task.PresentProduct) PresentAnimalProduct(); //出售果实 if (Task.SellProduct) SellProduct(ranch); SetMessageLn("牧场完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,牧场失败!"); }
private void GetAllMyFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_MYKAIXIN; SetMessageLn("刷新[我在开心网上的所有好友]..."); //login if (!this.ValidationLogin()) { if (AllMyFriendsFetched != null) AllMyFriendsFetched(_allMyFriendsList); return; } string content = RequestAllMyFriends(); ReadAllMyFriends(content, true); SetMessageLn("[我在开心网上的所有好友]信息刷新成功!"); //invoke event if (AllMyFriendsFetched != null) AllMyFriendsFetched(_allMyFriendsList); }); ExecuteTryCatchBlock(th, "[我在开心网上的所有好友]信息刷新失败!"); }
private void GetMatureFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_GARDEN; SetMessageLn("刷新[花园中有成熟果实的好友]..."); if (!this.ValidationLogin(true)) { if (MatureFriendsFetched != null) MatureFriendsFetched(_myGardenFriendsList); return; } string content = RequestHouseHomePage(false); content = RequestMatureFriends(); ReadMatureFriends(content, true); SetMessageLn("[花园中有成熟果实的好友]信息刷新成功!"); //invoke event if (MatureFriendsFetched != null) MatureFriendsFetched(_myGardenFriendsList); }); base.ExecuteTryCatchBlock(th, "[花园中有成熟果实的好友]信息刷新失败!"); }
private void GetBitableFriends() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_BITING; SetMessageLn("刷新[我可以去咬的人]..."); if (!this.ValidationLogin(true)) { if (BitableFriendsFetched != null) BitableFriendsFetched(_bitableFriendsList); return; } string content = RequestBiteHomePage(); content = RequestBitableFriends(); ReadBitableFriends(content, true); SetMessageLn("[我可以去咬的人]信息刷新成功!"); //invoke event if (BitableFriendsFetched != null) BitableFriendsFetched(_bitableFriendsList); }); base.ExecuteTryCatchBlock(th, "[我可以去咬的人]信息刷新失败!"); }
private void GetNovelChapters() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MODULE_NOVELCHAPTERS; SetMessage(string.Format("刷新[{0}]的章节...", _currentNovel.Name), true); Collection<ChapterInfo> chapters = new Collection<ChapterInfo>(); string content = HH.Get(_currentNovel.ChapterUrl); if (string.IsNullOrEmpty(content)) { LogHelper.Write("GetNovelChapters()--" + _currentNovel.ChapterUrl, "Empty http response!!!", LogSeverity.Warn); return; } content = StringHelper.GetMid(content, "<table border=\"0\" width=\"950\" cellspacing=\"0\" cellpadding=\"0\">", "</div>"); if (content != null) { int temp = 1; string strTemp =""; do { strTemp = string.Format(CHAPTER, temp); if (content.Contains(strTemp)) temp++; else break; } while (temp < 10000); for (int ix = 1; ix < temp; ix++) { ChapterInfo chapter = new ChapterInfo(); chapter.ChapterId = ix; chapter.ChapterName = string.Format(CHAPTER, ix); chapter.Url = _currentNovel.ChapterUrl.Substring(0, _currentNovel.ChapterUrl.LastIndexOf('/') + 1) + ix + ".html"; chapters.Add(chapter); } } _currentNovel.Chapters = chapters; SetMessage("小说章节获取成功!", true); if (NovelChaptersFetched != null) NovelChaptersFetched(chapters); }); base.ExecuteTryCatchBlock(th, "发生异常,获取小说章节失败!"); }
private void GetNovelContent() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MODULE_NOVELCONTENT; SetMessage(string.Format("刷新第{0}章的内容...", _currentPageIndex + 1), true); if (_currentPageIndex >= _currentNovel.Chapters.Count) _currentPageIndex = _currentNovel.Chapters.Count - 1; string content = HH.Get(_currentNovel.Chapters[_currentPageIndex].Url); if (string.IsNullOrEmpty(content)) { LogHelper.Write("GetNovelContent()" + _currentNovel.Name, "Empty http response!!!", LogSeverity.Warn); return; } content = StringHelper.GetMid(content, "<td width=\"100%\" align=\"left\" height=57>", "</td>"); content = StringHelper.FiltrateHtmlTags(content); PagingInfo paging = new PagingInfo(); paging.Required = true; paging.Total = _currentNovel.Chapters.Count; paging.Current = _currentPageIndex + 1; SetMessage("小说内容获取成功!", true); if (NovelContentFetched != null) NovelContentFetched(content, paging); }); base.ExecuteTryCatchBlock(th, "发生异常,获取小说内容失败!"); }
protected TryCatchBlock(TryCatchBlock antecedent, Action action) : this(antecedent) { this.Action = action; }
protected void ExecuteTryCatchBlock(TryCatchBlock method, string ErrorMsg) { try { method(); } catch (ThreadAbortException) { SetMessageLn("Execution Aborted!"); if (OperationFailed != null) OperationFailed(); } catch (ThreadInterruptedException) { SetMessageLn("Execution Aborted!"); if (OperationFailed != null) OperationFailed(); } catch (Exception ex) { Log4Helper.Write(ErrorMsg + this.Caption, ex); SetMessageLn(ErrorMsg + "Error:" + ex.Message); if (OperationFailed != null) OperationFailed(); } }
public void SendMessage(AccountInfo account, Collection <FriendInfo> friends, string msg, bool bMulti) { _threadMain = new Thread(new System.Threading.ThreadStart(delegate { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_SENDMESSAGE; SetMessageLn("开始群发消息..."); if (!this.ValidationLogin(account, true)) { if (SendMessageFinished != null) { SendMessageFinished(); } return; } if (!bMulti) { foreach (FriendInfo friend in friends) { RequestMessageSending(friend.Id.ToString(), msg); SetMessageLn(string.Format("已经给{0}({1})发送消息!", friend.Name, friend.Id)); } SetMessageLn("全部消息发送完毕!"); } else { StringBuilder sbuids = new StringBuilder(); StringBuilder sbnames = new StringBuilder(); string[,] sendList = new string[(friends.Count - 1) / 30 + 1, 2]; for (int ix = 0; ix < friends.Count; ix++) { sbuids.Append(friends[ix].Id.ToString()); if ((ix + 1) % 30 != 0 && ix != friends.Count - 1) { sbuids.Append(","); } sbnames.Append(friends[ix].Name); if ((ix + 1) % 30 != 0 && ix != friends.Count - 1) { sbnames.Append(","); } if ((ix + 1) % 30 == 0) { sendList[ix / 30, 0] = sbuids.ToString(); sendList[ix / 30, 1] = sbnames.ToString(); sbuids = new StringBuilder(); sbnames = new StringBuilder(); } } if (friends.Count % 30 != 0) { sendList[sendList.GetLength(0) - 1, 0] = sbuids.ToString(); sendList[sendList.GetLength(0) - 1, 1] = sbnames.ToString(); } for (int ix = 0; ix < sendList.GetLength(0); ix++) { RequestMessageSending(sendList[ix, 0], msg); SetMessageLn("给" + sendList[ix, 1] + "群发消息成功!"); } } if (SendMessageFinished != null) { SendMessageFinished(); } return; }); base.ExecuteTryCatchBlock(th, "发生异常,群发消息失败!"); })); _threadMain.IsBackground = true; _threadMain.Start(); }
private void GetDishInMenu() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_UPDATEDATA; SetMessageLn("刷新[菜谱中菜肴列表]..."); if (!this.ValidationLogin()) { if (DishesFetched != null) DishesFetched(null); return; } string content = RequestCafeHomePage(false); Collection<DishInfo> dishes = new Collection<DishInfo>(); int page = 0; do { HH.DelayedTime = Constants.DELAY_1SECONDS; content = HH.Get(string.Format("http://www.kaixin001.com/cafe/api_dishlist.php?verify={0}&page={1}&r=0.11418269015848637", DataConvert.GetEncodeData(this._verifyCode), page)); Collection<DishInfo> dishes2 = new Collection<DishInfo>(); dishes2 = ConfigCtrl.GetOriginalDishes(content); if (dishes2 == null || dishes2.Count == 0) break; else { foreach (DishInfo item in dishes2) { DishInfo dish = new DishInfo(); dish.Clone(item); dishes.Add(dish); } page += 1; } } while (true); if (dishes == null || dishes.Count == 0) SetMessageLn("[菜谱中菜肴列表]信息刷新失败!"); else SetMessageLn("[菜谱中菜肴列表]信息刷新成功!"); //invoke event if (DishesFetched != null) DishesFetched(dishes); }); base.ExecuteTryCatchBlock(th, "[菜谱中菜肴列表]信息刷新失败!"); }
private void SendRequest() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_MAINTAINCONTACT; SetMessageLn("开始发送添加好友请求..."); if (!this.ValidationLogin(_account)) { if (SendRequestFinished != null) SendRequestFinished(); return; } int num = 0; foreach (FriendInfo friend in _friends) { num++; SetMessageLn(string.Format("向#{0} {1}({2})发送请求:", num, friend.Name, friend.Id)); if (this.SendFriendRequest(friend.Id, _requestcontent)) SetMessage("成功!"); else SetMessage("失败!"); } SetMessageLn("发送添加好友请求完成!"); if (SendRequestFinished != null) SendRequestFinished(); }); base.ExecuteTryCatchBlock(th, "发生异常,发送添加好友请求失败!"); }
public void RunCafe() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_CAFE; SetMessageLn("开始开心餐厅..."); //cafe string contentHome = RequestCafeHomePage(false); contentHome = RequestAllCafeFriends(); ReadAllCafeFriends(contentHome, false); CafeInfo cafe = ReadCafe(this._verifyCode, CurrentAccount.UserId, true); if (cafe == null) { SetMessageLn("无法读取我的餐厅信息!"); return; } //帮忙好友 if (Task.HelpFriend) HelpFriend(); //SetMessageLn("afe.Grade=" + cafe.Grade); //if (cafe.Grade <= 20) //{ // Majia(cafe); // cafe = ReadCafe(this._verifyCode, CurrentAccount.UserId, false); // if (cafe == null) // { // SetMessageLn("无法读取我的餐厅信息!"); // return; // } //} //炒菜 if (Task.BoxClean || Task.Cook) BoxCleanCook(CurrentAccount.UserId, cafe); //雇员 if (Task.Hire) Hire(cafe); //赠送食物 if (Task.PresentFood) PresentFood(CurrentAccount.UserId, cafe); //收购食物 if (Task.PurchaseFood) PurchaseFood(cafe); //出售食物 if (Task.SellFood) SellFood(CurrentAccount.UserId, cafe); SetMessageLn("开心餐厅完成!"); }); base.ExecuteTryCatchBlock(th, "发生异常,开心餐厅失败!"); }
private void SaveFriendsToFile() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_MAINTAINCONTACT; SetMessageLn("开始导出所有好友列表..."); //start SetMessage("\r\n" + "============================== 开始 =============================="); int num = 0; foreach (AccountInfo account in _accounts) { try { num++; SetMessageLn("------ 共" + _accounts.Count + "个帐户,第" + num + "个帐户:" + account.UserName + "(" + account.Email + ") ------"); if (!this.ValidationLogin(account)) { continue; } SetMessageLn("取得[我在开心网上的所有好友]..."); string content = RequestAllMyFriends(); ReadAllMyFriends(content, false); SetMessageLn("[我在开心网上的所有好友]信息取得成功!"); this.LogOut(true); SetMessageLn("保存所有好友信息至文件..."); string result = ConfigCtrl.SaveContactToFile(_path, account, base.AllMyFriendsList); if (result == Constants.STATUS_SUCCESS) SetMessageLn("成功!"); else SetMessageLn("失败:" + result); } catch (ThreadAbortException) { LogHelper.Write("ToolMaintainContact.SaveFriendsToFile", account.UserName, LogSeverity.Info); } catch (ThreadInterruptedException) { LogHelper.Write("ToolMaintainContact.SaveFriendsToFile", account.UserName, LogSeverity.Info); } catch (Exception ex) { LogHelper.Write("ToolMaintainContact.SaveFriendsToFile", account.UserName, ex, LogSeverity.Error); SetMessageLn("发生异常,此账户操作失败!错误:" + ex.Message); continue; } } SetMessage("\r\n" + "============================== 完成 =============================="); if (AllFetchFinished != null) AllFetchFinished(); }); base.ExecuteTryCatchBlock(th, "发生异常,导出所有好友列表失败!"); }
private void RunAddFriend() { TryCatchBlock th = new TryCatchBlock(delegate { _module = Constants.MSG_ADDFRIENDS; SetMessageLn("开始互加好友..."); if (_addFriends.DeleteAllMessages) { SetMessageLn("清空所有账号的系统消息"); int num = 0; foreach (AccountInfo account in _addFriends.Accounts) { num++; SetMessageLn("正在清空#" + num + ":" + account.UserName + "(" + account.Email + ")" + "的所有系统消息..."); if (!this.ValidationLogin(account, false)) { //SetMessageLn(account.UserName + "(" + account.Email + ")" + "登录失败!"); continue; } HH.Post("http://www.kaixin001.com/msg/clear_sys_msg.php", ""); SetMessageLn(account.UserName + "(" + account.Email + ")" + "的所有系统消息已被删除!"); } } if (!_addFriends.ExecuteSendRequest && !_addFriends.ExecuteConfirmRequest) return; if (_addFriends.AddMode) { int num; if (_addFriends.ExecuteSendRequest) { SetMessageLn("发送添加好友请求:"); num = 0; for (int ix = 0; ix < _addFriends.Accounts.Count; ix++) { num++; SetMessageLn("账号#" + num + ":" + _addFriends.Accounts[ix].UserName + "(" + _addFriends.Accounts[ix].Email + ")" + "开始发送请求..."); if (!this.ValidationLogin(_addFriends.Accounts[ix], true)) { continue; } string content = RequestAllMyFriends(); ReadAllMyFriends(content, false); int newcount = 0; for (int iy = ix + 1; iy < _addFriends.Accounts.Count; iy++) { if (!IsAlreadyMyFriend(_addFriends.Accounts[iy].UserId)) { newcount++; SetMessageLn(string.Format("添加好友请求#{0} {1}({2}) :", newcount.ToString(), _addFriends.Accounts[iy].UserName, _addFriends.Accounts[iy].UserId)); if (this.SendFriendRequest(_addFriends.Accounts[iy].UserId)) SetMessage("成功!"); else SetMessage("失败!"); } } } } if (_addFriends.ExecuteConfirmRequest) { SetMessageLn("确认好友请求:"); num = 0; foreach (AccountInfo account in _addFriends.Accounts) { num++; SetMessageLn("账号#" + num + ":" + account.UserName + "(" + account.Email + ")" + "开始确认请求..."); if (!this.ValidationLogin(account, true)) continue; this.ConfirmFriend(); } } } else { int num; if (_addFriends.ExecuteSendRequest) { SetMessageLn("发送添加好友请求:"); num = 0; foreach (AccountInfo account in _addFriends.NewAccountsList) { num++; SetMessageLn("新账号#" + num + ":" + account.UserName + "(" + account.Email + ")" + "开始发送请求..."); if (!this.ValidationLogin(account, true)) { continue; } this.AddAllList(account, _addFriends.NewAccountsList, true); this.AddAllList(account, _addFriends.OldAccountsList, false); } } if (_addFriends.ExecuteConfirmRequest) { SetMessageLn("确认好友请求:"); num = 0; foreach (AccountInfo account in _addFriends.NewAccountsList) { num++; SetMessageLn("新账号#" + num + ":" + account.UserName + "(" + account.Email + ")" + "开始确认请求..."); if (!this.ValidationLogin(account, true)) continue; this.ConfirmFriend(); } num = 0; foreach (AccountInfo account in _addFriends.OldAccountsList) { num++; SetMessageLn("旧账号#" + num + ":" + account.UserName + "(" + account.Email + ")" + "开始确认请求..."); if (!this.ValidationLogin(account, true)) continue; this.ConfirmFriend(); } } } SetMessageLn("互加好友完成!"); if (AddFriendsFinished != null) AddFriendsFinished(); }); base.ExecuteTryCatchBlock(th, "发生异常,互加好友失败!"); }
public void Preprocess(ILConversion conversion, ConvertedRoutine routine) { if (routine.IsExceptionHandlingInfoPreprocessed) { return; } routine.IsExceptionHandlingInfoPreprocessed = true; routine.ExceptionHandlingInfo = new ExceptionHandlingInfo(); var handlingInfo = routine.ExceptionHandlingInfo; var methodDefinition = (MethodDefinition)routine.MethodReference; var methodDefinitionBody = methodDefinition.Body; if (!methodDefinitionBody.HasExceptionHandlers) { return; } foreach (var exceptionBlock in methodDefinitionBody.ExceptionHandlers) { switch (exceptionBlock.HandlerType) { case ExceptionHandlerType.Filter: { var filterBlock = new FilterBlock() { TryStartOffset = exceptionBlock.TryStart.Offset, TryEndOffset = exceptionBlock.TryEnd.Offset, HandlerEndOffset = exceptionBlock.HandlerEnd.Offset, FilterStartOffset = exceptionBlock.FilterStart?.Offset ?? -1, ExceptionHandler = exceptionBlock }; handlingInfo.ExceptionBlocks.Add(filterBlock); AddEvent(conversion, ExceptionBlockEventKind.Begin, handlingInfo, exceptionBlock.TryStart.Offset, filterBlock); AddEvent(conversion, ExceptionBlockEventKind.Finally, handlingInfo, exceptionBlock.HandlerStart.Offset, filterBlock); AddEvent(conversion, ExceptionBlockEventKind.EndBlock, handlingInfo, exceptionBlock.HandlerEnd.Offset, filterBlock); break; } case ExceptionHandlerType.Fault: { var faultBlock = new FaultBlock() { TryStartOffset = exceptionBlock.TryStart.Offset, TryEndOffset = exceptionBlock.TryEnd.Offset, HandlerEndOffset = exceptionBlock.HandlerEnd.Offset, FilterStartOffset = exceptionBlock.FilterStart?.Offset ?? -1, ExceptionHandler = exceptionBlock }; handlingInfo.ExceptionBlocks.Add(faultBlock); AddEvent(conversion, ExceptionBlockEventKind.Begin, handlingInfo, exceptionBlock.TryStart.Offset, faultBlock); AddEvent(conversion, ExceptionBlockEventKind.Finally, handlingInfo, exceptionBlock.HandlerStart.Offset, faultBlock); AddEvent(conversion, ExceptionBlockEventKind.EndBlock, handlingInfo, exceptionBlock.HandlerEnd.Offset, faultBlock); break; } case ExceptionHandlerType.Finally: { var finallyBlock = new TryFinallyBlock() { TryStartOffset = exceptionBlock.TryStart.Offset, TryEndOffset = exceptionBlock.TryEnd.Offset, HandlerEndOffset = exceptionBlock.HandlerEnd.Offset, FilterStartOffset = exceptionBlock.FilterStart?.Offset ?? -1, ExceptionHandler = exceptionBlock }; handlingInfo.ExceptionBlocks.Add(finallyBlock); AddEvent(conversion, ExceptionBlockEventKind.Begin, handlingInfo, exceptionBlock.TryStart.Offset, finallyBlock); AddEvent(conversion, ExceptionBlockEventKind.Finally, handlingInfo, exceptionBlock.HandlerStart.Offset, finallyBlock); AddEvent(conversion, ExceptionBlockEventKind.EndBlock, handlingInfo, exceptionBlock.HandlerEnd.Offset, finallyBlock); break; } case ExceptionHandlerType.Catch: { TryCatchBlock tryCatchBlock = null; for (int i = 0; i < handlingInfo.TryCatchEntries.Count; i++) { var x = handlingInfo.TryCatchEntries[i]; if (x.TryStartOffset == exceptionBlock.TryStart.Offset && x.TryEndOffset == exceptionBlock.TryEnd.Offset) { tryCatchBlock = x; } } if (tryCatchBlock == null) { tryCatchBlock = new TryCatchBlock() { // The first instruction that is included in the try catch block TryStartOffset = exceptionBlock.TryStart.Offset, // Gets the first instruction of the catch statement TryEndOffset = exceptionBlock.TryEnd.Offset, // Gets the first instruction that is outside of the catch statement HandlerEndOffset = exceptionBlock.HandlerEnd.Offset, FilterStartOffset = exceptionBlock.FilterStart?.Offset ?? -1, HandlerEntries = new Dictionary <int, List <ExceptionHandler> >() }; handlingInfo.TryCatchEntries.Add(tryCatchBlock); handlingInfo.ExceptionBlocks.Add(tryCatchBlock); System.Diagnostics.Debug.WriteLine($"Try-Catch: BEGIN @ {exceptionBlock.TryStart.Offset.ToString("X2")}"); AddEvent(conversion, ExceptionBlockEventKind.Begin, handlingInfo, exceptionBlock.TryStart.Offset, tryCatchBlock); } if (!tryCatchBlock.HandlerEntries.TryGetValue(exceptionBlock.HandlerStart.Offset, out List <ExceptionHandler> list)) { list = new List <ExceptionHandler>(); tryCatchBlock.HandlerEntries.Add(exceptionBlock.HandlerStart.Offset, list); } list.Add(exceptionBlock); System.Diagnostics.Debug.WriteLine($"Try-Catch: CATCH @ {exceptionBlock.HandlerStart.Offset.ToString("X2")}"); AddEvent(conversion, ExceptionBlockEventKind.Catch, handlingInfo, exceptionBlock.HandlerStart.Offset, tryCatchBlock, exceptionBlock); break; } default: { throw new NotSupportedException(); } } } for (int i = 0; i < handlingInfo.TryCatchEntries.Count; i++) { var tryCatchBlock = handlingInfo.TryCatchEntries[i]; ExceptionHandler lastHandlerEntry = null; var handlerEntriesListList = tryCatchBlock.HandlerEntries.Values.ToList(); for (int j = 0; j < handlerEntriesListList.Count; j++) { var currentHandlerEntryList = handlerEntriesListList[j]; for (int k = 0; k < currentHandlerEntryList.Count; k++) { var currentHandlerEntry = currentHandlerEntryList[k]; if (lastHandlerEntry == null) { lastHandlerEntry = currentHandlerEntry; } else if (currentHandlerEntry.HandlerEnd.Offset > lastHandlerEntry.HandlerEnd.Offset) { lastHandlerEntry = currentHandlerEntry; } } } if (lastHandlerEntry == null) { continue; } System.Diagnostics.Debug.WriteLine($"Try-Catch: END CATCH @ {lastHandlerEntry.HandlerEnd.Offset.ToString("X2")}"); AddEvent(conversion, ExceptionBlockEventKind.EndBlock, handlingInfo, lastHandlerEntry.HandlerEnd.Offset, tryCatchBlock); } }