Ejemplo n.º 1
0
        //No time processing is done, we will default to 1 min cycle. We might need to get this info from Preference or Web Access page.
        // On a right-click refresh we need to signal the thread

        //johnny : can we hook this up with the sync interval ?
        /// <summary>
        /// Get the collection list item
        /// </summary>
        /// <param name="waitTime">Reference: wait time set</param>
        private void GetCollectionListItem(out int waitTime)
        {
            waitTime = preAuthTime;

            try
            {
                lock (collectionList)
                {
                    Store         localStore = Store.GetStore();
                    ArrayList     CollectionArray;
                    CatalogInfo[] CatalogInfoArray;

                    collectionList.Clear();

                    ICSList domainList = localStore.GetDomainList();

                    foreach (ShallowNode sn in domainList)
                    {
                        Domain domain = localStore.GetDomain(sn.ID);
                        // skip local domain
                        if (domain.Name.Equals(Store.LocalDomainName))
                        {
                            continue;
                        }

                        DomainAgent da = new DomainAgent();
                        if (da.IsDomainRemoved(domain.ID))
                        {
                            continue;
                        }

                        Member   cmember    = domain.GetCurrentMember();
                        HostNode masterNode = cmember.HomeServer;
                        if (masterNode == null)
                        {
                            masterNode = domain.Host;
                        }

                        try {
                            log.Debug("GetCollectionList - Try ");

                            SimiasConnection smConn = new SimiasConnection(sn.ID, cmember.UserID,
                                                                           SimiasConnection.AuthType.BASIC,
                                                                           masterNode);

                            DiscoveryService dService            = new DiscoveryService();
                            DomainAgent      dAgent              = new DomainAgent();
                            bool             activeDomain        = dAgent.IsDomainActive(domain.ID);
                            bool             authenticatedDomain = dAgent.IsDomainAuthenticated(domain.ID);

                            if (activeDomain)
                            {
                                if (authenticatedDomain)
                                {
                                    //not even one is processed, then this will get processed immediately
                                    // and change the cycle time down
                                    if (!processedOne)
                                    {
                                        processedOne = true;
                                    }
                                    else
                                    {
                                        // we have processed atleast one, so cycle time will get set
                                    }
                                }
                                else
                                {
                                    //	new EventPublisher().RaiseEvent( new NeedCredentialsEventArgs( domain.ID) );
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }

                            dService.Url = masterNode.PrivateUrl;

                            smConn.Authenticate();
                            smConn.InitializeWebClient(dService, "DiscoveryService.asmx");

                            CatalogInfoArray = dService.GetAllCatalogInfoForUser(cmember.UserID);

                            CollectionArray = new ArrayList(Simias.Discovery.DiscoveryFramework.GetDetailedCollectionInformation(sn.ID, CatalogInfoArray, dService));
                            log.Info("CatalogInfoArray : {1} | CollectionArray : {0}", CollectionArray.Count, CatalogInfoArray.Length);

                            //TODO : Test this section for MultiDomain. Check for performance issues.
                        }
                        catch (Exception e)
                        {
                            // If DiscoveryWs is N/A  or not running , we skip.
                            log.Debug("GetCollectionList : Skipping Domain : {0} ID : {1} Trace : {2}",
                                      domain.Name, domain.ID, e.ToString());
                            continue;
                        }
                        //Get Information from all the Domain and make it available for consumption
                        // Add elemetn here . instead of assiging.

                        collectionList.AddRange(CollectionArray);
                        log.Debug("collectionList : {0}", collectionList.Count);
                    }
                }
                // next wait cycle
                // we might need to get this from a preference setting -- TODO
                // need to see if we need to dynamically increase the preAuthTime based on the active domain count
                if (processedOne)
                {
                    waitTime = defaultWait;
                }

                log.Debug("waittime set to {0} ms", waitTime);
            }
            catch (Exception ex)
            {
                log.Error("Final Exception : " + ex.ToString());
            }
            listEvent.Reset();
            return;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Connect to user home server and get the latest info about this collection
        /// </summary>
        public static CatalogInfo GetCatalogInfoItem(string CollectionID, string UserID, string DomainID)
        {
            CatalogInfo catInfo = null;

            try
            {
                //lock (collectionList)
                {
                    Store localStore = Store.GetStore();
                    //ArrayList CollectionArray;

                    Domain domain = localStore.GetDomain(DomainID);
                    // skip local domain
                    if (!domain.Name.Equals(Store.LocalDomainName))
                    {
                        DomainAgent da = new DomainAgent();
                        if (!da.IsDomainRemoved(domain.ID))
                        {
                            Member cmember = domain.GetCurrentMember();
                            if (cmember == null)
                            {
                                log.Debug("CetCollectionInfoItem : Member is null in local store");
                                throw new Exception("Member NULL");
                            }
                            HostNode masterNode = cmember.HomeServer; //HostNode.GetMaster(DomainID);//cmember.HomeServer;

                            try
                            {
                                log.Debug("GetCollectionInfoItem - Try ");

                                SimiasConnection smConn = new SimiasConnection(DomainID, cmember.UserID,
                                                                               SimiasConnection.AuthType.BASIC,
                                                                               masterNode);

                                DiscoveryService dService            = new DiscoveryService();
                                DomainAgent      dAgent              = new DomainAgent();
                                bool             activeDomain        = dAgent.IsDomainActive(domain.ID);
                                bool             authenticatedDomain = dAgent.IsDomainAuthenticated(domain.ID);

                                if (activeDomain)
                                {
                                    if (!authenticatedDomain)
                                    {
                                        new EventPublisher().RaiseEvent(new NeedCredentialsEventArgs(domain.ID));
                                        throw new Exception("Domain Not Authenticated");
                                    }
                                    dService.Url = masterNode.PrivateUrl;

                                    smConn.Authenticate();
                                    smConn.InitializeWebClient(dService, "DiscoveryService.asmx");

                                    catInfo = dService.GetCatalogInfoForCollection(CollectionID);
                                }
                            }
                            catch (Exception e)
                            {
                                // If DiscoveryWs is N/A  or not running , we skip.
                                log.Debug("GetCatalogInfoItem : Skipping Domain : {0} ID : {1} Trace : {2}",
                                          domain.Name, domain.ID, e.ToString());
                                throw e;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Final Exception : " + ex.ToString());
                throw ex;
            }
            return(catInfo);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Domain Watcher Thread.
        /// </summary>
        public void WatcherThread()
        {
            log.Debug("WatcherThread started");
            EventPublisher cEvent = new EventPublisher();

            Simias.Authentication.Status authStatus = null;

            // Let the caller know we're good to go
            this.started = true;

            do
            {
                //
                // Cycle through the domains
                //

                try
                {
                    //ICSList domainList = store.GetDomainList();
                    foreach (ShallowNode shallowNode in store.GetDomainList())
                    {
                        Domain cDomain = store.GetDomain(shallowNode.ID);
                        log.Debug("In domain watcher: domain id: {0} and wait time is {1}", shallowNode.ID, waitTime);

                        // Make sure this domain is a slave since we don't watch
                        // mastered domains.
                        if (cDomain.Role == SyncRoles.Slave)
                        {
                            DomainAgent domainAgent = new DomainAgent();

                            log.Debug("Checking domain: " + cDomain.Name);

                            // Skip this domain if it is inactive
                            if (domainAgent.IsDomainActive(cDomain.ID) == false)
                            {
                                log.Debug("  domain: " + cDomain.Name + " - is inactive");
                                continue;
                            }

                            // Skip this domain if it's already authenticated
                            if (domainAgent.IsDomainAuthenticated(cDomain.ID))
                            {
                                log.Debug("  domain: " + cDomain.Name + " - is authenticated");
                                continue;
                            }

                            // If the domain is default, attempt to get a full credential
                            // set which under the covers will attempt to get it from
                            // CASA.
                            if (store.DefaultDomain == cDomain.ID)
                            {
                                log.Debug("  domain is default - getting credentials");

                                Member           member           = cDomain.GetCurrentMember();
                                BasicCredentials basicCredentials =
                                    new BasicCredentials(
                                        cDomain.ID,
                                        cDomain.ID,
                                        member.Name);

                                if (basicCredentials.Cached == true)
                                {
                                    // We have credentials for this domain so
                                    // attempt to login

                                    log.Debug("  yes - we have credentials for default");
                                    log.Debug("  username: "******"  failed authentication. ");
                                        log.Debug(we.Message);

                                        if (we.Status == WebExceptionStatus.TrustFailure)
                                        {
                                            // The certificate is invalid. Force the client to
                                            // login thru a UI so the user can make a decision
                                            cEvent.RaiseEvent(
                                                new Simias.Client.Event.NotifyEventArgs(
                                                    "Domain-Up",
                                                    cDomain.ID,
                                                    System.DateTime.Now));
                                            continue;
                                        }
                                    }

                                    if (authStatus != null)
                                    {
                                        if (authStatus.statusCode == SCodes.Success ||
                                            authStatus.statusCode == SCodes.SuccessInGrace)
                                        {
                                            log.Debug("  successful authentication to the default domain");

                                            if (authStatus.statusCode == SCodes.SuccessInGrace)
                                            {
                                                log.Debug("  BUT - we're in grace");

                                                // Tell the clients we authenticated successfully
                                                // but that we're in a grace period

                                                cEvent.RaiseEvent(
                                                    new Simias.Client.Event.NotifyEventArgs(
                                                        "in-grace-period",
                                                        cDomain.ID,
                                                        System.DateTime.Now));
                                            }

                                            continue;
                                        }
                                    }
                                }
                                else
                                {
                                    log.Debug("  no credentials for the default domain - bummer");
                                }
                            }

                            if (domainAgent.IsDomainAutoLoginEnabled(cDomain.ID) == false)
                            {
                                log.Debug("  domain: " + cDomain.Name + " auto-login is disabled");
                                continue;
                            }

                            /*
                             *      The try-catch section below fixes the exception on the thick-clients during login. Wait for the member node to be synced to be synced before trying to ping the domain.
                             */
                            /*
                             * Commenting out this code since the member node sync happens immediately...
                             * Fix for bug #341552.
                             *                          try
                             *                          {
                             *                                  string userID = store.GetUserIDFromDomainID(shallowNode.ID);
                             *                                  Member m = cDomain.GetMemberByID(userID);
                             *                                  log.Debug("trying to get the member id: home server is: {0}", m.HomeServer.ID);
                             *                          }
                             *                          catch(Exception ex)
                             *                          {
                             *                                  continue;
                             *                          }
                             */
                            log.Debug("  attempting to ping the domain");
                            if (domainAgent.Ping(cDomain.ID) == true)
                            {
                                log.Debug("  domain up");
                                cEvent.RaiseEvent(
                                    new Simias.Client.Event.NotifyEventArgs(
                                        "Domain-Up",
                                        cDomain.ID,
                                        System.DateTime.Now));
                            }
                            else
                            {
                                log.Debug("  domain down");
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    log.Error("Exception at DomainWatcherThread(): {0}", e.Message);
                    log.Error("Exception at DomainWatcherThread(): {0}", e.StackTrace);
                }

                if (this.stop == false)
                {
                    stopEvent.WaitOne(waitTime, false);
                    waitTime = (waitTime * 2 < maxWaitTime) ? waitTime * 2 : maxWaitTime;
                }
            } while(this.stop == false);

            this.started = false;
            this.stopEvent.Close();
            this.stopEvent = null;
        }