/// <summary> /// Delete the collection from catalog /// </summary> /// <param name="domainID">Domain ID in which collection is present</param> /// <param name="collectionID">Collection ID to delete</param> public static void DeleteCollectionInCatalog(string domainID, string collectionID) { log.Debug("Domain ID {0}, col ID {1}", domainID, collectionID); Member member = Store.GetStore().GetDomain(domainID).GetCurrentMember(); HostNode hNode = GetHostNode(domainID, collectionID); if (hNode == null) { hNode = member.HomeServer; } try { log.Debug("DeleteCollectionInCatalog called from client"); DiscoveryService dService = new DiscoveryService(); SimiasConnection smConn = new SimiasConnection(domainID, member.UserID, SimiasConnection.AuthType.BASIC, hNode); smConn.InitializeWebClient(dService, "DiscoveryService.asmx"); dService.DeleteCollectionInCatalog(collectionID); } catch (Exception ex) { log.Error(ex.Message); } return; }
/// <summary> /// Remove the membership of collection from domain /// </summary> /// <param name="domainID">Domain ID where collection resides</param> /// <param name="collectionID">Collection ID to remove from domain</param> /// <returns></returns> public static bool RemoveMembership(string domainID, string collectionID) { bool removed = false; Domain domain = Store.GetStore().GetDomain(domainID); Member member = domain.GetCurrentMember(); HostNode hNode = GetHostNode(domainID, collectionID); if (hNode == null) { hNode = member.HomeServer; } try { DiscoveryService dService = new DiscoveryService(); SimiasConnection smConn = new SimiasConnection(domainID, member.UserID, SimiasConnection.AuthType.BASIC, hNode); smConn.InitializeWebClient(dService, "DiscoveryService.asmx"); removed = dService.RemoveMemberFromCollection(collectionID, member.UserID); } catch (Exception ex) { log.Error(ex.Message); } return(removed); }
/// <summary> /// Get the detailed information of collections for a domain /// </summary> /// <param name="domainID">ID of the domain whose collection info needed</param> /// <param name="catalogInfoArray">Details of the catalog</param> /// <param name="dService">object of Discovery service</param> /// <returns></returns> public static ArrayList GetDetailedCollectionInformation(string domainID, CatalogInfo[] catalogInfoArray, DiscoveryService dService) { ArrayList colInfo = new ArrayList(); DiscoveryService locService = dService; NameValueCollection collectionsOnHost = new NameValueCollection(); Member member = Store.GetStore().GetDomain(domainID).GetCurrentMember(); foreach (CatalogInfo ci in catalogInfoArray) { //Collect all the CollectionIDs for HostID. collectionsOnHost.Add(ci.HostID, ci.CollectionID); } foreach (string hostID in collectionsOnHost.AllKeys) { try { if (member.HomeServer != null && hostID == member.HomeServer.UserID) { //We already have a connection. Reuse it. colInfo.AddRange(locService.GetAllCollectionInfo(collectionsOnHost.GetValues(hostID), member.UserID)); } else { //Get all collection info in one call. HostNode hNode = HostNode.GetHostByID(domainID, hostID); SimiasConnection smConn = new SimiasConnection(domainID, member.UserID, SimiasConnection.AuthType.BASIC, hNode); DiscoveryService discService = new DiscoveryService(); smConn.InitializeWebClient(discService, "DiscoveryService.asmx"); colInfo.AddRange(discService.GetAllCollectionInfo(collectionsOnHost.GetValues(hostID), member.UserID)); } } catch (Exception ex) { log.Error(ex.Message); } } locService = null; return(colInfo); }
/// <summary> /// Puts the domain into sync queue for sync /// </summary> private void SyncDomain() { int retry = 10; while (true) { try { // Get a connection object to the server. connection = new SimiasConnection(hostDomain.ID, host.UserID, SimiasConnection.AuthType.PPK, hostDomain); // We need to get a one time password to use to authenticate. connection.Authenticate(); break; } catch { Thread.Sleep(10000); if (retry <= 0) { break; } } } syncClient = new CollectionSyncClient(hostDomain.ID, new TimerCallback(TimerFired)); while (true) { syncEvent.WaitOne(); try { syncClient.SyncNow(); } catch {} syncClient.Reschedule(true, 30); } }
/// <summary> /// Commits the member object on master server, will be called by slave /// </summary> /// <param name="domainID">domain id</param> /// <param name="member">member object to be committed</param> /// <param name="sn">shallow node object, but currently unused</param> /// <returns>true if success</returns> public bool CommitOnMaster(string domainID, Member member, ShallowNode sn) { Store store = Store.GetStore(); Domain domain = store.GetDomain(domainID); string userID = store.GetUserIDFromDomainID(domain.ID); HostNode mNode = HostNode.GetMaster(domainID); bool result = false; if (mNode == null) { return(false); } try { Node ModifiedNode = member as Node; log.Debug("going to call xnode constr and loading its : "); XmlDocument xNode = new XmlDocument(); xNode.LoadXml(ModifiedNode.Properties.ToString()); log.Debug("modifiednode.prop.string is : " + ModifiedNode.Properties.ToString()); SimiasConnection smConn = new SimiasConnection(domainID, userID, SimiasConnection.AuthType.PPK, mNode); SimiasWebService svc = new SimiasWebService(); svc.Url = mNode.PublicUrl; smConn.Authenticate(); smConn.InitializeWebClient(svc, "Simias.asmx"); log.Debug("going to call svc.commitdomainmember"); result = svc.CommitDomainMember(domain.ID, xNode); log.Debug("returned from web-service call and return is " + result); } catch (Exception ex) { log.Debug("simiasconnection to master failed: " + ex.ToString()); log.Debug("Could not establish connection to master for user: " + member.UserID); result = false; } return(result); }
/// <summary> /// sync the domain /// </summary> private void SyncDomain() { int retry = 10; log.Debug("Sync Domain entered.."); lock (CollectionSyncClient.MapObject) { CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncStarted; CollectionSyncClient.ServerSyncStatus &= ~CollectionSyncClient.StateMap.DomainSyncFinished; } while (true) { try { // Get a connection object to the server. connection = new SimiasConnection(hostDomain.ID, host.UserID, SimiasConnection.AuthType.PPK, hostDomain); // We need to get a one time password to use to authenticate. connection.Authenticate(); log.Debug("Connection successful...."); break; } catch (Exception ex) { log.Debug("Domain Sync, Exception creating a SimiasConnection {0} {1}", ex.Message, ex.StackTrace); Thread.Sleep(10000); if (--retry <= 0) { break; } } } syncClient = new CollectionSyncClient(hostDomain.ID, new TimerCallback(TimerFired)); while (true) { syncEvent.WaitOne(); retry = 3; while (retry-- > 0) { try { lock (CollectionSyncClient.MapObject) { CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncStarted; CollectionSyncClient.ServerSyncStatus &= ~CollectionSyncClient.StateMap.DomainSyncFinished; } log.Debug("About to Start Domain Sync"); syncClient.SyncNow(); log.Debug("Domain Sync Completed"); lock (CollectionSyncClient.MapObject) { CollectionSyncClient.ServerSyncStatus &= ~CollectionSyncClient.StateMap.DomainSyncStarted; CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncFinished; CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncOnce; } break; } catch (Exception ex) { log.Debug("Domain Sync, got an exception.{0} {1}", ex.Message, ex.StackTrace); Thread.Sleep(30 * 1000); log.Debug("Domain Sync, Possibly connection lost. Setting simias connection again"); try { connection.ClearConnection(); connection = new SimiasConnection(hostDomain.ID, host.UserID, SimiasConnection.AuthType.PPK, hostDomain); connection.Authenticate(); } catch (Exception SimiasConnEx) { log.Debug("Domain Sync, second Simias connection got exception.{0} {1}", SimiasConnEx.Message, SimiasConnEx.StackTrace); } log.Debug("Domain Sync, Simias authenticate for Domain Sync Connection successful...."); } if (retry == 1) { // Going to exit while loop, before that unset the domain sync flag, so other syns get chance lock (CollectionSyncClient.MapObject) { CollectionSyncClient.ServerSyncStatus &= ~CollectionSyncClient.StateMap.DomainSyncStarted; CollectionSyncClient.ServerSyncStatus |= CollectionSyncClient.StateMap.DomainSyncFinished; log.Debug("DomainSync: This was last retry, so unsetting the domainsync ON flag so that other sync threads will try..."); } } } syncClient.Reschedule(true, 30); } }
/// <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); }
//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; }