コード例 #1
0
        static void ConfigureWcfSendCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("send", (sendCmd) =>
            {
                sendCmd.Description          = "WcfRelay send command";
                var pathArgument             = sendCmd.Argument("path", "WcfRelay path");
                var connectionStringArgument = sendCmd.Argument("connectionString", "Relay ConnectionString");

                var numberOption           = sendCmd.Option(CommandStrings.NumberTemplate, CommandStrings.NumberDescription, CommandOptionType.SingleValue);
                var bindingOption          = sendCmd.Option(BindingOptionTemplate, BindingOptionDescription, CommandOptionType.SingleValue);
                var noClientAuthOption     = sendCmd.Option("--no-client-auth", "Skip client authentication", CommandOptionType.NoValue);
                var connectivityModeOption = sendCmd.Option(CommandStrings.ConnectivityModeTemplate, CommandStrings.ConnectivityModeDescription, CommandOptionType.SingleValue);
                var requestOption          = sendCmd.Option(CommandStrings.RequestTemplate, CommandStrings.RequestDescription, CommandOptionType.SingleValue);
                var requestDelayOption     = sendCmd.Option("-rd|--request-delay <delay>", "A TimeSpan indicating how long the listener should delay before responding to request", CommandOptionType.SingleValue);
                var openTimeoutOption      = sendCmd.Option("-ot|--open-timeout <timeout>", "A TimeSpan for configuring the Binding.OpenTimeout", CommandOptionType.SingleValue);
                var sendTimeoutOption      = sendCmd.Option("-st|--send-timeout <timeout>", "A TimeSpan for configuring the Binding.SendTimeout", CommandOptionType.SingleValue);
                var readTimeoutOption      = sendCmd.Option("-rt|--receive-timeout <timeout>", "A TimeSpan for configuring the Binding.ReceiveTimeout", CommandOptionType.SingleValue);
                var protocolOption         = sendCmd.AddSecurityProtocolOption();

                sendCmd.OnExecute(() =>
                {
                    ConfigureSecurityProtocol(protocolOption);

                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    string path             = pathArgument.Value ?? DefaultPath;
                    string request          = GetStringOption(requestOption, "Test Message Data");
                    if (string.IsNullOrEmpty(connectionString))
                    {
                        TraceMissingArgument(connectionStringArgument.Name);
                        sendCmd.ShowHelp();
                        return(1);
                    }

                    int number = GetIntOption(numberOption, 1);
                    var connectionStringBuilder       = new ServiceBusConnectionStringBuilder(connectionString);
                    Binding binding                   = GetBinding(bindingOption, noClientAuthOption, openTimeoutOption, sendTimeoutOption, readTimeoutOption);
                    ConnectivityMode connectivityMode = GetConnectivityMode(connectivityModeOption);
                    TimeSpan requestDelay             = requestDelayOption.HasValue() ? TimeSpan.Parse(requestDelayOption.Value()) : TimeSpan.Zero;
                    return(VerifySend(request, connectionStringBuilder, path, number, binding, noClientAuthOption.HasValue(), connectivityMode, requestDelay));
                });
            });
        }
コード例 #2
0
ファイル: HydrossSeries.cs プロジェクト: woohn/Pisces
        public override Series CreateScenario(TimeSeriesDatabaseDataSet.ScenarioRow scenario)
        {
            if (scenario.Name == ScenarioName)
            {
                return(this);
            }
            else
            {
                string fn = ConnectionStringUtility.GetFileName(scenario.Path, m_db.DataSource);
                Logger.WriteLine("Reading series from " + fn);
                var sr = m_db.GetNewSeriesRow(false);
                sr.ItemArray = SeriesCatalogRow.ItemArray;

                sr.ConnectionString = ConnectionStringUtility.Modify(sr.ConnectionString, "FileName", fn);
                Series s = new HydrossSeries(m_db, sr);
                s.ReadOnly     = true;
                s.ScenarioName = scenario.Name;
                return(s);
            }
        }
