Beispiel #1
0
        /// <summary>
        /// This function is the heart of the connection pool dictionary. It connects to a site
        /// and attaches the event handlers by executing a standard gettimestamp request
        /// so the connection can immediately begin processing queued query threads
        /// </summary>
        /// <param name="site">Site to which to connect</param>
        /// <param name="addToCxnCollection">Should the site be added to the pools connection collection?</param>
        /// <returns></returns>
        AbstractConnection connectWithReturn(Site site, bool addToCxnCollection)
        {
            //Site[] sites = _poolSites.ToArray();

            Site               currentSite = site;
            DataSource         src         = currentSite.Sources[0];
            AbstractDaoFactory factory     = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));
            AbstractConnection c           = factory.getConnection(src);

            //c.ConnectionId = new Guid();
            c.Account = _account;
            c.Account = new VistaAccount(c);
            c.Account.AuthenticationMethod = _account.AuthenticationMethod;
            c.Account.Permissions          = new Dictionary <string, AbstractPermission>();
            AbstractPermission cprs = new MenuOption("OR CPRS GUI CHART");

            cprs.IsPrimary = true;
            c.Account.Permissions.Add(cprs.Name, cprs);
            // this needs to be up here so we can reference it if an error occurs
            QueryThread  qt = new QueryThread("", new VistaToolsDao(null), "getTimestamp", new object[] { });
            EventHandler eh = new EventHandler(QueryThreadChanged);

            try
            {
                User user = (User)c.authorizedConnect(_credentials, cprs, src);
                c.IsAvailable = true;
                // initiliaze this connection's eventhandler by making a standard timestamp request
                qt.setConnection(c);
                qt.Changed += eh;
                _currentActiveConnections++;
                qt.execute();

                if (!(qt.Result is string))
                {
                    throw new ConnectionException("Connection does not appear to be active");
                }

                if (addToCxnCollection)
                {
                    addConnection(currentSite.Id, c);
                }
                return(c);
            }
            catch (Exception)
            {
                qt.Changed   -= eh;
                c.IsAvailable = false;
                _currentActiveConnections--;
                try
                {
                    c.disconnect();
                }
                catch (Exception) { }
            }
            return(null);
        }
Beispiel #2
0
        private void QueueChanged(object sender, EventArgs e)
        {
            QueryThreadPoolEventArgs arg = (QueryThreadPoolEventArgs)e;

            if (arg.QueueEventType == QueryThreadPoolEventArgs.QueueChangeEventType.QueryAdded)
            {
                // if connection available then execute
                AbstractConnection cxn = getAvailableConnection(arg.SiteId);
                if (cxn != null)
                {
                    QueryThread qt = _queue.dequeue(arg.SiteId);
                    qt.DequeueTimestamp = DateTime.Now;
                    qt.setConnection(cxn);
                    qt.Changed += new EventHandler(QueryThreadChanged);
                    qt.execute();
                }
            }
        }