コード例 #1
0
        protected override object DeleteAttachment(IDbDataSource host,
                                                   IFieldUpload upload, DataRow row, string path)
        {
            AttachmentResolver resolver = new AttachmentResolver(host);

            resolver.SetCommands(AdapterCommand.Delete);
            resolver.Delete(row[upload.ContentField].Value <int>(), false);
            return(resolver);
        }
コード例 #2
0
        public string Display(IFieldUpload upload, DataRow row)
        {
            TkDebug.AssertArgumentNull(upload, "upload", this);
            TkDebug.AssertArgumentNull(row, "row", this);

            return(string.Format(ObjectUtil.SysCulture, "<a href=\"{2}\" target=\"_blank\">{0}{1}</a>",
                                 row.GetString(upload.FileNameField), BaseUploadProcessor.FormatSize(row.GetValue <int>(upload.SizeField)),
                                 row.GetString(upload.ContentField)));
        }
コード例 #3
0
ファイル: Tk5UploadConfig.cs プロジェクト: madiantech/tkcore
        public Tk5UploadConfig(IFieldUpload fieldUpload)
        {
            TkDebug.AssertArgumentNull(fieldUpload, "fieldUpload", null);

            FileNameField   = fieldUpload.FileNameField;
            ServerPathField = fieldUpload.ServerPathField;
            ContentField    = fieldUpload.ContentField;
            MimeTypeField   = fieldUpload.MimeTypeField;
            SizeField       = fieldUpload.SizeField;
        }
コード例 #4
0
        public override string Display(IFieldUpload upload, DataRow row)
        {
            TkDebug.AssertArgumentNull(upload, "upload", this);
            TkDebug.AssertArgumentNull(row, "row", this);

            return(string.Format(ObjectUtil.SysCulture, "<a href=\"{2}\" target=\"_blank\">{0}{1}</a>",
                                 StringUtil.EscapeHtml(row.GetString(upload.FileNameField)),
                                 FormatSize(row.GetValue <int>(upload.SizeField)),
                                 StringUtil.EscapeHtmlAttribute(row.GetString(upload.ContentField))));
        }
コード例 #5
0
        protected override object InsertAttachment(IDbDataSource host, IFieldUpload upload,
                                                   DataRow row, string path)
        {
            string fileName = Path.GetFileName(path);
            string newPath  = Path.Combine(fUploadPath, fileName);

            row[upload.ServerPathField] = newPath;
            row[upload.ContentField]    = fVirtualPath + fileName;

            CopyFile(path, newPath);
            return(null);
        }
コード例 #6
0
        protected override object InsertAttachment(IDbDataSource host, IFieldUpload upload,
                                                   IFieldValueAccessor accessor, string path)
        {
            string fileName = Path.GetFileName(path);
            string newPath  = Path.Combine(fUploadPath, fileName);

            accessor.SetValue(upload.ServerPathField, newPath);
            accessor.SetValue(upload.ContentField, fVirtualPath + fileName);

            CopyFile(path, newPath);
            return(null);
        }
コード例 #7
0
 protected override object DeleteAttachment(IDbDataSource host, IFieldUpload upload,
                                            DataRow row, string path)
 {
     try
     {
         File.Delete(path);
     }
     catch
     {
     }
     return(null);
 }
コード例 #8
0
 protected override object DeleteAttachment(IDbDataSource host, IFieldUpload upload,
                                            IFieldValueAccessor accessor, string path)
 {
     try
     {
         accessor.SetValue(upload.ContentField, DBNull.Value);
         File.Delete(path);
     }
     catch
     {
     }
     return(null);
 }
コード例 #9
0
        protected override object UpdateAttachment(IDbDataSource host,
                                                   IFieldUpload upload, DataRow row, string oldPath, string newPath)
        {
            AttachmentResolver resolver = new AttachmentResolver(host);

            resolver.SetCommands(AdapterCommand.Update);
            resolver.Update(row[upload.ContentField].Value <int>(), row[upload.FileNameField].ToString(), newPath,
                            row[upload.MimeTypeField].ToString(),
                            File.ReadAllBytes(newPath), false);

            fDelFile = newPath;
            return(resolver);
        }
