internal static void RaiseSendingServiceChange(UnifiedBubbleGroup bubbleGroup)
 {
     if (_sendingServiceChanged != null)
     {
         _sendingServiceChanged(bubbleGroup);
     }
 }
Beispiel #2
0
 internal static void RaiseSendingServiceChange(UnifiedBubbleGroup bubbleGroup)
 {
     if (_sendingServiceChanged != null)
     {
         _sendingServiceChanged(bubbleGroup);
     }
 }
Beispiel #3
0
        internal static UnifiedBubbleGroup CreateUnifiedInternal(List <BubbleGroup> groups, BubbleGroup primaryGroup, string id = null)
        {
            var service = ServiceManager.GetUnified();

            if (service == null)
            {
                return(null);
            }

            var newBubble = new NewBubble(Time.GetNowUnixTimestamp(), Bubble.BubbleDirection.Incoming,
                                          Guid.NewGuid() + "@unified", null, false, service);
            var unified = new UnifiedBubbleGroup(groups, primaryGroup, newBubble, id);

            if (id == null)
            {
                var unread = groups.FirstOrDefault(BubbleGroupSettingsManager.GetUnread) != null;
                BubbleGroupSettingsManager.SetUnread(unified, unread);
            }

            foreach (var group in groups)
            {
                @group.RegisterUnified(unified);
            }

            var associatedPartiallyLoadedGroups = groups.Where(x => x.PartiallyLoaded).ToList();

            if (associatedPartiallyLoadedGroups.Any())
            {
                VisualBubble latest = null;
                foreach (var innerGroup in unified.Groups)
                {
                    var current = innerGroup.Bubbles.Last();
                    if (latest == null || current.Time > latest.Time)
                    {
                        latest = current;
                    }
                }
                if (latest != null)
                {
                    unified.Bubbles.Clear();
                    unified.Bubbles.Add(latest);
                }
                return(unified);
            }

            Populate(unified);

            return(unified);
        }
        public static List<BubbleGroup> DeleteUnified(UnifiedBubbleGroup unifiedGroup, bool deleteInnerGroups = true)
        {
            lock (BubbleGroupDatabase.OperationLock)
            {
                foreach (var group in unifiedGroup.Groups)
                {
                    @group.DeregisterUnified();
                    if (deleteInnerGroups)
                        Delete(@group);
                }

                BubbleGroupManager.BubbleGroupsRemove(unifiedGroup);
                BubbleGroupIndex.RemoveUnified(unifiedGroup.ID);

                return deleteInnerGroups ? null : unifiedGroup.Groups;
            }
        }
Beispiel #5
0
        public static List <BubbleGroup> DeleteUnified(UnifiedBubbleGroup unifiedGroup, bool deleteInnerGroups = true)
        {
            lock (BubbleGroupDatabase.OperationLock)
            {
                foreach (var group in unifiedGroup.Groups)
                {
                    @group.DeregisterUnified();
                    if (deleteInnerGroups)
                    {
                        Delete(@group);
                    }
                }

                BubbleGroupManager.BubbleGroupsRemove(unifiedGroup);
                BubbleGroupIndex.RemoveUnified(unifiedGroup.ID);

                return(deleteInnerGroups ? null : unifiedGroup.Groups);
            }
        }
Beispiel #6
0
 internal static void AddUnified(UnifiedBubbleGroup unifiedGroup)
 {
     lock (_dbLock)
     {
         RemoveUnified(unifiedGroup.ID);
         using (var db = new SqlDatabase <Entry>(Location, false))
         {
             if (!db.Failed)
             {
                 db.Add(new Entry
                 {
                     Guid    = unifiedGroup.ID,
                     Unified = true,
                     UnifiedBubbleGroupsGuids = unifiedGroup.Groups.Select(x => x.ID).
                                                Aggregate((current, next) => current + "," + next),
                     UnifiedPrimaryBubbleGroupGuid = unifiedGroup.PrimaryGroup.ID,
                     UnifiedSendingBubbleGroupGuid = unifiedGroup.SendingGroup.ID,
                 });
             }
         }
     }
 }
