コード例 #1
0
        public static void UpdatePartyParticipants(Service service,
                                                   string bubbleGroupAddress, Action <bool> finished = null)
        {
            var bubbleGroup =
                BubbleGroupManager.FindWithAddress(service, bubbleGroupAddress);

            if (bubbleGroup == null)
            {
                finished(false);
            }
            UpdatePartyParticipants(bubbleGroup, () =>
            {
                try
                {
                    BubbleGroupEvents.RaiseBubblesUpdated(bubbleGroup);
                }
                catch
                {
                    // do nothing
                }
                if (finished != null)
                {
                    finished(true);
                }
            });
        }
コード例 #2
0
 internal static void Update(BubbleGroup group, bool optimized = true, Action optimizedChainFinished = null)
 {
     if (optimized)
     {
         UpdateName(@group, () =>
         {
             UpdateGroupLegibleID(@group, () =>
             {
                 UpdatePartyParticipants(@group, () =>
                 {
                     if (optimizedChainFinished != null)
                     {
                         optimizedChainFinished();
                     }
                     else
                     {
                         BubbleGroupEvents.RaiseRefreshed(@group);
                         BubbleGroupEvents.RaiseBubblesUpdated(@group);
                         BubbleGroupEvents.RaiseInformationUpdated(@group);
                     }
                 });
             });
         });
     }
     else
     {
         UpdateName(@group);
         UpdateGroupLegibleID(@group);
         UpdatePartyParticipants(@group);
     }
 }
コード例 #3
0
        public static void SetNotQueuedToFailures(BubbleGroup group)
        {
            var groups = BubbleGroupManager.GetInner(@group).Where(x => !x.PartiallyLoaded &&
                                                                   (x.Service.QueuedBubblesParameters != null &&
                                                                    x.Service.QueuedBubblesParameters.SendingBubblesToFailOnServiceStart != null &&
                                                                    x.Service.QueuedBubblesParameters.SendingBubblesToFailOnServiceStart.Any()));

            var failed = new List <Tuple <BubbleGroup, VisualBubble> >();

            foreach (var innerGroup in groups)
            {
                foreach (var bubble in innerGroup)
                {
                    if (bubble.Direction == Bubble.BubbleDirection.Outgoing &&
                        bubble.Status == Bubble.BubbleStatus.Waiting)
                    {
                        if (innerGroup
                            .Service.QueuedBubblesParameters.SendingBubblesToFailOnServiceStart
                            .FirstOrDefault(x => x == bubble.GetType()) != null)
                        {
                            failed.Add(new Tuple <BubbleGroup, VisualBubble>(innerGroup, bubble));
                        }
                    }
                }
            }

            if (!failed.Any())
            {
                return;
            }

            var somethingUpdated = false;

            var failuresGroupedByBubbleGroup = failed.GroupBy(x => x.Item1);

            foreach (var failureGroup in failuresGroupedByBubbleGroup)
            {
                var groupOfBubbles = failureGroup.First().Item1;
                var bubbles        = failureGroup.Select(x => x.Item2).ToArray();

                foreach (var bubble in bubbles)
                {
                    bubble.Status = Bubble.BubbleStatus.Failed;
                }
                BubbleGroupDatabase.UpdateBubble(groupOfBubbles, bubbles, groupOfBubbles.Bubbles.Count + 100); // 100 is really a tolerance here (just in case)
                foreach (var bubble in bubbles)
                {
                    BubbleGroupEvents.RaiseBubbleFailed(bubble, groupOfBubbles);
                }
                somethingUpdated = true;
            }

            if (somethingUpdated)
            {
                BubbleGroupEvents.RaiseBubblesUpdated(@group);
                BubbleGroupEvents.RaiseRefreshed(@group);
            }
        }
