/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="action"></param> /// <param name="exceptionAction"></param> /// <param name="referenceId">This is the referenceId of the command</param> /// <param name="isMasterJob">Specifies whether the command is a master job.</param> protected void CommandRegister(MessageFilterWrapper key , Func <TransmissionPayload, List <TransmissionPayload>, Task> action , Func <Exception, TransmissionPayload, List <TransmissionPayload>, Task> exceptionAction = null , string referenceId = null , bool isMasterJob = false) { var handler = new H(); handler.Initialise(key, action, exceptionAction, referenceId, isMasterJob); mSupported.Add(key, handler); switch (Policy.CommandNotify) { case CommandNotificationBehaviour.OnRegistration: CommandNotify(key, false, isMasterJob); break; case CommandNotificationBehaviour.OnRegistrationIfStarted: if (Status == ServiceStatus.Running) { CommandNotify(key, false, isMasterJob); } break; } }
/// <summary> /// This method generated the SqlFilter for the message type. /// </summary> /// <param name="message">The message type to create the SqlFilter for.</param> /// <returns>Returns a SqlFilter.</returns> public static SqlFilter SqlFilterQuery(MessageFilterWrapper message) { StringBuilder sb = new StringBuilder(); SqlFilterQueryStatement(sb, message); return(new SqlFilter(sb.ToString())); }
/// <summary> /// This method creates the command handler. You can override this method to set additional properties. /// </summary> /// <param name="key">The message key</param> /// <param name="action">The execute action.</param> /// <returns>Returns the handler.</returns> protected virtual H CommandHandlerCreate(MessageFilterWrapper key, Func <TransmissionPayload, List <TransmissionPayload>, Task> action) { var handler = new H(); handler.Initialise(key, action); return(handler); }
public override void Start() { base.Start(); var wrapper = new MessageFilterWrapper(new ServiceMessageHeader(Service.ChannelId, "one", "two")); Service.Update(new[] { wrapper }.ToList()); }
public override void Start() { base.Start(); var wrapper = new MessageFilterWrapper(new ServiceMessageHeader(Service.ChannelId, "one", "two")); Service.ListenerCommandsActiveChange(new[] { wrapper }.ToList()); }
/// <summary> /// This is the constructor for registering a manual command. /// </summary> /// <param name="header">The ServiceMessageHeader route for the command.</param> /// <param name="command">The command to process.</param> /// <param name="referenceId">The optional reference id for tracking.</param> /// <param name="policy">The command policy.</param> public CommandMethodInline(ServiceMessageHeader header , Func <CommandMethodRequestContext, Task> command , string referenceId = null , CommandPolicy policy = null) : base(policy ?? new CommandPolicy() { OnProcessRequestException = ProcessRequestExceptionBehaviour.SignalSuccessAndSend500ErrorResponse }) { mKey = new MessageFilterWrapper(header, null); mCommand = command; mReferenceId = referenceId; }
/// <summary> /// /// </summary> /// <param name="header">The service message header</param> /// <param name="action">The command method action.</param> /// <param name="exceptionAction">An option exception action.</param> /// <param name="referenceId">This is the referenceId of the command</param> /// <param name="isMasterJob">Specifies whether the command is related to a master job.</param> protected void CommandRegister(ServiceMessageHeader header , Func <TransmissionPayload, List <TransmissionPayload>, Task> action , Func <Exception, TransmissionPayload, List <TransmissionPayload>, Task> exceptionAction = null , string referenceId = null , bool isMasterJob = false) { var wrapper = new MessageFilterWrapper(header, null); CommandRegister(wrapper, action, exceptionAction, referenceId); }
/// <summary> /// This method registers a particular command. /// </summary> /// <param name="channelId">The message channelId</param> /// <param name="messageType">The command channelId</param> /// <param name="actionType">The command action</param> /// <param name="command">The action delegate to execute.</param> protected void CommandRegister(string type, string messageType, string actionType, Func <TransmissionPayload, List <TransmissionPayload>, Task> action, Func <TransmissionPayload, List <TransmissionPayload>, Task> deadLetterAction = null, Func <Exception, TransmissionPayload, List <TransmissionPayload>, Task> exceptionAction = null) { var key = new ServiceMessageHeader(type, messageType, actionType); var wrapper = new MessageFilterWrapper(key); CommandRegister(wrapper, action, deadLetterAction, exceptionAction); }
/// <summary> /// /// </summary> /// <param name="channelId"></param> /// <param name="messageType"></param> /// <param name="actionType"></param> /// <param name="action"></param> /// <param name="exceptionAction"></param> /// <param name="referenceId">This is the referenceId of the command</param> protected void CommandRegister(string channelId, string messageType, string actionType, Func <TransmissionPayload, List <TransmissionPayload>, Task> action, Func <Exception, TransmissionPayload, List <TransmissionPayload>, Task> exceptionAction = null, string referenceId = null) { var key = new ServiceMessageHeader(channelId, messageType, actionType); var wrapper = new MessageFilterWrapper(key); CommandRegister(wrapper, action, exceptionAction, referenceId); }
/// <summary> /// This is the default constructor for the shared service. /// </summary> /// <param name="responseChannel">This is the internal response channel that the message will listen on.</param> /// <param name="cacheManager"></param> /// <param name="defaultRequestTimespan"></param> public PersistenceInternalService(string responseChannel = "internalpersistence" , ICacheManager <K, E> cacheManager = null , TimeSpan?defaultRequestTimespan = null) : base(cacheManager, defaultRequestTimespan) { mMessageType = typeof(E).Name; mResponseId = new MessageFilterWrapper(new ServiceMessageHeader(responseChannel, mMessageType), null); mResponseChannel = responseChannel; UseASPNETThreadModel = false; }
/// <summary> /// This method unregisters a particular command. /// </summary> /// <param name="key">Message filter wrapper key</param> protected void CommandUnregister(MessageFilterWrapper key) { var item = mSupported.Keys.FirstOrDefault((d) => d.Message == key); if (item != null) { mSupported.Remove(item); CommandNotify(item, true); } }
/// <summary> /// This method initialises the holder. /// </summary> public virtual void Initialise( MessageFilterWrapper key , Func <TransmissionPayload, List <TransmissionPayload>, Task> action , Func <Exception, TransmissionPayload, List <TransmissionPayload>, Task> exceptionAction = null , string referenceId = null , bool isMasterJob = false ) { Key = key; Action = action; ExceptionAction = exceptionAction; ReferenceId = referenceId; IsMasterJob = isMasterJob; }
/// <summary> /// This method unregisters a particular command. /// </summary> /// <param name="key">Message filter wrapper key</param> /// <param name="isMasterJob">Specifies whether the command is linked to a master job.</param> protected void CommandUnregister(MessageFilterWrapper key, bool isMasterJob) { if (mSupported.ContainsKey(key)) { var handler = mSupported[key]; if (handler.IsMasterJob == isMasterJob) { mSupported.Remove(key); mCommandCache.Clear(); CommandNotify(key, true, handler.IsMasterJob); } } }
public static E AttachCommand <E>(this E cpipe , Func <TransmissionPayload, List <TransmissionPayload>, IPayloadSerializationContainer, Task> commandFunction , MessageFilterWrapper message , string referenceId = null , int startupPriority = 100 , IPipelineChannelOutgoing <IPipeline> channelResponse = null ) where E : IPipelineChannelIncoming <IPipeline> { var command = new CommandInline(message, commandFunction, referenceId); cpipe.Pipeline.AddCommand(command, startupPriority, null, cpipe, channelResponse); return(cpipe); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="action"></param> /// <param name="exceptionAction"></param> /// <param name="referenceId">This is the referenceId of the command</param> protected void CommandRegister(MessageFilterWrapper key, Func <TransmissionPayload, List <TransmissionPayload>, Task> action, Func <Exception, TransmissionPayload, List <TransmissionPayload>, Task> exceptionAction = null, string referenceId = null) { Func <TransmissionPayload, List <TransmissionPayload>, Task> command = async(rq, rs) => { bool error = false; Exception actionEx = null; try { await action(rq, rs); } catch (Exception ex) { if (exceptionAction == null) { throw; } error = true; actionEx = ex; } try { if (error) { await exceptionAction(actionEx, rq, rs); } } catch (Exception ex) { throw; } }; CommandRegister(new CommandHolder(key, command, referenceId)); }
/// <summary> /// This method creates the appropriate SQL filter based on the MessageFilterWrapper /// </summary> /// <param name="sb">The string builder.</param> /// <param name="m">The message type to create the sql string for.</param> public static void SqlFilterQueryStatement(StringBuilder sb, MessageFilterWrapper m) { bool andFlag = false; Action <string, string> sqlParam = (id, val) => { if (!string.IsNullOrEmpty(val)) { if (andFlag) { sb.Append(" AND "); } andFlag = true; //FIX: Case sensitive pattern matchin in ServiceBus. sb.AppendFormat("{0}=\'{1}\'", id, val.ToLowerInvariant()); } }; if (!string.IsNullOrEmpty(m.ClientId)) { sqlParam("CorrelationServiceId", m.ClientId); } if (!string.IsNullOrEmpty(m.Header.ChannelId)) { sqlParam("ChannelId", m.Header.ChannelId); } if (!string.IsNullOrEmpty(m.Header.MessageType)) { sqlParam("MessageType", m.Header.MessageType); } if (!string.IsNullOrEmpty(m.Header.ActionType)) { sqlParam("ActionType", m.Header.ActionType); } }
/// <summary> /// This is the command holder that contains the necessary data to holds a mapping to a command method. /// </summary> /// <param name="message">The message.</param> /// <param name="command">The command action.</param> /// <param name="referenceId">The reference id.</param> public CommandHolder(MessageFilterWrapper message , Func <TransmissionPayload, List <TransmissionPayload>, Task> command , string referenceId = null) { if (message == null) { throw new CommandHolderException("message cannot be null"); } if (command == null) { throw new CommandHolderException("command cannot be null"); } if (message.Header.IsPartialKey && message.Header.ChannelId == null) { throw new CommandHolderException("You must supply a channel when using a partial key."); } Message = message; Command = command; ReferenceId = referenceId; }
/// <summary> /// This method initialises the holder. /// </summary> /// <param name="parent">The name of the parent container.</param> /// <param name="key"></param> /// <param name="action"></param> public virtual void Initialise(MessageFilterWrapper key, Func <TransmissionPayload, List <TransmissionPayload>, Task> action) { Key = key; Action = action; }
public CommandHolder(MessageFilterWrapper message) { Message = message; //RequiresQuorum = requiresQuorum; }
public CommandChange(bool isRemoval, MessageFilterWrapper key) { IsRemoval = isRemoval; Key = key; }
/// <summary> /// This method will notify the command container when a commands is added or removed. /// </summary> /// <param name="key">The key.</param> /// <param name="isRemoval">Set this to true to remove the command mapping, false is default.</param> /// <param name="isMasterJob">Specifies whether it is a master job.</param> protected void CommandNotify(MessageFilterWrapper key, bool isRemoval, bool isMasterJob) { FireAndDecorateEventArgs(OnCommandChange, () => new CommandChangeEventArgs(isRemoval, key, isMasterJob)); }
/// <summary> /// This is the constructor for registering a manual command. /// </summary> /// <param name="message">The message filter wrapper route to identify the command.</param> /// <param name="command">The command to process.</param> /// <param name="referenceId">The optional reference id for tracking.</param> public CommandInline(MessageFilterWrapper message , Func <TransmissionPayload, List <TransmissionPayload>, IPayloadSerializationContainer, Task> command , string referenceId = null) : base(null) { mCommandHolder = new CommandHolder(message, async(rq, rs) => await command(rq, rs, PayloadSerializer), referenceId); }
/// <summary> /// Starts with the specified supported listener message type. /// </summary> /// <param name="supported">The supported message type.</param> public virtual void Start(MessageFilterWrapper supported) { Start(new[] { supported }.ToList()); }
protected virtual bool SupportedResolve(MessageFilterWrapper inWrapper, out H command) { return(SupportedResolve(inWrapper.Header, out command)); }
public CommandChange(bool isRemoval, MessageFilterWrapper key, bool requiresQuorum = false) { IsRemoval = isRemoval; Key = key; RequiresQuorum = requiresQuorum; }
/// <summary> /// This method registers a particular command. /// </summary> /// <param name="channelId">The message channelId</param> /// <param name="messageType">The command channelId</param> /// <param name="actionType">The command action</param> /// <param name="command">The action delegate to execute.</param> protected void CommandRegister(MessageFilterWrapper key, Func <TransmissionPayload, List <TransmissionPayload>, Task> action, Func <TransmissionPayload, List <TransmissionPayload>, Task> deadLetterAction = null, Func <Exception, TransmissionPayload, List <TransmissionPayload>, Task> exceptionAction = null) { if (key == null) { throw new ArgumentNullException("CommandRegister: key cannot be null"); } Func <TransmissionPayload, List <TransmissionPayload>, Task> command = async(rq, rs) => { bool error = false; Exception actionEx = null; try { //Depending on the message type, execute the deadletter action. if (rq.IsDeadLetterMessage && deadLetterAction != null) { await deadLetterAction(rq, rs); } else { await action(rq, rs); } } catch (Exception ex) { if (exceptionAction == null) { throw; } error = true; actionEx = ex; } try { if (error) { await exceptionAction(actionEx, rq, rs); } } catch (Exception ex) { throw; } }; if (key.Header.IsPartialKey && key.Header.ChannelId == null) { throw new Exception("You must supply a channel when using a partial key."); } var cHolder = new CommandHolder(key); mSupported.Add(cHolder, CommandHandlerCreate(key, command)); switch (mPolicy.CommandNotify) { case CommandNotificationBehaviour.OnRegistration: CommandNotify(cHolder, false); break; case CommandNotificationBehaviour.OnRegistrationIfStarted: if (Status == ServiceStatus.Running) { CommandNotify(cHolder, false); } break; } }
/// <summary> /// Initializes a new instance of the <see cref="CommandChangeEventArgs"/> class. /// </summary> /// <param name="isRemoval">if set to <c>true</c> [is removal].</param> /// <param name="key">The key.</param> /// <param name="isMasterJob">if set to <c>true</c> [is master job].</param> public CommandChangeEventArgs(bool isRemoval, MessageFilterWrapper key, bool isMasterJob) { IsRemoval = isRemoval; Key = key; IsMasterJob = isMasterJob; }