Ejemplo n.º 1
0
        /// <summary>
        /// 分发资源数据。
        /// </summary>
        /// <param name="sc"></param>
        /// <param name="urls"></param>
        protected void IssueResourceData(StudentControl sc, string[] urls)
        {
            try
            {
                UserInfo info = this.UserInfo;
                if (info != null && this.NetService != null &&
                    sc != null && ((sc.State & StudentControl.EnumStudentState.Online) == StudentControl.EnumStudentState.Online) &&
                    urls != null && urls.Length > 0)
                {
                    IssueWorkFile data = new IssueWorkFile();
                    data.UID = info.UserID;
                    data.StudentID = sc.UserInfo.UserID;
                    data.WorkName = System.IO.Path.GetFileName(urls[0]);
                    data.Data = ZipUtils.Zip(urls);

                    this.OnMessageEvent(MessageType.Normal, string.Format("给[{0},{1}]下发资源:{2}", sc.UserInfo.UserName, sc.UserInfo.UserCode, data.WorkName));
                    this.NetService.SendIssueWork(data);
                }
            }
            catch (Exception x)
            {
                this.OnMessageEvent(MessageType.PopupWarn, string.Format("分发资源时发生异常:{0}", x.Message));
                Program.GlobalExceptionHandler(x);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="store"></param>
 /// <param name="ls"></param>
 /// <param name="handler"></param>
 private void IssueWorkData(LocalStudentWorkStore store,LocalStudent ls, RaiseChangedHandler handler)
 {
     lock (this)
     {
         if (store != null && ls != null && ls.HasWork())
         {
             LocalStudentWork lsw = ls.Work;
             int len = 0;
             if (lsw.WorkFiles != null && (len = lsw.WorkFiles.Count) > 0)
             {
                 this.RaiseChanged(handler, string.Format("下发[{0},{1}]作品数据{2}", ls.StudentName, ls.StudentCode, lsw.WorkName));
                 string[] filePaths = new string[len];
                 for (int i = 0; i < len; i++)
                 {
                     filePaths[i] = lsw.StudentWorkFilePath(store, ls, lsw.WorkFiles[i]);
                 }
                 byte[] data = ZipUtils.Zip(filePaths);
                 if (data != null && data.Length > 0)
                 {
                     IssueWorkFile issue = new IssueWorkFile();
                     issue.StudentID = ls.StudentID;
                     issue.WorkName = lsw.WorkName;
                     issue.UID = store.TeacherID;
                     issue.Time = DateTime.Now;
                     issue.Data = data;
                     this.netService.SendIssueWork(issue);
                 }
                 else
                 {
                     this.RaiseChanged(handler, string.Format("压缩数据文件失败![{0},{1}]", ls.StudentName, lsw.WorkName));
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 分发作品文件。
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public void SendIssueWork(IssueWorkFile data)
        {
            lock (this)
            {
                if (data != null && Program.STUDENTS != null)
                {
                    StudentEx stuEx = Program.STUDENTS[data.StudentID];
                    if (stuEx != null && !string.IsNullOrEmpty(stuEx.IP))
                    {
                        data.UID = this.info.UserID;
                        data.Time = DateTime.Now;
                        IPEndPoint host = new IPEndPoint(IPAddress.Parse(stuEx.IP), this.ports.FileDownTransfer);

                        ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object sender)
                        {
                            using (FileDownTcpClient client = new FileDownTcpClient((IPEndPoint)sender))
                            {
                                client.Changed += this.OnRaiseChanged;
                                client.Upload(data);
                            }
                        }), host);
                    }
                }
            }
        }