/// <summary> /// Start a document download /// </summary> /// <param name="logonId"></param> /// <param name="DocumentId"></param> /// <returns></returns> public StartDocumentDownloadReturnValue StartDocumentDownloadForMatter(Guid logonId, Guid projectId, int DocumentId /* TODO Replace this or add extra parameters needed to identify the document required */) { StartDocumentDownloadReturnValue ReturnValue = new StartDocumentDownloadReturnValue(); try { // Get the logged on user from the current logons and add their // ApplicationSettings the list of concurrent sessions. Host.LoadLoggedOnUser(logonId); try { switch (ApplicationSettings.Instance.UserType) { case DataConstants.UserType.Staff: // Can do everything break; case DataConstants.UserType.Client: case DataConstants.UserType.ThirdParty: if (!SrvMatterCommon.WebAllowedToAccessMatter(projectId)) { throw new Exception("Access denied"); } break; default: throw new Exception("Unknown UserType"); } // TODO this is just a test file name, you must put the ILB document extraction code here // and set SourceFileName appropriately string SourceFileName = @"c:\work\SetupWebLinkDemo.exe"; FileDownloadInfo FileInfoData = FileTransfer.StartFileDownload(logonId, SourceFileName, false); ReturnValue.TransferId = FileInfoData.TransferId; ReturnValue.FileName = FileInfoData.FileName; ReturnValue.Size = FileInfoData.Size; ReturnValue.ModifiedDate = FileInfoData.ModifiedDate; ReturnValue.Hash = FileInfoData.Hash; } finally { // Remove the logged on user's ApplicationSettings from the // list of concurrent sessions Host.UnloadLoggedOnUser(); } } catch (Exception ex) { ReturnValue.Success = false; ReturnValue.Message = ex.Message; } return(ReturnValue); }
/// <summary> /// Start the file download /// </summary> /// <param name="logonId">Logon id of user</param> /// <param name="FileName">Source file to be downloaded</param> /// <param name="FileIsTemp">If the source file to be downloaded is a temp file set this to true so that /// it will automatically be deleted at the end. /// e.g. if you have extratced a file from an archive into a temp file for download then set this /// to true</param> /// <returns></returns> public static FileDownloadInfo StartFileDownload(Guid logonId, string SourceFileName, bool FileIsTemp) { FileTransferData FileTransferData = Host.GetFileTransferData(logonId); FileTransferData.TransferId = Guid.NewGuid(); FileTransferData.IsDownload = true; FileTransferData.FileName = SourceFileName; if (FileIsTemp) { FileTransferData.TempFileName = SourceFileName; } else { FileTransferData.TempFileName = null; } FileDownloadInfo FileDownloadInfo = new FileDownloadInfo(); FileTransferData.FileStream = new FileStream(SourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read); try { FileInfo FInfo = new FileInfo(SourceFileName); FileTransferData.ModifiedDate = FInfo.LastWriteTime; FileTransferData.Size = FInfo.Length; FileDownloadInfo.TransferId = FileTransferData.TransferId; // Only return the filename without the path as this is irrelavent to the client FileDownloadInfo.FileName = Path.GetFileName(SourceFileName); FileDownloadInfo.ModifiedDate = FInfo.LastWriteTime; FileDownloadInfo.Size = FInfo.Length; FileDownloadInfo.Hash = FileTransferHash.CreateStreamMD5Hash(FileTransferData.FileStream); FileTransferData.FileStream.Seek(0, SeekOrigin.Begin); } catch { FileTransferData.Reset(); throw; } return(FileDownloadInfo); }