/// <summary>
        /// Generate URL for MetOffice data based on region and climate type.
        /// </summary>
        /// <param name="region">Name of region to be downloaded</param>
        /// <param name="climateType">Climate type that needs to be downloaded</param>
        /// <returns>URL string of the data</returns>
        public static string getWebURL(Region region, ClimateType climateType)
        {
            string climateTypeURL = FileDownloadHelper.getTypeURLPart(climateType);
            string filename       = FileDownloadHelper.getSiteFileName(region);

            return(String.Concat(baseURL, "/" + climateTypeURL, "/date", "/" + filename));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reset table WeatherFileDownload to default values.
        /// </summary>
        /// <returns>Status of table reset</returns>
        public bool ResetFileDownloadTable()
        {
            bool isReset = false;

            try
            {
                connection.DeleteAll <WeatherFileDownloadEntity>();

                foreach (Region region in Enum.GetValues(typeof(Region)))
                {
                    foreach (ClimateType ct in Enum.GetValues(typeof(ClimateType)))
                    {
                        WeatherFileDownloadEntity wfd = new WeatherFileDownloadEntity()
                        {
                            Region      = region,
                            ClimateType = ct,
                            TimeStamp   = DateTime.Now.AddDays(-50),
                            Filename    = FileDownloadHelper.getDBFileName(ct, region)
                        };

                        connection.Insert(wfd);
                    }
                }

                isReset = true;

                Log.Information("File download table is reset");
            }
            catch (Exception e) {
                Log.Error(e, " : error");
            }

            return(isReset);
        }
        /// <summary>
        /// Download the climate file based on region and climate type
        /// </summary>
        /// <param name="region">Name of region to be downloaded</param>
        /// <param name="climateType">Climate type that needs to be downloaded</param>
        /// <returns>Download status</returns>
        public static bool Download(Region region, ClimateType climateType)
        {
            string URL          = getWebURL(region, climateType);
            bool   isDownloaded = false;
            string txtData      = String.Empty;

            try
            {
                using (var webClient = new WebClient())
                {
                    txtData = webClient.DownloadString(URL);
                }

                filename = FileDownloadHelper.getDBFileName(climateType, region);
                File.WriteAllText(filepath + filename, txtData);

                Log.Information($"{filename} got downloaded");
            }
            catch (Exception e)
            {
                Log.Error(e, " : error");
            }

            if (txtData != String.Empty)
            {
                isDownloaded = true;
            }

            return(isDownloaded);
        }
Exemplo n.º 4
0
        public async Task <ApiResponse <DownloadAttachmentResponse> > DownloadAttachmentAsync(DownloadAttachmentRequest request)
        {
            var downloadResponse =
                new ApiResponse <DownloadAttachmentResponse>(new DownloadAttachmentResponse())
            {
                Body =
                {
                    LoanId            = request.LoanId,
                    EncompassDocument = request.EncompassDocument,
                    DownloadFullPath  = request.DownloadFullPath
                }
            };

            try
            {
                var getAttachmentUrl = await PullAttachmentDownloadUrlAsync(new GetAttachmentUrlRequest
                {
                    AccessToken  = request.AccessToken,
                    AttachmentId = request.EncompassDocument.DocumentId,
                    LoanId       = request.LoanId
                }).ConfigureAwait(false);

                if (!getAttachmentUrl.StatusCode.IsSuccessStatusCode())
                {
                    downloadResponse.Body.IsSuccessBit    = false;
                    downloadResponse.Body.FailureResponse = getAttachmentUrl.Body.FailureResponse;
                    return(downloadResponse);
                }

                var mediarUrl = getAttachmentUrl.Body.SuccessResponse.MediaUrl;
                _httpClient.DefaultRequestHeaders.Clear();
                _httpClient.DefaultRequestHeaders.Add(ConstantString.AuthorizationKey,
                                                      string.Format(ConstantString.AuthorizationValue, request.AccessToken));

                var fileResponse = await FileDownloadHelper.DownloadFileAsync(_httpClient, mediarUrl, request.DownloadFullPath).ConfigureAwait(false);

                downloadResponse.Body.MediaUrl = mediarUrl;
                downloadResponse.StatusCode    = fileResponse.StatusCode;
                downloadResponse.Headers       = fileResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString());

                if (!fileResponse.StatusCode.IsSuccessStatusCode())
                {
                    downloadResponse.Body.IsSuccessBit    = false;
                    downloadResponse.Body.FailureResponse = fileResponse.Body.ErrorResponse;
                }
                else
                {
                    downloadResponse.Body.IsSuccessBit = true;
                }
            }
            catch (Exception ex)
            {
                downloadResponse.Body.IsSuccessBit = false;
                var result = JsonConvert.SerializeObject(new { message = JsonConvert.SerializeObject(ex.Message), stackTrace = ex.StackTrace });
                downloadResponse.Body.FailureResponse.Details   = result;
                downloadResponse.Body.FailureResponse.ErrorCode = HttpStatusCode.InternalServerError.ToString();
            }

            return(downloadResponse);
        }
