http://www.codinghelmet.com/  

Wear a helmet. Even when coding.

net > sysexpand > web > filetransfer > manual > intro

Introduction
by Zoran Horvat @zoranh75

SysExpand FileTransfer library (SysExpand.Web.FileTransfer namespace) offers a solution to uploading and downloading files from remote client via a custom WCF service. Library implements key features important to any system which relies on remote file transfer:

  • Asynchronous file upload and download - both client and server are free to execute other operations while file is being transferred. Once the file transfer completes, client and server are asynchronously notified to cleanup local resources and to notify the user.
  • Progress monitoring - while file is transferred both client is periodically notified with progress. This is especially important for GUI progress indicators presented to the user.
  • Cancellation - user on the client side is free to cancel file transfer, which causes both server and client to clean up resources associated with the transfer.

General architecture of the file transfer system can be abstracted with the following picture.

General Architecture

Client's responsibility is to initiate file transfer (upload or download) and to manage parts of the files locally. Server's responsibility is to accept incoming requests from clients, validate them and manage parts of files that are transferred. SysExpand FileTransfer library is responsible to orchestrate all activities except those that are clearly specific to client or server implementation, like whether files are located on file system or in the database, etc. In more detailed representation, role of the FileTransfer library is shown in the following picture.

Detailed Architecture

FileTransfer library allows both client and server to implement file repository at their will. But when upload or download gets to tedious details, like progress indication or cancellation, FileTransfer comes into play with full solution to the problem. Parts of the client and server software are required to be coded around FileTransfer Client and Server libraries to complete the solution. In particular, these are the steps required to complete the working solution:

  • Implement IServerSessionsManager interface (SysExpand.Web.FileTransfer.Server namespace) which is responsible to manage file upload and download sessions on the server. Maintaining sessions is important step because file transfer is a lengthy operation and it must be tracked over a period of time.
  • Implement IServerFilesManager interface (SysExpand.Web.FileTransfer.Server namespace) which is responsible to load and store files on the server.
  • Define a WCF service which exposes specific methods proposed by FileTransfer library. Calls to these methods are simply routed to corresponding methods of the FileTransferServer class (SysExpand.Web.FileTransfer.Server namespace). Particular implementation is free to add methods that it requires for any other functionality that it provides beside file transfer.
  • Implement IClientFilesManager interface (SysExpand.Web.FileTransfer.Client namespace) which manages files at local repository.
  • Derive a class from FileTransferClient (SysExpand.Web.FileTransfer.Client namespace) which implements concrete calls to WCF service according to specification directed by FileTransfer library design.

These steps will be described in full detail in the following sections. At this moment we will only add a note that SysExpand FileTransfer library allows a programmer to write a full blown client-server application which uploads and downloads many files simultaneously in merely 300 lines of effective code. One such product is shown in the picture below. Code behind this demonstration is available in the Download section.

Demo Client

See also:

Published: Nov 26, 2012; Modified: Apr 14, 2013

ZORAN HORVAT

Zoran is software architect dedicated to clean design and CTO in a growing software company. Since 2014 Zoran is an author at Pluralsight where he is preparing a series of courses on design patterns, writing unit and integration tests and applying methods to improve code design and long-term maintainability.

Follow him on Twitter @zoranh75 to receive updates and links to new articles.

Watch Zoran's video courses at pluralsight.com (requires registration):

Tactical Design Patterns in .NET: Managing Responsibilities

Applying a design pattern to a real-world problem is not as straightforward as literature implicitly tells us. It is a more engaged process. This course gives an insight into tactical decisions we need to make when applying design patterns that have to do with separating and implementing class responsibilities. More...

Tactical Design Patterns in .NET: Control Flow

Improve your skills in writing simpler and safer code by applying coding practices and design patterns that are affecting control flow. More...

Improving Testability Through Design

This course tackles the issues of designing a complex application so that it can be covered with high quality tests. More...

Share this article

webmasters