Beispiel #1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (TopicId != 0)
            {
                hash ^= TopicId.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Description.Length != 0)
            {
                hash ^= Description.GetHashCode();
            }
            if (ImageUrl.Length != 0)
            {
                hash ^= ImageUrl.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #2
0
        public IAsyncEnumerable <Subscription> QueryAsync(string appId, TopicId topic, string?userId,
                                                          CancellationToken ct = default)
        {
            Guard.NotNullOrEmpty(appId);

            return(repository.QueryAsync(appId, topic, userId, ct));
        }
        private NTopicLeaveMessage(INTopicId topic)
        {
            var topicId = new TopicId();

            switch (topic.Type)
            {
            case TopicType.DirectMessage:
                topicId.Dm = topic.Id;
                break;

            case TopicType.Room:
                topicId.Room = topic.Id;
                break;

            case TopicType.Group:
                topicId.GroupId = topic.Id;
                break;
            }
            payload = new Envelope {
                TopicsLeave = new TTopicsLeave {
                    Topics =
                    {
                        new List <TopicId> {
                            topicId
                        }
                    }
                }
            };
        }
Beispiel #4
0
        public Task <Subscription> UpsertAsync(string appId, string userId, TopicId prefix, ICommand <Subscription> command, CancellationToken ct)
        {
            Guard.NotNull(command, nameof(command));

            return(Updater.UpdateRetriedAsync(5, async() =>
            {
                var(subscription, etag) = await repository.GetAsync(appId, userId, prefix, ct);

                if (subscription == null)
                {
                    if (!command.CanCreate)
                    {
                        throw new DomainObjectNotFoundException(prefix.ToString());
                    }

                    subscription = Subscription.Create(appId, userId, prefix);
                }

                await command.ExecuteAsync(subscription, serviceProvider, ct);

                await repository.UpsertAsync(subscription, etag, ct);

                return subscription;
            }));
        }
Beispiel #5
0
 public static IRuleBuilderOptions <T, string?> Topic <T>(this IRuleBuilder <T, string?> ruleBuilder)
 {
     return(ruleBuilder.Must(value =>
     {
         return value == null || TopicId.IsValid(value);
     }).WithMessage(Texts.ValidationTopic));
 }
 protected override InSingleProcessMemorySubscription NewSubscribeSubscription(Type messageType, SubscriptionId subscriptionId, TopicId topicId, SubscriptionMode subscriptionMode,
     bool acceptMessagesOlderThanSubscriptionTime, Action<object> messageHandler, string queueName)
 {
     return new InSingleProcessMemoryAuthorizedSubscription(
         this, AuthorizedMessageOperation.Subscribe, subscriptionId, topicId, messageType, queueName,
         subscriptionMode, acceptMessagesOlderThanSubscriptionTime, messageHandler, null, null, null
     );
 }
Beispiel #7
0
        public static Subscription Create(string appId, string userId, TopicId prefix)
        {
            var subscription = new Subscription {
                AppId = appId, UserId = userId, TopicPrefix = prefix
            };

            return(subscription);
        }
Beispiel #8
0
        public async Task <Subscription?> GetAsync(string appId, string userId, TopicId prefix, CancellationToken ct)
        {
            Guard.NotNullOrEmpty(appId, nameof(appId));

            var(subscription, _) = await repository.GetAsync(appId, userId, prefix, ct);

            return(subscription);
        }
Beispiel #9
0
        public async Task AddAllowedTopicAsync(string appId, string userId, TopicId prefix, CancellationToken ct = default)
        {
            var command = new AddUserAllowedTopic
            {
                Prefix = prefix
            };

            await userStore.UpsertAsync(appId, userId, command, ct);
        }
        public async Task <Subscription?> GetAsync(string appId, string userId, TopicId prefix, CancellationToken ct = default)
        {
            var topicPrefix = prefix.Id;

            var document =
                await Collection.Find(x => x.AppId == appId && x.UserId == userId && x.TopicPrefix == topicPrefix)
                .FirstOrDefaultAsync(ct);

            return(document?.ToSubscription());
        }
Beispiel #11
0
        public async Task DeleteAsync(string appId, TopicId path,
                                      CancellationToken ct = default)
        {
            using (Telemetry.Activities.StartActivity("MongoDbTopicRepository/DeleteAsync"))
            {
                var docId = MongoDbTopic.CreateId(appId, path);

                await Collection.DeleteOneAsync(x => x.DocId == docId, ct);
            }
        }
Beispiel #12
0
        public async Task DeleteAsync(string appId, string userId, TopicId prefix,
                                      CancellationToken ct = default)
        {
            using (Telemetry.Activities.StartActivity("MongoDbSubscriptionRepository/DeleteAsync"))
            {
                var id = MongoDbSubscription.CreateId(appId, userId, prefix);

                await Collection.DeleteOneAsync(x => x.DocId == id, ct);
            }
        }
        protected override void TryPublish(
            Type messageType, TopicId topicId, object message, StorageType storageType,
            bool waitForPublishConfirmation, TimeSpan publishConfirmationTimeout,
            Dictionary<string, string> headers, TimeSpan expiration)
        {
            InSingleProcessMemoryAuthorizer.Verify(AuthorizedMessageOperation.Publish, messageType, message, headers);

            base.TryPublish(messageType, topicId, message, storageType, waitForPublishConfirmation,
                publishConfirmationTimeout, headers, expiration);
        }
Beispiel #14
0
        public async Task DeletePrefixAsync(string appId, string userId, TopicId prefix,
                                            CancellationToken ct = default)
        {
            using (Telemetry.Activities.StartActivity("MongoDbSubscriptionRepository/DeletePrefixAsync"))
            {
                var filter = CreatePrefixFilter(appId, userId, prefix, true);

                await Collection.DeleteManyAsync(filter, ct);
            }
        }
 public static void ShowHelpByTopicId(Control parent, TopicId topicId)
 {
     // TODO
     // Check that this is assigning the correct chm file in all cases.  It would appear that
     // ConvertingToPdf and CleaningHiddenData will never look in the right help file as they have the
     // same values as the PES MOBILE topic IDs.
     Help.ShowHelp(parent,
         topicId == TopicId.PesMobileClientComponent || topicId == TopicId.PesMobileClient ? m_mobileHelpFile : m_clientHelpFile,
         HelpNavigator.TopicId, ((int)topicId).ToString(CultureInfo.InvariantCulture) );
 }
        public async Task <IActionResult> Register([FromBody] RegisterUserDto request)
        {
            string?userId    = null;
            string?userToken = null;

            if (request.CreateUser)
            {
                userId = Guid.NewGuid().ToString();

                var update = request.ToUpdate();

                var user = await userStore.UpsertAsync(App.Id, userId, update, HttpContext.RequestAborted);

                if (request.Topics?.Any() == true)
                {
                    var command = new Subscribe
                    {
                        TopicSettings = new NotificationSettings
                        {
                            [Providers.WebPush] = new NotificationSetting
                            {
                                Send = NotificationSend.Send
                            }
                        }
                    };

                    if (!string.IsNullOrEmpty(request.EmailAddress))
                    {
                        command.TopicSettings[Providers.Email] = new NotificationSetting
                        {
                            Send = NotificationSend.Send
                        };
                    }

                    foreach (var topic in request.Topics)
                    {
                        var topicId = new TopicId(topic);

                        await subscriptionStore.UpsertAsync(App.Id, userId, topicId, command, HttpContext.RequestAborted);
                    }
                }

                userToken = user.ApiKey;
            }

            var response = new RegisteredUserDto
            {
                PublicKey = webPushService.PublicKey,
                UserId    = userId,
                UserToken = userToken
            };

            return(Ok(response));
        }
Beispiel #17
0
        public async Task RemoveAllowedTopicAsync(string appId, string userId, TopicId prefix, CancellationToken ct = default)
        {
            var command = new RemoveUserAllowedTopic
            {
                Prefix = prefix
            };

            await userStore.UpsertAsync(appId, userId, command, ct);

            await repository.UnsubscribeByPrefixAsync(appId, userId, prefix, ct);
        }
Beispiel #18
0
        public async Task AllowedTopicRemoveAsync(string appId, string userId, TopicId prefix, CancellationToken ct)
        {
            var command = new RemoveUserAllowedTopic
            {
                Prefix = prefix
            };

            await userStore.UpsertAsync(appId, userId, command, ct);

            await repository.DeletePrefixAsync(appId, userId, prefix, ct);
        }
Beispiel #19
0
        public async Task <(Topic?Topic, string?Etag)> GetAsync(string appId, TopicId path,
                                                                CancellationToken ct = default)
        {
            using (Telemetry.Activities.StartActivity("MongoDbTopicRepository/GetAsync"))
            {
                var docId = MongoDbTopic.CreateId(appId, path);

                var document = await GetDocumentAsync(docId, ct);

                return(document?.ToTopic(), document?.Etag);
            }
        }
        public RabbitMQSubscription(
            IRabbitMQMessageBus messageBus, SubscriptionId subscriptionId, TopicId topicId, 
            Type messageType, string queueName, SubscriptionMode subscriptionMode, bool acceptMessagesOlderThanSubscriptionTime, 
            Action<object> messageHandler, 
            Action<object, object> messageHandlerWithProperties, 
            Action<object, Dictionary<string, string>> messageHandlerWithHeaders, 
            Action<object, object, Dictionary<string, string>> messageHandlerWithPropertiesAndHeaders)
            : base(subscriptionId, topicId, messageType, queueName, subscriptionMode, acceptMessagesOlderThanSubscriptionTime, messageHandler, messageHandlerWithProperties, messageHandlerWithHeaders, messageHandlerWithPropertiesAndHeaders)
        {
            if (topicId == null) throw new ArgumentNullException("topicId");

            MessageBus = messageBus;
        }
Beispiel #21
0
        public XmlNode ToXml(XmlDocument d)
        {
            XmlNode tx = d.CreateElement("comment");

            tx.AppendChild(umbraco.xmlHelper.addCDataNode(d, "body", Body));

            tx.Attributes.Append(umbraco.xmlHelper.addAttribute(d, "id", Id.ToString()));
            tx.Attributes.Append(umbraco.xmlHelper.addAttribute(d, "topicId", TopicId.ToString()));
            tx.Attributes.Append(umbraco.xmlHelper.addAttribute(d, "memberId", MemberId.ToString()));

            tx.Attributes.Append(umbraco.xmlHelper.addAttribute(d, "created", Created.ToString()));

            return(tx);
        }
Beispiel #22
0
        public bool Equals(ForumRecruitmentDetail input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     TopicId == input.TopicId ||
                     (TopicId.Equals(input.TopicId))
                     ) &&
                 (
                     MicrophoneRequired == input.MicrophoneRequired ||
                     (MicrophoneRequired != null && MicrophoneRequired.Equals(input.MicrophoneRequired))
                 ) &&
                 (
                     Intensity == input.Intensity ||
                     (Intensity != null && Intensity.Equals(input.Intensity))
                 ) &&
                 (
                     Tone == input.Tone ||
                     (Tone != null && Tone.Equals(input.Tone))
                 ) &&
                 (
                     Approved == input.Approved ||
                     (Approved != null && Approved.Equals(input.Approved))
                 ) &&
                 (
                     ConversationId == input.ConversationId ||
                     (ConversationId.Equals(input.ConversationId))
                 ) &&
                 (
                     PlayerSlotsTotal == input.PlayerSlotsTotal ||
                     (PlayerSlotsTotal.Equals(input.PlayerSlotsTotal))
                 ) &&
                 (
                     PlayerSlotsRemaining == input.PlayerSlotsRemaining ||
                     (PlayerSlotsRemaining.Equals(input.PlayerSlotsRemaining))
                 ) &&
                 (
                     Fireteam == input.Fireteam ||
                     (Fireteam != null && Fireteam.SequenceEqual(input.Fireteam))
                 ) &&
                 (
                     KickedPlayerIds == input.KickedPlayerIds ||
                     (KickedPlayerIds != null && KickedPlayerIds.SequenceEqual(input.KickedPlayerIds))
                 ));
        }
