public static IMessageQueue CreateInbound( string addressName, MessagePattern pattern, bool isTemporary = false, IMessageQueue originator = null) { var key = $"{Direction.Inbound}:{addressName}:{pattern}"; if (_Queues.ContainsKey(key)) { return(_Queues[key]); } var queue = Create(addressName, originator); queue.InitializeInbound(addressName, pattern, isTemporary); _Queues[key] = queue; return(_Queues[key]); }
public override void InitialiseOutbound(string name, MessagePattern pattern, bool isTemporary) { Initialise(Direction.Outbound, name, pattern, isTemporary); var queueManagerName = InitialiseQueueManager(); if (Pattern == MessagePattern.PublishSubscribe) { _topic = _queueManager.AccessTopic(Address, "", MQC.MQTOPIC_OPEN_AS_PUBLICATION, MQC.MQOO_OUTPUT); } else if (Pattern == MessagePattern.RequestResponse && IsTemporary) { _queue = _queueManager.AccessQueue(Address, MQC.MQOO_OUTPUT, queueManagerName, null, null); } else { _queue = _queueManager.AccessQueue(Address, MQC.MQOO_OUTPUT); } }
/// <summary> /// Factory method, builds and returns a <see cref="MessageNode"/> from a <see cref="MessagePattern"/>. /// </summary> /// <param name="pattern">A parsed <see cref="MessageFormat"/> pattern string</param> /// <returns>A <see cref="MessageNode"/> or a <see cref="ComplexArgStyleNode"/></returns> /// <exception cref="ArgumentException">if the <see cref="MessagePattern"/> is empty /// or does not represent a <see cref="MessageFormat"/> pattern</exception> /// <exception cref="ArgumentNullException">If <paramref name="pattern"/> is null.</exception> /// <stable>ICU 49</stable> public static MessageNode BuildMessageNode(this MessagePattern pattern) // ICU4N specific - turned it into an extension method { if (pattern == null) { throw new ArgumentNullException(nameof(pattern)); } int limit = pattern.CountParts() - 1; if (limit < 0) { throw new ArgumentException("The MessagePattern is empty"); } else if (pattern.GetPartType(0) != MessagePatternPartType.MsgStart) { throw new ArgumentException( "The MessagePattern does not represent a MessageFormat pattern"); } return(BuildMessageNode(pattern, 0, limit)); }
private static ComplexArgStyleNode BuildChoiceStyleNode(MessagePattern pattern, int start, int limit) { ComplexArgStyleNode node = new ComplexArgStyleNode(MessagePatternArgType.Choice); while (start < limit) { int valueIndex = start; MessagePatternPart part = pattern.GetPart(start); double value = pattern.GetNumericValue(part); start += 2; int msgLimit = pattern.GetLimitPartIndex(start); VariantNode variant = new VariantNode(); variant.Selector = pattern.GetSubstring(pattern.GetPart(valueIndex + 1)); variant.SelectorValue = value; variant.Message = BuildMessageNode(pattern, start, msgLimit); node.AddVariant(variant); start = msgLimit + 1; } return(node.Freeze()); }
public override void InitialiseInbound(string name, MessagePattern pattern, Dictionary <string, object> properties = null) { Initialise(Direction.Inbound, name, pattern, properties); switch (Pattern) { case MessagePattern.PublishSubscribe: //RequireProperty<string>("MulticastAddress"); _queue = new msmq.MessageQueue(Address); //_queue.MulticastAddress = GetPropertyValue<string>("MulticastAddress"); break; case MessagePattern.RequestResponse: _queue = _useTemporaryQueue ? msmq.MessageQueue.Create(Address) : new msmq.MessageQueue(Address); break; default: _queue = new msmq.MessageQueue(Address); break; } }
public override void InitialiseOutbound(string name, MessagePattern pattern, bool isTemporary, Dictionary <string, object> properties = null) { Initialise(Direction.Outbound, name, pattern, isTemporary, properties); EnsureContext(); switch (Pattern) { case MessagePattern.RequestResponse: _socket = _Context.Socket(SocketType.REQ); _socket.Connect(Address); break; case MessagePattern.FireAndForget: _socket = _Context.Socket(SocketType.PUSH); _socket.Connect(Address); break; case MessagePattern.PublishSubscribe: _socket = _Context.Socket(SocketType.PUB); _socket.Bind(Address); break; } }
public override void InitialiseInbound(string name, MessagePattern pattern, Dictionary <string, object> properties = null) { Initialise(Direction.Inbound, name, pattern, properties); EnsureContext(); switch (Pattern) { case MessagePattern.RequestResponse: _socket = _Context.Socket(SocketType.REP); _socket.Bind(Address); break; case MessagePattern.FireAndForget: _socket = _Context.Socket(SocketType.PULL); _socket.Bind(Address); break; case MessagePattern.PublishSubscribe: _socket = _Context.Socket(SocketType.SUB); _socket.Connect(Address); _socket.Subscribe("", Encoding.UTF8); break; } }
private static void StartListening <TWorkflow>(string name, MessagePattern pattern) where TWorkflow : IUserWorkflow, new() { var queue = MessageQueueFactory.CreateInbound(name, pattern); Console.WriteLine("Listening on: {0}", queue.Address); queue.Listen(x => { if (x.BodyType == typeof(UserUnsubscribed)) { var unsubscribedEvent = x.BodyAs <UserUnsubscribed>(); Console.WriteLine("Starting {0} for: {1}, at: {2}", typeof(TWorkflow).Name, unsubscribedEvent.EmailAddress, DateTime.Now.TimeOfDay); var workflow = new TWorkflow { EmailAddress = unsubscribedEvent.EmailAddress }; workflow.Run(); Console.WriteLine("Completed {0} for: {1}, at: {2}", typeof(TWorkflow).Name, unsubscribedEvent.EmailAddress, DateTime.Now.TimeOfDay); } }); }
private void StartListening <TWorkflow>(string name, MessagePattern pattern) where TWorkflow : IUserWorkflow, new() { var queue = MessageQueueFactory.CreateInbound(name, pattern); Log.WriteLine("Listening with queue type: {0}, on address: {1}", queue.GetType().Name, queue.Address); queue.Listen(x => { if (x.BodyType == typeof(UserUnsubscribed)) { var unsubscribedEvent = x.BodyAs <UserUnsubscribed>(); Log.WriteLine("Starting {0} for: {1}, at: {2}", typeof(TWorkflow).Name, unsubscribedEvent.EmailAddress, DateTime.Now.TimeOfDay); var workflow = new TWorkflow { EmailAddress = unsubscribedEvent.EmailAddress }; workflow.Run(); Log.WriteLine("Completed {0} for: {1}, at: {2}", typeof(TWorkflow).Name, unsubscribedEvent.EmailAddress, DateTime.Now.TimeOfDay); } }, _cancellationTokenSource.Token); }
private void PopulateRules() { sPatterns = new List<MessagePattern>(); using (Data.EMMDataContext db = Manager.GetContext) { foreach (Data.MessageType message in db.MessageTypes) { MessagePattern p = new MessagePattern(message.Name, message.MatchType, message.Expression); sPatterns.Add(p); } } }
/// <summary> /// Finds the <see cref="PluralFormat"/> sub-message for the given number, or the "other" sub-message. /// </summary> /// <param name="pattern">A <see cref="MessagePattern"/>.</param> /// <param name="partIndex">the index of the first <see cref="PluralFormat"/> argument style part.</param> /// <param name="selector">the <see cref="IPluralSelector"/> for mapping the number (minus offset) to a keyword.</param> /// <param name="context">worker object for the selector.</param> /// <param name="number">a number to be matched to one of the <see cref="PluralFormat"/> argument's explicit values, /// or mapped via the <see cref="IPluralSelector"/>.</param> /// <returns>the sub-message start part index.</returns> internal static int FindSubMessage( MessagePattern pattern, int partIndex, IPluralSelector selector, object context, double number) { int count = pattern.CountParts(); double offset; MessagePatternPart part = pattern.GetPart(partIndex); if (part.Type.HasNumericValue()) { offset = pattern.GetNumericValue(part); ++partIndex; } else { offset = 0; } // The keyword is null until we need to match against a non-explicit, not-"other" value. // Then we get the keyword from the selector. // (In other words, we never call the selector if we match against an explicit value, // or if the only non-explicit keyword is "other".) string keyword = null; // When we find a match, we set msgStart>0 and also set this boolean to true // to avoid matching the keyword again (duplicates are allowed) // while we continue to look for an explicit-value match. bool haveKeywordMatch = false; // msgStart is 0 until we find any appropriate sub-message. // We remember the first "other" sub-message if we have not seen any // appropriate sub-message before. // We remember the first matching-keyword sub-message if we have not seen // one of those before. // (The parser allows [does not check for] duplicate keywords. // We just have to make sure to take the first one.) // We avoid matching the keyword twice by also setting haveKeywordMatch=true // at the first keyword match. // We keep going until we find an explicit-value match or reach the end of the plural style. int msgStart = 0; // Iterate over (ARG_SELECTOR [ARG_INT|ARG_DOUBLE] message) tuples // until ARG_LIMIT or end of plural-only pattern. do { part = pattern.GetPart(partIndex++); MessagePatternPartType type = part.Type; if (type == MessagePatternPartType.ArgLimit) { break; } Debug.Assert(type == MessagePatternPartType.ArgSelector); // part is an ARG_SELECTOR followed by an optional explicit value, and then a message if (pattern.GetPartType(partIndex).HasNumericValue()) { // explicit value like "=2" part = pattern.GetPart(partIndex++); if (number == pattern.GetNumericValue(part)) { // matches explicit value return(partIndex); } } else if (!haveKeywordMatch) { // plural keyword like "few" or "other" // Compare "other" first and call the selector if this is not "other". if (pattern.PartSubstringMatches(part, "other")) { if (msgStart == 0) { msgStart = partIndex; if (keyword != null && keyword.Equals("other")) { // This is the first "other" sub-message, // and the selected keyword is also "other". // Do not match "other" again. haveKeywordMatch = true; } } } else { if (keyword == null) { keyword = selector.Select(context, number - offset); if (msgStart != 0 && keyword.Equals("other")) { // We have already seen an "other" sub-message. // Do not match "other" again. haveKeywordMatch = true; // Skip keyword matching but do getLimitPartIndex(). } } if (!haveKeywordMatch && pattern.PartSubstringMatches(part, keyword)) { // keyword matches msgStart = partIndex; // Do not match this keyword again. haveKeywordMatch = true; } } } partIndex = pattern.GetLimitPartIndex(partIndex); } while (++partIndex < count); return(msgStart); }
/// <summary> /// Selects the phrase for the given <paramref name="keyword"/>. /// </summary> /// <param name="keyword">A phrase selection keyword.</param> /// <returns>The string containing the formatted select message.</returns> /// <exception cref="ArgumentException">When the given keyword is not a "pattern identifier".</exception> /// <stable>ICU 4.4</stable> public string Format(string keyword) { //Check for the validity of the keyword if (!PatternProps.IsIdentifier(keyword)) { throw new ArgumentException("Invalid formatting argument."); } // If no pattern was applied, throw an exception if (msgPattern == null || msgPattern.CountParts() == 0) { throw new InvalidOperationException("Invalid format error."); } // Get the appropriate sub-message. int msgStart = FindSubMessage(msgPattern, 0, keyword); if (!msgPattern.JdkAposMode) { int msgLimit = msgPattern.GetLimitPartIndex(msgStart); return(msgPattern.PatternString.Substring(msgPattern.GetPart(msgStart).Limit, msgPattern.GetPatternIndex(msgLimit))); } // JDK compatibility mode: Remove SKIP_SYNTAX. StringBuilder result = null; int prevIndex = msgPattern.GetPart(msgStart).Limit; for (int i = msgStart; ;) { MessagePatternPart part = msgPattern.GetPart(++i); MessagePatternPartType type = part.Type; int index = part.Index; if (type == MessagePatternPartType.MsgLimit) { if (result == null) { return(pattern.Substring(prevIndex, index - prevIndex)); // ICU4N: Corrected 2nd arg } else { return(result.Append(pattern, prevIndex, index).ToString()); } } else if (type == MessagePatternPartType.SkipSyntax) { if (result == null) { result = new StringBuilder(); } result.Append(pattern, prevIndex, index); prevIndex = part.Limit; } else if (type == MessagePatternPartType.ArgStart) { if (result == null) { result = new StringBuilder(); } result.Append(pattern, prevIndex, index); prevIndex = index; i = msgPattern.GetLimitPartIndex(i); index = msgPattern.GetPart(i).Limit; MessagePattern.AppendReducedApostrophes(pattern, prevIndex, index, result); prevIndex = index; } } }
private void StartListening(string name, MessagePattern pattern) { }
public abstract void InitialiseInbound(string name, MessagePattern pattern, bool isTemporary);
public abstract void InitialiseInbound(string name, MessagePattern pattern, bool isTemporary, Dictionary <string, object> properties = null);
public abstract void InitialiseOutbound(string name, MessagePattern pattern, Dictionary <string, object> properties = null);
public override void InitialiseOutbound(string name, MessagePattern pattern, bool isTemporary) { Initialise(Direction.Outbound, name, pattern, isTemporary); _queue = new msmq.MessageQueue(Address); }
public override void InitialiseOutbound(string name, MessagePattern pattern, Dictionary <string, object> properties = null) { Initialise(Direction.Outbound, name, pattern, properties); _queue = new msmq.MessageQueue(Address); }
public MessagePattern AddBdMessagePattern(MessagePattern mp) { db.MessagePatterns.Add(mp); db.SaveChanges(); return(db.MessagePatterns.OrderBy(d => d.Id).LastOrDefault()); }
private string Format(/*Number*/ object numberObject, double number) { // If no pattern was applied, return the formatted number. if (msgPattern == null || msgPattern.CountParts() == 0) { return(numberFormat.Format(numberObject)); } // Get the appropriate sub-message. // Select it based on the formatted number-offset. double numberMinusOffset = number - offset; string numberString; if (offset == 0) { numberString = numberFormat.Format(numberObject); // could be BigDecimal etc. } else { numberString = numberFormat.Format(numberMinusOffset); } #pragma warning disable 612, 618 IFixedDecimal dec; // ICU4N TODO: //if (numberFormat is DecimalFormat) //{ // dec = ((DecimalFormat)numberFormat).GetFixedDecimal(numberMinusOffset); //} //else //{ dec = new FixedDecimal(numberMinusOffset); #pragma warning restore 612, 618 //} int partIndex = FindSubMessage(msgPattern, 0, pluralRulesWrapper, dec, number); // Replace syntactic # signs in the top level of this sub-message // (not in nested arguments) with the formatted number-offset. StringBuilder result = null; int prevIndex = msgPattern.GetPart(partIndex).Limit; for (; ;) { MessagePatternPart part = msgPattern.GetPart(++partIndex); MessagePatternPartType type = part.Type; int index = part.Index; if (type == MessagePatternPartType.MsgLimit) { if (result == null) { return(pattern.Substring(prevIndex, index - prevIndex)); // ICU4N: Corrected 2nd arg } else { return(result.Append(pattern, prevIndex, index).ToString()); } } else if (type == MessagePatternPartType.ReplaceNumber || // JDK compatibility mode: Remove SKIP_SYNTAX. (type == MessagePatternPartType.SkipSyntax && msgPattern.JdkAposMode)) { if (result == null) { result = new StringBuilder(); } result.Append(pattern, prevIndex, index); if (type == MessagePatternPartType.ReplaceNumber) { result.Append(numberString); } prevIndex = part.Limit; } else if (type == MessagePatternPartType.ArgStart) { if (result == null) { result = new StringBuilder(); } result.Append(pattern, prevIndex, index); prevIndex = index; partIndex = msgPattern.GetLimitPartIndex(partIndex); index = msgPattern.GetPart(partIndex).Limit; MessagePattern.AppendReducedApostrophes(pattern, prevIndex, index, result); prevIndex = index; } } }
public override void InitialiseInbound(string name, MessagePattern pattern, bool isTemporary, Dictionary <string, object> properties = null) { Initialise(Direction.Inbound, name, pattern, isTemporary, properties); _sqsClient = new AmazonSQSClient(_accessKey, _secretKey, RegionEndpoint.EUWest1); }
public abstract void InitializeInbound(string addressName, MessagePattern pattern, bool isTemporary = false);