Пример #1
0
        public PowerPathConfiguration Copy()
        {
            PowerPathConfiguration cp = new PowerPathConfiguration();

            cp.Builder           = this.Builder;
            cp.ListDatabases     = new List <string>(listDatabases);
            cp.ListServers       = new List <string>(listServers);
            cp.ValidDbConnection = this.ValidDbConnection;
            return(cp);
        }
 public BPServer(ApplicationContext AppContext)
 {
     //TODO: either use AppContext or remove it
     // https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.application.run
     //this.appcontext = AppContext;
     dicomserverconfig    = new DicomServerConfiguration();
     powerpathloginconfig = new PowerPathConfiguration();
     pploginform          = new PPLoginForm(powerpathloginconfig);
     pploginform.Closing += new System.ComponentModel.CancelEventHandler(this.pploginform_Closing);
     //note: Application.Run(pploginform) terminates when the form disposes
     pploginform.Show();
     Application.Run(AppContext);
 }
        private string FeedbackFromTestDatabaseConnect(PowerPathConfiguration serverlogin)
        {
            // ping first, as this is quicker
            //CONSIDER: refactor ping and Sql-db-connect into two async methods and wait for whomever comes first.
            if (false == PingHost(serverlogin.DataSource))
            {
                return("Server not found at: '" + serverlogin.DataSource + @"'!");
            }
            else
            {
                Log.Trace(@"Ping succeeded to " + serverlogin.DataSource);
            }
            try
            {
                using (SqlConnection db = new SqlConnection(serverlogin.ConnectionString))
                {
                    db.Open();
                    Log.Trace(@"Successful test-connect to PowerPath database: " + db.Database);
                    /* If we reached here, that means the connection to the database was successful. */
                    return("");
                }
            }
            catch (SqlException se)
            {
                // TODO: if server connected, but n = wrong database, then do something...
                switch (se.Number)
                {
                case 53:        // server unavailble
                                //TODO: ping test?
                    break;

                default:
                    break;
                }
                string strSqlException = "Sql Error connecting to PowerPath"
                                         + " with connectionstring: '" + serverlogin.ConnectionString
                                         + " with error: " + se.Message;
                //Log.Warn(strSqlException);
                return(strSqlException);
            }
            catch (Exception ex)
            {
                string strException = "Error connecting to PowerPath"
                                      + " with connectionstring: '" + serverlogin.ConnectionString
                                      + " with error: " + ex.Message;
                //Log.Error(strException);
                return(strException);
            }
        }
        /// <summary>
        /// Start the BPServer AFTER the PowerPath Db Form closes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pploginform_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            PPLoginForm ppform = (PPLoginForm)sender;

            powerpathloginconfig = ppform.ServerLogin.Copy();
            if (false == powerpathloginconfig.ValidDbConnection)
            {
                Log.Fatal("Failed to get a valid connection to PowerPath.");
                MessageBox.Show("Failed to get a valid connection to PowerPath.\r\nModality Worklist (MWL) is unavailable!");
                Environment.Exit(0);
                return;
            }
            else
            {
                Log.Debug("Valid valid connection to PowerPath, stating MWL server.");
                //drop messaging from form thread?
                //this.appContext.ExitThread();
            }

            this.RunServer();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="Builder"></param>
 public PPLoginForm(PowerPathConfiguration serverLogin)
 {
     this.serverlogin = serverLogin.Copy();
     InitializeComponent();
     BindControls();
 }