static void SendMessage(TopicType topic) { // Create a transaction because we are using a transactional queue. using (var trn = new MessageQueueTransaction()) { try { // Create queue object using (var queue = QueueHelper.GetQueueReference(@".\private$\mbp.message")) { queue.Formatter = new XmlMessageFormatter(); // push message onto queue (inside of a transaction) trn.Begin(); queue.Send(String.Format("{0} message", topic), topic.ToString(), trn); trn.Commit(); Console.WriteLine("==============================="); Console.WriteLine("{0} message queued", topic); Console.WriteLine("==============================="); Console.WriteLine(); } } catch { trn.Abort(); // rollback the transaction } } }
private bool ProcessCommand(Message message, TopicType topic) { // get the subscribers var subscriptions = new SubscriptionManager(); List <string> subscribers = subscriptions.GetSubscribers(topic); // loop through the subscribers and send the message using (var trn = new MessageQueueTransaction()) { foreach (var subscriberQueue in subscribers) { try { // Create queue object using (var queue = QueueHelper.GetQueueReference(subscriberQueue)) { queue.Formatter = new XmlMessageFormatter(); // push message onto queue (inside of a transaction) trn.Begin(); queue.Send((string)message.Body, topic.ToString(), trn); trn.Commit(); Console.WriteLine("{0} message queued on {1}", topic, subscriberQueue); } } catch { trn.Abort(); // rollback the transaction return(false); } } } return(true); // successfully sent the message on to subscribers }
public async Task <IActionResult> GetEventsByTopic(TopicType topic, int?page, int?count) { LogRequestInformation(topic.ToString()); var result = await _douService.GetEventsByTopic(topic, page, count); LogResponseInformation(result); return(Ok(result)); }
/// <summary> /// Manages the modular tasks pertaining to modification of the topic database(s). /// Or alternatively runs the topic command as usual if no reasonable alias or syntax can be leveraged. /// </summary> /// <param name="Command">The entire list of arguments used for the command, stringified.</param> /// <param name="TopicType">What type of topic database should be accessed. Either 'topic' or 'wyr'.</param> /// <returns>A <c>Task</c> object, which can be awaited until this method completes successfully.</returns> public async Task RunTopic(string Command, TopicType TopicType) { string Name = Regex.Replace(TopicType.ToString(), "([A-Z])([a-z]*)", " $1$2").Substring(1); if (!string.IsNullOrEmpty(Command)) { if (Enum.TryParse(Command.Split(" ")[0].ToLower().Pascalize(), out Enums.ActionType ActionType)) { if (RestrictionsDB.IsUserRestricted(Context.User, Databases.UserRestrictions.Restriction.TopicManagement) && ActionType != Enums.ActionType.Get) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("You aren't permitted to manage topics!") .WithDescription("You have been blacklisted from using this service. If you think this is a mistake, feel free to personally contact an administrator") .SendEmbed(Context.Channel); return; } string Topic = Command[(Command.Split(" ")[0].Length + 1)..];
static bool IsDescribed(TopicType topicType) { var memberInfo = typeof(TopicType).GetMember(topicType.ToString()).FirstOrDefault(); return(memberInfo != null); }
public static IHtmlContent DescribeTopicType(this IHtmlHelper html, TopicType topicType) { var memberInfo = typeof(TopicType).GetMember(topicType.ToString()).FirstOrDefault(); return(new HtmlString(memberInfo.GetCustomAttribute <DisplayAttribute>().Name)); }
public static string GetTopicTypeString(TopicType topicType) { return(topicType.ToString().Replace('_', ' ')); }