コード例 #4
0
        public static bool UpdateUnknownPartyParticipant(BubbleGroup bubbleGroup, string participantAddress, Action onAdded = null)
        {
            var service = bubbleGroup.Service;

            if (!ServiceManager.IsRunning(service))
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(participantAddress))
            {
                return(false);
            }

            if (bubbleGroup.FailedUnknownParticipants.FirstOrDefault(x =>
                                                                     bubbleGroup.Service.BubbleGroupComparer(x, participantAddress)) != null)
            {
                return(false);
            }

            try
            {
                service.GetBubbleGroupUnknownPartyParticipant(bubbleGroup, participantAddress, participant =>
                {
                    if (participant != null)
                    {
                        var contains = bubbleGroup.Participants.FirstOrDefault(x =>
                                                                               bubbleGroup.Service.BubbleGroupComparer(x.Address, participantAddress)) != null;
                        if (!contains)
                        {
                            participant.Unknown = true;
                            bubbleGroup.Participants.Add(participant);
                        }
                    }
                    else
                    {
                        bubbleGroup.FailedUnknownParticipants.Add(participantAddress);
                    }
                    if (onAdded != null)
                    {
                        onAdded();
                    }
                    BubbleGroupEvents.RaiseRefreshed(bubbleGroup);
                    BubbleGroupEvents.RaiseBubblesUpdated(bubbleGroup);
                });
            }
            catch (Exception ex)
            {
                Utils.DebugPrint("Error getting unknown bubble group participant: " + service.Information.ServiceName + ": " +
                                 ex.Message);
                return(false);
            }

            return(true);
        }
コード例 #5
0
 public static void UpdateStatus(VisualBubble b, Bubble.BubbleStatus status, BubbleGroup group,
                                 bool updateBubbleGroupBubbles = true)
 {
     b.Status = status;
     BubbleGroupDatabase.UpdateBubble(@group, b);
     if (updateBubbleGroupBubbles)
     {
         BubbleGroupEvents.RaiseBubblesUpdated(@group);
     }
     BubbleGroupEvents.RaiseRefreshed(@group);
 }
コード例 #6
0
ファイル: BubbleManager.cs プロジェクト: mjsir911/Disa-XMPP
 public static void UpdateStatus(VisualBubble[] bubbles, Bubble.BubbleStatus status, BubbleGroup group,
                                 bool updateBubbleGroupBubbles = true)
 {
     foreach (var bubble in bubbles)
     {
         bubble.Status = status;
     }
     BubbleGroupDatabase.UpdateBubble(@group, bubbles);
     if (updateBubbleGroupBubbles)
     {
         BubbleGroupEvents.RaiseBubblesUpdated(@group);
     }
     BubbleGroupEvents.RaiseRefreshed(@group);
 }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        internal static async void UpdatePartyParticipants(BubbleGroup bubbleGroup, Action finished = null)
        {
            var service = bubbleGroup.Service;

            if (!ServiceManager.IsRunning(service))
            {
                return;
            }

            if (!bubbleGroup.IsParty)
            {
                if (finished != null)
                {
                    finished();
                }
                return;
            }

            try
            {
                await service.GetBubbleGroupPartyParticipants(bubbleGroup, participants =>
                {
                    // we need to propogate the old participant photos to the new participant list
                    var newParticipants = participants == null ? new List <DisaParticipant>() : participants.ToList();
                    foreach (var oldParticipant in bubbleGroup.Participants)
                    {
                        var newParticipant = newParticipants.FirstOrDefault(x => service.BubbleGroupComparer(x.Address, oldParticipant.Address));
                        if (newParticipant != null)
                        {
                            newParticipant.Photo = oldParticipant.Photo;
                            newParticipant.IsPhotoSetFromService = oldParticipant.IsPhotoSetFromService;
                        }
                    }
                    // move all unknown participants over
                    foreach (var unknownParticipant in bubbleGroup.Participants.Where(x => x.Unknown))
                    {
                        if (newParticipants.FirstOrDefault(x => service.BubbleGroupComparer(x.Address, unknownParticipant.Address)) == null)
                        {
                            newParticipants.Add(unknownParticipant);
                        }
                    }
                    bubbleGroup.Participants = new ThreadSafeList <DisaParticipant>(newParticipants);
                    bubbleGroup.IsParticipantsSetFromService = true;
                    if (finished == null)
                    {
                        BubbleGroupEvents.RaiseBubblesUpdated(bubbleGroup);
                    }
                    else
                    {
                        finished();
                    }
                });
            }
            catch (Exception ex)
            {
                Utils.DebugPrint("Error updating bubble group participants: " + service.Information.ServiceName +
                                 " - " + bubbleGroup.Address + ": " + ex);
                if (finished != null)
                {
                    finished();
                }
            }
        }
