Exemple #1
0
        public void DataSourceAdd(string name, string description, string handler = null, string remotename = null, string copyright = "",
                                  string uri = "", List <DataSourceMapping> addMapping = null, List <String> removeMapping           = null)
        {
            ushort?remoteID = null;
            string resolvedHandlerAssemblyQualifiedName = null;

            //if (string.IsNullOrEmpty(remotename) && !String.IsNullOrEmpty(handler))
            //    ExtractHandlerAssemblyAndTypeName(handler, out toLoad, out handlerType);

            if (!string.IsNullOrEmpty(remotename) && String.IsNullOrEmpty(handler)) //federated
            {
                IFetchConfiguration remoteConfig;
                try
                {
                    RemoteFetchClient client = new RemoteFetchClient(new Uri(uri));
                    remoteConfig = client.GetConfiguration(DateTime.MaxValue);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Failed to retrieve configuration of the remote service.\n Exception message: " + ex.Message);
                }
                if (!remoteConfig.DataSources.Any(ds => ds.Name == remotename))
                {
                    throw new ArgumentException("Data source with given name does not exist on the remote service.");
                }
                remoteID = remoteConfig.DataSources.Where(ds => ds.Name == remotename).FirstOrDefault().ID;
            }
            else if (string.IsNullOrEmpty(remotename) && !String.IsNullOrEmpty(handler))//local
            {
                AssemblyStore gac = null;
                if (isConnectedToCloud)
                {
                    gac = astore;
                }
                resolvedHandlerAssemblyQualifiedName = ExtractHandlerAssemblyAndTypeName(handler, gac);
            }
            else if (!string.IsNullOrEmpty(remotename) && !String.IsNullOrEmpty(handler))
            {
                throw new ArgumentException("Handler and remote name can not be specified simultaneously.");
            }

            var localDs = db.GetDataSources(DateTime.MaxValue).ToArray();

            if (localDs.All(x => x.Name != name))
            {
                db.AddDataSource(name, description, copyright, resolvedHandlerAssemblyQualifiedName, ParserHelper.AppendDataSetUriWithDimensions(uri), remoteID, remotename);
            }
            else
            {
                throw new ArgumentException("Data source with given name already exists.");
            }
            SetMappings(name, addMapping, null);
        }
Exemple #2
0
        /// <summary>
        /// Requests the remote FetchClimate (federated) to process the FetchRequest
        /// </summary>
        /// <param name="remoteServiceURI">The URI of the remote service</param>
        /// <param name="request">Request to perform</param>
        /// <returns></returns>
        public virtual async Task <IFetchResponseWithProvenance> PerformRemoteRequestAsync(string remoteServiceURI, IFetchRequest request)
        {
            RemoteFetchClient rfc = new RemoteFetchClient(new Uri(remoteServiceURI));
            var resultDs          = await rfc.FetchAsync(request);

            return(new FetchResponseWithProvenance(
                       request,
                       resultDs[RequestDataSetFormat.ValuesVariableName].GetData(),
                       resultDs[RequestDataSetFormat.UncertaintyVariableName].GetData(),
                       resultDs.Variables.Contains(RequestDataSetFormat.ProvenanceVariableName)
                    ? resultDs[RequestDataSetFormat.ProvenanceVariableName].GetData()
                    : null));
        }
