protected override void EndProcessing()
        {
            Endpoint onClick = null;

            if (OnClick != null)
            {
                onClick = GenerateCallback(Id + "onClick", OnClick, null);
            }

            var counter = new Counter
            {
                AutoRefresh     = AutoRefresh,
                RefreshInterval = RefreshInterval,
                Callback        = GenerateCallback(Id),
                OnClick         = onClick,
                Format          = Format,
                Icon            = FontAwesomeIconsExtensions.GetIconName(Icon),
                Title           = Title,
                Id = Id,
                BackgroundColor = BackgroundColor?.HtmlColor,
                FontColor       = FontColor?.HtmlColor,
                Links           = Links,
                TextAlignment   = TextAlignment.GetName(),
                TextSize        = TextSize.GetName(),
                HasOnClick      = onClick != null
            };

            Log.Debug(JsonConvert.SerializeObject(counter));

            WriteObject(counter);
        }
        protected override void EndProcessing()
        {
            var page = new Page();

            page.Name            = Name;
            page.Url             = Url;
            page.Icon            = FontAwesomeIconsExtensions.GetIconName(Icon);
            page.Id              = Id;
            page.DefaultHomePage = DefaultHomePage;
            page.AutoRefresh     = AutoRefresh;
            page.RefreshInterval = RefreshInterval;

            if (Content != null && Endpoint != null)
            {
                throw new Exception("Content and Endpoint cannot both be specified.");
            }

            try
            {
                if (Endpoint != null)
                {
                    if (Url != null && !Url.StartsWith("/"))
                    {
                        Url = "/" + Url;
                    }

                    page.Callback = GenerateCallback(Id);
                    page.Dynamic  = true;
                }
                else
                {
                    var components = Content.Invoke();

                    foreach (var component in components)
                    {
                        var dashboardComponent = component.BaseObject as Component;
                        if (dashboardComponent != null)
                        {
                            page.Components.Add(dashboardComponent);
                        }
                    }

                    page.Dynamic = false;
                }
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.SyntaxError, page));

                page.Error = new Error
                {
                    Message  = ex.Message,
                    Location = this.MyInvocation.PositionMessage
                };
            }

            Log.Debug(JsonConvert.SerializeObject(page));

            WriteObject(page);
        }
Exemplo n.º 3
0
        protected override void EndProcessing()
        {
            var page = new Page();

            page.Name            = Name;
            page.Url             = Url;
            page.Icon            = FontAwesomeIconsExtensions.GetIconName(Icon);
            page.Id              = Id;
            page.DefaultHomePage = DefaultHomePage;
            page.AutoRefresh     = AutoRefresh;
            page.RefreshInterval = RefreshInterval;
            page.Title           = Title;
            page.Properties      = MyInvocation.BoundParameters;
            page.Blank           = Blank;
            page.Loading         = OnLoading?.Invoke();

            try
            {
                if (Url != null && !Url.StartsWith("/"))
                {
                    Url = "/" + Url;
                }

                if (Url == null && Name != null)
                {
                    page.Url = "/" + Name.Replace(' ', '-');
                }

                page.Name            = Name;
                page.Callback        = Content.GenerateCallback(Id, this, SessionState, ArgumentList);
                page.Callback.IsPage = true;
                page.Callback.Page   = page;
                page.Dynamic         = true;
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.SyntaxError, page));
                page.Error = new Error(ex);
            }

            Log.Debug(JsonConvert.SerializeObject(page));

            WriteObject(page);
        }