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;
        }