Пример #1
0
 public Action(string objectName, string actionName, string id, IActionEvent started, IActionEvent ended = null)
 {
     ObjectName   = objectName;
     ActionName   = actionName;
     Id           = id;
     Started      = started;
     Ended        = ended;
     innerActions = new List <IAction>();
 }
Пример #2
0
        /// <summary>
        /// Notifies the observer of the specified action.
        /// </summary>
        /// <param name="action">The action that originated this message.</param>
        /// <param name="actionEvent">The action event to notify the observer.</param>
        public async Task NotifyAsync(IAction action, IActionEvent actionEvent)
        {
            var messageTemplate = ObserverSettings.Settings.MessageTemplate(actionEvent.EventType);

            if (messageTemplate != null)
            {
                await SendWebPostAsync(actionEvent, messageTemplate);
            }
        }
Пример #3
0
 public void processTrigger(decimal trigger, IActionEvent evt = null)
 {
     EventHorizonBlazorInterop.Func <CachedEntity>(
         new object[]
     {
         new string[] { this.___guid, "processTrigger" }, trigger, evt
     }
         );
 }
Пример #4
0
        private IActionEvent GetEndEvent(IActionEvent starttEvent, IList <IActionEvent> events, int start)
        {
            for (int i = start; i < events.Count(); i++)
            {
                IActionEvent actionEvent = events[i];
                if (actionEvent.Id.Equals(starttEvent.Id))
                {
                    return(actionEvent);
                }
            }

            return(null);
        }
Пример #5
0
 public static bool TryGetFromObjEx <T>(this IActionEvent e, out T result)
 {
     if (e.IsError() && e.Target is ObjectException <T> ex)
     {
         result = ex.Target;
         return(true);
     }
     else
     {
         result = default;
         return(false);
     }
 }
Пример #6
0
 public static bool TryGet <T>(this IActionEvent e, out T result)
 {
     if (e.IsOk() && e.Target is T r)
     {
         result = r;
         return(true);
     }
     else
     {
         result = default;
         return(false);
     }
 }
Пример #7
0
        /// <summary>
        /// Sends the web post to the configured URL.
        /// </summary>
        /// <param name="actionEvent">The action event.</param>
        /// <param name="messageTemplate">The message template.</param>
        private async Task SendWebPostAsync(IActionEvent actionEvent, string messageTemplate)
        {
            try
            {
                Logger.LogTrace($"Sending WebPost to {ObserverSettings.Settings.Url()}...");
                using var request = new HttpRequestMessage(HttpMethod.Post, ObserverSettings.Settings.Url());
                var message = messageTemplate.FormatWith(actionEvent);
                Logger.LogTrace($"WebPost Message: {message}");
                request.Content = new StringContent(message, Encoding.UTF8, ObserverSettings.Settings.ContentType());

                using var response = await HttpClientFactory.GetHttpClient().SendAsync(request);

                response.EnsureSuccessStatusCode();
                Logger.LogTrace($"Sending WebPost to {ObserverSettings.Settings.Url()}...done");
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error sending WebPost message. Exception: {ex.Message}, Ignoring.", ex);
            }
        }
Пример #8
0
 public void SetEnded(IActionEvent ended)
 {
     Ended = ended;
 }
Пример #9
0
 public Task NotifyObserversAsync(IActionEvent actionEvent)
 {
     return(Task.CompletedTask);
 }
Пример #10
0
        // TODO linked-list

        public ITimeTrackable(IActionEvent actionEvent)
        {
            this.actionEvent = actionEvent;
        }
Пример #11
0
 public static bool IsOk(this IActionEvent @event) => @event.Type == ActionEventType.EvtOk;
Пример #12
0
 public static bool TrueFromObjEx <T>(this IActionEvent @event, Func <T, bool> predicate)
 {
     return(@event.TryGetFromObjEx <T>(out var result) && predicate(result));
 }
Пример #13
0
 public static bool IsRetry(this IActionEvent @event) => @event.Type == ActionEventType.EvtRetry;
Пример #14
0
 public static bool IsError(this IActionEvent @event) => @event.Type == ActionEventType.EvtError;
Пример #15
0
        public IList <IAction> ChronologicalListToTree(IList <IActionEvent> events)
        {
            if (events.Count() == 0)
            {
                return(null);
            }

            IActionEvent firstEvent = events.First();
            IActionEvent lastEvent  = GetEndEvent(firstEvent, events, 1);

            IAction firstAction = GetNewAction(firstEvent, lastEvent);

            IList <IAction> actions = new List <IAction>()
            {
                firstAction
            };

            IList <IAction> parentActions = new List <IAction>()
            {
                firstAction
            };

            for (int i = 1; i < events.Count(); i++)
            {
                IActionEvent actionEvent = events[i];

                IAction parentAction = parentActions.LastOrDefault();

                if (actionEvent == lastEvent)
                {
                    if (parentAction != null)
                    {
                        parentActions.Remove(parentAction);
                    }
                    continue;
                }

                if (parentAction == null)
                {
                    if (!actionEvent.Event.Equals(Event.Started))
                    {
                        throw new Exception();
                    }

                    firstEvent = actionEvent;
                    lastEvent  = GetEndEvent(firstEvent, events, i);

                    IAction nextSibling = GetNewAction(firstEvent, lastEvent);

                    actions.Add(nextSibling);

                    parentActions = new List <IAction>()
                    {
                        nextSibling
                    };

                    continue;
                }

                if (actionEvent.Event.Equals(Event.Started))
                {
                    IAction action = GetNewAction(actionEvent);
                    parentAction.AddActionChild(action);
                    parentActions.Add(action);
                }
                else if (actionEvent.Event.Equals(Event.Ended))
                {
                    parentAction.SetEnded(actionEvent);
                    parentActions.Remove(parentAction);
                }
            }


            return(actions);
        }
Пример #16
0
 private IAction GetNewAction(IActionEvent started, IActionEvent ended = null)
 {
     return(new Action(started.ObjectName, started.ActionName, started.Id, started, ended));
 }
Пример #17
0
 public static Exception GetEx(this IActionEvent @event) => @event.IsError() ? (Exception)@event.Target : null;
Пример #18
0
 public static string GetExMsg(this IActionEvent @event) => @event.GetEx()?.Message;
Пример #19
0
 public void AddAction(IActionEvent actionEvent)
 {
     actionEvent.ActivationTime += currentTime;
     queuedActions.Enqueue(actionEvent);
 }