Beispiel #23
0
        public async IAsyncEnumerable <Subscription> QueryAsync(string appId, TopicId topic, string?userId    = null,
                                                                [EnumeratorCancellation] CancellationToken ct = default)
        {
            using (Telemetry.Activities.StartActivity("MongoDbSubscriptionRepository/QueryAsyncByTopic"))
            {
                var filter = CreatePrefixFilter(appId, userId, topic, false);

                var find = Collection.Find(filter).SortBy(x => x.UserId);

                var lastSubscription = (MongoDbSubscription?)null;

                using (var cursor = await find.ToCursorAsync(ct))
                {
                    while (await cursor.MoveNextAsync(ct) && !ct.IsCancellationRequested)
                    {
                        foreach (var subscription in cursor.Current)
                        {
                            if (topic.Id.StartsWith(subscription.TopicPrefix, StringComparison.OrdinalIgnoreCase))
                            {
                                if (string.Equals(subscription.UserId, lastSubscription?.UserId, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (subscription.TopicPrefix.Length > lastSubscription !.TopicPrefix.Length)
                                    {
                                        lastSubscription = subscription;
                                    }
                                }
                                else
                                {
                                    if (lastSubscription != null)
                                    {
                                        yield return(lastSubscription.ToSubscription());
                                    }

                                    lastSubscription = subscription;
                                }
                            }
                        }
                    }
                }

                if (lastSubscription != null)
                {
                    yield return(lastSubscription.ToSubscription());
                }
            }
        }
Beispiel #24
0
        public bool Equals(CommentSummary input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     TopicId == input.TopicId ||
                     (TopicId.Equals(input.TopicId))
                     ) &&
                 (
                     CommentCount == input.CommentCount ||
                     (CommentCount.Equals(input.CommentCount))
                 ));
        }
