示例#1
0
 /// <summary>创建附件</summary>
 /// <param name="applicationName"></param>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static IAttachmentFileInfo CreateAttachmentFile(IAttachmentParentObject parent, HttpPostedFile file)
 {
     return(CreateAttachmentFile(parent,
                                 file.FileName,
                                 Path.GetExtension(file.FileName),
                                 file.ContentLength,
                                 StreamHelper.ToBytes(file.InputStream)));
 }
示例#2
0
 /// <summary>创建附件</summary>
 /// <param name="applicationName"></param>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static IAttachmentFileInfo CreateAttachmentFile(IAttachmentParentObject parent, string attachmentName, string fileType, int fileSize, byte[] fileData)
 {
     return(CreateAttachmentFile(parent,
                                 NewIdentity(),
                                 attachmentName,
                                 fileType,
                                 fileSize,
                                 fileData));
 }
示例#3
0
        public void TestSave()
        {
            Mock <IAttachmentParentObject> mock = this.factory.CreateMock <IAttachmentParentObject>(); //产生一个mock对象

            mock.Expects.Between(0, 5).GetProperty(m => m.EntityId, "test_" + DateHelper.GetTimestamp());
            mock.Expects.Between(0, 5).GetProperty(m => m.EntityClassName, KernelContext.ParseObjectType(typeof(AttachmentParentObject)));
            mock.Expects.Between(0, 5).GetProperty(m => m.AttachmentEntityClassName, KernelContext.ParseObjectType(typeof(AttachmentFileInfo)));
            mock.Expects.Between(0, 5).GetProperty(m => m.AttachmentFolder, "test");

            IAttachmentParentObject parent = mock.MockObject;

            IAttachmentFileInfo param = new AttachmentFileInfo(parent);

            param.Id             = UploadFileHelper.NewIdentity();
            param.AttachmentName = "test_" + DateHelper.GetTimestamp();
            param.FileType       = ".txt";

            param = AttachmentStorageContext.Instance.AttachmentFileService.Save(param);

            Assert.IsNotNull(param);
        }
示例#4
0
        /// <summary>创建附件</summary>
        /// <param name="applicationName"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static IAttachmentFileInfo CreateAttachmentFile(IAttachmentParentObject parent, string attachmentId, string attachmentName, string fileType, int fileSize, byte[] fileData)
        {
            // 创建对象构建器(Spring.NET)
            string springObjectFile = AttachmentStorageConfigurationView.Instance.Configuration.Keys["SpringObjectFile"].Value;

            SpringObjectBuilder objectBuilder = SpringObjectBuilder.Create(AttachmentStorageConfiguration.ApplicationName, springObjectFile);

            // 创建数据服务对象
            IAttachmentFileInfo param = objectBuilder.GetObject <IAttachmentFileInfo>(typeof(IAttachmentFileInfo), new object[] { parent });

            param.Id             = string.IsNullOrEmpty(attachmentId) ? NewIdentity() : attachmentId;
            param.AttachmentName = attachmentName;
            param.FileType       = fileType;
            param.FileSize       = fileSize;
            param.FileData       = fileData;
            param.CreatedDate    = DateTime.Now;

            // 虚拟路径需要创建时间和文件类型参数
            param.VirtualPath = UploadPathHelper.GetVirtualPathFormat(parent.AttachmentFolder, param);

            param.FolderRule = AttachmentStorageConfigurationView.Instance.PhysicalUploadFolderRule;

            return(param);
        }
示例#5
0
 public AttachmentFileInfo(IAttachmentParentObject parent)
 {
     this.Parent = parent;
 }