public JsonResult upload()
        {
            if (this.Request.Files.Count == 0)
            {
                return(Json(new { code = 1, msg = "no files" }));
            }

            string name     = this.Request.Form[0];
            int    block    = 0;
            int    blockNum = 0;

            int.TryParse(this.Request.Form[1], out block);
            int.TryParse(this.Request.Form[2], out blockNum);

            for (int i = 0; i < this.Request.Files.Count; i++)
            {
                HttpPostedFileBase file = this.Request.Files[i];
                var localPath           = Server.MapPath("/TempFile/" + this.Request.Form[0]);

                var fs = System.IO.File.Open(localPath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
                fs.Position = fs.Length;
                Int64  size   = fs.Length;
                byte[] buffer = new byte[1024 * 1024];

                while (true)
                {
                    var reads = file.InputStream.Read(buffer, 0, buffer.Length);
                    size += reads;

                    if (reads == 0)
                    {
                        break;
                    }

                    fs.Write(buffer, 0, reads);
                }

                fs.Close();

                if (block == (blockNum - 1))
                {
                    using (MDB mdb = new MDB())
                    {
                        DbAttachment dbAttr = new DbAttachment();
                        dbAttr.Name       = name;
                        dbAttr.Size       = size;
                        dbAttr.Path       = localPath;
                        dbAttr.RemotePath = "/website/" + DateTime.Now.ToString("yyyy_MM_dd") + "/" + DateTime.Now.ToString("HH_mm_ss") + "_" + dbAttr.Name;
                        dbAttr.CreateTime = DateTime.Now;
                        dbAttr.State      = 0;
                        mdb.Insert <DbAttachment>(dbAttr);
                    }
                }
            }

            YHFSUploader.Upload();

            return(Json(new { code = 0, msg = "" }));
        }
Exemplo n.º 2
0
 public ActionResult create(FormCollection form)
 {
     using (MDB db = new MDB())
     {
         Models.DbPipeline line = new Models.DbPipeline();
         line.Name = form["Name"];
         line.PipeIds.AddRange(form["Pipes"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
         line.ServantIds.AddRange(form["Servants"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
         line.IsParallel = form["IsParallel"] != "false";
         db.Insert(line);
         return(RedirectToAction("index"));
     }
 }
Exemplo n.º 3
0
        public ActionResult create(FormCollection form)
        {
            DbTask task = new DbTask();

            task.Name       = form["Name"];
            task.CreateTime = DateTime.Now;
            task.Inputs.AddRange(form["Inputs"].Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries));
            task.Pipelines.AddRange(form["Pipelines"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            task.Servants.AddRange(form["Servants"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            task.State = 0;

            using (MDB db = new MDB())
            {
                db.Insert <DbTask>(task);
            }

            return(RedirectToAction("index"));
        }
Exemplo n.º 4
0
        public void log(MaratonLog json)
        {
            if (json.errorMask != 0)
            {
                return;
            }

            using (MDB mdb = new MDB())
            {
                DbLog log = mdb.Find <DbLog>(x =>
                                             x.TaskID == json.taskID &&
                                             x.SubtaskID == json.subtaskID &&
                                             x.ServantID == json.servantID).FirstOrDefault();

                bool isNew = false;
                if (log == null)
                {
                    isNew = true;
                    log   = new DbLog();
                }

                log.ErrorMask = json.errorMask;

                Base64Decoder b64d            = new Base64Decoder();
                byte[]        encodingContent = b64d.GetDecoded(json.content);
                log.Content   = System.Text.ASCIIEncoding.Default.GetString(encodingContent);
                log.TaskID    = json.taskID;
                log.SubtaskID = json.subtaskID;
                log.ServantID = json.servantID;

                if (isNew)
                {
                    mdb.Insert <DbLog>(log);
                }
                else
                {
                    mdb.UpdateOne <DbLog>(x =>
                                          x.TaskID == json.taskID &&
                                          x.SubtaskID == json.subtaskID &&
                                          x.ServantID == json.servantID, log);
                }
            }
        }
Exemplo n.º 5
0
        public ActionResult create(FormCollection form)
        {
            int createNum = 1;

            int.TryParse(form["CreateNum"], out createNum);
            MaratonAPI api = new MaratonAPI();
            var        ls  = api.ServantList();

            if (ls == null)
            {
                ls = new List <Message.MessageServantStateReply>();
            }

            for (int i = 0; i < createNum; i++)
            {
                DbTask task = new DbTask();
                task.Name       = form["Name"] + "_" + (i + 1).ToString();
                task.CreateTime = DateTime.Now;
                task.Inputs.AddRange(form["Inputs"].Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries));
                task.Pipelines.AddRange(form["Pipelines"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));

                foreach (var item in ls)
                {
                    task.Servants.Add(item.id);
                }

                task.State = 0;

                using (MDB db = new MDB())
                {
                    db.Insert <DbTask>(task);
                }
            }

            return(RedirectToAction("index"));
        }