コード例 #9
0
        public static Task <List <Receipt> > Send(string[] serviceNames, bool scheduled = false)
        {
            return(Task <List <Receipt> > .Factory.StartNew(() =>
            {
                //PROCESS:  1) find all bubbles under serviceNames in db
                //          2) relate db entries to bubbles loaded into memory by Disa
                //          3) parallel send bubbles based respective to service
                //          4) delete all successful bubbles out of db

                lock (_sendLock)
                {
                    var nowUnixTimestamp = Time.GetNowUnixTimestamp();

                    var possibleBubblesFromDatabase = new List <Entry>();

                    lock (_dbLock)
                    {
                        using (var db = new SqlDatabase <Entry>(Location))
                        {
                            foreach (var possibleBubble in db.Store.Where(x => serviceNames.Contains(x.ServiceName)).Reverse())
                            {
                                if (!InsertBubble.IsSending(possibleBubble.Guid))
                                {
                                    possibleBubblesFromDatabase.Add(possibleBubble);
                                }
                            }
                        }
                    }

                    var possibleBubblesInDisa = new List <Tuple <Entry, VisualBubble> >();
                    foreach (var bubbleGroup in BubbleGroupManager.BubbleGroupsNonUnified)
                    {
                        var hasPossibleBubble = possibleBubblesFromDatabase.FirstOrDefault(x =>
                                                                                           x.BubbleGroupGuid != null && x.BubbleGroupGuid == bubbleGroup.ID) != null;
                        if (!hasPossibleBubble)
                        {
                            continue;
                        }

                        if (bubbleGroup.PartiallyLoaded)
                        {
                            BubbleGroupFactory.LoadFullyIfNeeded(bubbleGroup);
                        }

                        var bubblesToSetToFail = new List <Tuple <Entry, VisualBubble> >();
                        foreach (var bubble in bubbleGroup.Bubbles)
                        {
                            if (bubble.Status != Bubble.BubbleStatus.Waiting)
                            {
                                continue;
                            }

                            if (bubble.Direction != Bubble.BubbleDirection.Outgoing)
                            {
                                continue;
                            }

                            var possibleBubbleFromDatabase = possibleBubblesFromDatabase.FirstOrDefault(x => x.Guid == bubble.ID);
                            if (possibleBubbleFromDatabase != null)
                            {
                                // older than 10 minutes, fail
                                if (bubble.Time < (nowUnixTimestamp - 600))
                                {
                                    bubble.Status = Bubble.BubbleStatus.Failed;
                                    bubblesToSetToFail.Add(Tuple.Create(possibleBubbleFromDatabase, bubble));
                                    continue;
                                }

                                possibleBubblesInDisa.Add(new Tuple <Entry, VisualBubble>(possibleBubbleFromDatabase, bubble));
                            }
                        }
                        if (bubblesToSetToFail.Any())
                        {
                            BubbleGroupDatabase.UpdateBubble(bubbleGroup,
                                                             bubblesToSetToFail.Select(x => x.Item2).ToArray(), 100);
                            Remove(bubblesToSetToFail.Select(x => x.Item1).ToArray());
                            foreach (var bubble in bubblesToSetToFail)
                            {
                                BubbleGroupEvents.RaiseBubbleFailed(bubble.Item2, bubbleGroup);
                            }
                            BubbleGroupEvents.RaiseBubblesUpdated(bubbleGroup);
                            BubbleGroupEvents.RaiseRefreshed(bubbleGroup);
                        }
                    }

                    var sent = new List <Tuple <Entry, bool> >();

                    var possibleBubblesInDisaByService = possibleBubblesInDisa.GroupBy(x => x.Item1.ServiceName);
                    Parallel.ForEach(possibleBubblesInDisaByService, possibleBubblesInService =>
                    {
                        var failed = false;
                        foreach (var possibleBubble in possibleBubblesInService)
                        {
                            if (failed)
                            {
                                sent.Add(new Tuple <Entry, bool>(possibleBubble.Item1, false));
                                continue;
                            }

                            Utils.DebugPrint(">>>>>>>>>>> Sending queued bubble on "
                                             + possibleBubble.Item2.Service.Information.ServiceName + "!");

                            var sendBubbleTask = BubbleManager.Send(possibleBubble.Item2, true);
                            sendBubbleTask.Wait();
                            if (sendBubbleTask.Result)
                            {
                                Utils.DebugPrint(">>>>>>>>> Successfully sent queued bubble on " +
                                                 possibleBubble.Item2.Service.Information.ServiceName + "!");
                                sent.Add(new Tuple <Entry, bool>(possibleBubble.Item1, true));
                                lock (_dbLock)
                                {
                                    using (var db = new SqlDatabase <Entry>(Location))
                                    {
                                        db.Remove(possibleBubble.Item1);
                                    }
                                }
                                Utils.Delay(100).Wait();
                            }
                            else
                            {
                                Utils.DebugPrint(">>>>>>>>> Failed to send queued bubble on " +
                                                 possibleBubble.Item2.Service.Information.ServiceName + "!");
                                sent.Add(new Tuple <Entry, bool>(possibleBubble.Item1, false));
                                failed = true; // fail the entire chain for this service from here on out so messages aren't sent out of order
                            }
                        }
                    });

                    var receipts = sent.Select(x => new Receipt(x.Item1.Guid, x.Item2)).ToList();

                    if (!scheduled)
                    {
                        if (receipts.FirstOrDefault(x => !x.Success) != null)
                        {
                            ScheduleReSend(serviceNames);
                        }
                        else
                        {
                            var needToSendAgain = serviceNames.Where(x => BubbleQueueManager.HasQueuedBubbles(x, true, true)).ToArray();
                            if (needToSendAgain.Any())
                            {
                                Send(needToSendAgain);
                            }
                        }
                    }

                    SanityCheckup();

                    return receipts;
                }
            }));
        }
