Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
        protected override object InsertAttachment(IDbDataSource host, IFieldUpload upload,
                                                   IFieldValueAccessor accessor, string path)
        {
            AttachmentResolver resolver = new AttachmentResolver(host);

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

            fDelFile = path;
            return(resolver);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
0
        protected override object InsertAttachment(IDbDataSource host, IFieldUpload upload,
                                                   IFieldValueAccessor accessor, string path)
        {
            if (UseAliyunUploadMode)
            {
                FileConfig temp   = FileConfig.ReadFromJson(path);
                FileConfig config = new FileConfig(BucketName, temp.ObjectName);
                accessor.SetValue(upload.ServerPathField, config.AccessUrl);
                accessor.SetValue(upload.ContentField, config.ToString());

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

                config.UploadFile(path, originFileName);
            }
            return(null);
        }
Ejemplo n.º 8
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);
        }