public DocumentDownloadTests() { _requestID = new Guid("455120CE-78D7-45DA-8A22-A93900E3B774"); _dataPartnerDataMartID = new Guid("FB62CB4F-2F48-4DD7-B40D-A73D00DBA196"); //_analysisDataMartID = new Guid("FE0AD3E6-DBAE-40CB-9EC3-A8B00089D3E1"); _inputFilesFolder = @"C:\work\DR\" + _dataPartnerDataMartID.ToString("D"); if (!Directory.Exists(_inputFilesFolder)) { logger.Debug($"Input files folder does not exist, creating: { _inputFilesFolder }"); Directory.CreateDirectory(_inputFilesFolder); } string[] existingFiles = Directory.GetFiles(_inputFilesFolder); if (existingFiles.Length > 0) { logger.Debug($"Input files folder has existing files, deleting { existingFiles.Length } files."); for (int i = 0; i < existingFiles.Length; i++) { File.Delete(existingFiles[i]); } } logger.Debug("Creating network setting: Url=\"https://api-pmnuat.popmednet.org\", Username=\"\", Password=\"\""); _networkSetting = new DataMart.Lib.NetWorkSetting { NetworkName = "PMN UAT", HubWebServiceUrl = "https://api-pmnuat.popmednet.org", Username = "******", EncryptedPassword = "******" }; }
public HttpClientEx(Lpp.Dns.DataMart.Lib.NetWorkSetting ns, System.Security.Cryptography.X509Certificates.X509Certificate2 cert) { _NetworkSetting = ns; if (cert == null) { this._Client = new HttpClient() { Timeout = new TimeSpan(0, 10, 0) }; } else { var handler = new WebRequestHandler { ClientCertificateOptions = ClientCertificateOption.Manual, UseDefaultCredentials = false }; handler.ClientCertificates.Add(cert); this._Client = new HttpClient(handler) { Timeout = new TimeSpan(0, 10, 0) }; } System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11; var metadata = new DMCMetadata { DMCFileVersion = _FileVersion, DMCProductVersion = _ProductVersion }; var creds = Crypto.EncryptStringAES(string.Format("{0}:{1}", _NetworkSetting.Username, _NetworkSetting.DecryptedPassword), "PopMedNet Authorization", _NetworkSetting.EncryptionSalt); this._Credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(creds + ":" + "" + ":" + JsonConvert.SerializeObject(metadata))); this._Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("PopMedNet", _Credentials); this._Host = ns.HubWebServiceUrl.TrimEnd("/".ToCharArray()); }
public DocumentConcurrentUploadTests() { //string username = "******"; //string password = "******"; //logger.Debug($"Creating network setting: Url=\"https://api-pmndruat.popmednet.org\", Username=\"{username}\", Password=\"{password}\""); //_networkSetting = new DataMart.Lib.NetWorkSetting //{ // NetworkName = "PMN-DR UAT", // HubWebServiceUrl = "https://api-pmndruat.popmednet.org", // Username = username, // EncryptedPassword = password //}; string username = "******"; string password = "******"; logger.Debug($"Creating network setting: Url=\"http://localhost:14586\", Username=\"{username}\", Password=\"{password}\""); _networkSetting = new DataMart.Lib.NetWorkSetting { NetworkName = "Local Dev", HubWebServiceUrl = "http://localhost:14586", Username = username, EncryptedPassword = password }; }
static List <string> CreateTestFiles(string baseCacheFolderPath, DataMart.Lib.NetWorkSetting networkSetting) { if (!Directory.Exists(baseCacheFolderPath)) { Directory.CreateDirectory(baseCacheFolderPath); } if (!Directory.Exists(Path.Combine(baseCacheFolderPath, networkSetting.NetworkId.ToString()))) { Directory.CreateDirectory(Path.Combine(baseCacheFolderPath, networkSetting.NetworkId.ToString())); } if (!Directory.Exists(Path.Combine(baseCacheFolderPath, networkSetting.NetworkId.ToString(), networkSetting.DataMartList[0].DataMartId.ToString("D")))) { Directory.CreateDirectory(Path.Combine(baseCacheFolderPath, networkSetting.NetworkId.ToString(), networkSetting.DataMartList[0].DataMartId.ToString("D"))); } List <string> createdTestFiles = new List <string>(20); //create some fake cache files for (int i = 0; i < 3; i++) { Guid requestID = Guid.NewGuid(); string requestCacheFolder = Path.Combine(baseCacheFolderPath, networkSetting.NetworkId.ToString(), networkSetting.DataMartList[0].DataMartId.ToString("D"), requestID.ToString("D")); if (!Directory.Exists(requestCacheFolder)) { Directory.CreateDirectory(requestCacheFolder); } Guid fileID = Guid.NewGuid(); string filePath = Path.Combine(requestCacheFolder, string.Format("{0:D}.meta", fileID)); using (var fs = File.CreateText(filePath)) { fs.Close(); } createdTestFiles.Add(filePath); //alter the file time to be older than the cache duration File.SetCreationTimeUtc(filePath, DateTime.UtcNow.AddDays(-2)); File.SetLastWriteTime(filePath, DateTime.UtcNow.AddDays(-2)); filePath = Path.Combine(requestCacheFolder, string.Format("{0:D}.data", fileID)); using (var fs = File.CreateText(filePath)) { fs.Close(); } createdTestFiles.Add(filePath); File.SetCreationTimeUtc(filePath, DateTime.UtcNow.AddDays(-2)); File.SetLastWriteTime(filePath, DateTime.UtcNow.AddDays(-2)); } return(createdTestFiles); }
public void ShouldDeleteExpiredCachedFiles() { //initialize a fake datamart setting var networkSetting = new DataMart.Lib.NetWorkSetting { NetworkId = 99, NetworkName = "Cache Retention Test", DataMartList = new List <DataMart.Lib.DataMartDescription> { new DataMart.Lib.DataMartDescription { DataMartId = Guid.Parse("6C793581-BC1D-4B3B-8D0B-DA527D9CB00B"), DataMartName = "Cache Test DataMart", OrganizationId = "F2076C32-A86C-4271-AB19-E076FF0808A5", EnableResponseCaching = true, DaysToRetainCacheItems = 1 } } }; DeleteExistingCachedRequests(Path.Combine(BaseCacheFolderPath, networkSetting.NetworkId.ToString(), networkSetting.DataMartList[0].DataMartId.ToString("D"))); List <string> createdTestFiles = CreateTestFiles(BaseCacheFolderPath, networkSetting); //initialize cache retention service var retentionService = new Lib.Caching.CacheRetentionService(BaseCacheFolderPath, 1); retentionService.RegisterNetwork(networkSetting); //wait longer than the cache timer System.Threading.Thread.Sleep(Convert.ToInt32(TimeSpan.FromMinutes(1.25f).TotalMilliseconds)); //confirm that the cache removed the files on initialization of the network. foreach (string path in createdTestFiles) { Assert.IsTrue(File.Exists(path) == false, "File was not deleted on cache retention serice network initialization: " + path); } //create some new test files and make sure they get cleaned up by timer System.Threading.Thread.Sleep(Convert.ToInt32(TimeSpan.FromMinutes(1.25f).TotalMilliseconds)); createdTestFiles = CreateTestFiles(BaseCacheFolderPath, networkSetting); System.Threading.Thread.Sleep(Convert.ToInt32(TimeSpan.FromMinutes(1.25f).TotalMilliseconds)); //confirm that the cache removed the files on initialization of the network. foreach (string path in createdTestFiles) { Assert.IsTrue(File.Exists(path) == false, "File was not deleted on cache retention serice network timer elapse: " + path); } }