コード例 #1
0
        internal static ILocationDao getDao(AbstractConnection cxn)
        {
            if (!cxn.IsConnected)
            {
                throw new MdoException(MdoExceptionCode.USAGE_NO_CONNECTION, "Unable to instantiate DAO: unconnected");
            }
            AbstractDaoFactory f = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(cxn.DataSource.Protocol));

            return(f.getLocationDao(cxn));
        }
コード例 #2
0
        public static AbstractConnection authorizedConnect(string theUser, bool isBse)
        {
            string              securityPhrase = (isBse ? "" : "NON-BSE");
            MockApp             theApp         = getTheApp(securityPhrase);
            DataSource          src            = VistaSetups.getSrc(theApp.SiteTable, theApp.LoginSitecode);
            AbstractDaoFactory  f           = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));
            AbstractConnection  cxn         = f.getConnection(src);
            AbstractCredentials credentials = getVisitCredentials(theApp);
            AbstractPermission  permission  = new MenuOption(theApp.User.PermissionString);

            theApp.User = (User)cxn.authorizedConnect(credentials, permission, null);
            return(cxn);
        }
コード例 #3
0
        public UserTO loginActiveDirectory(string domain, string username, string password)
        {
            UserTO result = new UserTO();

            if (String.IsNullOrEmpty(domain) || String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                result.fault = new FaultTO("Must supply domain, username and password");
            }

            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                DataSource src = new DataSource()
                {
                    SiteId = new SiteId("1"), Modality = "FEDUID", Protocol = "LDAP", Provider = domain
                };
                AbstractDaoFactory f   = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));
                LdapConnection     cxn = new LdapConnection(src);
                cxn.Account = new LdapAccount(cxn);

                LdapCredentials creds = new LdapCredentials()
                {
                    AccountName = username, AccountPassword = password
                };

                using (new Impersonator(mySession.MdwsConfiguration.LdapConfiguration.RunasUser))
                {
                    string guid = cxn.Account.authenticate(creds);

                    LdapUserDao  dao = new LdapUserDao(cxn);
                    IList <User> guidLookupResult = dao.userLookupList(new KeyValuePair <string, string>("", guid));

                    if (guidLookupResult.Count != 1)
                    {
                        throw new ApplicationException("Unexpected error - more than one user returned for authenticated user's GUID");
                    }

                    return(new UserTO(guidLookupResult[0]));
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Use this setup method to authenticate to a real Vista system (both production and test) for the prupose
        /// of running a 'live' test(s)
        /// </summary>
        /// <param name="siteId">The site to authenticate against - should have a corresponding 'User###' entry in your secret-testObjects.xml file with valid credentials</param>
        /// <returns>AbstractConnection</returns>
        public AbstractConnection setup(string siteId)
        {
            DataSource         source = this.SiteTable.getSite(siteId).Sources[0]; // TBD - should we loop through data sources to make sure we get VISTA protocol?
            AbstractDaoFactory f      = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(source.Protocol));

            if (String.Equals(source.Protocol, "VISTA"))
            {
                return(this.Cxn = VistaSetups.authorizedConnect("User" + siteId, false));
            }
            else
            {
                return(this.Cxn = f.getConnection(source));
            }
        }
コード例 #5
0
        //public UserTO updateActiveDirectoryProfile(string domain, string username, string password, string title,
        //    string officePhone, string faxNumber, string addressLine1, string addressLine2, string addressLine2,
        //    string city, string state, string zip, string office,

        public UserArray ldapUserLookup(string uid, string domainSearchRoot)
        {
            UserArray result = new UserArray();

            if (String.IsNullOrEmpty(uid))
            {
                result.fault = new FaultTO("Must supply domain, username and password");
            }

            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                DataSource src = new DataSource()
                {
                    SiteId = new SiteId("1"), Modality = "FEDUID", Protocol = "LDAP", Provider = "GC://dc=va,dc=gov"
                };
                if (!String.IsNullOrEmpty(domainSearchRoot))
                {
                    src.Provider = domainSearchRoot;
                }
                AbstractDaoFactory f   = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));
                LdapConnection     cxn = new LdapConnection(src);
                cxn.Account = new LdapAccount(cxn);

                LdapUserDao dao = new LdapUserDao(cxn);

                IList <User> users = null;
                using (new Impersonator(mySession.MdwsConfiguration.LdapConfiguration.RunasUser))
                {
                    users = dao.userLookupList(new KeyValuePair <String, String>("", uid));
                }

                result = new UserArray(users);
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return(result);
        }
