protected byte[] ReadFile(Guid fileID, Guid lockID, string clientFileName, int startPos, int bufferCount, out string error)
        {
            RemoteFileStorageService provider = new RemoteFileStorageService();
            ReadFileParameter        para     = new ReadFileParameter();
            ReadFileItemData         item     = new ReadFileItemData();

            para.InputData.Add(item);
            item.PhysicalFileID = fileID;
            item.ClientFileName = clientFileName;
            item.LockID         = lockID;
            item.Position       = startPos;
            item.ReadCount      = bufferCount;
            ReadFileResult result = provider.ReadFile(para);

            error = null;
            if (result != null)
            {
                if (result.Succeed)
                {
                    if (result.ExecuteResult.Count > 0)
                    {
                        ReadFileResultItemData itemResult = result.ExecuteResult[0];
                        if (itemResult != null)
                        {
                            return(itemResult.ReadData);
                        }
                    }
                    error = string.Format("不存在ID为:{0}的文件.", fileID);
                }
                else
                {
                    error = result.InnerException.ErrorMessage;
                }
            }
            else
            {
                error = "读取文件失败.";
            }
            return(null);
        }
Пример #2
0
        protected ReadFileResultItemData ReadFileItem(ReadFileItemData itemParam, Guid userID, DbTransaction trans)
        {
            ReadFileResultItemData    item         = new ReadFileResultItemData();
            IRecordLockedDataProvider dataProvider = RecordLockedDataProvider;

            if (dataProvider != null)
            {
                RecordLockedManager.ServiceProxy.SetDataProvider(dataProvider);
            }
            if (itemParam.LockID != Guid.Empty)
            {
                RecordLockedManager.UpdateLockInfo(itemParam.LockID, DateTime.UtcNow.Add(RecordLocked.DefaultExpireTimeSpan));
            }
            string extendsionName = string.Empty;

            if (!string.IsNullOrEmpty(itemParam.ClientFileName))
            {
                extendsionName = Path.GetExtension(itemParam.ClientFileName);
            }

            item.ReadData = FileStorageManager.ReadFile(this.DataProvider, itemParam.PhysicalFileID, extendsionName, itemParam.Position, itemParam.ReadCount);
            return(item);
        }