public override Stream GetMaterialContent(string contentID)
        {
            MaterialContent content = MaterialContentAdapter.Instance.Load(builder => builder.AppendItem("CONTENT_ID", contentID)).SingleOrDefault();
            Stream          result  = null;

            if (content != null)
            {
                if (content.ContentData == null)
                {
                    content.ContentData = new byte[0];
                }

                result = new MemoryStream(content.ContentData);
            }
            else
            {
                //数据库里如果没有附件,则从文件系统获取(基类实现)
                if (this.DestFileInfo != null)
                {
                    result = base.GetMaterialContent(contentID);
                }
                else
                {
                    throw new SystemSupportException(string.Format("不能找到ContentID为'{0}'的附件内容", contentID));
                }
            }

            return(result);
        }
        private void SaveMaterialContentFromFile(MaterialContent content)
        {
            SourceFileInfo.NullCheck("SourceFileInfo");

            if (CheckSourceFileExists)
            {
                ExceptionHelper.FalseThrow(SourceFileInfo.Exists, string.Format(Resources.FileNotFound, SourceFileInfo.Name));
            }

            if (SourceFileInfo.Exists)
            {
                content.FileSize = SourceFileInfo.Length;

                using (TransactionScope scope = TransactionScopeFactory.Create())
                {
                    using (FileStream stream = SourceFileInfo.OpenRead())
                    {
                        MaterialContentAdapter.Instance.Update(content, stream);

                        TransactionScopeFactory.AttachCommittedAction(new Action <TransactionEventArgs>(Current_TransactionCompleted), false);
                    }

                    scope.Complete();
                }
            }
        }
 public override void SaveMaterialContent(MaterialContent content)
 {
     if (content.ContentData == null)
     {
         SaveMaterialContentFromFile(content);
     }
     else
     {
         SaveMaterialContentFromData(content);
     }
 }
Example #4
0
        public MaterialContent GenerateMaterialContent()
        {
            MaterialContent content = new MaterialContent();

            content.ContentID  = this.ID;
            content.FileName   = this.OriginalName;
            content.RelativeID = this.ResourceID;
            content.Class      = this.MaterialClass;
            content.Creator    = this.Creator;

            return(content);
        }
Example #5
0
        public override void SaveMaterialContent(MaterialContent content)
        {
            SourceFileInfo.NullCheck("SourceFileInfo");
            DestFileInfo.NullCheck("DestFileInfo");

            if (CheckSourceFileExists)
            {
                ExceptionHelper.FalseThrow(SourceFileInfo.Exists, string.Format(Resource.FileNotFound, SourceFileInfo.Name));
            }

            MoveFile(SourceFileInfo, DestFileInfo);
        }
        private static MaterialContent PrepareMaterialContent(UploadFileHistory history, Stream fileStream)
        {
            MaterialContent content = new MaterialContent();

            content.ContentID  = GetMaterialContentID(history);
            content.Creator    = history.Operator;
            content.FileName   = history.OriginalFileName;
            content.FileSize   = fileStream.Length;
            content.RelativeID = content.ContentID;
            content.Class      = "UploadFileHistory";

            return(content);
        }
Example #7
0
        /// <summary>
        /// 初始化,或者准备MaterialContent
        /// </summary>
        public void EnsureMaterialContent()
        {
            this._Content = GenerateMaterialContent();

            if (this.IsEmpty() == false)
            {
                EnsureEmptyImage();
            }
            else
            {
                this._Content.ContentData            = null;
                this._Content.PhysicalSourceFilePath = null;
            }
        }
        public void Insert(UploadFileHistory history, Stream fileStream)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(fileStream != null, "fileStream");

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                Insert(history);

                MaterialContent content = PrepareMaterialContent(history, fileStream);

                MaterialContentAdapter.Instance.Update(content, fileStream);

                scope.Complete();
            }
        }
        private void SaveMaterialContentFromData(MaterialContent content)
        {
            content.FileSize = content.ContentData.Length;

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                using (MemoryStream stream = new MemoryStream(content.ContentData))
                {
                    MaterialContentAdapter.Instance.Update(content, stream);

                    TransactionScopeFactory.AttachCommittedAction(new Action <TransactionEventArgs>(Current_TransactionCompleted), false);
                }

                scope.Complete();
            }
        }
Example #10
0
        /// <summary>
        /// 克隆附件的内容
        /// </summary>
        /// <returns></returns>
        public MaterialContent Clone()
        {
            MaterialContent result = new MaterialContent();

            result.ContentID              = this.ContentID;
            result.RelativeID             = this.RelativeID;
            result._Creator               = this._Creator;
            result.Class                  = this.Class;
            result.ContentData            = this.ContentData;
            result.CreateTime             = this.CreateTime;
            result.FileName               = this.FileName;
            result.FileSize               = this.FileSize;
            result.UpdateTime             = this.UpdateTime;
            result.PhysicalSourceFilePath = this.PhysicalSourceFilePath;

            return(result);
        }