コード例 #10
0
        protected override object UpdateAttachment(IDbDataSource host, IFieldUpload upload,
                                                   DataRow row, string oldPath, string newPath)
        {
            string fileName = Path.GetFileName(newPath);

            row[upload.ContentField] = fVirtualPath + fileName;
            //Add By Gaolq 2018/8/15
            string toPath = Path.Combine(fUploadPath, fileName);

            row[upload.ServerPathField] = toPath;
            CopyFile(newPath, toPath);
            return(null);
        }
コード例 #11
0
        protected override object UpdateAttachment(IDbDataSource host, IFieldUpload upload,
                                                   IFieldValueAccessor accessor, string oldPath, string newPath)
        {
            string fileName = Path.GetFileName(newPath);

            accessor.SetValue(upload.ContentField, fVirtualPath + fileName);
            //Add By Gaolq 2018/8/15
            string toPath = Path.Combine(fUploadPath, fileName);

            accessor.SetValue(upload.ServerPathField, toPath);

            CopyFile(newPath, toPath);
            return(null);
        }
コード例 #12
0
        protected override object InsertAttachment(IDbDataSource host,
                                                   IFieldUpload upload, DataRow row, string path)
        {
            AttachmentResolver resolver = new AttachmentResolver(host);

            resolver.SetCommands(AdapterCommand.Insert);
            byte[] fileData = File.ReadAllBytes(path);
            row[upload.ContentField] = resolver.Insert(
                row[upload.FileNameField].ToString(), path,
                row[upload.MimeTypeField].ToString(), fileData, false);

            fDelFile = path;
            return(resolver);
        }
コード例 #13
0
 protected override object DeleteAttachment(IDbDataSource host, IFieldUpload upload,
                                            IFieldValueAccessor accessor, string path)
 {
     try
     {
         var json = accessor.GetValue(upload.ContentField);
         accessor.SetValue(upload.ContentField, DBNull.Value);
         FileConfig config = FileConfig.ReadFromJson(json);
         config.Delete();
     }
     catch
     {
     }
     return(null);
 }
コード例 #14
0
 protected override object DeleteAttachment(IDbDataSource host, IFieldUpload upload,
                                            DataRow row, string path)
 {
     try
     {
         var json = row[upload.ContentField].ToString();
         row[upload.ContentField] = DBNull.Value;
         FileConfig config = FileConfig.ReadFromJson(json);
         config.Delete();
     }
     catch
     {
     }
     return(null);
 }
コード例 #15
0
        public object Process(IDbDataSource host, IFieldUpload upload, DataRow row, UpdateKind kind)
        {
            switch (kind)
            {
            case UpdateKind.Insert:
                string path = row[upload.ServerPathField].ToString();
                if (!string.IsNullOrEmpty(path))
                {
                    return(InsertAttachment(host, upload, row, path));
                }
                break;

            case UpdateKind.Update:
                string originalPath = row[upload.ServerPathField, DataRowVersion.Original].ToString();
                string newPath      = row[upload.ServerPathField].ToString();
                if (originalPath != newPath)
                {
                    if (string.IsNullOrEmpty(originalPath))
                    {
                        // 原先没有,当前实际是新建
                        return(InsertAttachment(host, upload, row, newPath));
                    }
                    else if (string.IsNullOrEmpty(newPath))
                    {
                        // 现在没有,当前实际是删除
                        var result = DeleteAttachment(host, upload, row, originalPath);
                        row[upload.FileNameField] = DBNull.Value;
                        return(result);
                    }
                    else
                    {
                        // 原先和现在都有,当前实际是覆盖
                        return(UpdateAttachment(host, upload, row, originalPath, newPath));
                    }
                }

                break;

            case UpdateKind.Delete:
                if (row[upload.ContentField] != DBNull.Value)
                {
                    return(DeleteAttachment(host, upload, row,
                                            row[upload.ServerPathField].ToString()));
                }
                break;
            }
            return(null);
        }
