using System;
using System.IO;
using System.Runtime.Serialization;
namespace AppLimit.CloudComputing.SharpBox
{
///
/// This enum describes the data transfer direction
///
public enum nTransferDirection
{
///
/// Defines that the target data stream should be uploaded into the cloud file container
///
nUpload,
///
/// Defines that the data from the cloud file container should be downloaded into the target data stream
///
nDownload
};
///
/// This class contains the arguments which can be used when a data transfer operation is running
///
public class FileDataTransferEventArgs : EventArgs, ICloneable
{
///
/// Set this to true to abort the transfer
///
public bool Cancel { get; set; }
///
/// The amount of bytes currently transfered
///
public long CurrentBytes { get; internal set; }
///
/// The amount of bytes which has to be transfered in total
///
public long TotalBytes { get; internal set; }
///
/// Overall progress in %
///
public int PercentageProgress { get; internal set; }
///
/// The calculated transfer rate for this operation overall(Kbits/s)
///
public long TransferRateTotal { get; internal set; }
///
/// The current messured transfer rate (Kbits/s)
///
public long TransferRateCurrent { get; internal set; }
///
/// The estimated finish time if this transfer
///
public TimeSpan OpenTransferTime { get; internal set; }
///
/// A reference to the associated cloud file system entry
///
public ICloudFileSystemEntry FileSystemEntry { get; internal set; }
///
/// A use specific context
///
public object CustomnContext { get; internal set; }
///
/// ctor
///
public FileDataTransferEventArgs()
{
Cancel = false;
}
#region ICloneable Members
///
/// This method implements to clone interface to support a deep copy
/// of everything what we use to report the progress of a operation
///
///
public object Clone()
{
var e = new FileDataTransferEventArgs
{
CurrentBytes = CurrentBytes,
CustomnContext = CustomnContext,
FileSystemEntry = FileSystemEntry,
OpenTransferTime = OpenTransferTime,
PercentageProgress = PercentageProgress,
TotalBytes = TotalBytes,
TransferRateCurrent = TransferRateCurrent,
TransferRateTotal = TransferRateTotal,
Cancel = false
};
return e;
}
#endregion
}
///
/// This delegate can be used as callback for upload or download operation in the
/// data streams.
///
/// sender object of the event
/// event args
public delegate void FileOperationProgressChanged(object sender, FileDataTransferEventArgs e);
///
/// This interface implements a specifc transfer logic which can be used
/// to transport data from a local data stream to a remote filesystem entry
/// and back
///
public interface ICloudFileDataTransfer
{
///
/// This method transfers data between a local data stream and the remote filesystem entry on
/// byte level
///
///
///
void Transfer(Stream targetDataStream, nTransferDirection direction);
///
/// This method transfers data between a local data stream and the remote filesystem entry on
/// byte level
///
///
///
///
///
void Transfer(Stream targetDataStream, nTransferDirection direction, FileOperationProgressChanged progressCallback, object progressContext);
///
/// This method transfers data between a local data stream and the remote filesystem entry on
/// byte level. This API triggers the callback in an async manner this means the transfer process
/// is not blocked during the consumer is in the handler
///
///
///
///
///
void TransferAsyncProgress(Stream targetDataStream, nTransferDirection direction, FileOperationProgressChanged progressCallback, object progressContext);
///
/// Allows native access to the download stream of the associated file.
/// Ensure that this stream will be disposed clearly!
///
Stream GetDownloadStream();
///
/// Allows native access to the upload stream of the associated file
/// Ensure that this stream will be disposed clearly!
///
///
Stream GetUploadStream(long uploadSize);
///
/// This method supports the serialization of object graphs into the remote file container
///
///
///
void Serialize(IFormatter dataFormatter, object objectGraph);
///
/// This method allows to deserialize an object graph from the remote file container
///
///
///
object Deserialize(IFormatter dataFormatter);
IResumableUploadSession CreateResumableSession(long bytesToTransfer);
void AbortResumableSession(IResumableUploadSession transferSession);
void Transfer(IResumableUploadSession transferSession, Stream data, long dataLength);
}
}