コード例 #6
0
        void growPool()
        {
            if (_consecutiveCxnErrorCount > this.PoolSource.MaxConsecutiveErrors) // we want to recognize when a site might be down, network issues, etc. - wait to retry if we have many connection failures without success
            {
                if (DateTime.Now.Subtract(_lastSuccessfulCxn).CompareTo(this.PoolSource.WaitOnMaxConsecutiveErrors) < 0)
                {
                    // LogUtils.getInstance().Log(String.Format("{0} consecutive failed connection attempts... waiting {1} to start new cxns", _consecutiveCxnErrorCount, this.PoolSource.WaitOnMaxConsecutiveErrors.Subtract(DateTime.Now.Subtract(_lastSuccessfulCxn))));
                    return; // don't start any new cxns if we've seen a lot of errors and haven't waited at least 5 mins (or configurable timespan)
                }
                else // waited configured time, reset error vars so growPool will try creating cxns
                {
                    //LogUtils.getInstance().Log("Resetting error related vars so will re-try instantiating cxns.. " + ((ConnectionPoolSource)this.PoolSource).CxnSource.SiteId.Id);
                    _consecutiveCxnErrorCount = 0;
                    _lastSuccessfulCxn        = DateTime.Now;
                }
            }
            if ((_cleanupTasks.Count + this.TotalResources) >= this.PoolSource.MaxPoolSize)
            {
                //LogUtils.getInstance().Log("The # of cleanup tasks scheduled + the number of current resources exceeds the max pool size - waiting until cleanup tasks are addressed to grow");
                return; // too many cleanup tasks scheduled! don't grow the pool until the cxns we've attempted to start have been addressed
            }
            // i think there may be a possible race condition here where a cxn may be disconnected during the size
            int growSize = this.PoolSource.PoolExpansionSize;

            if ((this.TotalResources + growSize) > this.PoolSource.MaxPoolSize) // if the growth would expand the pool above the max pool size, only grow by the amount allowed
            {
                growSize = this.PoolSource.MaxPoolSize - this.TotalResources;
            }
            //LogUtils.getInstance().Log(String.Format("Connection pool at min size {0}/{1} - growing by {2}. Current total resources: {3} - site: {4}", this.PoolSource.MinPoolSize, this.PoolSource.MaxPoolSize, growSize, this.TotalResources, ((ConnectionPoolSource)this.PoolSource).CxnSource.SiteId.Id));
            for (int i = 0; i < growSize; i++)
            {
                ConnectionThread a = new ConnectionThread();
                _startedCxns.Add(a);
                a.Connection = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(((ConnectionPoolSource)this.PoolSource).CxnSource.Protocol))
                               .getConnection(((ConnectionPoolSource)this.PoolSource).CxnSource);
                // Task connectTask = new Task(() => connect(a));
                //  a.Thread = connectTask;
                // connectTask.Start();
                //connect(a);
                Thread t = new Thread(new ParameterizedThreadStart(connect));
                a.Thread = t;
                t.Start(a);
            }
        }
コード例 #7
0
ファイル: ConnectionPoolTest.cs プロジェクト: marcsommer/mdo
        public void testIsAlive()
        {
            VistaPoolConnection cxn = (VistaPoolConnection)AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant("PVISTA")).getConnection(_localSource.CxnSource);

            cxn.connect();
            login(cxn);

            cxn.setTimeout(new TimeSpan(0, 0, 1)); // set this low - one second - so the test can run quickly

            Assert.IsTrue(cxn.isAlive());

            System.Threading.Thread.Sleep(500); // sleep for less than timeout     \
            //                                                                      \
            cxn.heartbeat();
            Assert.IsTrue(cxn.isAlive());

            System.Threading.Thread.Sleep(500); // sleep for less than timeout     --  These three add up to more than timeout

            cxn.heartbeat();
            Assert.IsTrue(cxn.isAlive());
            //                                                                      /
            System.Threading.Thread.Sleep(500); // sleep for less than timeout     /

            cxn.heartbeat();
            Assert.IsTrue(cxn.isAlive());


            System.Threading.Thread.Sleep(1100);// sleep for more than timeout

            Assert.IsFalse(cxn.isAlive());

            Assert.IsFalse(cxn.IsConnected);

            try
            {
                new VistaPatientDao(cxn).match("m1234");
                Assert.Fail("Uh-oh! Previous line should have thrown exception!");
            }
            catch (Exception)
            {
                // cool!
            }
        }
