public void Setup()
 {
     streams         = new List <StreamReader>();
     fileProcessor   = new FileProcessor(streams);
     yesterdayFolder = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
     yesterdayFile   = DateTime.Now.AddDays(-1).ToString("yy-MM-dd");
     originalFile    = $@"C:\Users\Gabriel\Documents\Top-Level\{yesterdayFolder}\{yesterdayFile}-0.0.0.0..csv";
     details         = new CurlDetails();
 }
Beispiel #2
0
 public BusinessLogic(ILogger logger, IScriptProcessor scriptProcessor, IFileProcessor fileProcessor, IEmailProcessor emailProcessor, IDatabaseLogic databaseLogic)
 {
     curlDetails          = new CurlDetails();
     this.logger          = logger;
     this.scriptProcessor = scriptProcessor;
     this.fileProcessor   = fileProcessor;
     this.emailProcessor  = emailProcessor;
     this.databaseLogic   = databaseLogic;
 }
Beispiel #3
0
        public static List <string> GetNetworkYesterdayFiles(CurlDetails details)
        {
            var files = new List <string>();

            if (!details.SiteNumbers.Any())
            {
                return(files);
            }

            files.AddRange(details.SiteNumbers.Select(siteNumber => Path.Combine(UncPaths[1], $"{siteNumber}", $"{siteNumber}--{details.Yesterday:yyyy-MM-dd}" + ".csv")));

            return(files);
        }
Beispiel #4
0
        public HttpResponseHeaders GetSessionId(CurlDetails details)
        {
            var handler = new HttpClientHandler
            {
                ClientCertificateOptions = ClientCertificateOption.Automatic
            };

            using (var httpClient = new HttpClient(handler))
                using (var request = new HttpRequestMessage(new HttpMethod("POST"), details.MainUrl))
                {
                    request.Headers.TryAddWithoutValidation("X-Application", "3rdParty");
                    var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{details.Username}:{details.Password}"));
                    request.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);
                    var response = httpClient.SendAsync(request);
                    return(response.Result.Headers);
                }
        }
Beispiel #5
0
        private static StreamReader StartProcess(CurlDetails details, string specificUrl)
        {
            using (var process = new Process())
            {
                process.StartInfo.Domain                 = details.Domain;
                process.StartInfo.FileName               = details.CurlApplication;
                process.StartInfo.Verb                   = "runas";
                process.StartInfo.Arguments              = "/c " + details.GetCommand(specificUrl);
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.Start();

                process.WaitForExit(Constants.TIME_OUT);
                return(process.StandardOutput);
            }
        }
Beispiel #6
0
        public bool ConnectToFs01(CurlDetails details)
        {
            var isUpdated          = false;
            var username           = ConfigurationManager.AppSettings["FS01UN"];
            var password           = ConfigurationManager.AppSettings["FS01PS"];
            var decrypted          = encryptionProcessor.Decrypt(password, 1);
            var networkCredentials = new NetworkCredential(username, decrypted, details.Domain);
            var netCache           = new CredentialCache {
                { "\\FS01", 80, "Basic", networkCredentials }
            };
            var credential = netCache.GetCredential("\\FS01", 80, "Basic");

            if (credential != null)
            {
                var ping  = new Ping();
                var reply = ping.Send("192.168.10.150", 100);
                if (reply?.Status == IPStatus.Success)
                {
                    isUpdated = true;
                }
            }

            return(isUpdated);
        }
Beispiel #7
0
 public StreamReader RequestFile(CurlDetails details)
 {
     return(StartProcess(details, details.FileUrl));
 }
Beispiel #8
0
 public StreamReader GetDomains(CurlDetails details)
 {
     return(StartProcess(details, details.DomainUrl));
 }
 public BusinessLogic()
 {
     databaseLogic = new DatabaseLogic();
     encryptionProcessor = new Processor();
     curlDetails = new CurlDetails();
 }
Beispiel #10
0
 public static string SetAttemptText(CurlDetails details) =>
 "1x attempt to download file " +
 $"for '{details.DomainId}' domain " +
 $"for '{details.Yesterday:D}' " +
 $"done on '{details.Today:D}' " +
 $"at '{details.Today:HH:mm}'." +
Beispiel #11
0
 public static string GetAttemptsFilename(CurlDetails details) =>
 Path.Combine(ROOT_PATH, $"{details.Directory.Name}", $"{details.Yesterday:yy-MM-dd}-{details.DomainId} attempts.txt");