예제 #1
0
		/// <summary>
		/// Gets a new client to the attached document store, safe for use by a single-thread.
		/// </summary>
		/// <returns></returns>
		public static IAttachedDocumentStore GetClient()
		{
			// always construct a new instance of each object here, so we don't have to worry about thread-safety
			var ftpSettings = new AttachedDocumentSettings();
			var ftp = new FtpFileTransfer(
				ftpSettings.FtpUserId,
				ftpSettings.FtpPassword,
				ftpSettings.FtpBaseUrl,
				ftpSettings.FtpPassiveMode);
			return new FtpAttachedDocumentStore(ftp, Path.GetTempPath());
		}
예제 #2
0
		/// <summary>
		/// Downloads a document at a specified relativeUrl to a temporary file.
		/// </summary>
		/// <param name="documentSummary"></param>
		/// <returns>The location of the downloaded file.</returns>
		public static string DownloadFile(AttachedDocumentSummary documentSummary)
		{
			Platform.CheckForNullReference(documentSummary, "documentSummary");

			// if already cached locally, return local file name
			var tempFile = TempFileManager.Instance.GetFile(documentSummary.DocumentRef);
			if (!string.IsNullOrEmpty(tempFile))
				return tempFile;

			var ftpFileTransfer = new FtpFileTransfer(
				AttachedDocumentSettings.Default.FtpUserId,
				AttachedDocumentSettings.Default.FtpPassword,
				AttachedDocumentSettings.Default.FtpBaseUrl,
				AttachedDocumentSettings.Default.FtpPassiveMode);

			var fullUrl = new Uri(ftpFileTransfer.BaseUri, documentSummary.ContentUrl);
			var fileExtension = Path.GetExtension(fullUrl.LocalPath).Trim('.');
			var localFilePath = TempFileManager.Instance.CreateFile(documentSummary.DocumentRef, fileExtension,
			                                                        fn => ftpFileTransfer.Download(new FileTransferRequest(fullUrl, fn)),
			                                                        TimeSpan.FromSeconds(AttachedDocumentSettings.Default.DownloadCacheTimeToLive));

			return localFilePath;
		}
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="ftpFileTransfer">FTP file transfer object.</param>
		/// <param name="tempPath">A path that can be used to store downloaded document files.</param>
		public FtpAttachedDocumentStore(FtpFileTransfer ftpFileTransfer, string tempPath)
		{
			_ftpFileTransfer = ftpFileTransfer;
			_tempPath = tempPath;
		}