Beispiel #1
0
        public static void CompareLinuxToVMSCGI(string payload,TimeInterval interval= TimeInterval.Irregular)
        {
            //Program.Main(new string[] { "--cgi=instant", "--payload=?"+payload });

            TimeSeriesDatabase db = TimeSeriesDatabase.InitDatabase(new Arguments(new string[]{}));
            WebTimeSeriesWriter c = new WebTimeSeriesWriter(db,interval,payload);
            var fn = FileUtility.GetTempFileName(".txt");
            Console.WriteLine("linux temp file:"+fn);
            c.Run(fn);

            TextFile tf = new TextFile(fn);
            tf.DeleteLines(0, 1);

            var fnhyd0 = FileUtility.GetTempFileName(".txt");
            Console.WriteLine("vms temp file:" + fnhyd0);
            string url = "https://www.usbr.gov/pn-bin/webarccsv.pl?";

            if( interval == TimeInterval.Irregular || interval == TimeInterval.Hourly)
                url = "https://www.usbr.gov/pn-bin/webdaycsv.pl?";
            Web.GetFile(url + payload, fnhyd0);

              var tf2 = new TextFile(fnhyd0);

              if (!CompareHydrometData(tf, tf2))
              {
              // do detailed comparision.
              var diff = TextFile.Compare(tf, tf2);

              if (diff.Length > 0)
              {
                  for (int i = 0; i < tf.Length; i++)
                  {
                      Console.WriteLine(tf[i]);
                  }
              }
              Assert.IsTrue(diff.Length == 0);
              }
        }
Beispiel #2
0
        private static string RunTest(string payload, TimeInterval interval)
        {
            Performance p = new Performance();
            TimeSeriesDatabase db = TimeSeriesDatabase.InitDatabase(new Arguments(new string[] { }));
            WebTimeSeriesWriter c = new WebTimeSeriesWriter(db,interval,payload);
            var fn = FileUtility.GetTempFileName(".txt");
            c.Run(fn);

            if (File.Exists(fn))
                p.Report(File.ReadAllLines(fn).Length + " lines read");
            else
                p.Report();
            return fn;
        }
Beispiel #3
0
        /// <summary>
        /// Examples:
        /// 
        /// --cgi=sites --propertyFilter=program:agrimet --json_required_properties=json_extra
        /// --cgi=instant
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var siteType = ""; // agrimet, hydromet (blank means all)
            var cgi = "";
            var json_property_stubs = "";
            var payload = "";
            var p = new OptionSet();
            var format = "json";
            var verbose = false;
            bool selfHost = false;
            var sqLiteDatabaseFileName = "";

            p.Add("server", x => selfHost = true);
            p.Add("cgi=", "required cgi to execute cgi=sites|series|instant|daily|wyreport", x => cgi = x);
            p.Add("json_property_stubs=", "comma separated list of properties (i.e. 'region,url,') to created empty stubs if neeed ",
                              x => json_property_stubs = x);
            p.Add("site-type=", "filter agrimet sites", x => siteType = BasicDBServer.SafeSqlLikeClauseLiteral(x));
            p.Add("payload=", "test query data for a CGI", x => payload = x);
            p.Add("format=", "format json(default) | csv ", x => format = x);
            p.Add("verbose", " get more details", x => verbose = true);
            p.Add("database", "filename for SQLite database", x => sqLiteDatabaseFileName = x);

            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            Database.InitDB(args);
            var db = Database.DB();

            if (selfHost)
            {
                try
                {
                    var serverUri = "http://localhost:8080";
                    var cfg = new HostConfiguration();
                    //cfg.RewriteLocalhost = false;
                    //c..fg.UrlReservations.CreateAutomatically=true;
                    var host = new Nancy.Hosting.Self.NancyHost(cfg, new Uri(serverUri));
                    //var host = new Nancy.Hosting.Self.NancyHost();
                    using (host)
                    {
                        host.Start();
                        Console.WriteLine("Running on " + serverUri);
                        Console.ReadLine();
                    }
                }
                catch (Exception nancyEx)
                {

                    Console.WriteLine(nancyEx.Message);
                }
                return;
            }

            if (cgi == "")
            {
                ShowHelp(p);
                return;
            }

            if (verbose)
            {
                Console.Write("Content-type: text/html\n\n");
                Logger.EnableLogger();
                Logger.WriteLine("verbose=true");
                Logger.WriteLine("payload = " + payload);
            }

            if (cgi == "inventory")
            {
                Console.Write("Content-Type: text/html\n\n");
                db.Inventory();
            }
            else if (cgi == "sites")
            {
                if (format == "json")
                {
                    JSONSites d = new JSONSites(db);
                    d.Execute(json_property_stubs.Split(','), siteType);
                }
                else if (format == "csv")
                {
                    SiteCsvTable c = new SiteCsvTable(db);
                    c.Execute(siteType);
                }
            }
            else if (cgi == "instant" || cgi == "daily")
            {
                try
                {
                    WebTimeSeriesWriter c = null;
                    if (cgi == "instant")
                        c = new WebTimeSeriesWriter(db, TimeInterval.Irregular, payload);

                    else
                    if (cgi == "daily")
                        c = new WebTimeSeriesWriter(db, TimeInterval.Daily, payload);

                    c.Run();
                }
                catch (Exception e)
                {
                    Logger.WriteLine("Error: " + e.Message);
                }
            }
            else if (cgi == "wyreport")
            {
                try
                {
                    WaterYearReport wy = new WaterYearReport(db, payload);
                    wy.Run();
                }
                catch (Exception e)
                {

                    Logger.WriteLine("Error: " + e.Message);
                }
            }
            else if (cgi == "site")
            {
                SiteInfoCGI si = new SiteInfoCGI(db);
                si.Run(payload);
            }
            else if (cgi == "test-perf-large")
            {
                var c = new HydrometGCITests();
                c.CGI_PerfTestLarge();

            }
            else if (cgi == "test-perf-small")
            {
                var c = new HydrometGCITests();
                c.CGI_PerfTestSmall();
            }
            else if (cgi == "dump")
            {
                var c = new HydrometGCITests();
                c.DumpTest();
            }
            else
            {
                Console.WriteLine("invalid cgi: " + cgi);
            }
        }