Beispiel #25
0
        public async Task Should_be_fast()
        {
            var empty = Guid.Empty.ToString();

            var count = await _.Repository.Collection.CountDocumentsAsync(new BsonDocument());

            var random = new Random();

            const int Count = 1_000_000;

            if (count < Count)
            {
                var inserts = new List <MongoDbSubscription>();

                for (var i = 0; i < Count; i++)
                {
                    TopicId randomTopic = $"{Guid.NewGuid()}/{random.Next(10000)}/{random.Next(10000)}/{random.Next(10000)}/{random.Next(10000)}/{random.Next(10000)}a";

                    inserts.Add(new MongoDbSubscription
                    {
                        DocId       = Guid.NewGuid().ToString(),
                        AppId       = empty,
                        TopicArray  = randomTopic.GetParts(),
                        TopicPrefix = randomTopic,
                        UserId      = empty
                    });
                }

                await _.Repository.Collection.InsertManyAsync(inserts);
            }

            var topicToSearch = $"{Guid.NewGuid()}/{random.Next(10000)}/{random.Next(10000)}a";

            await ToList(_.Repository.QueryAsync(empty, topicToSearch));
            await ToList(_.Repository.QueryAsync(empty, topicToSearch));

            var watch = Stopwatch.StartNew();

            await ToList(_.Repository.QueryAsync(empty, topicToSearch));

            watch.Stop();

            Assert.InRange(watch.ElapsedMilliseconds, 0, 20);
        }