Beispiel #7
0
        private static void Populate(UnifiedBubbleGroup unified)
        {
            var innerGroupsCursors = unified.Groups.Select(@group => new Tuple <BubbleGroup, long>(@group, -1)).ToList();

            var allBubbles = new List <VisualBubble>();
            var day        = 1;

            var handles = OpenDatabaseStreams(unified).ToList();

GetMoreBubbles:
            var result = LoadDatabaseBubblesOnUnitInto(unified, day, handles, innerGroupsCursors);

            innerGroupsCursors = result.Item2;
            day++;
            var bubbles = result.Item1;

            if (bubbles != null)
            {
                allBubbles.AddRange(bubbles);
            }
            var endReached = result.Item2.Count(cursor => cursor.Item2 == -2);

            if (endReached == result.Item2.Count)
            {
                goto End;
            }
            if (bubbles == null)
            {
                goto GetMoreBubbles;
            }
            if (allBubbles.Count < 100)
            {
                goto GetMoreBubbles;
            }

End:

            CloseDatabaseStreams(handles);

            allBubbles.TimSort((x, y) => x.Time.CompareTo(y.Time));
            Func <VisualBubble, VisualBubble> tryFindRealBubble = incoming =>
            {
                foreach (var bubble in
                         unified.Groups.SelectMany(@group => @group.Bubbles.Where(bubble => bubble.ID == incoming.ID)))
                {
                    return(bubble);
                }

                return(incoming);
            };

            for (var i = 0; i < allBubbles.Count; i++)
            {
                allBubbles[i] = tryFindRealBubble(allBubbles[i]);
            }
            unified.Bubbles.Clear();
            foreach (var bubble in allBubbles)
            {
                unified.Bubbles.Add(bubble);
            }
            unified.UnifiedGroupLoaded = true;
        }
Beispiel #8
0
 public static BubbleGroup FindFirstInnerWithRegisteredService(UnifiedBubbleGroup unifiedGroup)
 {
     return(unifiedGroup.Groups.FirstOrDefault(x =>
                                               ServiceManager.IsRegistered(x.Service)));
 }
 public static BubbleGroup FindFirstInnerWithRegisteredService(UnifiedBubbleGroup unifiedGroup)
 {
     return unifiedGroup.Groups.FirstOrDefault(x =>
         ServiceManager.IsRegistered(x.Service));
 }
 private static IEnumerable<Tuple<BubbleGroup, Stream>> OpenDatabaseStreams(UnifiedBubbleGroup group)
 {
     return OpenDatabaseStreams(@group.Groups);
 }
 private static Tuple<List<VisualBubble>, List<Tuple<BubbleGroup, long>>> LoadDatabaseBubblesOnUnitInto(UnifiedBubbleGroup group, int day, List<Tuple<BubbleGroup, Stream>> handles, 
     List<Tuple<BubbleGroup, long>> cursors, string[] bubbleTypes = null, Func<VisualBubble, bool> comparer = null)
 {
     return LoadDatabaseBubblesOnUnitInto(group.Groups, day, handles, cursors, bubbleTypes, comparer);
 }
        private static UnifiedBubbleGroup CreateUnifiedInternal(List<BubbleGroup> groups, BubbleGroup primaryGroup, string id = null)
        {
            var service = ServiceManager.GetUnified();
            if (service == null)
                return null;

            var newBubble = new NewBubble(Time.GetNowUnixTimestamp(), Bubble.BubbleDirection.Incoming,
                Guid.NewGuid() + "@unified", null, false, service);
            var unified = new UnifiedBubbleGroup(groups, primaryGroup, newBubble, id);
            if (id == null)
            {
                var unread = groups.FirstOrDefault(BubbleGroupSettingsManager.GetUnread) != null;
                BubbleGroupSettingsManager.SetUnread(unified, unread);
            }

            foreach (var group in groups)
            {
                @group.RegisterUnified(unified);
            }

            var associatedPartiallyLoadedGroups = groups.Where(x => x.PartiallyLoaded).ToList();
            if (associatedPartiallyLoadedGroups.Any())
            {
                VisualBubble latest = null;
                foreach (var innerGroup in unified.Groups)
                {
                    var current = innerGroup.Last();
                    if (latest == null || current.Time > latest.Time)
                    {
                        latest = current;
                    }
                }
                if (latest != null)
                {
                    unified.Bubbles.Clear();
                    unified.Bubbles.Add(latest);
                }
                return unified;
            }

            Populate(unified);

            return unified;
        }
