Example #1
0
 /// <summary>
 /// 右键菜单处理。
 /// </summary>
 /// <param name="sc"></param>
 /// <param name="type"></param>
 protected void SCContextMenu(StudentControl sc, StudentControl.EnumContextMenuType type)
 {
     try
     {
         UserInfo info = this.UserInfo;
         if (sc == null || sc.UserInfo == null || info == null)
         {
             return;
         }
         StudentEx stu = Program.STUDENTS[sc.UserInfo.UserID];
         if (stu == null)
         {
             return;
         }
         switch (type)
         {
             case StudentControl.EnumContextMenuType.Offline:
                 {
                     #region 强制学生离线。
                     if (this.NetService != null)
                     {
                         HostCloseBroadcast data = new HostCloseBroadcast();
                         data.HostID = data.UID = info.UserID;
                         if (this.NetService.SendBroadcastPortMSG(data, sc.UserIP))
                         {
                             if ((stu.Status & StudentControl.EnumStudentState.Online) == StudentControl.EnumStudentState.Online)
                             {
                                 stu.Status &= ~StudentControl.EnumStudentState.Online;
                             }
                             stu.Status |= StudentControl.EnumStudentState.Offline;
                             this.UpdateStudentControl(stu);
                         }
                     }
                     #endregion
                 }
                 break;
             case StudentControl.EnumContextMenuType.TemplateDelete:
                 {
                     #region 删除学生。
                     if (!string.IsNullOrEmpty(this.ClassID) && !string.IsNullOrEmpty(this.CatalogID))
                     {
                         LocalStudentWorkStore store = LocalStudentWorkStore.DeSerializer(info.UserID, this.CatalogID, this.ClassID);
                         if (store != null && store.Students != null)
                         {
                             LocalStudent ls = store.Students[sc.UserInfo.UserID];
                             if (ls != null && store.Students.Remove(ls))
                             {
                                 WorkStoreHelper.DeleteStudentToQueueStore(new WorkStoreHelper.DeleteStudentQueueEntity(ls.StudentID, store.FileSavePath()));
                                 StudentEx stuEx = Program.STUDENTS[ls.StudentID];
                                 if (Program.STUDENTS.Remove(stuEx))
                                 {
                                     this.menuItemRefresh_Click(null, null);
                                 }
                             }
                         }
                     }
                     #endregion
                 }
                 break;
         }
     }
     catch (Exception x)
     {
         this.OnMessageEvent(MessageType.PopupWarn, string.Format("右键菜单处理:{0}", x.Message));
         Program.GlobalExceptionHandler(x);
     }
 }
        private void sendHostCloseBroadcast(IPEndPoint broadcastAddr)
        {
            try
            {
                if (broadcastAddr == null) return;
                using (UdpClient udpClient = new UdpClient())
                {
                    HostCloseBroadcast hostClose = new HostCloseBroadcast();
                    hostClose.UID = hostClose.HostID = this.info.UserID;

                    byte[] buf = this.Serialize(hostClose);
                    if (buf != null && buf.Length > 0)
                    {
                        this.RaiseChanged("发送主机关闭广播...");
                        udpClient.Send(buf, buf.Length, broadcastAddr);
                    }
                }
                this.RaiseChanged("广播发送已停止!");
            }
            catch (Exception ex)
            {
                this.OnExceptionRecord(ex, this.GetType());
                this.RaiseChanged("发送主机关闭广播异常:" + ex.Message);
            }
        }