コード例 #3
0
ファイル: SpreadsheetGearSeries.cs プロジェクト: woohn/Pisces
        //public static SpreadsheetGearSeries ReadFromConnectionString(string connectionString,
        //    string dataPath)
        //{
        //    SpreadsheetGearSeries rval = CreateFromConnectionString(connectionString, dataPath);
        //    rval.Read();
        //    return rval;
        //}



        public static SpreadsheetGearSeries CreateFromConnectionString(string connectionString,
                                                                       string dataPath)
        {
            string fileName = ConnectionStringUtility.GetToken(connectionString, "FileName", "");

            if (!Path.IsPathRooted(fileName))
            {
                fileName = Path.Combine(dataPath, fileName);
            }
            SpreadsheetGearSeries rval = new SpreadsheetGearSeries(
                fileName,
                ConnectionStringUtility.GetToken(connectionString, "SheetName", ""),
                ConnectionStringUtility.GetToken(connectionString, "DateColumn", ""),
                ConnectionStringUtility.GetToken(connectionString, "ValueColumn", ""),
                ConnectionStringUtility.GetBoolean(connectionString, "IsWaterYearFormat", false),
                ConnectionStringUtility.GetToken(connectionString, "SiteColumn", ""),
                ConnectionStringUtility.GetToken(connectionString, "SiteFilter", "")
                );

            return(rval);
        }
コード例 #4
0
        private string GetScenarioFileName(TimeSeriesDatabaseDataSet.ScenarioRow scenario)
        {
            var rval         = m_filename;
            var pathFileName = ConnectionStringUtility.GetFileName(scenario.Path, m_db.Server.DataSource);

            if (File.Exists(pathFileName)) // filename specified in path
            {
                rval = pathFileName;
            }
            else
            { // derive filename from  ScenarioName
                var path = Path.GetDirectoryName(m_filename);
                var x    = Path.Combine(path, scenario.Name + ".rdf");
                if (File.Exists(x))
                {
                    rval = x;
                }
            }

            return(rval);
        }
コード例 #5
0
        private void CreateSeries(AccessDB mdb, string plantName, string dataType, int parentID)
        {
            string[] dTcfs  = { "QBPF", "QOUT", "FRCSPILL", "BYPSPILL" };
            string[] dTMW   = { "AVGEN", "SYSGEN", "SYSSURP", "SYSDP" };
            string[] dTksfd = { "ENDSTO", "ECC", "URC" };
            string[] dTfeet = { "ENDELEV", "ECCFT", "URCFT" };

            string units = "";

            if (dTcfs.Contains(dataType) == true)
            {
                units = "cfs";
            }
            else
            if (dTMW.Contains(dataType) == true)
            {
                units = "aMW";
            }
            else
            if (dTksfd.Contains(dataType) == true)
            {
                units = "ksfd";
            }
            else
            if (dTfeet.Contains(dataType) == true)
            {
                units = "feet";
            }
            else
            {
                Logger.WriteLine("Error: unsupported data type '" + dataType + "'");
            }
            string name      = plantName + " " + dataType + " " + units;
            string sheetName = plantName + " " + dataType;
            string cs        = "FileName=" + m_mdbFileName + ";PlantName=" + plantName + ";DataType=" + dataType; // connection string

            cs = ConnectionStringUtility.MakeFileNameRelative(cs, m_databasePath);
            seriesCatalog.AddSeriesCatalogRow(ID++, parentID, false, ID, "BpaHydsimSeriesAccess", name, sheetName, units,
                                              TimeInterval.Monthly.ToString(), "Parameter", "", "BpaHydsimSeriesAccess", cs, "", "", true);
        }
