/// <summary> /// Create a proxy for collection /// </summary> /// <param name="poBox">POBox</param> /// <param name="subscription">Subscription</param> /// <returns>True if successfull, else false</returns> private bool CreateCollectionProxy(POBox poBox, Subscription subscription) { bool createdProxy = false; // Refresh the subscription. subscription = poBox.Refresh(subscription) as Subscription; // See if the member Node ID is specified yet. if (subscription.ToMemberNodeID != null) { // Check to make sure the collection proxy doesn't already exist. if (poBox.StoreReference.GetCollectionByID(subscription.SubscriptionCollectionID) == null) { // create slave stub subscription.CreateSlave(poBox.StoreReference); log.Debug(" created collection proxy."); } createdProxy = true; } return(createdProxy); }
/// <summary> /// Invite the subscription to POBox /// </summary> /// <param name="poBox">POBox to which subscription to be added</param> /// <param name="subscription">Subscription to be invited to POBox</param> /// <returns>True if successfull else false</returns> private bool DoInvited(POBox poBox, Subscription subscription) { bool result = false; Store store = Store.GetStore(); log.Debug("SubscriptionThread::DoInvited called"); POBoxService poService = new POBoxService(); // Resolve the PO Box location for the invitee Uri poUri = DomainProvider.ResolvePOBoxLocation(subscription.DomainID, subscription.ToIdentity); if (poUri != null) { poService.Url = poUri.ToString() + poServiceLabel; log.Debug("Calling POService::Invite at: " + poService.Url); } else { log.Error(" Could not resolve the PO Box location for: " + subscription.FromIdentity); return(result); } // // If the Domain Type is "ClientServer" credentials are needed for // posting an invitation. In workgroup, credentials aren't needed. // Domain domain = store.GetDomain(subscription.DomainID); if (domain.ConfigType == Simias.Storage.Domain.ConfigurationType.ClientServer) { try { WebState webState = new WebState(subscription.DomainID, subscription.FromIdentity); webState.InitializeWebClient(poService, domain.ID); } catch (NeedCredentialsException) { log.Debug(" no credentials - back to sleep"); return(result); } } // // Make sure the shared collection has sync'd to the server before inviting // Collection cSharedCollection = store.GetCollectionByID(subscription.SubscriptionCollectionID); if (cSharedCollection == null) { return(result); } if (cSharedCollection.Role == SyncRoles.Slave && cSharedCollection.MasterIncarnation == 0) { log.Debug( "Failed POBoxService::Invite - collection: {0} hasn't sync'd to the server yet", subscription.SubscriptionCollectionID); return(result); } // // Make sure the subscription node has sync'd up to the server as well // if (poBox.Role == SyncRoles.Slave) { Node cNode = poBox.Refresh(subscription); if (cNode.MasterIncarnation == 0) { log.Debug( "Failed POBoxService::Invite - inviter's subscription {0} hasn't sync'd to the server yet", subscription.MessageID); return(result); } } // Remove location of the POBox service log.Debug("Connecting to the Post Office Service : " + poService.Url); try { // Set the remote state to received. // And post the subscription to the server. Simias.Storage.Member me = poBox.GetCurrentMember(); subscription.FromIdentity = me.UserID; subscription.FromName = me.Name; // Make sure that this user has sufficient rights to send this invitation. Simias.Storage.Member me2 = cSharedCollection.GetMemberByID(me.UserID); if ((me2 == null) || (me2.Rights != Access.Rights.Admin)) { // The user did not have sufficient rights to send this invitation. // Delete the subscription and don't try to send it anymore. log.Info("User {0} did not have sufficient rights to share collection {1}", me.Name, cSharedCollection.Name); poBox.Commit(poBox.Delete(subscription)); return(true); } POBoxStatus status = poService.Invite(subscription.GenerateSubscriptionMessage()); if (status == POBoxStatus.Success) { log.Debug("Successfully invited {0} to collection {1}.", subscription.FromName, subscription.SubscriptionCollectionName); subscription.SubscriptionState = SubscriptionStates.Posted; poBox.Commit(subscription); result = true; } else if (status == POBoxStatus.InvalidAccessRights) { // The user did not have sufficient rights to send this invitation. // Delete the subscription and don't try to send it anymore. log.Info("User {0} did not have sufficient rights to share collection {1}", me.Name, cSharedCollection.Name); poBox.Commit(poBox.Delete(subscription)); result = true; } else if (status == POBoxStatus.UnknownIdentity) { // The invited user no longer exists on the server roster // possibly due to scoping changes by the administrator log.Info("User {0} does not exist in the server domain", me.Name); poBox.Commit(poBox.Delete(subscription)); result = true; } else { log.Debug("Failed the remote invite call - Status: " + status.ToString()); } } catch { log.Debug("Failed POBoxService::Invite - target: " + poService.Url); } return(result); }