public static void WriteLine(params object[] args) { StackTrace st = new StackTrace(); var index = Math.Min(1, st.FrameCount); var frame = st.GetFrame(index); string msg = string.Empty; if (frame != null) { var m = frame.GetMethod().Name; msg = string.Format("{0} [{1}] ({2})", DateTime.Now.ToLongTimeString(), System.Threading.Thread.CurrentThread.ManagedThreadId, m); } else { msg = string.Format("{0} [{1}]", DateTime.Now.ToLongTimeString(), System.Threading.Thread.CurrentThread.ManagedThreadId); } if (args != null) { msg += " : "; msg = args.Aggregate(msg, (current, arg) => current + arg.ToString() + ','); } msg = msg.TrimEnd(','); System.Diagnostics.Debug.WriteLine(msg); Console.WriteLine(msg); OutputForm.SetText(msg); }
private void ChatRoomApi_ReceiveMessageHandler(long roomId, NIMChatRoom.Message message) { if (message.MessageType == NIMChatRoomMsgType.kNIMChatRoomMsgTypeRobot) { OutputForm.SetText("机器人消息:\n" + message.MessageAttachment + "\n" + message.Body); } else { string item = string.Format("{0}:\r\n{1}\r\n", message.SenderNickName, message.MessageAttachment); Action action = () => { this.receivedmsgListbox.Items.Add(item); }; this.Invoke(action); } }
void OnQueryMembersCompleted(long roomId, NIM.ResponseCode errorCode, MemberInfo[] members, NIMChatRoom.NIMChatRoomGetMemberType type) { if (errorCode == NIM.ResponseCode.kNIMResSuccess) { OutputForm.SetText(members.Dump()); if (members == null) { return; } foreach (var member in members) { AddMemberToListview(member, type); } } else { MessageBox.Show("查询聊天室成员失败:" + errorCode.ToString()); } }
private void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button != MouseButtons.Right || string.IsNullOrEmpty(e.Node.Name)) { return; } var roomId = long.Parse(e.Node.Name); ContextMenu menu = new ContextMenu(); MenuItem item1 = null; if (!_joinedRoomIdSet.Contains(roomId)) { item1 = new MenuItem("进入聊天室", (s, arg) => { NIM.Plugin.ChatRoom.RequestLoginInfo(roomId, (response, authResult) => { if (response == NIM.ResponseCode.kNIMResSuccess) { NIMChatRoom.LoginData data = new NIMChatRoom.LoginData(); data.Icon = "http://image.baidu.com/search/detail?ct=503316480&z=&tn=baiduimagedetail&ipn=d&word=%E5%AE%A0%E7%89%A9&step_word=&ie=utf-8&in=&cl=2&lm=-1&st=-1&cs=69099631,2544305882&os=4219122898,2688632801&simid=&pn=0&rn=1&di=0&ln=1000&fr=&fmq=1461830763275_R_D&fm=&ic=0&s=undefined&se=&sme=&tab=0&width=&height=&face=undefined&is=&istype=2&ist=&jit=&bdtype=-1&gsm=0&objurl=http%3A%2F%2Fimg.taopic.com%2Fuploads%2Fallimg%2F110906%2F1382-110Z611025585.jpg&rpstart=0&rpnum=0"; data.Nick = "【C# Client】"; NIMChatRoom.ChatRoomApi.Login(roomId, authResult, data); } }); }); } else { item1 = new MenuItem("离开聊天室", (s, arg) => { NIMChatRoom.ChatRoomApi.Exit(roomId); }); MenuItem item2 = new MenuItem("聊天室信息", (s, arg) => { NIMChatRoom.ChatRoomApi.GetRoomInfo(roomId, (a, b, c) => { Action action = () => { ObjectPropertyInfoForm form = new ObjectPropertyInfoForm(); form.TargetObject = c; form.Show(); }; this.Invoke(action); }); }); MenuItem item3 = new MenuItem("聊天室成员", (s, arg) => { QueryMembers(roomId); }); MenuItem item4 = new MenuItem("消息历史", (s, arg) => { NIMChatRoom.ChatRoomApi.QueryMessageHistoryOnline(roomId, 0, 50, (a, b, c) => { if (b == NIM.ResponseCode.kNIMResSuccess) { OutputForm.SetText(c.Dump()); } }); }); MenuItem item5 = new MenuItem("发送测试消息", (s, arg) => { NIMChatRoom.Message msg = new NIMChatRoom.Message(); msg.MessageType = NIMChatRoom.NIMChatRoomMsgType.kNIMChatRoomMsgTypeText; msg.MessageAttachment = "这是一条测试消息 " + DateTime.Now.ToString() + " " + new Random().NextDouble().ToString(); NIMChatRoom.ChatRoomApi.SendMessage(roomId, msg); }); menu.MenuItems.Add(item2); menu.MenuItems.Add(item3); menu.MenuItems.Add(item4); menu.MenuItems.Add(item5); menu.MenuItems.Add("发送文件", (s, arg) => { var files = System.IO.Directory.GetFiles("."); if (files != null && files.Any()) { NIM.Nos.NosAPI.Upload(files[0], (ret, url) => { if (ret == 200) { NIM.NIMMessageAttachment attach = new NIM.NIMMessageAttachment(); attach.RemoteUrl = url; attach.DisplayName = System.IO.Path.GetFileName(files[0]); attach.FileExtension = System.IO.Path.GetExtension(files[0]); NIMChatRoom.Message msg = new NIMChatRoom.Message(); msg.MessageType = NIMChatRoomMsgType.kNIMChatRoomMsgTypeFile; msg.RoomId = roomId; msg.MessageAttachment = attach.Serialize(); NIMChatRoom.ChatRoomApi.SendMessage(roomId, msg); } }, null); } }); } menu.MenuItems.Add(item1); menu.Show(treeView1, e.Location); }