コード例 #6
0
ファイル: TextSeries.cs プロジェクト: ruo2012/Pisces
        /// <summary>
        /// checks LastWriteTime in connection string and compares to
        /// the FileName in the connection string to see if a update is possible and is needed
        /// </summary>
        /// <param name="s"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static bool CanUpdateFromFile(string connectionString, string dataPath)
        {
            string d        = ConnectionStringUtility.GetToken(connectionString, "LastWriteTime", "");
            var    fileName = ConnectionStringUtility.GetToken(connectionString, "FileName", "");

            if (!Path.IsPathRooted(fileName))
            {
                fileName = Path.Combine(dataPath, fileName);
            }

            DateTime t = DateTime.MinValue;

            if (!DateTime.TryParse(d, out t))
            {
                Logger.WriteLine("Update Error: Could not parse LastWriteTime in '" + connectionString + "'");
                return(false);
            }



            if (!File.Exists(fileName))
            {
                Logger.WriteLine("Update Error: File does not exist '" + fileName + "'");
                return(false);
            }

            DateTime fileTime = File.GetLastWriteTime(fileName);

            fileTime = Convert.ToDateTime(fileTime.ToString(Series.DateTimeFormatInstantaneous));

            bool rval = fileTime != t;

            if (!rval)
            {
                Logger.WriteLine("No update required");
            }

            return(rval);
        }
コード例 #7
0
        public void LoadTree()
        {
            m_db.SuspendTreeUpdates();
            var colNames = xls.ColumnNames("Run0");
            var sc       = m_db.GetSeriesCatalog();

            var root = m_db.AddFolder("URGWOM");
            var sr   = m_db.GetNewSeriesRow();
            int id   = sr.id;

            foreach (var item in colNames)
            {
                Series s = new UrgwomSeries(excelFilename, "Run0", item);
                s.ConnectionString = ConnectionStringUtility.MakeFileNameRelative(s.ConnectionString, m_db.DataSource);
                s.Name             = item;
                s.Parameter        = item;
                sc.AddSeriesCatalogRow(s, id, root.ID, "");
                id++;
            }

            m_db.Server.SaveTable(sc);
            m_db.ResumeTreeUpdates();
        }
コード例 #8
0
        private int GetScenarioNumber(TimeSeriesDatabaseDataSet.ScenarioRow scenario)
        {
            var sn = ConnectionStringUtility.GetIntFromConnectionString(scenario.Path, "ScenarioNumber");

            if (sn >= 0) // scenario number specified (use existing filename)
            {
                return(sn);
            }

            if (m_scenarioNumber >= 0 && m_db != null)
            {
                int idx = Array.IndexOf(m_db.GetScenarios().GetNames(), scenario.Name);
                if (idx >= 0)
                {
                    sn = idx + 1;
                }
            }
            else
            {
                sn = m_scenarioNumber;
            }
            return(sn);
        }
コード例 #9
0
        static void ConfigureWcfCreateCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("create", (createCmd) =>
            {
                createCmd.Description = "Create a WcfRelay";

                var pathArgument             = createCmd.Argument("path", "WcfRelay path");
                var connectionStringArgument = createCmd.Argument("connectionString", "Relay ConnectionString");

                var relayTypeOption = createCmd.Option(
                    "-t|--relaytype <relaytype>", "The RelayType (nettcp|http)", CommandOptionType.SingleValue);
                var requireClientAuthOption = createCmd.Option(
                    CommandStrings.RequiresClientAuthTemplate, CommandStrings.RequiresClientAuthDescription, CommandOptionType.SingleValue);
                var protocolOption = createCmd.AddSecurityProtocolOption();

                createCmd.OnExecute(async() =>
                {
                    ConfigureSecurityProtocol(protocolOption);
                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(pathArgument.Value))
                    {
                        TraceMissingArgument(string.IsNullOrEmpty(connectionString) ? connectionStringArgument.Name : pathArgument.Name);
                        createCmd.ShowHelp();
                        return(1);
                    }

                    var connectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
                    RelayTraceSource.TraceInfo($"Creating WcfRelay '{pathArgument.Value}' in {connectionStringBuilder.Endpoints.First().Host}...");
                    var relayDescription = new RelayDescription(pathArgument.Value, GetRelayType(relayTypeOption));
                    relayDescription.RequiresClientAuthorization = GetBoolOption(requireClientAuthOption, true);
                    var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
                    await namespaceManager.CreateRelayAsync(relayDescription);
                    RelayTraceSource.TraceInfo($"Creating WcfRelay '{pathArgument.Value}' in {connectionStringBuilder.Endpoints.First().Host} succeeded");
                    return(0);
                });
            });
        }
