Пример #1
0
        public IHttpActionResult GetVideo(HttpRequestMessage request)
        {
            string deviceCode = string.Empty;

            ////检查授权
            if (request.Headers.Authorization == null || TokenHelper.CheckAuth(request.Headers.Authorization.Parameter, out deviceCode) == false)
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.Unauthorized, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.Unauthorized, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.Unauthorized)
                }));
            }
            //检查超时
            if (!TokenHelper.IsTokenOnline(deviceCode, DateTime.Now))
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.InternalServerError, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.OverTime, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.OverTime)
                }));
            }
            softwareupdate sf = null;

            using (BemEntities db = new BemEntities())
            {
                if (db.softwareupdate.Where(m => m.type == 1).Count() > 0)
                {
                    sf = db.softwareupdate.Where(m => m.type == 1).OrderByDescending(m => m.uploadTime).First();
                }
            }
            if (sf == null)
            {
                return(Content <ApiErrorInfo>(HttpStatusCode.NotFound, new ApiErrorInfo()
                {
                    errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound)
                }));
            }
            else
            {
                string filePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content");
                string packPath = filePath + "\\video\\" + sf.version;

                if (!System.IO.File.Exists(packPath))
                {
                    return(Content <ApiErrorInfo>(HttpStatusCode.NotFound, new ApiErrorInfo()
                    {
                        errcode = (int)ErrorCode.ObjectNotFound, errmsg = ErrorCodeTransfer.GetErrorString(ErrorCode.ObjectNotFound)
                    }));
                }
                string  path = string.Format(@"{0}/{1}", FtpHelper.VideoFtpURL, sf.version);
                FtpPath vf   = new FtpPath();
                vf.FtpURL = path;
                return(Ok(vf));
            }
        }
Пример #2
0
        // GET: SoftwareUpdate
        public ActionResult Index()
        {
            string name, error;

            if (CookieHelper.HasCookie(out name, out error) == false)
            {
                return(RedirectToAction("", "LoginUI"));
            }
            else
            {
                new RoleHelper().GetRoles(name, out role, out department1Code, out loginName);
                ViewData["VisitorRole"] = role;
                ViewData["username"]    = loginName;
            }

            UpdatesPackage package    = new UpdatesPackage();
            softwareupdate updateInfo = null;

            try
            {
                package.devices = new List <clientdevice>();
                using (BemEntities db = new BemEntities())
                {
                    if (db.softwareupdate.Where(m => m.type == 0).OrderByDescending(m => m.uploadTime).Count() > 0)
                    {
                        updateInfo = db.softwareupdate.Where(m => m.type == 0).OrderByDescending(m => m.uploadTime).First();
                    }
                    package.updateInfo = updateInfo;
                    var devlist = db.clientdevice;
                    foreach (var dev in devlist)
                    {
                        package.devices.Add(dev);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取软件升级信息出错", ex);
            }
            return(View(package));
        }
Пример #3
0
        public async Task <ActionResult> Upload(HttpPostedFileBase file)
        {
            try
            {
                if (file == null)
                {
                    return(Content("上传为空,请重新选择", "text/html"));
                }
                string path      = file.FileName;
                string content   = string.Empty;
                string extension = Path.GetExtension(path);
                if (extension.ToLower() != ".mp4")
                {
                    return(Content("上传文件格式错误,当前只支持mp4文件", "text/html"));
                }

                string fileName   = Path.GetFileName(path);
                string savePath   = Server.MapPath("~/Content");
                string folderPath = savePath + "\\video";
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }
                List <string> prePackagePath = new List <string>();
                if (new DirectoryInfo(folderPath).GetFiles().Where(m => Path.GetExtension(m.FullName).ToLower() == ".mp4").Count() > 0)
                {
                    List <FileInfo> files = new DirectoryInfo(folderPath).GetFiles().Where(m => Path.GetExtension(m.FullName).ToLower() == ".mp4").ToList();
                    foreach (var item in files)
                    {
                        prePackagePath.Add(item.FullName);   //把其他的文件保存,以便新文件进来后,把老文件删除
                    }
                }
                string newFileName = Path.GetFileNameWithoutExtension(file.FileName);
                if (prePackagePath.Where(m => Path.GetFileName(m) == fileName).Count() > 0)
                {
                    newFileName = newFileName + "(1)";
                }
                await Task.Run(delegate()
                {
                    using (FileStream fileToSave = new FileStream(folderPath + "\\" + newFileName + ".mp4", FileMode.Create, FileAccess.Write))
                    {
                        byte[] bytes = new byte[file.InputStream.Length];
                        file.InputStream.Read(bytes, 0, (int)file.InputStream.Length);
                        fileToSave.Write(bytes, 0, bytes.Length);
                        fileToSave.Flush();
                    }
                    foreach (var item in prePackagePath)
                    {
                        try
                        {
                            System.IO.File.Delete(item);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error("视频文件删除失败", ex);
                        }
                    }
                    softwareupdate updatesOne = new softwareupdate();
                    updatesOne.version        = newFileName + ".mp4";
                    updatesOne.uploadTime     = DateTime.Now;
                    updatesOne.type           = 1;
                    using (BemEntities db = new BemEntities())
                    {
                        db.softwareupdate.Add(updatesOne);
                        db.SaveChanges();
                    }
                });

                return(Content("OK", "text/html"));
            }
            catch (Exception ex)
            {
                //日志记录
                LogHelper.Error("上传视频文件失败", ex);
                return(Content("上传视频文件失败,请检查", "text/html"));
            }
        }