Exemple #3
0
        public List <string> Mirror(string source)
        {
            IFetchConfiguration remoteConfig;

            try
            {
                RemoteFetchClient client = new RemoteFetchClient(new Uri(source));
                remoteConfig = client.GetConfiguration(DateTime.MaxValue);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to retrieve configuration of the remote service.\n Exception message: " + ex.Message);
            }
            var res = new List <string>();
            HashSet <string> varsToIgnore = new HashSet <string>();
            var localVars = db.GetEnvVariables().ToArray();
            var localDs   = db.GetDataSources(DateTime.MaxValue).ToArray();

            foreach (var i in remoteConfig.EnvironmentalVariables)
            {
                var mayBeLocal = localVars.FirstOrDefault(x => x.DisplayName == i.Name);
                if (mayBeLocal == null)
                {
                    try
                    {
                        db.AddVariable(i.Name, i.Description, i.Units);
                        res.Add("Added variable " + i.Name + " with description: \"" + i.Description + "\" and units: " + i.Units);
                    }
                    catch (Exception ex)
                    {
                        varsToIgnore.Add(i.Name);
                        res.Add("Failed to add variable " + i.Name + ". Mappings referring it will be ignored. \nException message: " + ex.Message);
                    }
                }
                else if (mayBeLocal.Description != i.Description || mayBeLocal.Units != i.Units)
                {
                    varsToIgnore.Add(i.Name);
                    res.Add("Variable " + i.Name + @" already exists, but its description and/or units don't match those of corresponding variable on the remote service. Therefore no new data sources will be bound to it.");
                }
            }

            foreach (var i in remoteConfig.DataSources)
            {
                if (localDs.All(x => x.Name != i.Name))
                {
                    try
                    {
                        db.AddDataSource(i.Name, i.Description, i.Copyright, null, source, i.ID, i.Name);
                        res.Add("Added data source " + i.Name + ".\nDescription:\t" + i.Description + "\nCopyright:\t" + i.Copyright);
                        foreach (var j in i.ProvidedVariables)
                        {
                            if (!varsToIgnore.Contains(j))
                            {
                                try
                                {
                                    db.SetMapping(i.Name, j, j, true, true);
                                    res.Add("Bound data source " + i.Name + " to variable " + j + ".");
                                }
                                catch (Exception ex)
                                {
                                    res.Add("Failed to bind data source " + i.Name + " to variable " + j + ".\nException message: " + ex.Message);
                                }
                            }
                            else
                            {
                                res.Add("Data source " + i.Name + " was not bound to variable " + j + " even though such mapping existed on the remote service.");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        res.Add("Failed to federate datasource " + i.Name + ".\nException message: " + ex.Message);
                    }
                }
                else
                {
                    res.Add("Data source " + i.Name + " already exists. Therefore no such data source will be federated nor would be added any mappings referring it.");
                }
            }

            return(res);
        }
Exemple #4
0
        public void DataSourceSet(string name, string handler         = null, string remotename = null, string uri = null, string copyright = null, string description = null,
                                  List <DataSourceMapping> addMapping = null, List <String> removeMapping = null)
        {
            var localDs = db.GetDataSources(DateTime.MaxValue).ToArray();

            if (localDs.All(x => x.Name != name))
            {
                throw new ArgumentException("Specified data source does not exist.");
            }

            ushort?remoteID = null;

            if (!String.IsNullOrEmpty(handler) && String.IsNullOrEmpty(remotename))
            {
                AssemblyStore gac = null;
                if (isConnectedToCloud)
                {
                    gac = new AssemblyStore(storageConnectionString);
                }
                var resolvedHandlerAssemblyQualifiedName = ExtractHandlerAssemblyAndTypeName(handler, gac);
                db.SetDataSourceProcessor(name, resolvedHandlerAssemblyQualifiedName, null, null);
            }
            else if (String.IsNullOrEmpty(handler) && !String.IsNullOrEmpty(remotename))
            {
                IFetchConfiguration remoteConfig;
                try
                {
                    RemoteFetchClient client = new RemoteFetchClient(new Uri(uri));
                    remoteConfig = client.GetConfiguration(DateTime.MaxValue);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Failed to retrieve configuration of the remote service.\n Exception message: " + ex.Message);
                }
                if (!remoteConfig.DataSources.Any(ds => ds.Name == remotename))
                {
                    throw new ArgumentException("Data source with given name does not exist on the remote service.");
                }
                remoteID = remoteConfig.DataSources.Where(ds => ds.Name == remotename).FirstOrDefault().ID;
                db.SetDataSourceProcessor(name, null, remoteID, remotename);
            }
            if (!string.IsNullOrEmpty(remotename) && !String.IsNullOrEmpty(handler))
            {
                throw new ArgumentException("Handler and remote name can not be specified simultaneously.");
            }

            if (!String.IsNullOrEmpty(uri))
            {
                db.SetDataSourceUri(name, ParserHelper.AppendDataSetUriWithDimensions(uri));
            }

            //if (isHidden != null)
            //    db.SetDataSourceHidden(name, isHidden);

            if (copyright != null)
            {
                db.SetDataSourceCopyright(name, copyright);
            }

            if (description != null)
            {
                db.SetDataSourceDescription(name, description);
            }

            SetMappings(name, addMapping, removeMapping);
        }