コード例 #10
0
        static void ConfigureWcfTestCommand(CommandLineApplication wcfCommand)
        {
            wcfCommand.RelayCommand("test", (testCmd) =>
            {
                testCmd.Description          = "WcfRelay tests";
                var connectionStringArgument = testCmd.Argument("connectionString", "Relay ConnectionString");
                var numberOption             = testCmd.Option(CommandStrings.NumberTemplate, CommandStrings.NumberDescription, CommandOptionType.SingleValue);
                var testNameOption           = testCmd.Option("-t|--tests", "A regex to pick which tests to run", CommandOptionType.SingleValue);

                testCmd.OnExecute(async() =>
                {
                    string connectionString = ConnectionStringUtility.ResolveConnectionString(connectionStringArgument);
                    if (string.IsNullOrEmpty(connectionString))
                    {
                        TraceMissingArgument(connectionStringArgument.Name);
                        testCmd.ShowHelp();
                        return(1);
                    }

                    int number = GetIntOption(numberOption, 1);
                    return(await RunWcfTestsAsync(connectionString, number, testNameOption.Value()));
                });
            });
        }
コード例 #11
0
 public UsgsGroundWaterLevelSeries(TimeSeriesDatabase db, Reclamation.TimeSeries.TimeSeriesDatabaseDataSet.SeriesCatalogRow sr)
     : base(db, sr)
 {
     m_site_no = ConnectionStringUtility.GetToken(ConnectionString, "site_no", "");
 }
