Exemple #1
0
        public void SetDataSourceUriProcedureTest()
        {
            db.TruncateTables();

            db.AddDataSource(
                "NCEP/NCAR Reanalysis 1 (regular grid)",
                "The NCEP/NCAR Reanalysis 1 project is using a state-of-the-art analysis/forecast system to perform data assimilation using past data from 1948 to the present",
                "NCEP Reanalysis data provided by the NOAA/OAR/ESRL PSD, Boulder, Colorado, USA, from their Web site at http://www.esrl.noaa.gov/psd/",
                "Microsoft.Research.Science.FetchClimate2.DataSources.NCEPReanalysisGaussGridDataSource, NCEPReanalysisDataSource",
                "123", null, null);

            Thread.Sleep(time);
            DateTime TIME_AFTER_INSERTING = DateTime.UtcNow;

            Thread.Sleep(time);
            db.SetDataSourceUri("NCEP/NCAR Reanalysis 1 (regular grid)", "TestUri");
            Thread.Sleep(time);
            DateTime TIME_AFTER_URI_SET = DateTime.UtcNow;

            var Sources = db.GetDataSources(TIME_AFTER_INSERTING).ToArray();
            GetDataSourcesResult ExpectedSource = new GetDataSourcesResult()
            {
                Name            = "NCEP/NCAR Reanalysis 1 (regular grid)",
                Description     = "The NCEP/NCAR Reanalysis 1 project is using a state-of-the-art analysis/forecast system to perform data assimilation using past data from 1948 to the present",
                Copyright       = "NCEP Reanalysis data provided by the NOAA/OAR/ESRL PSD, Boulder, Colorado, USA, from their Web site at http://www.esrl.noaa.gov/psd/",
                FullClrTypeName = "Microsoft.Research.Science.FetchClimate2.DataSources.NCEPReanalysisGaussGridDataSource, NCEPReanalysisDataSource",
                Uri             = "123"
            };

            Assert.AreEqual(ExpectedSource.Name, Sources[0].Name);
            Assert.AreEqual(ExpectedSource.Copyright, Sources[0].Copyright);
            Assert.AreEqual(ExpectedSource.Description, Sources[0].Description);
            Assert.AreEqual(ExpectedSource.FullClrTypeName, Sources[0].FullClrTypeName);
            Assert.AreEqual(ExpectedSource.Uri, Sources[0].Uri);


            Sources        = db.GetDataSources(TIME_AFTER_URI_SET).ToArray();
            ExpectedSource = new GetDataSourcesResult()
            {
                Name            = "NCEP/NCAR Reanalysis 1 (regular grid)",
                Description     = "The NCEP/NCAR Reanalysis 1 project is using a state-of-the-art analysis/forecast system to perform data assimilation using past data from 1948 to the present",
                Copyright       = "NCEP Reanalysis data provided by the NOAA/OAR/ESRL PSD, Boulder, Colorado, USA, from their Web site at http://www.esrl.noaa.gov/psd/",
                FullClrTypeName = "Microsoft.Research.Science.FetchClimate2.DataSources.NCEPReanalysisGaussGridDataSource, NCEPReanalysisDataSource",
                Uri             = "TestUri"
            };

            Assert.AreEqual(ExpectedSource.Name, Sources[0].Name);
            Assert.AreEqual(ExpectedSource.Copyright, Sources[0].Copyright);
            Assert.AreEqual(ExpectedSource.Description, Sources[0].Description);
            Assert.AreEqual(ExpectedSource.FullClrTypeName, Sources[0].FullClrTypeName);
            Assert.AreEqual(ExpectedSource.Uri, Sources[0].Uri);
        }
Exemple #2
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);
        }