Exemplo n.º 5
0
        public void CheckFileDownloaded()
        {
            if (!FileDownloadHelper.CheckFileDownloaded("XBRL"))
            {
                Assert.Fail("File not Downloaded");
            }

            SeleniumDriver.driver.Quit();
            SeleniumDriver.driver.Dispose();
        }
Exemplo n.º 6
0
        public void Are_download_tokens_unique()
        {
            // Arrange
            var helper = new FileDownloadHelper(null);

            // Act
            var t1 = helper.CreateDownloadToken();
            var t2 = helper.CreateDownloadToken();

            // Assert
            t1.Should().NotBe(t2);
        }
Exemplo n.º 7
0
        public void Get_default_token_expiry_time_if_no_setting_is_available()
        {
            // Arrange
            var settings          = new CmiSettings();
            var defaultExpiryTime = 10;
            var helper            = new FileDownloadHelper(settings);

            // Act
            var result = helper.GetConfigValueTokenValidTime();

            // Assert
            result.Should().Be(defaultExpiryTime);
        }
Exemplo n.º 8
0
        public void Get_correct_configured_token_expiry_time()
        {
            // Arrange
            var settings = new CmiSettings {
                ["tokenValidTime"] = "123"
            };
            var helper = new FileDownloadHelper(settings);

            // Act
            var result = helper.GetConfigValueTokenValidTime();

            // Assert
            result.Should().Be(123);
        }
Exemplo n.º 9
0
        public void CreateReport()
        {
            GridHelper.IframeInContainerId = "adminModal";

            FileDownloadHelper.DownloadEmptyTempletAndUpdate();

            FileDownloadHelper.CheckTempletsList();

            FileDownloadHelper.DeleteTemplet();

            FileDownloadHelper.DownloadReport();

            FileDownloadHelper.UploadEditedExcelReport();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Reset entire database and Load data
        /// </summary>
        public static bool InitialLoad()
        {
            bool      isLoaded = false;
            WeatherDB wdb      = new WeatherDB();

            //Truncate tables
            wdb.TruncateTable("WeatherFileDownload");
            wdb.TruncateTable("WeatherData");

            //Reset WeatherFileDownload table
            wdb.ResetFileDownloadTable();

            //Download all data
            WeatherDownload.DownloadAll();

            //Insert or update data
            foreach (Region region in Enum.GetValues(typeof(Region)))
            {
                foreach (ClimateType ct in Enum.GetValues(typeof(ClimateType)))
                {
                    var  filename     = FileDownloadHelper.getDBFileName(ct, region); // get filename from table based on region & climate
                    bool isLatestFile = WeatherParser.isLatestFile(filename, wdb);    // Verify if downloaded file is latest

                    if (isLatestFile)
                    {
                        var list = WeatherParser.FormatWeatherData(filename, ct, region); // Parse the latest file into WeatherDataEntity

                        Log.Information($"\n Loading  : {ct} , {region}");
                        var count = wdb.BulkInsertOrUpdate(list); //Insert or Update data

                        Log.Information(count["insert"] + " inserted");
                        Log.Information(count["update"] + " updated");
                        Log.Information(count["nochange"] + " no change");

                        wdb.UpdateFileTimeStamp(filename);
                    }
                }
            }

            return(isLoaded);
        }
Exemplo n.º 11
0
 void Awake()
 {
     fileDownloadHelper = GetComponent <FileDownloadHelper>();
 }