コード例 #8
0
ファイル: AccountLib.cs プロジェクト: monkeyglasses/mdws
        // This is the core visit method the others are using. The permission must have been set before
        // getting here.
        internal User doTheVisit(string sitecode, AbstractCredentials credentials, AbstractPermission permission)
        {
            Site       site = mySession.SiteTable.getSite(sitecode);
            DataSource src  = site.getDataSourceByModality("HIS");

            if (src == null)
            {
                throw new Exception("No HIS data source at site " + sitecode);
            }

            AbstractDaoFactory factory = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));

            myCxn = factory.getConnection(src);
            myCxn.Account.AuthenticationMethod = mySession.DefaultVisitMethod;

            if (!MdwsUtils.isValidCredentials(myCxn.Account.AuthenticationMethod, credentials, permission))
            {
                throw new Exception("Invalid credentials");
            }

            object result = null;

            if (myCxn.Account.AuthenticationMethod == VistaConstants.BSE_CREDENTIALS_V2WEB)
            {
                result = myCxn.authorizedConnect(credentials, permission,
                                                 new DataSource()
                {
                    ConnectionString = mySession.MdwsConfiguration.BseValidatorConnectionString
                });
            }
            else
            {
                result = myCxn.authorizedConnect(credentials, permission, null);
            }
            if (result.GetType().Name.EndsWith("Exception"))
            {
                throw (Exception)result;
            }
            else
            {
                return((User)result);
            }
        }
コード例 #9
0
        public DataSourceArray connectToLoginSite(string sitecode)
        {
            DataSourceArray result = new DataSourceArray();

            if (String.IsNullOrEmpty(sitecode))
            {
                result.fault = new FaultTO(NO_SITECODE);
            }
            else if (mySession.SiteTable == null)
            {
                result.fault = new FaultTO(NO_SITE_TABLE);
            }
            else if (mySession.SiteTable.getSite(sitecode) == null)
            {
                result.fault = new FaultTO(SITE_NOT_IN_SITE_TABLE);
            }
            else if (mySession.ConnectionSet != null && mySession.ConnectionSet.Count > 0 && mySession.ConnectionSet.HasConnection(sitecode))
            {
                result.fault = new FaultTO(ALREADY_CONNECTED_TO_SITE);
            }
            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                Site               site    = mySession.SiteTable.getSite(sitecode);
                DataSource         src     = site.getDataSourceByModality("HIS");
                AbstractDaoFactory factory = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));
                AbstractConnection c       = factory.getConnection(src);
                c.connect();
                result = new DataSourceArray(src);
                result.items[0].welcomeMessage = c.getWelcomeMessage();
                mySession.ConnectionSet.Add(c);
            }
            catch (Exception e)
            {
                result.fault = new FaultTO(e.Message);
            }
            return(result);
        }
コード例 #10
0
ファイル: ConnectionPool.cs プロジェクト: marcsommer/mdo
        void growPool()
        {
            //Console.WriteLine("Connection pool at min size {0} - growing by {1}", this.PoolSource.MinPoolSize, this.PoolSource.PoolExpansionSize);
            int growSize = this.PoolSource.PoolExpansionSize;

            if (this.TotalResources + growSize > this.PoolSource.MaxPoolSize) // if the growth would expand the pool above the max pool size, only grow by the amount allowed
            {
                growSize = this.PoolSource.MaxPoolSize - this.TotalResources;
            }
            for (int i = 0; i < growSize; i++)
            {
                ConnectionThread a = new ConnectionThread();
                a.Connection = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(((ConnectionPoolSource)this.PoolSource).CxnSource.Protocol))
                               .getConnection(((ConnectionPoolSource)this.PoolSource).CxnSource);
                Thread t = new Thread(new ParameterizedThreadStart(connect));
                a.Thread = t;
                t.Start(a);
                _startedCxns.Add(a);
            }
        }
