public static void UpdateParties(Service service, string participantAddress) { Utils.DebugPrint("Updating bubble group parties that contain participant address: " + participantAddress); foreach (var @group in BubbleGroupManager.FindAll(@group => @group.IsParty && @group.Service == service && @group.Participants.Any())) { foreach (var participant in @group.Participants) { //TODO: this needs to be made into a comparer eventually //TODO: as it stands... a participant with address 16041234567 != 6041234567 if (participant.Address != participantAddress) { continue; } Utils.DebugPrint("Updating " + @group.ID + " (party) with name " + (@group.Title != null ? @group.Title : "[unknown]")); Update(@group); break; //don't update the same group again } } }
public static void SendLastPresence(Service service) { if (!service.Information.DoesSupport(typeof(PresenceBubble))) { return; } lock (LastPresenceBubbles) { var presenceBubble = LastPresenceBubbles.FirstOrDefault(pb => pb.Service == service); if (presenceBubble == null) { return; } Utils.DebugPrint("Sending last presence for service " + service.Information.ServiceName + ". " + (presenceBubble.Available ? "Available." : "Unavailable.")); Send(presenceBubble); if (presenceBubble.Available) { return; } foreach (var group in BubbleGroupManager.FindAll(presenceBubble.Service)) { @group.PresenceType = PresenceBubble.PresenceType.Unavailable; } } }
public static void SendPresence(Service service, bool available, bool justAddIfNoLastPresence = false) { if (!service.Information.DoesSupport(typeof(PresenceBubble))) { return; } var presenceBubble = new PresenceBubble(Time.GetNowUnixTimestamp(), Bubble.BubbleDirection.Outgoing, null, false, service, available); Utils.DebugPrint("Sending " + (presenceBubble.Available ? "available" : "unavailble") + " to " + presenceBubble.Service.Information.ServiceName); lock (LastPresenceBubbles) { Action a = () => { LastPresenceBubbles.RemoveAll(pb => pb.Service == presenceBubble.Service); LastPresenceBubbles.Add(presenceBubble); }; if (!justAddIfNoLastPresence) { a(); } else { var hasPresence = LastPresenceBubbles.Any(x => x.Service == presenceBubble.Service); if (hasPresence) { // do-nothing } else { a(); } } } if (!justAddIfNoLastPresence && ServiceManager.IsRunning(service)) { Send(presenceBubble); } if (justAddIfNoLastPresence) { return; } if (available) { return; } foreach (var group in BubbleGroupManager.FindAll(service)) { @group.PresenceType = PresenceBubble.PresenceType.Unavailable; } }
public static void ResetSyncsIfHasAgent(Service service) { if (!SupportsSync(service)) { return; } foreach (var group in BubbleGroupManager.FindAll(service)) { group.NeedsSync = true; } }
public static void UpdateStatus(Service service, string bubbleId, Bubble.BubbleStatus status) { var serviceGroups = BubbleGroupManager.FindAll(service); foreach (var group in serviceGroups) { foreach (var bubble in @group) { if (bubble.ID == bubbleId) { UpdateStatus(bubble, status, @group); return; } } } }
public static void SendSubscribe(Service service, bool subscribe) { if (!service.Information.DoesSupport(typeof(SubscribeBubble))) { return; } Utils.DebugPrint((subscribe ? "Subscribing" : "Unsubscribing") + " to " + service.Information.ServiceName + " solo bubble groups."); foreach (var bubbleGroup in BubbleGroupManager.FindAll(g => !g.IsParty && g.Service == service)) { SendSubscribe(bubbleGroup, subscribe); } }
public static bool ResetSyncsIfHasAgent(Service service, string bubbleGroupAddress) { if (!SupportsSync(service)) { return(false); } foreach (var group in BubbleGroupManager.FindAll(service)) { if (service.BubbleGroupComparer(group.Address, bubbleGroupAddress)) { group.NeedsSync = true; return(true); } } return(false); }
public static void SetNotQueuedToFailures(Service service) { if (service is UnifiedService) { return; } if (service.QueuedBubblesParameters == null || service.QueuedBubblesParameters.BubblesNotToQueue == null || !service.QueuedBubblesParameters.BubblesNotToQueue.Any()) { return; } foreach (var group in BubbleGroupManager.FindAll(service)) { SetNotQueuedToFailures(@group); } }
public static void Update(Service service, bool optimized = true) { const int Interval = 5; var updateCounter = 0; var groupsDoneCounter = 0; var groups = BubbleGroupManager.FindAll(service); var updateCounterThreshold = groups.Count / Interval; foreach (var group in groups) { Action chainFinished = null; if (groups.Count >= Interval) { chainFinished = () => { Action <bool> doUpdate = singleton => { BubbleGroupEvents.RaiseRefreshed(groups); BubbleGroupEvents.RaiseBubblesUpdated(groups); BubbleGroupEvents.RaiseInformationUpdated(groups); }; groupsDoneCounter++; if (groupsDoneCounter % Interval == 0) { updateCounter++; doUpdate(false); } // do the remainder one by one ... else if (updateCounter >= updateCounterThreshold) { doUpdate(true); } }; } Update(@group, optimized, chainFinished); } }
private static void StopInternal(Service registeredService, bool clearFailures = true) { if (!IsRegistered(registeredService)) { throw new ServiceSchedulerException("Could not locate service " + registeredService.Information.ServiceName + ". Are you sure you registered it?"); } if (clearFailures) { ClearFailures(registeredService); } Action deAuthenticate = () => { try { registeredService.Deauthenticate(); } catch (NotImplementedException) { } catch (Exception ex) { GetFlags(registeredService).DeauthenticationFailed = true; Utils.DebugPrint(registeredService.Information.ServiceName + "service failed to deauthenticate. " + "This may lead to a memory leak. Problem: " + ex.Message); } }; Action disconnect = () => { try { registeredService.Disconnect(); } catch (NotImplementedException) { } catch (Exception ex) { GetFlags(registeredService).DisconnectionFailed = true; Utils.DebugPrint(registeredService.Information.ServiceName + "service failed to disconnect. " + "This may lead to a memory leak. Problem: " + ex.Message); } }; if (registeredService.Information.Procedure == ServiceInfo.ProcedureType.AuthenticateConnect) { deAuthenticate(); disconnect(); } else if (registeredService.Information.Procedure == ServiceInfo.ProcedureType.ConnectAuthenticate) { disconnect(); deAuthenticate(); } //there may be exceptions, but we have to remove the service. GetFlags(registeredService).Running = false; foreach ( var group in BubbleGroupManager.FindAll( x => x.Service == registeredService && !(x is UnifiedBubbleGroup))) { @group.Typing = false; @group.PresenceType = PresenceBubble.PresenceType.Unavailable; } }