Beispiel #26
0
        public bool Equals(PollResponse input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     TopicId == input.TopicId ||
                     (TopicId.Equals(input.TopicId))
                     ) &&
                 (
                     Results == input.Results ||
                     (Results != null && Results.SequenceEqual(input.Results))
                 ) &&
                 (
                     TotalVotes == input.TotalVotes ||
                     (TotalVotes.Equals(input.TotalVotes))
                 ));
        }
        protected Subscription(
            SubscriptionId subscriptionId, TopicId topicId, Type messageType,
            string queueName,
            SubscriptionMode subscriptionMode,
            bool acceptMessagesOlderThanSubscriptionTime, 
            Action<object> messageHandler,
            Action<object, object> messageHandlerWithProperties,
            Action<object, Dictionary<string, string>> messageHandlerWithHeaders,
            Action<object, object, Dictionary<string, string>> messageHandlerWithPropertiesAndHeaders)
        {
            if ((messageHandler != null) && (messageHandlerWithProperties != null))
                throw new ArgumentException("MessageHandler and MessageHandlerWithProperties cannot be both assigned!");

            SubscriptionId = subscriptionId;
            TopicId = topicId;
            MessageType = messageType;
            SubscriptionMode = subscriptionMode;
            AcceptMessagesOlderThanSubscriptionTime = acceptMessagesOlderThanSubscriptionTime;
            MessageHandler = messageHandler;
            MessageHandlerWithHeaders = messageHandlerWithHeaders;
            MessageHandlerWithProperties = messageHandlerWithProperties;
            MessageHandlerWithPropertiesAndHeaders = messageHandlerWithPropertiesAndHeaders;
            QueueName = queueName;
        }