コード例 #12
0
        /**********************************
        *
        * Create a tree file that is usable by pisces
        *
        * input :  riverware rdf file
        * output : comma seperated tree file.
        *
        *
        *  // example portion of input file.
        *  (this input file is using snapshots in riverware)
        *  -----------------------------------
        *  object_type: SnapShotObj
        *  object_name: Most Likely 2
        *  slot_name: Andrews Gage 12447390 at RM 3_5_Gage Outflow
        *  END_SLOT_PREAMBLE
        *  units: cfs
        *
        *  // example output.  There is no nesting of tree levels for now.
        *  RiverwareName,Description,RiverwareDataType,Level,Units
        *  Riverware Results,,,0,
        *  Yakima River at Parker PARW,Yakima River at Parker PARW,Gage Outflow,1,cfs
        *  Yakima River at Grandview,Yakima River at Grandview,Gage Inflow,1,cfs
        *  ...
        *
        **********************************/
        public static void AddRiverWareFileToDatabase(string rdfFilename, PiscesFolder parent,
                                                      TimeSeriesDatabase db)
        {
            Reclamation.Core.TextFile tf = new Reclamation.Core.TextFile(rdfFilename);

            #region notes

            /*
             * SnapShotStyle...
             * -------------------------------------
             * 2001-9-29 24:00
             * 2001-9-30 24:00
             * object_type: SnapShotObj
             * object_name: Most Likely 2     ### scernario name
             * slot_name: Andrews Gage 12447390 at RM 3_5_Gage Outflow   # object_name slotName are combined.
             * END_SLOT_PREAMBLE
             * units: cfs
             *
             * Regular Style ...
             * ---------------------------------------
             * END_COLUMN
             * END_SLOT
             * object_type: StreamGage
             * object_name: Yakima 202_0 at Easton EASW
             * slot_name: Gage Outflow
             * END_SLOT_PREAMBLE
             * units: cfs
             * scale: 1
             *
             */
            #endregion

            int          number_of_runs = LookupNumberOfRuns(tf);
            PiscesFolder folder         = parent;
            if (number_of_runs == 1)
            {
                folder = db.AddFolder(parent, Path.GetFileNameWithoutExtension(rdfFilename));
            }

            int sz = tf.Length;
            // object_type and object_name should occur on consecutive lines.
            int         index      = tf.IndexOfBoth("object_name:", "slot_name:", 0);
            var         objectList = new List <string>(); //list to avoid duplicates in tree
            Performance p1         = new Performance();
            Performance p2         = new Performance();
            p2.Pause();
            int counter = 0;

            db.SuspendTreeUpdates();
            var sc = db.GetSeriesCatalog();
            Dictionary <string, int> objTypeID = new Dictionary <string, int>();
            Dictionary <string, int> objNameID = new Dictionary <string, int>();
            while (index < sz && index > 0)
            {
                //slot_name: Andrews Gage 12447390 at RM 3_5_Gage Outflow
                string slot_name   = tf[index + 1].Substring(11); //Andrews Gage 12447390 at RM 3_5_Gage Outflow
                string object_type = tf[index - 1].Substring(13);
                string object_name = tf[index].Substring(13);
                string units       = tf[index + 3].Substring(6).Trim();

                string tag = object_name + ":" + slot_name;
                if (!objectList.Contains(tag))
                {
                    int scenarioNumber = -1;
                    if (number_of_runs > 1)
                    {
                        scenarioNumber = 1;
                    }

                    RiverWareSeries s;
                    if (object_type == "SnapShotObj")
                    {
                        s = new RiverWareSeries(rdfFilename, "", slot_name, scenarioNumber, true, units);
                    }
                    else
                    {
                        s = new RiverWareSeries(rdfFilename, object_name, slot_name, scenarioNumber, false, units);
                    }
                    s.Units            = units;
                    s.ConnectionString = ConnectionStringUtility.MakeFileNameRelative(s.ConnectionString, db.DataSource);
                    p2.Continue();


                    if (object_type.Contains("Reservoir"))
                    {
                        object_type = "Reservoir";
                    }
                    else if (object_type.Contains("Reach"))
                    {
                        object_type = "Reach";
                    }
                    else if (object_type.Contains("Diversion"))
                    {
                        object_type = "Diversion";
                    }
                    else if (object_type.Contains("Canal"))
                    {
                        object_type = "Canal";
                    }

                    int id = sc.NextID();
                    if (!sc.FolderExists(object_type, folder.ID))
                    {
                        objTypeID.Add(object_type, id);
                        sc.AddFolder(object_type, id, folder.ID);
                        id++;
                    }
                    if (!sc.FolderExists(object_name, objTypeID[object_type]))
                    {
                        objNameID.Add(object_name, id);
                        sc.AddFolder(object_name, id, objTypeID[object_type]);
                        id++;
                    }
                    sc.AddSeriesCatalogRow(s, id, objNameID[object_name], "");
                    objectList.Add(tag);
                }

                index = tf.IndexOfBoth("object_name:", "slot_name:", index + 2);
                counter++;
            }
            p1.Report("total");
            p2.Report("db.add()");
            //398.7732813 seconds elapsed. total
            //384.6792607 seconds elapsed. db.add()

            // disable tree refresh (doubles perf)
            // 255.9736646 seconds elapsed. total
            // 241.7702669 seconds elapsed. db.add()

            // implemented member ExternalDataSource
            //34.8756696 seconds elapsed. total
            //20.3753912 seconds elapsed. db.add()

            var convention = Reclamation.TimeSeries.RiverWare.ImportRiverWare.ScenarioConvention.Default;
            if (number_of_runs > 1) // Multiple runs.
            {                       // show dialog to allow water year naming or traces
                var dlg = new Reclamation.TimeSeries.RiverWare.ImportRiverWare();
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    convention = dlg.NamingConvention;
                }


                // Add Scenarios.
                var tblScen = db.GetScenarios();
                for (int i = 0; i < number_of_runs; i++)
                {
                    string name = "Run" + i;
                    if (convention == RiverWare.ImportRiverWare.ScenarioConvention.ByYear)
                    {
                        name = (dlg.FirstYear + i).ToString();
                    }
                    //string scenarioPath = ConnectionStringUtility.MakeFileNameRelative("FileName=" + item, DB.Filename);
                    tblScen.AddScenarioRow(name, true, "ScenarioNumber=" + (i + 1).ToString());
                }
                db.Server.SaveTable(tblScen);
            }
            db.Server.SaveTable(sc);
            db.ResumeTreeUpdates();
            db.RefreshFolder(parent);
        }
