Пример #1
0
        /// <summary>保存附件信息</summary>
        public static void Upload(IAttachmentFileInfo file)
        {
            // -------------------------------------------------------
            // 保存 数据库
            // 数据库 支持数据库集群
            // -------------------------------------------------------

            if (AttachmentStorageConfigurationView.Instance.DistributedFileStorageMode == "ON")
            {
                DistributedFileInfo param = new DistributedFileInfo();

                param.Id          = file.Id;
                param.VirtualPath = file.VirtualPath;
                param.FileData    = file.FileData;

                AttachmentStorageContext.Instance.AttachmentDistributedFileService.Save(param);
            }

            // -------------------------------------------------------
            // 保存 二进制数据
            // -------------------------------------------------------

            string path = UploadPathHelper.CombinePhysicalPath(file.Parent.AttachmentFolder, string.Format("{0}{1}", file.Id, file.FileType));

            if (!File.Exists(path))
            {
                UploadPathHelper.TryCreateDirectory(path);

                ByteHelper.ToFile(file.FileData, path);
            }
        }
Пример #2
0
        public void TestCombinePhysicalPath()
        {
            string attachmentFolder = "test";
            string fileName         = "123.doc";

            DateTime datetime = DateTime.Now;

            string path1 = AttachmentStorageConfigurationView.Instance.PhysicalUploadFolder
                           + attachmentFolder + "/"
                           + datetime.Year + "/" + (((datetime.Month - 1) / 3) + 1) + "Q/" + datetime.Month + "/"
                           + fileName;

            path1 = DirectoryHelper.FormatLocalPath(path1);

            string path2 = UploadPathHelper.CombinePhysicalPath(attachmentFolder, fileName);

            Assert.AreEqual(path1, path2);
        }
Пример #3
0
        /// <summary>保存附件信息</summary>
        public void Save()
        {
            AttachmentStorageContext.Instance.AttachmentFileService.Save(this);

            // -------------------------------------------------------
            // 保存 二进制数据
            // -------------------------------------------------------

            string path = UploadPathHelper.CombinePhysicalPath(Parent.AttachmentFolder, string.Format("{0}{1}", Id, FileType));

            UploadPathHelper.TryCreateDirectory(path);

            ByteHelper.ToFile(FileData, path);

            // -------------------------------------------------------
            // 保存 二进制信息
            // -------------------------------------------------------

            DistributedFileStorage.Upload(this);
        }