void OnEnable()
    {
        uploader = GetComponent<UploadAndDownload>();

        if (uploader == null)
            Debug.LogWarning("Downloader not initialised!");
        else
        {
            UploadAndDownload.onUploadComplete += OnUploadComplete;
            UploadAndDownload.onError += OnError;
            UploadAndDownload.onUploadProgress += OnUploadProgress;
        }
    }
Exemplo n.º 2
0
        private void check_User()
        {
            if (this.tb_userName.Text.Length > 0)
            {
                Exception exception;
                try
                {
                    StudentServiceModel model = new StudentServiceModel();//new StudentService().getStudent(this.tb_userName.Text, "~!{#$@cdf3}");
                    if (false && model.version != 4)
                    {
                        MessageBox.Show("版本太低,请从新下载最新的版本");
                        //Application.Exit();
                    }
                    else if (true || model != null)
                    {
                        if (false && model.starttime.ToString() == "0001/1/1 0:00:00")
                        {
                            MessageBox.Show("没有该堂考试信息。。。");
                            //Application.Exit();
                        }
                        else
                        {
                            TimeSpan span  = (TimeSpan)(model.currenttime - model.starttime);
                            TimeSpan span2 = (TimeSpan)(model.endtime - model.currenttime);
                            if (false && span2.Minutes < 0)
                            {
                                MessageBox.Show("考试时间已过请联系管理员。。。");
                                //Application.Exit();
                            }
                            else if (false && span.Minutes < 0)
                            {
                                MessageBox.Show("未到考试时间。。。");
                                //Application.Exit();
                            }
                            else
                            {
                                //StudentModel.isReGeneration = model.isregeneration;
                                //StudentModel.studentNumber = model.studentnumber;
                                //StudentModel.mac = model.mac;
                                //StudentModel.chooseNumber = model.choosenumber;
                                //StudentModel.gapfillingNumber = model.gapfillingnumber;
                                //StudentModel.calculationNumber = model.calculationnumber;
                                //StudentModel.endTime = model.endtime;
                                //StudentModel.examCode = model.examcode;
                                //StudentModel.grade = model.grade;
                                //StudentModel.startTime = model.starttime;
                                //StudentModel.status = model.status;
                                //StudentModel.studentName = model.studentname;
                                //StudentModel.studentClass = model.studentclass;

                                StudentModel.isReGeneration    = true;
                                StudentModel.studentNumber     = "02166407";
                                StudentModel.mac               = "FF:FF:FF:FF:FF:FF";
                                StudentModel.chooseNumber      = generateChoice();     //"ChapterOne_25,3,2,1,4,|ChapterTwo_9,1,4,2,3,|ChapterThree_3,3,1,4,2,|ChapterFour_11,4,2,1,3,|ChapterFive_3,4,1,2,3,|";
                                StudentModel.gapfillingNumber  = generateGapFilling(); //"g_four_1.xml|g_one_2.xml|g_five_1.xml|g_six_1.xml|g_two_2_6.xml|";
                                StudentModel.calculationNumber = generateCal();        //"c8.xml|c1.xml|c3.xml|c10.xml|";
                                StudentModel.endTime           = DateTime.Now.AddDays(1);
                                StudentModel.examCode          = 2;
                                StudentModel.grade             = 0;
                                StudentModel.startTime         = DateTime.Now.AddDays(-1);
                                StudentModel.status            = 0;
                                StudentModel.studentName       = "AMFairy";
                                StudentModel.studentClass      = "NEU Mathe";

                                if (true || (StudentModel.mac.Length == 0) || ((StudentModel.mac == new GetMacAddress().getmac()) && (StudentModel.status == 1)))
                                {
                                    string str2;
                                    string str3;
                                    string str = "temp";
                                    SupportTools.DirectoryIsExist("temp");
                                    SupportTools.DirectoryIsExist("temp/generate");
                                    SupportTools.DirectoryIsExist("temp/UA");
                                    if (!StudentModel.isReGeneration)
                                    {
                                        str2 = StudentModel.examCode + "/" + StudentModel.studentNumber;
                                        str3 = "Parameter.zip";
                                        try
                                        {
                                            UploadAndDownload.DownloadFile(str2, str3);
                                            Zip.Extract("./" + str + "/" + str3, "./", 0x400);
                                            UploadAndDownload.DownloadFile(str2, "Answer.zip");
                                            Zip.Extract("./" + str + "/Answer.zip", "./", 0x400);
                                        }
                                        catch (Exception)
                                        {
                                            try
                                            {
                                                UploadAndDownload.DownloadFile(str2, str3);
                                                Zip.Extract("./" + str + "/" + str3, "./", 0x400);
                                                UploadAndDownload.DownloadFile(str2, "AnswerCopy.zip");
                                                Zip.Extract("./" + str + "/AnswerCopy.zip", "./", 0x400);
                                            }
                                            catch (Exception exception2)
                                            {
                                                exception = exception2;
                                                MessageBox.Show("试卷还原的参数下载失败");
                                            }
                                        }
                                    }
                                    List <string> list  = new List <string>();
                                    List <string> list2 = new List <string>();
                                    foreach (string str4 in StudentModel.chooseNumber.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                                    {
                                        string[] strArray2 = str4.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                        list.Add(strArray2[0]);
                                        string[] strArray3 = strArray2[0].Split(new char[] { '_' });
                                        list2.Add(strArray3[0]);
                                    }
                                    try
                                    {
                                        MessageBox.Show("即将开始考试,请耐心等待试卷生成");
                                        for (int j = 0; j < list.Count; j++)
                                        {
                                            str2 = list2[j];
                                            str3 = list[j] + ".zip";

                                            UploadAndDownload2.DownloadFile(str2, str3);
                                        }
                                    }
                                    catch (Exception exception3)
                                    {
                                        exception = exception3;
                                        MessageBox.Show("从服务器上下载文件失败\r\n" + exception.Message);
                                    }
                                    for (int i = 0; i < list.Count; i++)
                                    {
                                        str2 = list2[i];
                                        Zip.Extract("./temp/" + (list[i] + ".zip"), "./temp", 0x400);
                                    }
                                    new Origination().Show();
                                    base.Hide();
                                }
                                else
                                {
                                    MessageBox.Show("在另外一台机器上登陆了。。。");
                                    //Application.Exit();
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("输入的学号不存在或不在考试时间范围内");
                        //Application.Exit();
                    }
                }
                catch (Exception exception4)
                {
                    exception = exception4;
                    if (exception.Message.Contains("System.Number.ParseInt32"))
                    {
                        MessageBox.Show("未安排你的考试");
                    }
                    else
                    {
                        MessageBox.Show("连接服务器错误。。。" + exception.Message);
                    }
                    //Application.Exit();
                }
            }
            else
            {
                MessageBox.Show("请输入学号");
            }
        }
Exemplo n.º 3
0
        public ActionResult SaveTicket(Models.Ticket.ViewModelTicket ticket, string description, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                ticket.TicketId        = Convert.ToInt32(UnitOfTicket.Next());
                ticket.OpenDateAndTime = DateTime.Now.ToLocalTime();
                ticket.UserId          = User.Identity.GetUserName();
                var user = (System.Security.Claims.ClaimsIdentity)User.Identity;
                ticket.CompanyId = Convert.ToInt32(user.FindFirstValue("CompanyId"));
                ticket.StatusId  = 1;


                var ret = Repository._priorityTime.Where(x => x.PriorityId == ticket.PriorityId)
                          .Select(x => x.SlaTime).FirstOrDefault();


                ticket.SlaExpiration = CalculateSla.AddWithinWorkingHours(ticket.OpenDateAndTime,
                                                                          TimeSpan.FromHours(ret), 9, 8);


                this.UnitOfTicket.Save(ticket);

                // Chech if exists files
                var path = string.Empty;
                if (file != null)
                {
                    path = UploadAndDownload.Upload(file, ticket.TicketId);
                }


                var actions = new Models.Ticket.Action
                {
                    TicketId          = ticket.TicketId,
                    ActionDescription = description,
                    StatusId          = ticket.StatusId,
                    Date       = DateTime.Now.ToLocalTime(),
                    AlteredBy  = User.Identity.Name,
                    SendToUser = true,
                    SlaRest    = TimeSpan.FromHours(
                        Repository._priorityTime
                        .Where(x => x.PriorityId == ticket.PriorityId)
                        .Select(x => x.SlaTime).FirstOrDefault()),
                    Files       = path,
                    IterationId = 1
                };

                this.UnitOfTicketAction.Save(actions);

                //return RedirectToAction(nameof(NewTicket));
                if (User.IsInRole("User") || User.IsInRole("SuperUser"))
                {
                    return(RedirectToAction(nameof(MyTickets)));
                }
                else
                {
                    return(RedirectToAction(nameof(TicketList)));
                }
            }
            else
            {
                return(View(nameof(NewTicket), ticket));
            }
        }
Exemplo n.º 4
0
        public JsonResult DownloadFile(string path)
        {
            UploadAndDownload.Download(path);

            return(Json(JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        public JsonResult SaveTicketAjaxUpdate(ViewModelTicket ticket, string description, bool SendToUser, HttpPostedFileBase file)
        {
            var diff       = TimeSpan.Zero;
            var diffTime   = 0.0;
            var lastStatus = UnitOfTicketAction.Where(x => x.TicketId == ticket.TicketId)
                             .OrderByDescending(x => x.IterationId)
                             .Select(x => x.StatusId).FirstOrDefault();


            if (ticket.StatusId == 6 || ticket.StatusId == 7 &&
                lastStatus != 6 && lastStatus != 7)
            {
                ticket.ClosedDateTime = DateTime.Now.ToLocalTime();
            }

            else if (ticket.StatusId == 3 || ticket.StatusId == 4 || ticket.StatusId == 5 &&
                     lastStatus != 3 && lastStatus != 4 && lastStatus != 5)
            {
                var sla       = new CalculateSla();
                var TotalTime = sla.SlaRestTime(ticket.TicketId);

                var time = CalculateSla.SubtractWithinWorkingHours(DateTime.Now.ToLocalTime(), (int)TotalTime);

                ticket.SlaExpiration = CalculateSla.AddWithinWorkingHours(DateTime.Now.ToLocalTime(), TimeSpan.FromHours(time), 9, 8);


                /*
                 * var dateTicket = UnitOfTicket.Where(x => x.TicketId == ticket.TicketId)
                 * .Select(x => x.SlaExpiration).FirstOrDefault();
                 *  diffTime = dateTicket.Subtract(DateTime.Now.ToLocalTime()).TotalHours;
                 * CalculateSla.SubtractWithinWorkingHours(DateTime.Now.ToLocalTime(), (int)diffTime);
                 */
            }

            else if (ticket.StatusId == 2 && lastStatus == 3 ||
                     lastStatus == 4 || lastStatus == 5)
            {
                var slaRest = UnitOfTicketAction.Where(x => x.TicketId == ticket.TicketId).OrderByDescending(x => x.IterationId).Select(x => x.SlaRest).FirstOrDefault();
                //diff = slaRest;
                diffTime = slaRest.TotalHours;
                ticket.ClosedDateTime = DateTime.Now.ToLocalTime().Add(slaRest);
            }

            var path = string.Empty;

            if (file != null)
            {
                path = UploadAndDownload.Upload(file, ticket.TicketId);
            }



            //If Ticket exist then Update Ticket
            this.UnitOfTicket.Update(ticket, ticket.TicketId);

            var actions = new Models.Ticket.Action
            {
                TicketId          = ticket.TicketId,
                ActionDescription = description,
                StatusId          = ticket.StatusId,
                Date       = DateTime.Now.ToLocalTime(),
                PriorityId = ticket.PriorityId,
                AlteredBy  = User.Identity.Name,
                SendToUser = SendToUser,
                //SlaRest = TimeSpan.FromHours(diffTime),
                IterationId = UnitOfTicketAction.Where(x => x.TicketId == ticket.TicketId).Max(x => x.IterationId) + 1
            };


            if (!string.IsNullOrEmpty(description))
            {
                UnitOfTicketAction.Save(actions);
            }


            return(Json(new { actions, ticket }, JsonRequestBehavior.AllowGet));
        }
	void OnDownloadComplete(UploadAndDownload.Data data)
	{
		Debug.Log("Download Competed, Donwloaded bytes : "+data.bytes.Length);
		
	}