public void TestIsValidType() { var corgi = new ParseObject("Corgi"); var corgiRelation = corgi.GetRelation<ParseObject>("corgi"); Assert.IsTrue(ParseEncoder.IsValidType(322)); Assert.IsTrue(ParseEncoder.IsValidType(0.3f)); Assert.IsTrue(ParseEncoder.IsValidType(new byte[]{ 1, 2, 3, 4 })); Assert.IsTrue(ParseEncoder.IsValidType("corgi")); Assert.IsTrue(ParseEncoder.IsValidType(corgi)); Assert.IsTrue(ParseEncoder.IsValidType(new ParseACL())); Assert.IsTrue(ParseEncoder.IsValidType(new ParseFile("Corgi", new byte[0]))); Assert.IsTrue(ParseEncoder.IsValidType(new ParseGeoPoint(1, 2))); Assert.IsTrue(ParseEncoder.IsValidType(corgiRelation)); Assert.IsTrue(ParseEncoder.IsValidType(new DateTime())); Assert.IsTrue(ParseEncoder.IsValidType(new List<object>())); Assert.IsTrue(ParseEncoder.IsValidType(new Dictionary<string, string>())); Assert.IsTrue(ParseEncoder.IsValidType(new Dictionary<string, object>())); Assert.IsFalse(ParseEncoder.IsValidType(new ParseAddOperation(new List<object>()))); Assert.IsFalse(ParseEncoder.IsValidType(Task<ParseObject>.FromResult(new ParseObject("Corgi")))); Assert.Throws<MissingMethodException>(() => ParseEncoder.IsValidType(new Dictionary<object, object>())); Assert.Throws<MissingMethodException>(() => ParseEncoder.IsValidType(new Dictionary<object, string>())); }
private async Task LoadEverything() { //ScriptManager.RegisterStartupScript(this, this.GetType(), "scrollPanel", "scrollPanel();", true); IEnumerable<ParseObject> conversations = await GetConversations(); DataTable dt = InitConversationTable(); foreach (ParseObject conv in conversations) { //ConversationPanel pnl = (ConversationPanel)LoadControl("~/UserControls/ConversationPanel.ascx"); //string theirNumber = conv.Get<string>("baseUserId1") == UserID ? "2" : "1"; //ParseObject tempTheirPublicData = conv.Get<ParseObject>("publicUserData" + theirNumber); //await tempTheirPublicData.FetchIfNeededAsync(); //pnl.TheirName = tempTheirPublicData.Get<string>("displayName"); //pnl.LastMessage = await GetFirstMessageText(conv); //pnl.TheirUserID = tempTheirPublicData.ObjectId; //pnlConversations.ContentTemplateContainer.Controls.Add(pnl); //pnlConversations.Controls.Add(pnl); DataRow dr = dt.NewRow(); string theirNumber = conv.Get<string>("baseUserId1") == UserID ? "2" : "1"; ParseObject tempTheirPublicData = conv.Get<ParseObject>("publicUserData" + theirNumber); await tempTheirPublicData.FetchIfNeededAsync(); dr["TheirName"] = tempTheirPublicData.Get<string>("displayName"); string lastMessage = await GetFirstMessageText(conv); dr["LastMessage"] = lastMessage.Length <= 30 ? lastMessage : lastMessage.Substring(0, 30) + "..."; dr["TheirUserID"] = tempTheirPublicData.ObjectId; ParseFile profilePic = tempTheirPublicData.Get<ParseFile>("profilePic"); dr["ProfilePicUrl"] = profilePic == null ? "Images/default_prof_pic.png" : profilePic.Url.ToString(); dt.Rows.Add(dr); } repConversations.DataSource = dt; repConversations.DataBind(); if (Session["ConversationUserId"] != null) { RecipientPublicData = await GetStudentPublicData(Session["ConversationUserId"].ToString()); Conversation = await GetThisConversation(RecipientPublicData.Get<string>("baseUserId")); if (Conversation == null) { } else { ParseRelation<ParseObject> relation = Conversation.GetRelation<ParseObject>("messages"); IEnumerable<ParseObject> messages = await relation.Query.OrderBy("createdAt").FindAsync(); DataTable messageData = InitMessageTable(); foreach (ParseObject mes in messages) { DataRow dr = messageData.NewRow(); dr["Text"] = mes.Get<string>("text"); dr["WasSentByMe"] = mes.Get<string>("senderBaseUserId") == UserID; dr["SentAt"] = mes.Get<DateTime>("sentAt").ToString(); messageData.Rows.Add(dr); } repMessages.DataSource = messageData; repMessages.DataBind(); await RemoveNotificationsForConversation(); } tbType.Enabled = true; btnSend.Enabled = true; } else { tbType.Enabled = false; btnSend.Enabled = false; } }
private async Task<string> GetFirstMessageText(ParseObject conversation) { var relation = conversation.GetRelation<ParseObject>("messages"); var query = from mes in relation.Query orderby mes.CreatedAt descending select mes; ParseObject message = await query.FirstAsync(); return message.Get<string>("text"); }