コード例 #16
0
        public object Process(IDbDataSource host, IFieldUpload upload, IFieldValueAccessor provider, UpdateKind kind)
        {
            switch (kind)
            {
            case UpdateKind.Insert:
                string path = provider[upload.ServerPathField].ToString();
                if (!string.IsNullOrEmpty(path))
                {
                    return(InsertAttachment(host, upload, provider, path));
                }
                break;

            case UpdateKind.Update:
                string originalPath = provider.GetOriginValue(upload.ServerPathField).ToString();
                string newPath      = provider[upload.ServerPathField].ToString();
                if (originalPath != newPath)
                {
                    if (string.IsNullOrEmpty(originalPath))
                    {
                        // 原先没有,当前实际是新建
                        return(InsertAttachment(host, upload, provider, newPath));
                    }
                    else if (string.IsNullOrEmpty(newPath))
                    {
                        // 现在没有,当前实际是删除
                        var result = DeleteAttachment(host, upload, provider, originalPath);
                        provider.SetValue(upload.FileNameField, DBNull.Value);
                        return(result);
                    }
                    else
                    {
                        // 原先和现在都有,当前实际是覆盖
                        return(UpdateAttachment(host, upload, provider, originalPath, newPath));
                    }
                }

                break;

            case UpdateKind.Delete:
                if (provider[upload.ContentField] != DBNull.Value)
                {
                    return(DeleteAttachment(host, upload, provider,
                                            provider[upload.ServerPathField].ToString()));
                }
                break;
            }
            return(null);
        }
コード例 #17
0
        protected IEnumerable <string> GetListSelectFields(TkDbContext context,
                                                           IFieldUpload upload, IFieldInfoIndexer indexer, bool showSize, bool showContent,
                                                           bool showMimeType, bool showServerPath)
        {
            TkDebug.AssertArgumentNull(upload, "upload", this);
            TkDebug.AssertArgumentNull(indexer, "indexer", this);

            string result;

            if (showSize)
            {
                result = GetUploadItemField(context, indexer, upload.SizeField);
                if (result != null)
                {
                    yield return(result);
                }
            }
            if (showContent)
            {
                result = GetUploadItemField(context, indexer, upload.ContentField);
                if (result != null)
                {
                    yield return(result);
                }
            }
            if (showMimeType)
            {
                result = GetUploadItemField(context, indexer, upload.MimeTypeField);
                if (result != null)
                {
                    yield return(result);
                }
            }
            if (showServerPath)
            {
                result = GetUploadItemField(context, indexer, upload.ServerPathField);
                if (result != null)
                {
                    yield return(result);
                }
            }
        }
コード例 #18
0
        public UploadInfo CreateValue(IFieldUpload upload, DataRow row)
        {
            TkDebug.AssertArgumentNull(upload, "upload", this);
            TkDebug.AssertArgumentNull(row, "row", this);

            string fileName = row.GetString(upload.FileNameField);

            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            UploadInfo info = new UploadInfo
            {
                FileName    = fileName,
                ContentType = row.GetString(upload.MimeTypeField),
                ServerPath  = row.GetString(upload.ServerPathField),
                FileSize    = row.GetValue <int>(upload.SizeField),
                WebPath     = row.GetString(upload.ContentField)
            };

            return(info);
        }
コード例 #19
0
        protected override object UpdateAttachment(IDbDataSource host, IFieldUpload upload,
                                                   IFieldValueAccessor accessor, string oldPath, string newPath)
        {
            if (UseAliyunUploadMode)
            {
                FileConfig temp   = FileConfig.ReadFromJson(newPath);
                string     json   = accessor.GetValue(upload.ContentField);
                FileConfig config = FileConfig.ReadFromJson(json);
                accessor.SetValue(upload.ServerPathField, config.AccessUrl);

                temp.RemoveTo(config);
            }
            else
            {
                string     json   = accessor.GetValue(upload.ContentField);
                FileConfig config = FileConfig.ReadFromJson(json);
                accessor.SetValue(upload.ServerPathField, config.AccessUrl);
                string originFileName = accessor.GetValue(upload.FileNameField);

                config.UploadFile(newPath, originFileName);
            }
            return(null);
        }
