Beispiel #1
0
        public bool RemovePerson(IPerson person, bool automated = false, bool useNonAutomatedIfFound = false)
        {
            var probe = GroupSubscription.Where(i => i.GroupId == Id && i.PersonId == person.Id).FirstOrDefault();

            if (probe == null)
            {
                return(false);
            }

            if (automated)
            {
                if (!probe.IsImport)
                {
                    if (!useNonAutomatedIfFound)
                    {
                        return(false);
                    }
                }
            }

            probe.Remove();

            Base.Current.Log.KeyValuePair(person.Locator, $"REMOVE from {ToString()}", Message.EContentType.Info);

            return(true);
        }
Beispiel #2
0
        public bool AddSubscription(int subscriberId, int groupId)
        {
            IRepository<GroupSubscription> subscriptionsRepo = UnitOfWork.Repository<GroupSubscription>();

            GroupSubscription newSubscription = new GroupSubscription
            {
                SubscriberId = subscriberId,
                GroupId = groupId,
                DateJoined = DateTime.Now
            };

            GroupSubscription insertedSubscription = subscriptionsRepo.Insert(newSubscription);
            return insertedSubscription != null;
        }
Beispiel #3
0
 private ActiveSubscription ConvertGroup(GroupSubscription sub)
 {
     if (sub == null)
     {
         return(DefaultSubscription());
     }
     return(new ActiveSubscription()
     {
         GroupName = sub.GroupName,
         RateLimit = sub.Subscription.RateLimit,
         AnalysisCap = sub.Subscription.AnalysisCap,
         Expires = sub.Subscription.Expires,
         IsDefault = false
     });
 }
Beispiel #4
0
        public bool AddPerson(IPerson person, bool automated = false, bool useNonAutomatedIfFound = false)
        {
            var probe = GroupSubscription.Where(i => i.GroupId != Id || i.PersonId != person.Id).FirstOrDefault();

            if (probe != null)
            {
                if (probe.Active)
                {
                    return(false);
                }
            }

            if (probe != null)
            {
                if (!probe.Active)
                {
                    probe.Active = true;
                }
            }
            else
            {
                probe = new GroupSubscription
                {
                    GroupId  = Id,
                    PersonId = person.Id,
                    Active   = true
                };
            }

            if (!probe.IsImport)
            {
                if (automated)
                {
                    if (useNonAutomatedIfFound)
                    {
                        probe.IsImport = true;
                    }
                }
            }

            probe.Save();

            Base.Current.Log.KeyValuePair(person.Locator, $"ADD to {ToString()}", Message.EContentType.Info);

            return(true);
        }
Beispiel #5
0
        public SubscriberModel AddSubscriber(SubscriberWithFirstGroupModel model)
        {
            IRepository<Subscriber> subscriberRepo = UnitOfWork.Repository<Subscriber>();
            IRepository<GroupSubscription> groupSubRepo = UnitOfWork.Repository<GroupSubscription>();

            Subscriber newSub = new Subscriber
            {
                Name = model.Name,
                Surname = model.Surname,
                Email = model.Email
            };

            Subscriber insertedSub = subscriberRepo.Insert(newSub);

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

            model.Id = insertedSub.Id;

            if (model.FirstGroupId.HasValue)
            {
                GroupSubscription subscription = new GroupSubscription
                {
                    GroupId = model.FirstGroupId.Value,
                    SubscriberId = model.Id,
                    DateJoined = DateTime.Now
                };

                GroupSubscription createdSubscription = groupSubRepo.Insert(subscription);
                if (createdSubscription == null)
                {
                    return null;
                }
            }

            return model;
        }
Beispiel #6
0
        public async Task <GroupAssignment> Assign(ClusterManager metadata, GroupSubscription groupSubscription)
        {
            Dictionary <string, Subscription> subscriptions = groupSubscription.groupSubscription();
            var allSubscribedTopics = new HashSet <string>();

            foreach (var topic in subscriptions.SelectMany(e => e.Value.Topics))
            {
                allSubscribedTopics.Add(topic);
            }

            var partitionsPerTopic = new Dictionary <string, int>();

            foreach (string topic in allSubscribedTopics)
            {
                int numPartitions = (await metadata.GetTopic(topic)).Partitions.Count;
                if (numPartitions > 0)
                {
                    partitionsPerTopic.Add(topic, numPartitions);
                }
                else
                {
                    log.debug("Skipping assignment for topic {} since no metadata is available", topic);
                }
            }

            Dictionary <string, List <TopicPartition> > rawAssignments = Assign(partitionsPerTopic, subscriptions);

            // this class maintains no user data, so just wrap the results
            var assignments = new Dictionary <string, Assignment>();

            foreach (var assignmentEntry in rawAssignments)
            {
                assignments.Add(assignmentEntry.Key, new Assignment(0, assignmentEntry.Value, null));
            }
            return(new GroupAssignment(assignments));
        }
Beispiel #7
0
 public IEnumerable <GroupSubscription> GetSubscriptions(bool includeInactive = true)
 {
     return(GroupSubscription.Where(i => i.GroupId == Id && (includeInactive || i.Active)));
 }
 /// <summary>
 /// There are no comments for GroupSubscription in the schema.
 /// </summary>
 public void AddToGroupSubscription(GroupSubscription groupSubscription)
 {
     base.AddObject("GroupSubscription", groupSubscription);
 }
 /// <summary>
 /// Create a new GroupSubscription object.
 /// </summary>
 /// <param name="roleType">Initial value of RoleType.</param>
 /// <param name="subscriptionID">Initial value of SubscriptionID.</param>
 public static GroupSubscription CreateGroupSubscription(string roleType, int subscriptionID)
 {
     GroupSubscription groupSubscription = new GroupSubscription();
     groupSubscription.RoleType = roleType;
     groupSubscription.SubscriptionID = subscriptionID;
     return groupSubscription;
 }
 public void Subscribe(GroupSubscription subscription)
 {
     throw new System.NotImplementedException();
 }