Beispiel #13
0
 public void RegisterUnified(UnifiedBubbleGroup unified)
 {
     Unified = unified;
 }
Beispiel #14
0
 private static Tuple <List <VisualBubble>, List <Tuple <BubbleGroup, long> > > LoadDatabaseBubblesOnUnitInto
     (UnifiedBubbleGroup group, int day, List <Tuple <BubbleGroup, Stream> > handles,
     List <Tuple <BubbleGroup, long> > cursors, string[] bubbleTypes = null, Func <VisualBubble, bool> comparer = null)
 {
     return(LoadDatabaseBubblesOnUnitInto(group.Groups, day, handles, cursors, bubbleTypes, comparer));
 }
        private static void Populate(UnifiedBubbleGroup unified)
        {
            var innerGroupsCursors = unified.Groups.Select(@group => new Tuple<BubbleGroup, long>(@group, -1)).ToList();

            var allBubbles = new List<VisualBubble>();
            var day = 1;

            var handles = OpenDatabaseStreams(unified).ToList();

            GetMoreBubbles:
            var result = LoadDatabaseBubblesOnUnitInto(unified, day, handles, innerGroupsCursors);
            innerGroupsCursors = result.Item2;
            day++;
            var bubbles = result.Item1;
            if (bubbles != null)
            {
                allBubbles.AddRange(bubbles);
            }
            var endReached = result.Item2.Count(cursor => cursor.Item2 == -2);
            if (endReached == result.Item2.Count)
            {
                goto End;
            }
            if (bubbles == null)
            {
                goto GetMoreBubbles;
            }
            if (allBubbles.Count < 100)
            {
                goto GetMoreBubbles;
            }

            End:

            CloseDatabaseStreams(handles);

            allBubbles.TimSort((x, y) => x.Time.CompareTo(y.Time));
            Func<VisualBubble, VisualBubble> tryFindRealBubble = incoming =>
            {
                foreach (var bubble in
                    unified.Groups.SelectMany(@group => @group.Where(bubble => bubble.ID == incoming.ID)))
                {
                    return bubble;
                }

                return incoming;
            };
            for (var i = 0; i < allBubbles.Count; i++)
            {
                allBubbles[i] = tryFindRealBubble(allBubbles[i]);
            }
            unified.Bubbles.Clear();
            foreach (var bubble in allBubbles)
            {
                unified.Bubbles.Add(bubble);
            }
            unified.UnifiedGroupLoaded = true;
        }
Beispiel #16
0
 private static IEnumerable <Tuple <BubbleGroup, Stream> > OpenDatabaseStreams(UnifiedBubbleGroup group)
 {
     return(OpenDatabaseStreams(@group.Groups));
 }
 internal static void AddUnified(UnifiedBubbleGroup unifiedGroup)
 {
     lock (_dbLock)
     {
         RemoveUnified(unifiedGroup.ID);
         using (var db = new SqlDatabase<Entry>(Location, false))
         {
             if (!db.Failed)
             {
                 db.Add(new Entry
                 {
                     Guid = unifiedGroup.ID,
                     Unified = true,
                     UnifiedBubbleGroupsGuids = unifiedGroup.Groups.Select(x => x.ID).
                         Aggregate((current, next) => current + "," + next),
                     UnifiedPrimaryBubbleGroupGuid = unifiedGroup.PrimaryGroup.ID,
                     UnifiedSendingBubbleGroupGuid = unifiedGroup.SendingGroup.ID,
                 });
             }
         }
     }
 }