예제 #1
0
        private void WatchCreated(object sender, FileSystemEventArgs e)
        {
            Thread.Sleep(3000);
            FileInfo   fi = new FileInfo(e.FullPath);
            FileResult fr = rf.UploadFile(fi.FullName, CacheService.Instance.GetStuToken());

            if (fr != null)
            {
                if (fr.code == "200")
                {
                    //关联文件与记录
                    List <Attach> attaches = new List <Attach>();
                    foreach (Student s in CacheService.Instance.GetStudentList())
                    {
                        Attach a = new Attach {
                            subjectId = s.RecordId, ownerId = s.Id, type = type
                        };
                        attaches.Add(a);
                    }

                    AttachResult ar = rf.AttachRecordWithFile(CacheService.Instance.ExperimentId, fr.data.id, attaches, CacheService.Instance.GetStuToken());

                    if (ar != null)
                    {
                        if (ar.code == "200")
                        {
                            UploadFile up = new UploadFile()
                            {
                                FileName = fi.Name, FileType = fileType, Status = UploadFile.SUCCESS, FilePath = fi.FullName, Id = fr.data.id, Color = "#FF979797", Operation = UploadFile.OPENDOC
                            };
                            this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                        }
                        else
                        {
                            UploadFile up = new UploadFile()
                            {
                                FileName = fi.Name, FileType = fileType, Status = UploadFile.FAIL, FilePath = fi.FullName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD
                            };
                            this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                        }
                    }
                    else
                    {
                        UploadFile up = new UploadFile()
                        {
                            FileName = fi.Name, FileType = fileType, Status = UploadFile.FAIL, FilePath = fi.FullName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD
                        };
                        this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                    }
                }
                else
                {
                    UploadFile up = new UploadFile()
                    {
                        FileName = fi.Name, FileType = fileType, Status = UploadFile.FAIL, FilePath = fi.FullName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD
                    };
                    this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                }
            }
            else
            {
                UploadFile up = new UploadFile()
                {
                    FileName = fi.Name, FileType = fileType, Status = UploadFile.FAIL, FilePath = fi.FullName, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD
                };
                this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
            }
        }
        private void OpenLabel_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Label label = sender as Label;

            UploadFile uploadFile = null;

            foreach (UploadFile uf in this.upfiles)
            {
                if (uf.FilePath.Equals(label.Tag.ToString()))
                {
                    uploadFile = uf;
                }
            }
            if (uploadFile != null)
            {
                if (label.Content.Equals(UploadFile.OPENDOC))
                {
                    String doc = uploadFile.FilePath.Substring(0, uploadFile.FilePath.Length - uploadFile.FilePath.Split('\\')[uploadFile.FilePath.Split('\\').Length - 1].Length);
                    System.Diagnostics.Process.Start("explorer.exe ", doc);
                }
                else if (label.Content.Equals(UploadFile.REUPLOAD))
                {
                    String token = CacheService.Instance.GetStuToken();

                    FileResult fr = rf.UploadFile(uploadFile.FilePath, token);

                    //获取文件名字
                    String file_name = uploadFile.FilePath.Split('\\')[uploadFile.FilePath.Split('\\').Length - 1];

                    if (fr != null)
                    {
                        if (fr.code == "200")
                        {
                            //关联文件与记录
                            List <Attach> attaches = new List <Attach>();
                            foreach (Student s in CacheService.Instance.GetStudentList())
                            {
                                Attach a = new Attach {
                                    subjectId = s.RecordId, ownerId = s.Id, type = "EXPERIMENT_RECORD_FILE"
                                };
                                attaches.Add(a);
                            }

                            AttachResult ar = rf.AttachRecordWithFile(CacheService.Instance.ExperimentId, fr.data.id, attaches, CacheService.Instance.GetStuToken());

                            if (ar != null)
                            {
                                if (ar.code == "200")
                                {
                                    uploadFile.Status    = UploadFile.SUCCESS;
                                    uploadFile.Color     = "#FF979797";
                                    uploadFile.Operation = UploadFile.OPENDOC;
                                    fileList.Items.Refresh();
                                }
                                else
                                {
                                    LSMessageBox.Show("关联文件错误", ar.message);
                                    uploadFile.Status    = UploadFile.FAIL;
                                    uploadFile.Color     = "Red";
                                    uploadFile.Operation = UploadFile.REUPLOAD;
                                    fileList.Items.Refresh();
                                }
                            }
                            else
                            {
                                LSMessageBox.Show("网络错误", "网络异常");
                                uploadFile.Status    = UploadFile.FAIL;
                                uploadFile.Color     = "Red";
                                uploadFile.Operation = UploadFile.REUPLOAD;
                                fileList.Items.Refresh();
                            }
                        }
                        else
                        {
                            LSMessageBox.Show("上传文件错误", fr.message);
                            uploadFile.Status    = UploadFile.FAIL;
                            uploadFile.Color     = "Red";
                            uploadFile.Operation = UploadFile.REUPLOAD;
                            fileList.Items.Refresh();
                        }
                    }
                    else
                    {
                        LSMessageBox.Show("网络错误", "网络异常");
                        uploadFile.Status    = UploadFile.FAIL;
                        uploadFile.Color     = "Red";
                        uploadFile.Operation = UploadFile.REUPLOAD;
                        fileList.Items.Refresh();
                    }
                }
            }
        }
예제 #3
0
        private void videoSourcePlayer_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();

            if (task.Contains(0))
            {
                String timepath = DateTime.Now.Hour.ToString() + "_" + DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString() + "_" + device_id;
                string img      = this.save_path + "\\" + timepath + ".jpg";
                bitmap.Save(img);
                task.Remove(0);

                FileResult fr = rf.UploadFile(img, CacheService.Instance.GetStuToken());
                if (fr != null)
                {
                    if (fr.code == "200")
                    {
                        //关联文件与记录
                        List <Attach> attaches = new List <Attach>();
                        foreach (Student s in CacheService.Instance.GetStudentList())
                        {
                            Attach a = new Attach {
                                subjectId = s.RecordId, ownerId = s.Id, type = "EXPERIMENT_RECORD_IMAGE"
                            };
                            attaches.Add(a);
                        }

                        AttachResult ar = rf.AttachRecordWithFile(CacheService.Instance.ExperimentId, fr.data.id, attaches, CacheService.Instance.GetStuToken());

                        if (ar != null)
                        {
                            if (ar.code == "200")
                            {
                                UploadFile up = new UploadFile()
                                {
                                    FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.SUCCESS, FilePath = img, Id = fr.data.id, Color = "#FF979797", Operation = UploadFile.OPENDOC
                                };
                                this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                            }
                            else
                            {
                                UploadFile up = new UploadFile()
                                {
                                    FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.FAIL, FilePath = img, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD
                                };
                                this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                            }
                        }
                        else
                        {
                            UploadFile up = new UploadFile()
                            {
                                FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.FAIL, FilePath = img, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD
                            };
                            this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                        }
                    }
                    else
                    {
                        UploadFile up = new UploadFile()
                        {
                            FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.FAIL, FilePath = img, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD
                        };
                        this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                    }
                }
                else
                {
                    UploadFile up = new UploadFile()
                    {
                        FileName = timepath + ".jpg", FileType = fileType, Status = UploadFile.FAIL, FilePath = img, Id = -1, Color = "Red", Operation = UploadFile.REUPLOAD
                    };
                    this.cb.Dispatcher.BeginInvoke(updateListBoxAction, this.cb, up);
                }
            }
            GC.Collect();
        }