Beispiel #28
0
 public MoveResult MoveContents(TopicId from, TopicId to)
 {
     if (from is null)
     {
         throw new ArgumentNullException(nameof(from));
     }
     if (to is null)
     {
         throw new ArgumentNullException(nameof(to));
     }
     if (!user.Authorized("move_contents"))
     {
         return(MoveResult.Unauthorized);
     }
     if (db.IsAlreadyMoved(from))
     {
         return(MoveResult.AlreadyMoved);
     }
     if (db.UpdateEntryTopics(from, to))
     {
         return(MoveResult.Success);
     }
     return(MoveResult.AlreadyMoved);
 }
Beispiel #29
0
        private async Task CheckWhitelistAsync(string appId, string userId, TopicId topic, CancellationToken ct = default)
        {
            var user = await userStore.GetCachedAsync(appId, userId, ct);

            if (user == null)
            {
                throw new DomainObjectNotFoundException(userId);
            }

            if (user.AllowedTopics == null)
            {
                return;
            }

            if (user.AllowedTopics.Count == 0 && !user.RequiresWhitelistedTopics)
            {
                return;
            }

            if (!user.AllowedTopics.Any(x => topic.StartsWith(x)))
            {
                throw new DomainForbiddenException("Topic is not whitelisted.");
            }
        }
Beispiel #30
0
        internal NTopicId(TopicId message)
        {
            switch (message.IdCase)
            {
            case TopicId.IdOneofCase.Dm:
                Id   = message.Dm;
                Type = TopicType.DirectMessage;
                break;

            case TopicId.IdOneofCase.Room:
                Id   = message.Room;
                Type = TopicType.Room;
                break;

            case TopicId.IdOneofCase.GroupId:
                Id   = message.GroupId;
                Type = TopicType.Group;
                break;

            default:
                // TODO log a warning?
                break;
            }
        }
 public static void ShowHelpByTopicId(Control parent, TopicId topicId)
 {
     Help.ShowHelp(parent, topicId == TopicId.PesMobileClientComponent || topicId == TopicId.PesMobileClient ? m_mobileHelpFile : m_clientHelpFile,
             HelpNavigator.TopicId, ((int)topicId).ToString(CultureInfo.InvariantCulture));
 }
 public InSingleProcessMemoryAuthorizedSubscription(IInSingleProcessMemoryMessageBus messageBus, AuthorizedMessageOperation operation, SubscriptionId subscriptionId, TopicId topicId, Type messageType, string queueName, SubscriptionMode subscriptionMode, bool acceptMessagesOlderThanSubscriptionTime, Action<object> messageHandler, Action<object, object> messageHandlerWithProperties, Action<object, Dictionary<string, string>> messageHandlerWithHeaders, Action<object, object, Dictionary<string, string>> messageHandlerWithPropertiesAndHeaders)
     : base(messageBus, subscriptionId, topicId, messageType, queueName, subscriptionMode, acceptMessagesOlderThanSubscriptionTime, messageHandler, messageHandlerWithProperties, messageHandlerWithHeaders, messageHandlerWithPropertiesAndHeaders)
 {
     Operation = operation;
 }
 public static void ShowHelpByTopicId(Control parent, TopicId topicId)
 {
     Help.ShowHelp(parent, m_helpFile,
             HelpNavigator.TopicId, ((int)topicId).ToString(System.Globalization.CultureInfo.InvariantCulture));
 }
