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
        public override async Task Transfer(VideoHeader header, Stream source)
        {
            Guard.NotNull(() => header, header);
            Guard.NotNull(() => source, source);
            var transfer = next.Transfer(header, source);
            var name     = next.ResolveName(header);
            await transfer.ConfigureAwait(false);

            await postAction.AfterTransfer(name).ConfigureAwait(false);
        }
        public override async Task Transfer(VideoHeader header, Stream source)
        {
            Guard.NotNull(() => header, header);
            Guard.NotNull(() => source, source);
            var result = await priorAction.BeforeTransfer(header, source).ConfigureAwait(false);

            using (result.source)
            {
                await next.Transfer(result.header, result.source).ConfigureAwait(false);
            }
        }
Beispiel #4
0
        public async Task Transfer()
        {
            Assert.IsFalse(File.Exists(outFile));
            VideoHeader header = new VideoHeader(new Host("Camera", IPAddress.Any), "test.txt");

            using (StreamReader reader = new StreamReader(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "Test.txt")))
            {
                await instance.Transfer(header, reader.BaseStream).ConfigureAwait(false);
            }

            Assert.IsTrue(File.Exists(outFile));
        }
Beispiel #5
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 Task Transfer(VideoHeader header, Stream source)
 {
     Guard.NotNull(() => header, header);
     Guard.NotNull(() => source, source);
     return(another.Transfer(ConstructHeader(header), source));
 }