Exemplo n.º 1
0
 void ConditionalRelay(IAppMessage Message)
 {
     if (allow(Message))
     {
         Broker().Route(Message);
     }
 }
Exemplo n.º 2
0
 public CommandProcessExecutionLog(bool Executed = true, IAppMessage Message = null)
 {
     this.ErrorMessages  = MutableList.Create <string>();
     this.StatusMessages = MutableList.Create <string>();
     this.Executed       = Executed;
     this.AppMessage     = Message ?? global::AppMessage.Empty;
 }
Exemplo n.º 3
0
    public static IAppMessage Combine(IAppMessage m1, IAppMessage m2)
    {
        if (Object.ReferenceEquals(m1, m2))
        {
            return(m1);
        }

        var level    = (EventLevel)Math.Min((int)m1.EventLevel, (int)m2.EventLevel);
        var template = "FIX ME" + m1.MessageTemplate + "\r\n" + m2.MessageTemplate;
        var ts       = m1.Timestamp >= m2.Timestamp ? m1.Timestamp : m2.Timestamp;
        var content  = new
        {
            Part1 = m1.SemanticContent,
            Part2 = m2.SemanticContent
        };
        var state = new AppMessgaeState(
            Template: template,
            Content: content,
            Timestamp: ts,
            CorrelationToken: m2.CT,
            Level: level,
            MessageType: m2.MessageType
            );

        return(new AppMessage(state));
    }