コード例 #11
0
        public DataSourceArray connectToLoginSite(string sitecode)
        {
            // TODO - FIX!!! This is very ugly - here so that SOAP and REST services can both be stateful or stateless
            if (!Convert.ToBoolean(_mySession.MdwsConfiguration.AllConfigs[MdwsConfigConstants.CONNECTION_POOL_CONFIG_SECTION][MdwsConfigConstants.CONNECTION_POOLING]))
            {
                return(new gov.va.medora.mdws.ConnectionLib(_mySession).connectToLoginSite(sitecode));
            }

            DataSourceArray result = new DataSourceArray();

            try
            {
                MdwsUtils.checkNullArgs(MdwsUtils.getArgsDictionary(System.Reflection.MethodInfo.GetCurrentMethod().GetParameters(), new List <object>()
                {
                    sitecode
                }));
                MdwsUtils.checkSiteTable(_mySession, sitecode);
                MdwsUtils.checkConnections(_mySession, sitecode);

                Site               site    = _mySession.SiteTable.getSite(sitecode);
                DataSource         src     = site.getDataSourceByModality("HIS");
                AbstractDaoFactory factory = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));

                // REST
                SessionMgr.getInstance().setConnection(_mySession, sitecode);
                // END REST
                result = new DataSourceArray(src);

                result.items[0].welcomeMessage = "TODO - implement cached connection messages in pool";
            }
            catch (Exception e)
            {
                result.fault = new FaultTO(e.Message);
            }
            finally
            {
                //RestSessionMgr.getInstance().returnConnections(_mySession);
            }
            return(result);
        }
コード例 #12
0
        protected void TestVistaSettingsClick(object sender, EventArgs e)
        {
            int port = 0;

            if (String.IsNullOrEmpty(textboxVistaIp.Text) || String.IsNullOrEmpty(textboxVistaPort.Text) ||
                !Int32.TryParse(textboxVistaPort.Text, out port))
            {
                labelMessage.Text = "Invalid Vista connection parameters. Please be sure to enter a valid IP address and port number";
                return;
            }

            DataSource testSrc = new DataSource();

            testSrc.Provider = textboxVistaIp.Text;
            testSrc.Modality = "HIS";
            testSrc.Port     = port;
            testSrc.Protocol = "VISTA";
            testSrc.SiteId   = new SiteId("900", "Test"); // this site id doesn't matter - it's just there because a site ID is expected by the code below

            string welcomeMsg = "";

            try
            {
                AbstractDaoFactory factory = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(testSrc.Protocol));
                AbstractConnection cxn     = factory.getConnection(testSrc);
                cxn.connect();
                welcomeMsg = cxn.getWelcomeMessage();
                cxn.disconnect();
            }
            catch (Exception exc)
            {
                labelMessage.Text = "Unable to connect to that datasource. Please check your test system and try again." +
                                    "This might help figure out why:</p><p>" + exc.ToString() + "</p>";
                return;
            }

            labelMessage.Text = "<p>You rock. Connection successfully established. You should put this site in your VhaSites.xml " +
                                "file is you'd like it to be available later on via MDWS.</p><p>" + welcomeMsg + "</p>";
        }
コード例 #13
0
        public DataSourceTO connectSite(string sitecode)
        {
            DataSourceTO result = new DataSourceTO();

            if (String.IsNullOrEmpty(sitecode))
            {
                result.fault = new FaultTO(NO_SITECODE);
            }
            else if (mySession.SiteTable == null || mySession.SiteTable.getSite(sitecode) == null)
            {
                result.fault = new FaultTO(NO_SITE_TABLE);
            }
            else if (mySession.ConnectionSet != null && mySession.ConnectionSet.Count > 0 && mySession.ConnectionSet.HasConnection(sitecode))
            {
                result.fault = new FaultTO(ALREADY_CONNECTED_TO_SITE);
            }
            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                Site               site       = (Site)mySession.SiteTable.Sites[sitecode];
                DataSource         dataSource = site.getDataSourceByModality("HIS");
                AbstractDaoFactory factory    = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(dataSource.Protocol));
                AbstractConnection c          = factory.getConnection(dataSource);
                c.connect();
                result = new DataSourceTO(dataSource);
                result.welcomeMessage = c.getWelcomeMessage();
                mySession.ConnectionSet.Add(c);
            }
            catch (Exception e)
            {
                result.fault = new FaultTO(e.Message);
            }
            return(result);
        }
