protected override void EndProcessing()
        {
            Log.Info($"{Name} - {MyInvocation.ScriptName} - {AutoReload}");

            if (string.IsNullOrEmpty(MyInvocation.ScriptName) && AutoReload)
            {
                WriteWarning("AutoReload does not work on the command line. You must save your file as a script.");
            }

            var server = new Server(Name, MyInvocation.ScriptName, AutoReload, Host, Port);

            var options = new DashboardOptions();

            options.StaticEndpoints = Endpoint;
            options.Port            = Port;
            options.Wait            = Wait;
            options.Certificate     = Certificate;
            options.CertificateFile = CertificateFile;
            options.Password        = CertificateFilePassword;
            options.EndpointInitializationScript = EndpointInitializationScript?.GenerateCallback("IS", SessionState);
            options.PublishedFolders             = PublishedFolder;

            try
            {
                server.Start(options);
            }
            catch (AggregateException ex)
            {
                Log.Error("Failed to start dashboard.", ex);
                throw ex.GetBaseException();
            }

            WriteObject(server);
        }
Exemple #2
0
        protected override void EndProcessing()
        {
            var dashboard = new Dashboard();

            dashboard.Title                = Title;
            dashboard.NavBarColor          = NavBarColor?.HtmlColor;
            dashboard.NavBarFontColor      = NavBarFontColor?.HtmlColor;
            dashboard.BackgroundColor      = BackgroundColor?.HtmlColor;
            dashboard.FontColor            = FontColor?.HtmlColor;
            dashboard.NavbarLinks          = NavbarLinks;
            dashboard.Scripts              = Scripts;
            dashboard.Stylesheets          = Stylesheets;
            dashboard.CyclePages           = CyclePages;
            dashboard.CyclePagesInterval   = CyclePagesInterval;
            dashboard.Footer               = Footer;
            dashboard.NavBarLogo           = NavBarLogo;
            dashboard.InitializationScript = EndpointInitializationScript?.GenerateCallback("IS", SessionState, false);
            dashboard.GeoLocation          = GeoLocation;

            if (Theme != null)
            {
                var themeService = new ThemeService();
                Theme.RenderedContent = themeService.Create(Theme);
                dashboard.Themes      = new [] { Theme };
            }
            else
            {
                var themeService = new ThemeService();
                var defaultTheme = themeService.LoadThemes().First(m => m.Name.Equals("Default"));
                defaultTheme.RenderedContent = themeService.Create(defaultTheme);
                dashboard.Themes             = new [] { defaultTheme };
            }

            AddDynamicParameters(dashboard);
            ValidateModel(dashboard);

            if (ParameterSetName == "Content")
            {
                var page = new Page();
                page.Name = "home";
                dashboard.Pages.Add(page);

                try
                {
                    var components = Content.Invoke();

                    foreach (var component in components)
                    {
                        var dashboardComponent = component.BaseObject as Component;
                        if (dashboardComponent != null)
                        {
                            page.Components.Add(dashboardComponent);
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.SyntaxError, dashboard));

                    dashboard.Error = ex.Message;
                }
            }

            if (ParameterSetName == "Pages")
            {
                dashboard.Pages.AddRange(Pages);
            }

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

            WriteObject(dashboard);
        }