Ejemplo n.º 1
0
        /// <summary>
        /// 批量删除文件(删除所有规格的文件)
        /// </summary>
        /// <remarks>
        /// 删除前先备份
        /// </remarks>
        /// <example>
        /// DeleteFile("UserPortrait", new string[] {"5cb47724-9f52-4ad0-8098-5877bdd4f278",""8cby7724-9f52-4ad0-8098-5877bdd4ed78",new string[]{"101","212"});
        /// </example>
        /// <param name="key">配置文件Key</param>
        /// <param name="fileNameList">文件名列表</param>
        /// <param name="dateList">日期列表,如new string[]{"20091010","20091020"}</param>
        /// <param name="userFolders">自定义的文件夹名</param>
        /// <returns>是否删除成功</returns>
        public static bool DeleteFile(string key, string[] fileNameList, string[] dateList, string[] userFolders)
        {
            if (string.IsNullOrEmpty(key) || fileNameList == null || fileNameList.Length == 0)
            {
                return(false);
            }

            ImageServiceClientProxy client = new ImageServiceClientProxy();

            return(client.DeleteFile(key, fileNameList, dateList, userFolders));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 通用的删除文件方法(删除所有规格的文件)
        /// </summary>
        /// <remarks>
        /// 删除前先备份
        /// </remarks>
        /// <example>
        /// GeneralDeleteFile(@"Feike\20091230\7a2bb63b-cc1b-419a-b0d0-ff2bd8b6fbea")
        /// </example>
        /// <param name="filePath">文件完整的相对路径</param>
        /// <returns>是否删除成功</returns>
        public static bool GeneralDeleteFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(false);
            }

            ImageServiceClientProxy client = new ImageServiceClientProxy();

            return(client.DeleteNormalFile(new string[] { filePath }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 批量的通用的删除文件方法(删除所有规格的文件)
        /// </summary>
        /// <remarks>
        /// 删除前先备份
        /// </remarks>
        /// <example>
        /// GeneralDeleteFile(new string[] { @"Feike\20091230\7a2bb63b-cc1b-419a-b0d0-ff2bd8b6fbea")});
        /// </example>
        /// <param name="filePaths">文件完整的相对路径</param>
        /// <returns>是否删除成功</returns>
        public static bool GeneralDeleteFile(string[] filePaths)
        {
            if (filePaths == null || filePaths.Length < 1)
            {
                return(false);
            }

            ImageServiceClientProxy client = new ImageServiceClientProxy();

            return(client.DeleteNormalFile(filePaths));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 上传文件并返回缩略图大小a
        /// </summary>
        /// <param name="postedFile">上传的文件对象</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <param name="thumbnailInfo">缩略图信息</param>
        /// <returns></returns>
        public static FileMessage UploadFileAndReturnInfo(HttpPostedFileBase postedFile, string key, out FileInfor fileInfor, out ThumbnailInfo thumbnailInfo)
        {
            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;

            fileInfor     = new FileInfor();
            thumbnailInfo = new ThumbnailInfo();

            FileMessage f = client.GetFileName(key, postedFile.ContentLength, postedFile.FileName, out fileKey, out fileExt);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName    = fileKey;
                    fileInfor.FileSize    = postedFile.ContentLength;
                    fileInfor.FileExtName = fileExt;

                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName   = fileKey;
                    inValue.KeyName    = key;
                    inValue.FileExt    = fileExt;
                    inValue.SaveOrigin = true;

                    if (postedFile.InputStream.CanRead)
                    {
                        //byte[] content = new byte[postedFile.ContentLength + 1];
                        //postedFile.InputStream.Read(content, 0, postedFile.ContentLength);
                        //inValue.FileData = new MemoryStream(content);
                        inValue.FileData = postedFile.InputStream;
                        thumbnailInfo    = client.UploadFileAndReturnInfo(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return(FileMessage.UnknowError);
                    }

                    return(FileMessage.Success);
                }
                catch
                {
                    return(FileMessage.UnknowError);
                }
            }
            else
            {
                return(f);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 上传文件并返回缩略图大小
        /// </summary>
        /// <param name="postedFile">上传的文件对象</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <param name="thumbnailInfo">缩略图信息</param>
        /// <returns></returns>
        public static FileMessage UploadFileAndReturnInfo(string key, Stream inputStream, int contentLength, string fileName, out FileInfor fileInfor, out ThumbnailInfo thumbnailInfo)
        {
            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;

            fileInfor     = new FileInfor();
            thumbnailInfo = new ThumbnailInfo();

            FileMessage f = client.GetFileName(key, contentLength, fileName, out fileKey, out fileExt);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName = fileKey;
                    fileInfor.FileSize = contentLength;

                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName   = fileKey;
                    inValue.KeyName    = key;
                    inValue.FileExt    = fileExt;
                    inValue.SaveOrigin = true;

                    if (inputStream.CanRead)
                    {
                        inValue.FileData = inputStream;
                        thumbnailInfo    = client.UploadFileAndReturnInfo(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return(FileMessage.UnknowError);
                    }

                    return(FileMessage.Success);
                }
                catch
                {
                    return(FileMessage.UnknowError);
                }
            }
            else
            {
                return(f);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 上传文件并返回缩略图大小
        /// </summary>
        /// <param name="postedFile">上传的文件</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <param name="thumbnailInfo">缩略图信息</param>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        public static FileMessage UploadFileAndReturnInfo(HttpPostedFileBase postedFile, string key, out FileInfor fileInfor, out ThumbnailInfo thumbnailInfo, int userId)
        {
            string useridstr = userId.ToString();

            if (useridstr.Length < 9)
            {
                for (int i = 0; i < (9 - useridstr.Length); i++)
                {
                    useridstr = "0" + useridstr;
                }
            }

            string[] folders = new string[2];
            folders[0] = useridstr.Substring(0, 3);
            folders[1] = useridstr.Substring(3, 3);

            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;

            fileInfor     = new FileInfor();
            thumbnailInfo = new ThumbnailInfo();

            FileMessage f = client.GetFileNameByUser(key, postedFile.ContentLength, postedFile.FileName, null, out fileKey, out fileExt, folders);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName = fileKey;
                    fileInfor.FileSize = postedFile.ContentLength;

                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName   = fileKey;
                    inValue.KeyName    = key;
                    inValue.FileExt    = fileExt;
                    inValue.SaveOrigin = true;

                    if (postedFile.InputStream.CanRead)
                    {
                        //byte[] content = new byte[postedFile.ContentLength + 1];
                        //postedFile.InputStream.Read(content, 0, postedFile.ContentLength);
                        //inValue.FileData = new MemoryStream(content);
                        inValue.FileData = postedFile.InputStream;
                        thumbnailInfo    = client.UploadFileAndReturnInfo(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return(FileMessage.UnknowError);
                    }

                    return(FileMessage.Success);
                }
                catch
                {
                    return(FileMessage.UnknowError);
                }
            }
            else
            {
                return(f);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 上传文件并返回缩略图大小
        /// </summary>
        /// <param name="postedFile">上传的文件</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <param name="thumbnailInfo">缩略图信息</param>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        public static FileMessage UploadFileAndReturnInfo(HttpPostedFileBase postedFile, string key, out FileInfor fileInfor, out ThumbnailInfo thumbnailInfo, int userId)
        {

            string useridstr = userId.ToString();

            if (useridstr.Length < 9)
            {
                for (int i = 0; i < (9 - useridstr.Length); i++)
                {
                    useridstr = "0" + useridstr;
                }
            }

            string[] folders = new string[2];
            folders[0] = useridstr.Substring(0, 3);
            folders[1] = useridstr.Substring(3, 3);

            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;

            fileInfor = new FileInfor();
            thumbnailInfo = new ThumbnailInfo();

            FileMessage f = client.GetFileNameByUser(key, postedFile.ContentLength, postedFile.FileName, null, out fileKey, out fileExt, folders);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName = fileKey;
                    fileInfor.FileSize = postedFile.ContentLength;

                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName = fileKey;
                    inValue.KeyName = key;
                    inValue.FileExt = fileExt;
                    inValue.SaveOrigin = true;

                    if (postedFile.InputStream.CanRead)
                    {
                        //byte[] content = new byte[postedFile.ContentLength + 1];
                        //postedFile.InputStream.Read(content, 0, postedFile.ContentLength);
                        //inValue.FileData = new MemoryStream(content);
                        inValue.FileData = postedFile.InputStream;
                        thumbnailInfo = client.UploadFileAndReturnInfo(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return FileMessage.UnknowError;
                    }

                    return FileMessage.Success;
                }
                catch
                {
                    return FileMessage.UnknowError;
                }
            }
            else
            {
                return f;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 上传文件并返回缩略图大小
        /// </summary>
        /// <param name="postedFile">上传的文件对象</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <param name="thumbnailInfo">缩略图信息</param>
        /// <returns></returns>
        public static FileMessage UploadFileAndReturnInfo(string key, Stream inputStream, int contentLength, string fileName, out FileInfor fileInfor, out ThumbnailInfo thumbnailInfo)
        {
            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;
            fileInfor = new FileInfor();
            thumbnailInfo = new ThumbnailInfo();

            FileMessage f = client.GetFileName(key, contentLength, fileName, out fileKey, out fileExt);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName = fileKey;
                    fileInfor.FileSize = contentLength;

                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName = fileKey;
                    inValue.KeyName = key;
                    inValue.FileExt = fileExt;
                    inValue.SaveOrigin = true;

                    if (inputStream.CanRead)
                    {
                        inValue.FileData = inputStream;
                        thumbnailInfo = client.UploadFileAndReturnInfo(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return FileMessage.UnknowError;
                    }

                    return FileMessage.Success;
                }
                catch
                {
                    return FileMessage.UnknowError;
                }
            }
            else
            {
                return f;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 批量删除文件(删除所有规格的文件)
        /// </summary>
        /// <remarks>
        /// 删除前先备份
        /// </remarks>
        /// <example>
        /// DeleteFile("UserPortrait", new string[] {"5cb47724-9f52-4ad0-8098-5877bdd4f278",""8cby7724-9f52-4ad0-8098-5877bdd4ed78",new string[]{"101","212"});
        /// </example>
        /// <param name="key">配置文件Key</param>
        /// <param name="fileNameList">文件名列表</param>
        /// <param name="dateList">日期列表,如new string[]{"20091010","20091020"}</param>
        /// <param name="userFolders">自定义的文件夹名</param>
        /// <returns>是否删除成功</returns>
        public static bool DeleteFile(string key, string[] fileNameList, string[] dateList, string[] userFolders)
        {
            if (string.IsNullOrEmpty(key) || fileNameList == null || fileNameList.Length == 0)
            {
                return false;
            }

            ImageServiceClientProxy client = new ImageServiceClientProxy();

            return client.DeleteFile(key, fileNameList, dateList, userFolders);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 批量的通用的删除文件方法(删除所有规格的文件)
        /// </summary>
        /// <remarks>
        /// 删除前先备份
        /// </remarks>
        /// <example>
        /// GeneralDeleteFile(new string[] { @"Feike\20091230\7a2bb63b-cc1b-419a-b0d0-ff2bd8b6fbea")});
        /// </example>
        /// <param name="filePaths">文件完整的相对路径</param>
        /// <returns>是否删除成功</returns>
        public static bool GeneralDeleteFile(string[] filePaths)
        {
            if (filePaths == null || filePaths.Length < 1)
            {
                return false;
            }

            ImageServiceClientProxy client = new ImageServiceClientProxy();

            return client.DeleteNormalFile(filePaths);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 通用的删除文件方法(删除所有规格的文件)
        /// </summary>
        /// <remarks>
        /// 删除前先备份
        /// </remarks>
        /// <example>
        /// GeneralDeleteFile(@"Feike\20091230\7a2bb63b-cc1b-419a-b0d0-ff2bd8b6fbea")
        /// </example>
        /// <param name="filePath">文件完整的相对路径</param>
        /// <returns>是否删除成功</returns>
        public static bool GeneralDeleteFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return false;
            }

            ImageServiceClientProxy client = new ImageServiceClientProxy();

            return client.DeleteNormalFile(new string[] { filePath });
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 上传文件并返回缩略图大小a
        /// </summary>
        /// <param name="postedFile">上传的文件对象</param>
        /// <param name="key">服务端配置索引名</param>
        /// <param name="fileInfor">文件上传后返回的信息对象</param>
        /// <param name="thumbnailInfo">缩略图信息</param>
        /// <returns></returns>
        public static FileMessage UploadFileAndReturnInfo(HttpPostedFileBase postedFile, string key, out FileInfor fileInfor, out ThumbnailInfo thumbnailInfo)
        {
            ImageServiceClientProxy client = new ImageServiceClientProxy();
            string fileKey;
            string fileExt;
            fileInfor = new FileInfor();
            thumbnailInfo = new ThumbnailInfo();

            FileMessage f = client.GetFileName(key, postedFile.ContentLength, postedFile.FileName, out fileKey, out fileExt);

            if (f == FileMessage.Success)
            {
                try
                {
                    fileInfor.FileName = fileKey;
                    fileInfor.FileSize = postedFile.ContentLength;
                    fileInfor.FileExtName = fileExt;

                    FileUploadMessage inValue = new FileUploadMessage();
                    inValue.FileName = fileKey;
                    inValue.KeyName = key;
                    inValue.FileExt = fileExt;
                    inValue.SaveOrigin = true;

                    if (postedFile.InputStream.CanRead)
                    {
                        //byte[] content = new byte[postedFile.ContentLength + 1];
                        //postedFile.InputStream.Read(content, 0, postedFile.ContentLength);
                        //inValue.FileData = new MemoryStream(content);
                        inValue.FileData = postedFile.InputStream;
                        thumbnailInfo = client.UploadFileAndReturnInfo(inValue);
                        inValue.FileData.Close();
                        inValue.FileData.Dispose();
                    }
                    else
                    {
                        return FileMessage.UnknowError;
                    }

                    return FileMessage.Success;
                }
                catch
                {
                    return FileMessage.UnknowError;
                }
            }
            else
            {
                return f;
            }
        }