• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

djsuperchief / Kyameru / 15064152942

16 May 2025 08:28AM UTC coverage: 87.848% (-3.2%) from 91.081%
15064152942

Pull #195

github

web-flow
Merge 05572bb23 into 9f1f537c4
Pull Request #195: 189 Go Live

501 of 630 branches covered (79.52%)

Branch coverage included in aggregate %.

175 of 203 new or added lines in 21 files covered. (86.21%)

93 existing lines in 13 files now uncovered.

2875 of 3213 relevant lines covered (89.48%)

22.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.38
/source/components/Kyameru.Component.Ftp/Implementation/From.cs
1
using Kyameru.Component.Ftp.Contracts;
2
using Kyameru.Component.Ftp.Settings;
3
using Kyameru.Core.Contracts;
4
using Kyameru.Core.Entities;
5
using System;
6
using System.Collections.Generic;
7
using System.Net;
8
using System.Text;
9
using System.Threading;
10
using System.Threading.Tasks;
11
using System.Timers;
12
using Kyameru.Core;
13
using Kyameru.Core.Sys;
14
using Timer = System.Timers.Timer;
15

16
namespace Kyameru.Component.Ftp
17
{
18
    /// <summary>
19
    /// FTP From Component
20
    /// </summary>
21
    /// <remarks>
22
    /// Async not really implemented, needs more work and should really be using sftp.
23
    /// </remarks>
24
    public class From : IFtpFrom
25
    {
26
        private readonly FtpSettings ftpSettings;
27
        private readonly IWebRequestUtility webRequestUtility;
28
        private FtpClient ftp;
29
        private Timer poller;
30

31
        private bool _isStopping = false;
7✔
32

33
        /// <summary>
34
        /// Initializes a new instance of the <see cref="From"/> class.
35
        /// </summary>
36
        /// <param name="headers"></param>
37
        public From(Dictionary<string, string> headers, IWebRequestUtility webRequestUtility)
7✔
38
        {
7✔
39
            ftpSettings = new FtpSettings(headers.ToFromConfig());
7✔
40
            this.webRequestUtility = webRequestUtility;
7✔
41
        }
7✔
42

UNCOV
43
        public bool PollerIsActive => poller.Enabled;
×
44

45
        public event AsyncEventHandler<RoutableEventData> OnActionAsync;
46

47
        /// <summary>
48
        /// Event raised when logging.
49
        /// </summary>
50
        public event EventHandler<Log> OnLog;
51

52
        /// <summary>
53
        /// Sets up the component.
54
        /// </summary>
55
        public void Setup()
56
        {
6✔
57
            ftp = new FtpClient(ftpSettings, webRequestUtility);
6✔
58
            poller = new Timer(ftpSettings.PollTime);
6✔
59
            poller.Elapsed += Poller_Elapsed;
6✔
60
            poller.AutoReset = true;
6✔
61
            ftp.OnDownloadFile += Ftp_OnDownloadFile;
6✔
62
            ftp.OnLog += Ftp_OnLog;
6✔
63
            ftp.OnError += Ftp_OnError;
6✔
64
            webRequestUtility.OnLog += WebRequestUtility_OnLog;
6✔
65
        }
6✔
66

67
        /// <summary>
68
        /// Event triggered when timer elapses.
69
        /// </summary>
70
        /// <param name="sender">Object sending the event.</param>
71
        /// <param name="e">Elapsed arguments.</param>
72
        private void Poller_Elapsed(object sender, ElapsedEventArgs e)
73
        {
44✔
74
            if (!_isStopping)
44✔
75
            {
42✔
76
                ftp.Poll();
42✔
77
            }
41✔
78
            else
79
            {
2✔
80
                poller.Stop();
2✔
81
            }
2✔
82
        }
43✔
83

84
        /// <summary>
85
        /// Logs an error event.
86
        /// </summary>
87
        /// <param name="sender">Object sending the event.</param>
88
        /// <param name="e">Exception being raised.</param>
89
        private void Ftp_OnError(object sender, Exception e)
90
        {
45✔
91
            OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Error, Resources.ERROR_FTPPROCESSING, e));
45!
92
        }
45✔
93

94
        /// <summary>
95
        /// Event raised when logging.
96
        /// </summary>
97
        /// <param name="sender">Object sending</param>
98
        /// <param name="e">Event message.</param>
99
        private void Ftp_OnLog(object sender, string e)
100
        {
3✔
101
            OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Information, e));
3✔
102
        }
3✔
103

104
        /// <summary>
105
        /// Event raised when file is downloaded.
106
        /// </summary>
107
        /// <param name="sender">Object sending the event.</param>
108
        /// <param name="e">Message to route.</param>
109
        private void Ftp_OnDownloadFile(object sender, Routable e)
110
        {
3✔
111
            OnActionAsync?.Invoke(this, new RoutableEventData(e, new CancellationToken()));
3✔
112
        }
3✔
113

114
        public async Task StartAsync(CancellationToken cancellationToken)
115
        {
5✔
116
            if (!cancellationToken.IsCancellationRequested)
5✔
117
            {
5✔
118
                ftp.Poll();
5✔
119
                poller.Start();
5✔
120
            }
5✔
121

122
            await Task.CompletedTask;
5✔
123
        }
5✔
124

125
        public async Task StopAsync(CancellationToken cancellationToken)
126
        {
4✔
127
            _isStopping = true;
4✔
128
            poller.AutoReset = false;
4✔
129
            poller.Stop();
4✔
130
            poller.Enabled = false;
4✔
131
            await Task.CompletedTask;
4✔
132
        }
4✔
133

134
        private void WebRequestUtility_OnLog(object sender, string e)
135
        {
1✔
136
            OnLog?.Invoke(this, new Log(Microsoft.Extensions.Logging.LogLevel.Information, e));
1!
137
        }
1✔
138
    }
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc