Beispiel #1
0
        private async Task ProcessFile(string file)
        {
            StreamReader stream = null;

            try
            {
                var tracking = new Host("FTP", IPAddress.Loopback);
                var header   = new VideoHeader(tracking, file);
                if (!destination.IsDownloaded(header))
                {
                    log.Info("Copy <{0}>", file);
                    stream = new StreamReader(file);
                    await destination.Transfer(header, stream.BaseStream).ConfigureAwait(false);
                }
                else
                {
                    log.Info("File is already copied <{0}", file);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            finally
            {
                stream?.Dispose();
            }
        }
Beispiel #2
0
        private async Task ProcessFile(FtpClient client, FtpListItem item)
        {
            Stream stream = null;

            try
            {
                var header = new VideoHeader(tracking.Host, item.FullName);
                if (!destination.IsDownloaded(header))
                {
                    log.Info("Downloading <{0}> from [{1}]", item.FullName, tracking.Host.Name);
                    stream = await client.OpenReadAsync(item.FullName).ConfigureAwait(false);

                    await destination.Transfer(header, stream).ConfigureAwait(false);

                    var reply = await client.GetReplyAsync(CancellationToken.None).ConfigureAwait(false);

                    if (reply.Success)
                    {
                        log.Info(
                            "Download Success:{0} Message:{1}: Type:{2} Code:{3} From: [{4}]",
                            reply.Success,
                            reply.Message,
                            reply.Type,
                            reply.Code,
                            tracking.Host.Name);
                    }
                    else
                    {
                        log.Error(
                            "Download Error:{0} Type:{1}: Code:{2} From: [{3}]",
                            reply.ErrorMessage,
                            reply.Type,
                            reply.Code,
                            tracking.Host.Name);
                    }
                }
                else
                {
                    log.Info("File is already downloaded - <{0}> {1}", item.FullName, tracking.Host.Name);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            finally
            {
                stream?.Dispose();
            }
        }
 public bool IsDownloaded(VideoHeader header)
 {
     Guard.NotNull(() => header, header);
     return(next.IsDownloaded(header));
 }
 public bool IsDownloaded(VideoHeader header)
 {
     Guard.NotNull(() => header, header);
     return(another.IsDownloaded(ConstructHeader(header)));
 }