コード例 #10
0
        public static void SetNotQueuedToFailures(BubbleGroup group)
        {
            var nowUnixTimeStamp = Time.GetNowUnixTimestamp();

            var groups = BubbleGroupManager.GetInner(@group).Where(x =>
                                                                   (x.Service.QueuedBubblesParameters != null &&
                                                                    x.Service.QueuedBubblesParameters.BubblesNotToQueue != null &&
                                                                    x.Service.QueuedBubblesParameters.BubblesNotToQueue.Any()));

            if (!groups.Any())
            {
                return;
            }

            foreach (var innerGroup in groups)
            {
                if (HasNotQueued(innerGroup))
                {
                    if (innerGroup.PartiallyLoaded)
                    {
                        BubbleGroupFactory.LoadFullyIfNeeded(innerGroup);
                    }

                    var bubblesSetToFailed = new List <VisualBubble>();

                    foreach (var bubble in innerGroup.Bubbles)
                    {
                        if (bubble.Direction == Bubble.BubbleDirection.Outgoing &&
                            bubble.Status == Bubble.BubbleStatus.Waiting)
                        {
                            if (innerGroup
                                .Service.QueuedBubblesParameters.BubblesNotToQueue
                                .FirstOrDefault(x => x == bubble.GetType()) != null)
                            {
                                var failBubble = innerGroup
                                                 .Service.QueuedBubblesParameters.SendingBubblesToFailOnServiceStart
                                                 .FirstOrDefault(x => x == bubble.GetType()) != null;

                                // Older than 10 minutes, fail it regardless.
                                if (!failBubble && bubble.Time < (nowUnixTimeStamp - 600))
                                {
                                    failBubble = true;
                                }

                                if (failBubble)
                                {
                                    RemoveNotQueued(bubble);
                                    bubble.Status = Bubble.BubbleStatus.Failed;
                                    bubblesSetToFailed.Add(bubble);
                                }
                            }
                        }
                    }

                    if (bubblesSetToFailed.Any())
                    {
                        BubbleGroupDatabase.UpdateBubble(innerGroup, bubblesSetToFailed.ToArray(), 100);
                        foreach (var bubble in bubblesSetToFailed)
                        {
                            BubbleGroupEvents.RaiseBubbleFailed(bubble, innerGroup);
                        }
                        BubbleGroupEvents.RaiseBubblesUpdated(innerGroup);
                        BubbleGroupEvents.RaiseRefreshed(innerGroup);
                    }
                }
            }

            NotQueuedSanityCheckup();
        }