public void SetFetchEngineProcedureTest() { string[] Expected; db.TruncateTables(); DateTime TIME_BEFORE_INSERTING = DateTime.UtcNow; Thread.Sleep(time); db.SetFetchEngine("Fetch1"); Thread.Sleep(time); DateTime TIME_MIDDLE_INSERTING = DateTime.UtcNow; Thread.Sleep(time); db.SetFetchEngine("Fetch2"); Thread.Sleep(time); DateTime TIME_AFTER_INSERTING = DateTime.UtcNow; Thread.Sleep(time); //STEP 1 var Sources = db.GetFetchEngine(TIME_AFTER_INSERTING).ToArray(); Expected = new string[] { "Fetch1", "Fetch2" }; Assert.AreEqual(1, Sources.Length); foreach (var item in Sources) { Assert.IsTrue(Expected.Contains(item.FullClrTypeName)); } //STEP 2 Sources = db.GetFetchEngine(TIME_MIDDLE_INSERTING).ToArray(); Expected = new string[] { "Fetch1" }; Assert.AreEqual(1, Sources.Length); foreach (var item in Sources) { Assert.IsTrue(Expected.Contains(item.FullClrTypeName)); } //STEP 3 Sources = db.GetFetchEngine(TIME_BEFORE_INSERTING).ToArray(); Expected = new string[] { }; Assert.AreEqual(0, Sources.Length); }
/// <summary>Returns the ExtendedConfiguration for the time specifed or null if time is before first timestamp in configuration database</summary> /// <param name="utcTime">UTC time to fetch the configuration for or DateTime.MaxValue for latest timestamp </param> /// <returns>ExtendedConfiguration object or null</returns> public ExtendedConfiguration GetConfiguration(DateTime utcTime) { using (FetchConfigurationDataClassesDataContext db = new FetchConfigurationDataClassesDataContext(connectionString)) { if (utcTime == DateTime.MaxValue) { utcTime = (DateTime)db.GetLatestTimeStamp().First().TimeStamp; } else if (utcTime < db.GetFirstTimeStamp().First().TimeStamp) { return(null); } List <ExtendedDataSourceDefinition> dataSourcesList = new List <ExtendedDataSourceDefinition>(); Dictionary <string, VariableDefinition> supportedVars = new Dictionary <string, VariableDefinition>(); var dataSources = db.GetDataSources(utcTime); var dsVariables = db.GetEnvVariables().ToArray(); foreach (var ds in dataSources) { var mapping = db.GetMapping(utcTime, ds.Name).ToArray(); var providedVars = mapping.Where(mp => mp.IsOutbound != null && (bool)mp.IsOutbound).Select(mp => mp.FetchVariableName).ToArray(); ExtendedDataSourceDefinition dsd = new ExtendedDataSourceDefinition((ushort)ds.ID, ds.Name, ds.Description, ds.Copyright, ds.Uri, ds.FullClrTypeName, providedVars, (ds.RemoteName != null) ? ds.Uri : string.Empty, mapping.ToDictionary(map => map.FetchVariableName, map => map.DataVariableName), ds.RemoteName, (ushort)(ds.RemoteID == null ? -1 : ds.RemoteID)); dataSourcesList.Add(dsd); foreach (var envVar in providedVars) { if (!supportedVars.ContainsKey(envVar)) { var v = dsVariables.Where(dsv => dsv.DisplayName == envVar).First(); supportedVars[envVar] = new VariableDefinition(v.DisplayName, v.Units, v.Description); } } } return(new ExtendedConfiguration(utcTime, dataSourcesList.ToArray(), supportedVars.Values.ToArray()) { FetchEngineTypeName = db.GetFetchEngine(utcTime).First().FullClrTypeName }); } }