Example #11
0
        /// <summary>
        /// 根据附件信息生成MaterialContent
        /// </summary>
        /// <returns></returns>
        private MaterialContent GenerateExistsMaterialContent()
        {
            MaterialContent content = new MaterialContent();

            content.ContentID  = this.ID;
            content.FileName   = this.OriginalName;
            content.RelativeID = this.ResourceID;
            content.Class      = this.MaterialClass;

            if (DeluxePrincipal.IsAuthenticated)
            {
                content.Creator = DeluxeIdentity.CurrentUser;
            }

            if (this._Content != null)
            {
                content.ContentData = this._Content.ContentData;
            }

            return(content);
        }
Example #12
0
        public override void DeleteMaterialContent(MaterialContent content)
        {
            DestFileInfo.NullCheck("DestFileInfo");

            DeleteFile(DestFileInfo);
        }
        public virtual void DoModifyFileOperations(string rootPath, MaterialFileOeprationInfo fileOperation, MaterialContent content)
        {
            var task = new InvokeServiceTask()
            {
                TaskID    = UuidHelper.NewUuidString(),
                TaskTitle = string.Format(this.taskTitleTemplate, fileOperation.Material.OriginalName, fileOperation.Material.ID),
            };

            var parameters = new WfServiceOperationParameterCollection
            {
                new WfServiceOperationParameter("rootPath", rootPath),
                new WfServiceOperationParameter("fileOperation", fileOperation.Operation.ToString()),
                new WfServiceOperationParameter("materialConnectionName",
                                                DbConnectionMappingContext.GetMappedConnectionName(MaterialAdapter.Instance.GetConnectionName())),
                new WfServiceOperationParameter("contentConnectionName",
                                                DbConnectionMappingContext.GetMappedConnectionName(MaterialContentAdapter.Instance.ConnectionName)),
                new WfServiceOperationParameter("materialId", fileOperation.Material.ID),
                new WfServiceOperationParameter("url", fileOperation.Material.ShowFileUrl)
            };


            task.SvcOperationDefs.Add(new WfServiceOperationDefinition(
                                          new WfServiceAddressDefinition(WfServiceRequestMethod.Post, null, ResourceUriSettings.GetConfig().Paths[this.resourceUri].Uri.ToString()),
                                          "DoFileToDocService", parameters, "ReturnValue")
                                      );

            DbConnectionMappingContext.DoMappingAction(
                DbConnectionMappingContext.GetMappedConnectionName(InvokeServiceTaskAdapter.Instance.ConnectionName),
                InvokeServiceTaskAdapter.Instance.ConnectionName,
                () =>
            {
                InvokeServiceTaskAdapter.Instance.Update(task);
            });
        }
Example #14
0
        // <summary>
        /// 初始化,或者准备MaterialContent
        /// </summary>
        public void EnsureMaterialContent()
        {
            this._Content = GenerateExistsMaterialContent();

            EnsureNotChangedMaterial();
        }
Example #15
0
 private void DoFileOperation(string rootPathName, MaterialFileOeprationInfo fileOp, MaterialContent content)
 {
     MaterialFileOperationSettings.GetConfig().Operations.ForEach(op =>
                                                                  op.DoModifyFileOperations(rootPathName, fileOp, content));
 }
 public abstract void SaveMaterialContent(MaterialContent content);
        public void DoModifyFileOperations(string rootPathName, MaterialFileOeprationInfo fileOp, MaterialContent content)
        {
            string uploadRootPath = AppPathConfigSettings.GetConfig().Paths[rootPathName].Dir;

            ExceptionHelper.CheckStringIsNullOrEmpty(uploadRootPath, "uploadRootPath");

            IMaterialContentPersistManager persistManager = GetMaterialContentPersistManager(rootPathName, fileOp);

            if (content == null)
            {
                content = fileOp.Material.GenerateMaterialContent();
            }

            switch (fileOp.Operation)
            {
            case FileOperation.Add:
            case FileOperation.Update:
                persistManager.SaveMaterialContent(content);
                break;

            case FileOperation.Delete:
                persistManager.DeleteMaterialContent(content);
                break;

            default:
                break;
            }
        }
 public abstract void DeleteMaterialContent(MaterialContent content);
 public override void DeleteMaterialContent(MaterialContent content)
 {
     MaterialContentAdapter.Instance.Delete(content);
 }