Beispiel #34
0
 public Task DeleteAsync(string appId, string userId, TopicId prefix, CancellationToken ct)
 {
     return(repository.DeleteAsync(appId, userId, prefix, ct));
 }
 protected static string RoutingKeyFor(TopicId topicId)
 {
     var routingKey = topicId == TopicId.Default ? "#" : topicId.Value;
     return routingKey;
 }
Beispiel #36
0
 public MoveResult MoveContentsC(TopicId from, TopicId to)
 {
     // ... still quite a code here
     return(MoveResult.Success);
 }
Beispiel #37
0
        public async Task SubscribeWhenNotFoundAsync(string appId, string userId, TopicId prefix, CancellationToken ct = default)
        {
            await CheckWhitelistAsync(appId, userId, prefix, ct);

            await repository.SubscribeAsync(appId, new SubscriptionUpdate { UserId = userId, TopicPrefix = prefix }, ct);
        }
Beispiel #38
0
 public Task <Subscription?> GetAsync(string appId, string userId, TopicId prefix, CancellationToken ct = default)
 {
     return(repository.GetAsync(appId, userId, prefix, ct));
 }
Beispiel #39
0
        public string Render()
        {
            StringBuilder sb = new StringBuilder();

            if (Rating == -1)
            {
                Rating = DataProvider.Instance().Topics_GetRating(TopicId);
            }
            if (Enabled)
            {
                sb.Append("<ul id=\"af-rater\" class=\"af-rater ");
            }
            else
            {
                sb.Append("<ul class=\"af-rater ");
            }

            if (Rating > 0)
            {
                sb.Append(" rate" + Rating.ToString());
            }
            sb.Append("\">");
            if (Enabled)
            {
                sb.Append("<li onmouseover=\"amaf_hoverRate(this,1);\" onmouseout=\"amaf_hoverRate(this);\" onclick=\"amaf_changeRate(1," + TopicId.ToString() + ");\">&nbsp;</li>");
                sb.Append("<li onmouseover=\"amaf_hoverRate(this,2);\" onmouseout=\"amaf_hoverRate(this);\" onclick=\"amaf_changeRate(2," + TopicId.ToString() + ");\">&nbsp;</li>");
                sb.Append("<li onmouseover=\"amaf_hoverRate(this,3);\" onmouseout=\"amaf_hoverRate(this);\" onclick=\"amaf_changeRate(3," + TopicId.ToString() + ");\">&nbsp;</li>");
                sb.Append("<li onmouseover=\"amaf_hoverRate(this,4);\" onmouseout=\"amaf_hoverRate(this);\" onclick=\"amaf_changeRate(4," + TopicId.ToString() + ");\">&nbsp;</li>");
                sb.Append("<li onmouseover=\"amaf_hoverRate(this,5);\" onmouseout=\"amaf_hoverRate(this);\" onclick=\"amaf_changeRate(5," + TopicId.ToString() + ");\">&nbsp;</li>");
            }
            else
            {
                sb.Append("<li>&nbsp;</li>");
                sb.Append("<li>&nbsp;</li>");
                sb.Append("<li>&nbsp;</li>");
                sb.Append("<li>&nbsp;</li>");
                sb.Append("<li>&nbsp;</li>");
            }

            sb.Append("</ul>");
            if (Enabled)
            {
                sb.Append("<input type=\"hidden\" value=\"" + Rating.ToString() + "\" id=\"af-rate-value\" />");
            }

            return(sb.ToString());
        }