public async Task Enter() { var f = false; var query = new AVQuery <AVObject>("Account").WhereContains("name", "x"); var liveQuery = await query.SubscribeAsync(); liveQuery.OnLiveQueryReceived += (sender, e) => { Console.WriteLine(e.Scope); Assert.AreEqual(e.Scope, "enter"); f = true; }; var q = AVObject.GetQuery("Account"); var go = await q.GetAsync("5df7268cd4b56c00748e91af"); go["name"] = "xxx"; await go.SaveAsync(); Console.WriteLine(go.ObjectId); while (!f) { await Task.Delay(100); } go["name"] = "yyy"; await go.SaveAsync(); Console.WriteLine("Test enter done!"); }
async private void InitChildCategories() { IEnumerable <AVObject> categories = null; AVObject parentCategory = null; var parentTask = AVObject.GetQuery("Category").GetAsync(this.parent_category.SelectedValue).ContinueWith(r => { parentCategory = r.Result; }); await parentTask; var task = AVObject.GetQuery("Category").WhereEqualTo("parent", parentCategory).FindAsync().ContinueWith(r => { categories = r.Result; var datasource = new DataTable(); datasource.Columns.Add("categoryName"); datasource.Columns.Add("objectId"); foreach (var category in categories) { datasource.Rows.Add(new[] { category["name"], category.ObjectId }); } this.child_category.DataSource = datasource; this.child_category.DataTextField = "categoryName"; this.child_category.DataValueField = "objectId"; this.child_category.DataBind(); }); await task; }
public async Task Leave() { var f = false; var query = new AVQuery <AVObject>("Account").WhereContains("name", "s"); var liveQuery = await query.SubscribeAsync(); liveQuery.OnLiveQueryReceived += (sender, e) => { Console.WriteLine(e.Scope); Assert.AreEqual(e.Scope, "leave"); f = true; }; var q = AVObject.GetQuery("Account"); var go = await q.GetAsync("5df0b08f5620710073a95ccd"); go["name"] = "aaa"; await go.SaveAsync(); Console.WriteLine(go.ObjectId); while (!f) { await Task.Delay(100); f = true; } go["name"] = "sss"; await go.SaveAsync(); Console.WriteLine("Test leave done!"); }
async private void InitPictures() { IEnumerable <AVObject> blogs = null; var task = AVObject.GetQuery("Blog").WhereGreaterThan(this.report_count_key, 0).OrderByDescending(this.report_count_key).FindAsync().ContinueWith(r => { blogs = r.Result; datasource = new DataTable(); datasource.Columns.Add("用户名"); datasource.Columns.Add("举报数"); datasource.Columns.Add("图片"); datasource.Columns.Add("objectId"); foreach (var blog in blogs) { datasource.Rows.Add(new[] { blog["username"], blog["report_count"], ((AVFile)blog["thumbnail"]).Url, blog.ObjectId }); } this.gridview_picture.DataSource = datasource; this.gridview_picture.DataBind(); this.gridview_user.Visible = false; this.gridview_picture.Visible = true; }); await task; }
async private void DeletePicture(string objectId) { AVObject blog = null; await AVObject.GetQuery("Blog").GetAsync(objectId).ContinueWith(r => { blog = r.Result; blog.DeleteAsync(); }); }
public void TestGetQuery() { AVObject.RegisterSubclass <SubClass>(); AVQuery <AVObject> query = AVObject.GetQuery("UnregisteredSubClass"); Assert.AreEqual("UnregisteredSubClass", query.GetClassName()); Assert.Throws <ArgumentException>(() => AVObject.GetQuery("SubClass")); AVPlugins.Instance.SubclassingController.UnregisterSubclass(typeof(SubClass)); }
async private void UploadPictures() { List <AVUser> selectedUserList = new List <AVUser>(); if (this.Page.Session[SESSIONKEY] == null) { this.InitUsers(); } var users = (IEnumerable <AVUser>) this.Page.Session[SESSIONKEY]; foreach (ListItem item in this.choosen_users.Items) { if (item.Selected) { AVUser user = users.First(u => u.ObjectId == item.Value); selectedUserList.Add(user); } } Random random = new Random(); int userCount = selectedUserList.Count; AVObject selectedCategory = await AVObject.GetQuery("Category").GetAsync(this.child_category.SelectedValue); int hack_pop = this.pop_check.Checked ? 1 : 0; var uploadedFiles = this.file_upload.PostedFiles; foreach (var file in uploadedFiles) { var fullSizeImage = this.ResizeImageWithSize(file.InputStream, fullSizeRect); var thumbnailImage = this.ResizeImageWithSize(file.InputStream, thumbnailSizeRect); AVFile imageFull = new AVFile(file.FileName, this.GetBytesFromImage(fullSizeImage)); await imageFull.SaveAsync(); AVFile imageThumbnail = new AVFile(string.Format("thumbnail_{0}", file.FileName), this.GetBytesFromImage(thumbnailImage)); await imageThumbnail.SaveAsync(); this.SaveBlog(selectedUserList[random.Next(userCount)], selectedCategory.ObjectId, imageThumbnail.ObjectId, imageFull.ObjectId, hack_pop); } }
//右键快捷菜单“删除好友” private void ContextMenuDelete_Click(object sender, RoutedEventArgs e) { App.Current.Dispatcher.Invoke((Action)(async() => { UserList friend = MyFriendsList[friendlist.SelectedIndex]; if (MessageBox.Show("确定要删除" + friend.Name + "吗", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { //移除listitem,再重新绑定listitemsource MyFriendsList.RemoveAt(friendlist.SelectedIndex); friendlist.ItemsSource = null; friendlist.ItemsSource = MyFriendsList; new Tip("提示", "已成功解除与" + friend.Name + "的好友关系", 3).Show(); //将对方踢出自己的FriendsConversation,对方触发onkick事件 await User.KickAsync(FriendsConversation, member: friend.Friend.ObjectId); //再将双方单独的_Conversation删除 try { List <string> members = new List <string>(); members.Add(AVUser.CurrentUser.ObjectId); members.Add(friend.Friend.ObjectId); await(await AVObject.GetQuery("_Conversation").WhereEqualTo("m", members).FirstAsync()).DeleteAsync(); } catch { try { List <string> members = new List <string>(); members.Add(friend.Friend.ObjectId); members.Add(AVUser.CurrentUser.ObjectId); await(await AVObject.GetQuery("_Conversation").WhereEqualTo("m", members).FirstAsync()).DeleteAsync(); } catch { MessageBox.Show("你早就被人家拉黑了"); } } //重新获取FriendsConversation FriendsConversation = await User.GetConversationAsync(AVUser.CurrentUser.Get <string>("Friends")); } })); }
public void SendGetRankListMsgCS() { if (MainSystem.Instance.isOpenNetWork) { string userName = LoginSystem.Instance._userName; Debug.Log("NetWork SendGetRankListMsgCS " + userName); AVObject gameScore = new AVObject("GameScore"); AVQuery <AVObject> query = AVObject.GetQuery("GameScore"); query = query.WhereContains("playerName", userName).OrderByDescending("score"); query.FindAsync().ContinueWith(t => { Task task = Task.FromResult(0); int cnt = 0; List <int> list_score = new List <int>(); foreach (AVObject result in t.Result) { gameScore = result; if (cnt < 5) { cnt = cnt + 1; list_score.Add(gameScore.Get <int>("score")); } } Debug.Log("NetWork SendResultMsg get rank."); rankListTemp = list_score; _isRankListFinish = true; }); } else { _isRankListFinish = true; rankListTemp.Clear(); rankListTemp.Add(111); rankListTemp.Add(222); } }
//添加好友事件监听(好友邀请事件:同意,拒绝,好友邀请反馈事件:同意) private void OnInvited(object sender, AVIMOnInvitedEventArgs e) { //排除自身引发的事件 if (e.InvitedBy != AVUser.CurrentUser.ObjectId) { App.Current.Dispatcher.Invoke((Action)(async() => { AVIMConversation InvitedConversation = await User.GetConversationAsync(e.ConversationId); AVUser InvitedUser = await AVUser.Query.GetAsync(e.InvitedBy); //好友邀请事件 if (InvitedConversation.IsUnique) { //同意 if (MessageBox.Show(InvitedUser.Username + "请求添加您为好友,是否通过?", "添加好友请求", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { //将对方加入自己的FriendsConversation await User.InviteAsync(FriendsConversation, e.InvitedBy); //重新获取FriendsConversation==》不必要 FriendsConversation = await User.GetConversationAsync(AVUser.CurrentUser.Get <string>("Friends")); //重新绑定listbox数据 BindingFriendListSrouce(e.InvitedBy); } //拒绝 else { //拒绝即为删除邀请者创建的Conversation try { List <string> members = new List <string>(); members.Add(AVUser.CurrentUser.ObjectId); members.Add(InvitedUser.ObjectId); await(await AVObject.GetQuery("_Conversation").WhereEqualTo("m", members).FirstAsync()).DeleteAsync(); } catch { try { List <string> members = new List <string>(); members.Add(InvitedUser.ObjectId); members.Add(AVUser.CurrentUser.ObjectId); await(await AVObject.GetQuery("_Conversation").WhereEqualTo("m", members).FirstAsync()).DeleteAsync(); } catch { MessageBox.Show("给舔狗一条活路吧"); } } finally { new Tip("提醒", "已拒绝 " + InvitedUser.Username + "的好友邀请", 3); } } } //好友邀请反馈事件:同意 if (!InvitedConversation.IsUnique) { //将对方加入自己的FriendsConversation if (!FriendsConversation.MemberIds.Contains(e.InvitedBy)) { new Tip("提醒", "已成功添加 " + InvitedUser.Username); await User.InviteAsync(FriendsConversation, e.InvitedBy); //重新获取FriendsConversation==》不必要 FriendsConversation = await User.GetConversationAsync(AVUser.CurrentUser.Get <string>("Friends")); //重新绑定listbox数据 BindingFriendListSrouce(e.InvitedBy); } } })); } }