コード例 #14
0
ファイル: Order.cs プロジェクト: monkeyglasses/mdo-cxn-pool
        internal static IOrdersDao getDao(AbstractConnection cxn)
        {
            AbstractDaoFactory f = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(cxn.DataSource.Protocol));

            return(f.getOrdersDao(cxn));
        }
コード例 #15
0
ファイル: ClaimsLib.cs プロジェクト: monkeyglasses/mdws
        internal void buildConnectionSetForGetClaimants()
        {
            Dictionary <string, AbstractConnection> cxns = new Dictionary <string, AbstractConnection>(3);

            //DataSource nptSrc = new DataSource();
            //nptSrc.Protocol = "NPT";
            //nptSrc.SiteId = new SiteId("NPT", "National Patient Table");
            //AbstractConnection nptCxn = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.NPT).getConnection(nptSrc);
            //try
            //{
            //    nptCxn.connect();
            //    cxns.Add("NPT", nptCxn);
            //}
            //catch (Exception ex)
            //{
            //}

            DataSource adrSrc = new DataSource();

            adrSrc.Protocol         = "ADR";
            adrSrc.SiteId           = new SiteId("ADR", "Administrative Data Repository");
            adrSrc.ConnectionString = gov.va.medora.mdo.dao.oracle.adr.AdrConstants.DEFAULT_CXN_STRING;
            AbstractConnection adrCxn = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.ADR).getConnection(adrSrc);

            try
            {
                adrCxn.connect();
                cxns.Add("ADR", adrCxn);
            }
            catch (Exception ex)
            {
            }

            DataSource vadirSrc = new DataSource();

            vadirSrc.Protocol         = "VADIR";
            vadirSrc.SiteId           = new SiteId("VADIR", "VA-DoD Information Repository");
            vadirSrc.ConnectionString = gov.va.medora.mdo.dao.oracle.vadir.VadirConstants.DEFAULT_CXN_STRING;
            AbstractConnection vadirCxn = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.VADIR).getConnection(vadirSrc);

            try
            {
                vadirCxn.connect();
                cxns.Add("VADIR", vadirCxn);
            }
            catch (Exception ex)
            {
            }

            DataSource vbacorpSrc = new DataSource();

            vbacorpSrc.Protocol         = "VBACORP";
            vbacorpSrc.SiteId           = new SiteId("VBACORP", "VBA Corp");
            vbacorpSrc.ConnectionString = gov.va.medora.mdo.dao.oracle.vbacorp.VbacorpConstants.DEFAULT_CXN_STRING;
            AbstractConnection vbacorpCxn = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.VBACORP).getConnection(vbacorpSrc);

            try
            {
                vbacorpCxn.connect();
                cxns.Add("VBACORP", vbacorpCxn);
            }
            catch (Exception ex)
            {
            }

            mySession.ConnectionSet = new ConnectionSet(cxns);
        }
コード例 #16
0
ファイル: CdwAccount.cs プロジェクト: govtmirror/RAPTOR-1
        internal AbstractConnection initializeVistaConnection()
        {
            DataSource vistaDataSource = new DataSource();

            vistaDataSource.Provider = Cxn.DataSource.Provider;
            vistaDataSource.Port     = Cxn.DataSource.Port;
            vistaDataSource.SiteId   = new SiteId("CDW");

            // Use the factory to ensure that the vista connection is initialized with the right Factory-defined Connection Strategy
            gov.va.medora.mdo.dao.vista.VistaDaoFactory factory         = (vista.VistaDaoFactory)AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.VISTA);
            gov.va.medora.mdo.dao.vista.VistaConnection vistaConnection = (vista.VistaConnection)factory.getConnection(vistaDataSource);

            vistaConnection.connect();

            return(vistaConnection);
        }