コード例 #13
0
        private void AddBpaHydsimClick(object sender, EventArgs e)
        {
            var dlg = new Reclamation.TimeSeries.ScenarioPicker.ScenarioPicker();

            dlg.Text = "Select Hydsim Output Files";
            dlg.Dialog.DefaultExt = ".mdb";
            dlg.Dialog.Filter     = "BPA Hydsim Access (*.mdb, *.accdb)|*.mdb;*.accdb|All Files|*.*";
            dlg.Dialog.Title      = "Open BPA Hydsim Access File";

            try
            {
                DB.SuspendTreeUpdates();
                var result = dlg.ShowDialog();

                if (result == DialogResult.OK)
                {
                    if (dlg.ScenariosChecked && dlg.ScenarioFiles.Count > 0)
                    {
                        //create scenarios
                        ShowAsBusy("Reading Hydsim data");
                        var tblScen = DB.GetScenarios();

                        foreach (var item in dlg.ScenarioFiles)
                        {
                            string scenarioPath = ConnectionStringUtility.MakeFileNameRelative("FileName=" + item, DB.DataSource);
                            tblScen.AddScenarioRow(Path.GetFileNameWithoutExtension(item), true, scenarioPath, 0);
                        }
                        //add first file in the list to the tree
                        if (dlg.AddToTreeChecked)
                        {
                            var bpa = new BpaHydsim.BpaHydsimTreeAccess(dlg.ScenarioFiles[0], DB.DataSource, DB.NextSDI(), this.CurrentFolder.ID);
                            var tbl = bpa.CreateTree();
                            DB.Server.SaveTable(tbl);
                        }

                        DB.Server.SaveTable(tblScen);
                        DatabaseChanged();
                    }
                    else
                    if (dlg.AddToTreeChecked)
                    {
                        //add to tree, but not to scenairo list
                        ShowAsBusy("Reading Hydsim data");
                        for (int i = 0; i < dlg.ScenarioFiles.Count; i++)
                        {
                            string fn  = dlg.ScenarioFiles[i].ToString();
                            var    bpa = new BpaHydsim.BpaHydsimTreeAccess(fn, DB.DataSource, DB.NextSDI(), this.CurrentFolder.ID);
                            var    tbl = bpa.CreateTree();
                            DB.Server.SaveTable(tbl);
                        }
                        DatabaseChanged();
                    }
                }
            }

            finally
            {
                ShowAsReady("Done with Hydsim import");
                DB.ResumeTreeUpdates();
            }
        }
コード例 #14
0
        string m_path; //   //CHJ/YT//IR-MONTH/IRVZZBZD/

        public UsaceSeries(TimeSeriesDatabase db, TimeSeriesDatabaseDataSet.SeriesCatalogRow sr)
            : base(db, sr)
        {
            m_path             = ConnectionStringUtility.GetToken(sr.ConnectionString, "DssPath", "");
            ExternalDataSource = true;
        }
コード例 #15
0
        public IDbConnection GetConnection()
        {
            var settings = ConnectionStringUtility.GetConnectionStringSettings(_connectionStringName);

            return(CreateConnection(settings.ConnectionString, settings.ProviderName));
        }
コード例 #16
0
 public string GetConnectionStringParameter(string name, string defaultValue = "")
 {
     return(ConnectionStringUtility.GetToken(this.Path, name, defaultValue));
 }
コード例 #17
0
 private void Init(TimeSeriesDatabase db)
 {
     fileName     = ConnectionStringUtility.GetFileName(ConnectionString, db.DataSource);
     ScenarioName = Path.GetFileNameWithoutExtension(fileName);
 }