/// <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
                });
            }
        }
Example #2
0
        /// <summary>
        /// Process the request with a local data source specified by its definition
        /// </summary>
        /// <param name="request">A request to process</param>
        /// <param name="dataSource">A data source definition to process the request with</param>
        /// <returns></returns>
        private async Task <IFetchResponseWithProvenance> ProcessWithLocalDataSourceAsync(IFetchRequest request, ExtendedDataSourceDefinition dataSource)
        {
            if (dataSource.IsFederated)
            {
                throw new InvalidOperationException("Expected local data source definition, while passed definition is federated data source");
            }
            var instance = await DataSourceHandlerCache.GetInstanceAsync(dataSource.HandlerTypeName, dataSource.Uri);

            StandaloneRequestContext ctx = new StandaloneRequestContext(
                TranslateRequestIntoDsNamings(request, dataSource),
                this,
                dataSource.DsToEnvMapping,
                instance.Storage,
                dataSource.ID);
            var values = await instance.Handler.ProcessRequestAsync(ctx);

            var uncertainty = ctx.ReportUncertainty();

            if (uncertainty == null)
            {
                uncertainty = ArrayHelper.GetConstantArray <double>(request.Domain.GetDataArrayShape(), Double.MaxValue);
            }
            return(new FetchResponseWithProvenance(request, values, uncertainty,
                                                   ArrayHelper.GetConstantArray <ushort>(request.Domain.GetDataArrayShape(), dataSource.ID)));
        }
Example #3
0
        /// <summary>
        /// Process the request with federated data source specified by its definition
        /// </summary>
        /// <param name="request">A request to process</param>
        /// <param name="ds">A data source definition to process the request with</param>
        /// <returns></returns>
        private async Task <IFetchResponseWithProvenance> ProcessWithFederatedDataSourceAsync(IFetchRequest request, ExtendedDataSourceDefinition ds)
        {
            if (!ds.IsFederated)
            {
                throw new InvalidOperationException("Expected federated data source definition, while passed definition is local data source");
            }
            var res = await PerformRemoteRequestAsync(ds.Uri, new FetchRequest(
                                                          ds.EnvToDsMapping[request.EnvironmentVariableName], //using remove env names
                                                          request.Domain,
                                                          request.ReproducibilityTimestamp,
                                                          new string[] { ds.RemoteDataSourceName } //using remote ds name
                                                          ));

            return(new FetchResponseWithProvenance(request,// note here, that we don't convert env var names back, we simply take the initial request and append it with the result arrays
                                                   res.Values,
                                                   res.Uncertainty,
                                                   ArrayHelper.GetConstantArray <ushort>(request.Domain.GetDataArrayShape(), ds.ID)));
        }
Example #4
0
 /// <summary>
 /// Process the request with a data source specified by its definition
 /// </summary>
 /// <param name="request">A request to process</param>
 /// <param name="dataSource">A data source definition to process the request with</param>
 /// <returns></returns>
 private async Task <IFetchResponseWithProvenance> ProcessWithDataSourceAsync(IFetchRequest request, ExtendedDataSourceDefinition dataSource)
 {
     traceSource.TraceEvent(TraceEventType.Information, 7, string.Format("One data source {0} serves the request", dataSource.Name));
     if (!dataSource.IsFederated) //local
     {
         return(await ProcessWithLocalDataSourceAsync(request, dataSource));
     }
     else //federated
     {
         return(await ProcessWithFederatedDataSourceAsync(request, dataSource));
     }
 }
Example #5
0
        private static IFetchRequest TranslateRequestIntoDsNamings(IFetchRequest request, ExtendedDataSourceDefinition dataSource)
        {
            string dsName;

            if (dataSource.EnvToDsMapping.TryGetValue(request.EnvironmentVariableName, out dsName))
            {
                return(new FetchRequest(dsName, request.Domain, request.ReproducibilityTimestamp, request.ParticularDataSource));
            }
            else
            {
                return(request);
            }
        }