Example #1
0
        public void SetEnvVariableUnitsTest()
        {
            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.NCEPReanalysisRegularGridDataSource, NCEPReanalysisDataSource",
                "msds:az?name=ReanalysisRegular&DefaultEndpointsProtocol=http&AccountName=fetch&AccountKey=1Y0EOrnCX6ULY8c3iMHg9rrul2BWbPHKsHUceZ7SSh+ShM/q9K0ml49gQm+PE7G7i7zCvrpuT",
                null, null);
            db.AddVariable("MyVariable", "MyDescription", "MyUnits");
            Thread.Sleep(time);
            db.SetMapping("NCEP/NCAR Reanalysis 1 (regular grid)", "MyVariable", "TestDataSourceVariable", true, true);


            var variable = db.GetEnvVariables(/*DateTime.UtcNow*/).Where(x => x.DisplayName == "MyVariable").ToList();

            Assert.AreEqual(variable.Count, 1);
            Assert.AreEqual(variable[0].Units, "MyUnits");


            db.SetEnvVariableUnits("MyVariable", "NewMyUnits");

            var variable2 = db.GetEnvVariables(/*DateTime.UtcNow*/).Where(v => v.DisplayName == "MyVariable").ToList();

            Assert.AreEqual(variable2.Count, 1);
            Assert.AreEqual(variable2[0].Units, "NewMyUnits");
        }
Example #2
0
        public void VariableSet(string name, string description = null, string units = null)
        {
            var vars = db.GetEnvVariables().Select(x => x.DisplayName).ToList();

            if (vars.Contains(name))
            {
                var errs = new List <string>();
                try
                {
                    if (units != null)
                    {
                        db.SetEnvVariableUnits(name, units);
                    }
                }
                catch (Exception ex)
                {
                    errs.Add("Failed to alter units of a variable. Reason:\n" + ex.Message);
                }

                try
                {
                    if (description != null)
                    {
                        db.SetEnvVariableDescription(name, description);
                    }
                }
                catch (Exception ex)
                {
                    errs.Add("Failed to alter description of a variable. Reason:\n" + ex.Message);
                }

                if (errs.Count > 0)
                {
                    throw new Exception(errs.Aggregate((x, y) => x + "\n" + y));
                }
            }
            else
            {
                throw new ArgumentException("Variable with given name does not exists.");
            }
        }