Exemplo n.º 4
0
        /// <summary>
        /// Called whenever the router instance receives an appgram
        /// </summary>
        /// <param name="value">The appgram value</param>
        void IObserver <InboundAppgram> .OnNext(InboundAppgram value)
        {
            try
            {
                var    segment = value.Segment;
                byte[] buffer  = segment.Buffer;
                int    offset  = segment.Offset;
                int    end     = segment.End;

                if (offset >= end)
                {
                    throw new Exception("Received appgram with no content");
                }

                byte        header  = segment.Buffer[segment.Offset];
                MessageType type    = (MessageType)(header >> 4);
                IAppMessage message = _createMessage(type);
                offset = message.Deserialize(buffer, offset, end);

                InboundUnconfirmedRequest request = null;
                request = _processMessage(value, message, buffer, offset, end);

                if (request != null)
                {
                    _unconfirmedRequestObservers.Next(request);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 5
0
 public static IAppMessage CommandCompletionError(ICommandResult result, IAppMessage CompletionMessage)
 => error("Successfully executed the @CommandName command but was unable to complete it: @CompletionError",
          new
 {
     result.Spec.CommandName,
     CompletionError = CompletionMessage.Format()
 });
Exemplo n.º 6
0
 public CommandResult(TSpec spec, object payload, bool succeeded, IAppMessage message, long subid, CorrelationToken?ct = null)
 {
     this.Spec             = spec;
     this.Payload          = payload;
     this.Succeeded        = succeeded;
     this.Message          = message;
     this.SubmissionId     = subid;
     this.CorrelationToken = ct;
 }
Exemplo n.º 7
0
 public AgentNotification(SystemNodeIdentifier Host, SystemIdentifier System,
                          AgentIdentifier Agent, ServiceAgentState State, IAppMessage Message)
 {
     this.Host    = Host;
     this.System  = System;
     this.Agent   = Agent;
     this.State   = State;
     this.Message = Message;
 }
Exemplo n.º 8
0
 public NotificationAppService(
     INotificationDefinitionManager notificationDefinitionManager,
     IUserNotificationManager userNotificationManager,
     INotificationSubscriptionManager notificationSubscriptionManager,
     IAppMessage notificationManager)
 {
     _notificationDefinitionManager   = notificationDefinitionManager;
     _userNotificationManager         = userNotificationManager;
     _notificationSubscriptionManager = notificationSubscriptionManager;
     _notificationManager             = notificationManager;
 }
Exemplo n.º 9
0
        public void SendAppMessage(IAppMessage message)
        {
            var targetModule = this._moduleMgr.GetAppModule(message.TargetModule);

            if (targetModule.IsNull())
            {
                return;
            }
            targetModule.ProcessRequest(message);

            //_appMsgQueue.Enqueue(message);
        }
Exemplo n.º 10
0
        public MoveTenantsToAnotherEditionJob(
            IRepository <Tenant> tenantRepository,
            EditionManager editionManager,

            IUnitOfWorkManager unitOfWorkManager, IAppMessage appMessage)
        {
            _tenantRepository = tenantRepository;
            _editionManager   = editionManager;

            _unitOfWorkManager = unitOfWorkManager;
            _appMessage        = appMessage;

            EventBus = NullEventBus.Instance;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Sends a raw appgram
        /// </summary>
        /// <param name="address">The address of the destination device</param>
        /// <param name="expectingReply">True if a response is expected, false otherwise</param>
        /// <param name="message">The header message</param>
        /// <param name="content">The content of the appgram</param>
        internal void SendRaw(Address address, bool expectingReply, IAppMessage message, BufferSegment content)
        {
            lock (_lock)
            {
                OutboundAppgram appgram = new OutboundAppgram();
                appgram.Content        = new AppgramContent(message, content);
                appgram.Destination    = address;
                appgram.ExpectingReply = expectingReply;
                appgram.Priority       = NetgramPriority.Normal;

                if (_router != null)
                {
                    _router.SendAppgram(appgram);
                }
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a valued option with optional message content
 /// </summary>
 /// <param name="value">The encapsulated value</param>
 /// <param name="message">An optional message</param>
 public Option(T value, IAppMessage message = null)
 {
     if (value is IOption)
     {
         var o = value as IOption;
         this.Exists  = o.IsSome;
         this.Message = message ?? o.Message ?? AppMessage.Empty;
         this.value   = this.Exists ?
                        (o.Value is T ? (T)o.Value : value)
             : default;
     }
     else
     {
         this.Exists  = (value != null);
         this.value   = value;
         this.Message = message ?? AppMessage.Empty;
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Processes a received message
        /// </summary>
        /// <param name="appgram">The appgram that contains the received message</param>
        /// <param name="message">The message</param>
        /// <param name="buffer">The buffer containing the message content</param>
        /// <param name="offset">The start of the content within the buffer</param>
        /// <param name="end">The end of the content within the buffer</param>
        /// <returns>The inbound unconfirmed request to propagate, if any</returns>
        private InboundUnconfirmedRequest _processMessage(InboundAppgram appgram, IAppMessage message, byte[] buffer, int offset, int end)
        {
            var source  = appgram.Source;
            var segment = new BufferSegment(buffer, offset, end);
            InboundUnconfirmedRequest request = null;

            switch (message.Type)
            {
            case MessageType.ConfirmedRequest:
                _txManager.ProcessConfirmedRequest(source, (ConfirmedRequestMessage)message, segment);
                break;

            case MessageType.UnconfirmedRequest:
                request = _processUnconfirmedRequest(appgram, (UnconfirmedRequestMessage)message, buffer, offset, end);
                break;

            case MessageType.SimpleAck:
                _txManager.ProcessSimpleAck(source, (SimpleAckMessage)message);
                break;

            case MessageType.ComplexAck:
                _txManager.ProcessComplexAck(source, (ComplexAckMessage)message, segment);
                break;

            case MessageType.SegmentAck:
                _txManager.ProcessSegmentAck(source, (SegmentAckMessage)message);
                break;

            case MessageType.Error:
                _txManager.ProcessError(source, (ErrorMessage)message);
                break;

            case MessageType.Reject:
                _txManager.ProcessReject(source, (RejectMessage)message);
                break;

            case MessageType.Abort:
                _txManager.ProcessAbort(source, (AbortMessage)message);
                break;
            }

            return(request);
        }
Exemplo n.º 14
0
    /// <summary>
    /// Formats the message for display
    /// </summary>
    /// <param name="message">The message to format</param>
    /// <param name="template">The template to apply</param>
    /// <param name="ts">Specifies whether timestamp should be prepended to message output</param>
    /// <param name="args">Valus used to populate template variables</param>
    /// <returns></returns>
    internal static string Format(IAppMessage message, string template, bool ts, params object[] args)
    {
        var argValues = from arg in args
                        from m in TypedMessageDataMember.Get(arg.GetType()).Values
                        let argName = m.Member.GetOptionalAttribute <DisplayNameAttribute>().MapValueOrDefault(a => a.DisplayName, m.Name)
                                      select new
        {
            ArgName  = argName,
            ArgValue = m.GetValue(arg)?.ToString() ?? String.Empty
        };
        var output = template;

        foreach (var argValue in argValues)
        {
            output = output.Replace($"$({argValue.ArgName})", argValue.ArgValue)
                     .Replace($"@{argValue.ArgName}", argValue.ArgValue);
        }

        return((ts ? message.Timestamp.ToString() : string.Empty) + " " + output);
    }
Exemplo n.º 15
0
    public CorrelationToken?Route(IAppMessage message, bool immediate)
    {
        if (!RoutedMessages.TryAdd(message.MessageId, message.MessageId))
        {
            return(message.CT);
        }

        Sentinel?.Invoke(message);

        foreach (var mtn in subscribers.Keys)
        {
            if (mtn == message.MessageType || mtn == nameof(IAppMessage))
            {
                foreach (var subscriber in subscribers[mtn])
                {
                    subscriber.Observer(message);
                }
            }
        }
        return(message.CT);
    }
        public ImportUsersToExcelJob(
            RoleManager roleManager,
            IUserListExcelDataReader userListExcelDataReader,
            IInvalidUserExporter invalidUserExporter,
            IUserPolicy userPolicy,
            IEnumerable <IPasswordValidator <User> > passwordValidators,
            IPasswordHasher <User> passwordHasher,


            ILocalizationManager localizationManager,
            IObjectMapper objectMapper, IDataFileObjectManager dataFileObjectManager, IAppMessage appMessage)
        {
            _roleManager             = roleManager;
            _userListExcelDataReader = userListExcelDataReader;
            _invalidUserExporter     = invalidUserExporter;
            _userPolicy         = userPolicy;
            _passwordValidators = passwordValidators;
            _passwordHasher     = passwordHasher;

            _objectMapper          = objectMapper;
            _dataFileObjectManager = dataFileObjectManager;
            _appMessage            = appMessage;
            _localizationSource    = localizationManager.GetSource(AppConsts.LocalizationSourceName);
        }
Exemplo n.º 17
0
        public object ProcessRequest(IAppMessage request)
        {
            var key = request.Extensions[AppSystem.Message_Key];

            if (!key.IsNull())
            {
                if (key == AppSystem.Message_Navigation)
                {
                    return(Navigation.Value);
                }
            }

            var report = request.Body.As <IReportViewModel>();

            if (report == null)
            {
                return(request.Body);
            }
            else
            {
                report.Initialize();
                return(report);
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Creates a <see cref="Option{T}"/> with a value
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static Option <T> some <T>(T value, IAppMessage message = null)
 => new Option <T>(value, message);
Exemplo n.º 19
0
 /// <summary>
 /// Creates a <see cref="Option{T}"/> with no value
 /// </summary>
 /// <typeparam name="T">The type of the optional value</typeparam>
 /// <returns></returns>
 public static Option <T> none <T>(IAppMessage message = null)
 => Option <T> .None(message ?? AppMessage.Empty);
Exemplo n.º 20
0
    /// <summary>
    /// Renders a message for display
    /// </summary>
    /// <param name="Message"></param>
    /// <param name="Orignator"></param>
    /// <returns></returns>
    public static string Format(this IAppMessage Message, SystemNodeIdentifier Orignator)
    {
        var tsFmt = Message.Timestamp.FormatTimestamp();

        return(concat(tsFmt, " ", Orignator, "> ", Message.Format(false)));
    }
Exemplo n.º 21
0
 public FileWriteResult(FilePath DstPath, IAppMessage Message)
     : base(Message, DstPath)
 {
     this.DstPath = DstPath;
 }
Exemplo n.º 22
0
 public static FileWriteResult Failure(FilePath DstPath, IAppMessage Message)
 => new FileWriteResult(DstPath, Message);
Exemplo n.º 23
0
 public static FileWriteResult Success(FilePath DstPath, IAppMessage Message = null)
 => new FileWriteResult(DstPath, Message ?? AppMessage.Inform($"The {DstPath} file was successfully written"));
Exemplo n.º 24
0
 /// <summary>
 /// Populates a Some with optional message content
 /// </summary>
 /// <param name="Value">The encapsulated value</param>
 /// <param name="Message">The associated message</param>
 /// <returns></returns>
 public static Option <T> Some(T Value, IAppMessage Message = null)
 => new Option <T>(Value, Message ?? AppMessage.Empty);
Exemplo n.º 25
0
 internal static string Format(IAppMessage message, string prepend, string postpend, bool ts)
 => (!string.IsNullOrWhiteSpace(prepend) ? $"{prepend} {message.Format(false)}" : message.Format(ts))
 + (!string.IsNullOrWhiteSpace(postpend) ? $" {postpend}" : String.Empty);
Exemplo n.º 26
0
 /// <summary>
 /// Returns some(message) if the message is nonemty; otherwise none
 /// </summary>
 /// <param name="message">The message to adjudicate</param>
 /// <returns></returns>
 public static Option <IAppMessage> ToOption(this IAppMessage message)
 => message == null?Option.None <IAppMessage>()
     : message.IsEmpty ? Option.None <IAppMessage>()
       : Option.Some(message);
Exemplo n.º 27
0
 public static bool IsWarning(this IAppMessage m)
 => m.EventLevel == EventLevel.Warning;
Exemplo n.º 28
0
 public static bool IsError(this IAppMessage m)
 => m.EventLevel == EventLevel.Error || m.EventLevel == EventLevel.Critical;
Exemplo n.º 29
0
 public static bool IsBabble(this IAppMessage m)
 => m.EventLevel == EventLevel.Verbose;
Exemplo n.º 30
0
 Option(bool isSome, T value, IAppMessage message)
 {
     this.Exists  = isSome;
     this.value   = value;
     this.Message = message ?? AppMessage.Empty;
 }