コード例 #20
0
        protected override object UpdateAttachment(IDbDataSource host, IFieldUpload upload,
                                                   DataRow row, string oldPath, string newPath)
        {
            if (UseAliyunUploadMode)
            {
                FileConfig temp   = FileConfig.ReadFromJson(newPath);
                string     json   = row[upload.ContentField].ToString();
                FileConfig config = FileConfig.ReadFromJson(json);
                row[upload.ServerPathField] = config.AccessUrl;

                temp.RemoveTo(config);
            }
            else
            {
                string     json   = row[upload.ContentField].ToString();
                FileConfig config = FileConfig.ReadFromJson(json);
                row[upload.ServerPathField] = config.AccessUrl;
                string originFileName = row[upload.FileNameField].ToString();

                config.UploadFile(newPath, originFileName);
            }
            return(null);
        }
コード例 #21
0
        public override UploadInfo CreateValue(IFieldUpload upload, IFieldValueProvider provider)
        {
            TkDebug.AssertArgumentNull(upload, "upload", this);
            TkDebug.AssertArgumentNull(provider, "provider", this);

            string fileName = provider.GetValue(upload.FileNameField);

            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }

            UploadInfo info = new UploadInfo
            {
                FileName    = fileName,
                ContentType = provider.GetValue(upload.MimeTypeField),
                ServerPath  = provider.GetValue(upload.ServerPathField),
                FileSize    = provider.GetValue <int>(upload.SizeField),
                WebPath     = provider.GetValue(upload.ContentField)
            };

            return(info);
        }
コード例 #22
0
        protected override object InsertAttachment(IDbDataSource host, IFieldUpload upload,
                                                   DataRow row, string path)
        {
            if (UseAliyunUploadMode)
            {
                FileConfig temp   = FileConfig.ReadFromJson(path);
                FileConfig config = new FileConfig(BucketName, temp.ObjectName);
                row[upload.ServerPathField] = config.AccessUrl;
                row[upload.ContentField]    = config.ToString();

                temp.RemoveTo(config);
            }
            else
            {
                string     fileName = Path.GetFileNameWithoutExtension(path);
                FileConfig config   = new FileConfig(BucketName, fileName);
                row[upload.ServerPathField] = config.AccessUrl;
                row[upload.ContentField]    = config.ToString();
                string originFileName = row[upload.FileNameField].ToString();

                config.UploadFile(path, originFileName);
            }
            return(null);
        }
コード例 #23
0
 public IEnumerable <string> GetListSelectFields(TkDbContext context,
                                                 IFieldUpload upload, IFieldInfoIndexer indexer)
 {
     return(null);
 }
コード例 #24
0
 public virtual object Process(IDbDataSource host, IFieldUpload upload, DataRow row, UpdateKind kind)
 {
     return(null);
 }
コード例 #25
0
 protected abstract object DeleteAttachment(IDbDataSource host, IFieldUpload upload,
                                            DataRow row, string path);
コード例 #26
0
 protected abstract object UpdateAttachment(IDbDataSource host, IFieldUpload upload,
                                            DataRow row, string oldPath, string newPath);
コード例 #27
0
 public abstract IEnumerable <string> GetListSelectFields(TkDbContext context,
                                                          IFieldUpload upload, IFieldInfoIndexer indexer);
コード例 #28
0
 public abstract UploadInfo CreateValue(IFieldUpload upload, DataRow row);
コード例 #29
0
 public abstract string Display(IFieldUpload upload, DataRow row);
コード例 #30
0
 protected abstract object DeleteAttachment(IDbDataSource host, IFieldUpload upload,
                                            IFieldValueAccessor accessor, string path);