Esempio n. 1
0
        public void Download(S_FileInfo fileInfo, string SpaceID, string ArchiveType, bool CheckCar = false)
        {
            var user     = FormulaHelper.GetUserInfo();
            var entities = FormulaHelper.GetEntities <DocConstEntities>();

            if (fileInfo.Space == null)
            {
                throw new Formula.Exceptions.BusinessException("没有获取到申请文件的配置空间信息,无法进行申请下载");
            }
            if (fileInfo.ConfigInfo == null)
            {
                throw new Formula.Exceptions.BusinessException("没有获取到申请文件的文件配置类别信息,无法进行申请下载");
            }
            var carItem = entities.Set <S_CarInfo>().FirstOrDefault(d => d.FileID == fileInfo.ID &&
                                                                    d.State != "Finish" && d.UserID == user.UserID && d.Type == "DownLoad");

            if (carItem == null)
            {
                carItem              = new S_CarInfo();
                carItem.ID           = FormulaHelper.CreateGuid();
                carItem.NodeID       = fileInfo.NodeID;
                carItem.Type         = ItemType.DownLoad.ToString();
                carItem.UserID       = user.UserID;
                carItem.UserName     = user.UserName;
                carItem.CreateDate   = DateTime.Now;
                carItem.FileID       = fileInfo.ID;
                carItem.SpaceID      = SpaceID;
                carItem.ConfigID     = fileInfo.ConfigInfo.ID;
                carItem.Name         = fileInfo.CreateCarName();//fileInfo.Name;
                carItem.Code         = fileInfo.DataEntity.GetValue("Code");
                carItem.State        = ItemState.New.ToString();
                carItem.DataType     = fileInfo.ConfigInfo.Name;
                carItem.CreateUser   = user.UserName;
                carItem.CreateUserID = user.UserID;
                var attchments = new List <string>();
                ArchiveType = "MainFile,Attachments," + ArchiveType;
                foreach (var item in ArchiveType.Split(','))
                {
                    if (!string.IsNullOrEmpty(fileInfo.CurrentAttachment.DataEntity.GetValue(item)))
                    {
                        attchments.Add(fileInfo.CurrentAttachment.DataEntity.GetValue(item));
                    }
                }
                carItem.Attachments = string.Join(",", attchments);
                entities.Set <S_CarInfo>().Add(carItem);
            }
            else if (CheckCar)
            {
                throw new Formula.Exceptions.BusinessException("该文件已在下载车中,请前往下载车申请下载");
            }
        }