Пример #1
0
        protected override void EndProcessing()
        {
            Log.Info($"{Name} - {MyInvocation.ScriptName} - {AutoReload}");

            if (EndpointInitialization == null)
            {
                EndpointInitialization = UDRunspaceFactory.GenerateInitialSessionState(SessionState);
            }

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

            if (Force)
            {
                var existingServer = Server.Servers.FirstOrDefault(m => m.Port == Port || m.Name == m.Name);
                if (existingServer != null)
                {
                    existingServer.Stop();
                    Server.Servers.Remove(existingServer);
                }
            }

            var server = new Server(Name, MyInvocation.ScriptName, AutoReload, Host, Port, Certificate != null || CertificateFile != null);

            var options = new DashboardOptions();

            options.StaticEndpoints             = Endpoint;
            options.Port                        = Port;
            options.HttpsPort                   = HttpsPort.HasValue ? HttpsPort.Value : Port;
            options.Wait                        = Wait;
            options.Certificate                 = Certificate;
            options.CertificateFile             = CertificateFile;
            options.Password                    = CertificateFilePassword;
            options.EndpointInitialSessionState = EndpointInitialization;
            options.PublishedFolders            = PublishedFolder;
            options.ListenAddress               = ListenAddress;
            options.DisableTelemetry            = DisableTelemetry;
            options.Properties                  = MyInvocation.BoundParameters;

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

            WriteObject(server);
        }
Пример #2
0
        protected override void EndProcessing()
        {
            if (EndpointInitialization == null)
            {
                EndpointInitialization = UDRunspaceFactory.GenerateInitialSessionState(SessionState);
            }

            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.EndpointInitialSessionState = EndpointInitialization;
            dashboard.GeoLocation                 = GeoLocation;
            dashboard.IdleTimeout                 = IdleTimeout;
            dashboard.Navigation                  = Navigation;

            if (!AssetService.Instance.Frameworks.ContainsKey(DefaultFramework))
            {
                throw new Exception($"Invalid DefaultFramework specified. Valid frameworks are {AssetService.Instance.Frameworks.Keys.Aggregate((x,y) => x + ", " + y )}");
            }

            dashboard.FrameworkAssetId = AssetService.Instance.Frameworks[DefaultFramework];

            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 };
            }

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

                try
                {
                    var components = Content.Invoke();

                    foreach (var component in components)
                    {
                        if (component.BaseObject is Component dashboardComponent)
                        {
                            page.Components.Add(dashboardComponent);
                        }

                        if (component.BaseObject is Dictionary <string, object> dictionary)
                        {
                            page.Components.Add(new GenericComponent(dictionary));
                        }

                        if (component.BaseObject is Hashtable hashtable)
                        {
                            page.Components.Add(new GenericComponent(hashtable));
                        }
                    }
                }
                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);
        }
Пример #3
0
        protected override void EndProcessing()
        {
            if (EndpointInitialization == null)
            {
                EndpointInitialization = UDRunspaceFactory.GenerateInitialSessionState(SessionState);
            }

            var dashboard = new Dashboard();

            dashboard.Title       = Title;
            dashboard.Scripts     = Scripts;
            dashboard.Stylesheets = Stylesheets;
            dashboard.EndpointInitialSessionState = EndpointInitialization;
            dashboard.GeoLocation = GeoLocation;
            dashboard.IdleTimeout = IdleTimeout;
            dashboard.Properties  = MyInvocation.BoundParameters;

            if (!AssetService.Instance.Frameworks.ContainsKey(DefaultFramework))
            {
                throw new Exception($"Invalid DefaultFramework specified. Valid frameworks are {AssetService.Instance.Frameworks.Keys.Aggregate((x,y) => x + ", " + y )}");
            }

            dashboard.FrameworkAssetId = AssetService.Instance.Frameworks[DefaultFramework];

            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 };
            }

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

                try
                {
                    page.Id              = Guid.NewGuid().ToString();
                    page.Callback        = Content.GenerateCallback(page.Id, this, SessionState, new object[0]);
                    page.Callback.IsPage = true;
                    page.Callback.Page   = page;
                    page.Dynamic         = true;
                }
                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);
        }