Example #1
0
        /// <summary>
        ///     Initializes a new instance of the
        ///     <see cref="AlfredPowerModule" />
        ///     class.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when one or more required arguments are null.
        /// </exception>
        /// <param name="container"> The container. </param>
        public AlfredPowerModule([NotNull] IObjectContainer container)
            : base(container)
        {
            if (container == null) { throw new ArgumentNullException(nameof(container)); }

            AlfredStatusWidget = new TextWidget(Resources.AlfredCoreModule_AlfredNotSet,
                                                BuildWidgetParameters(@"lblStatus"));

            InitializeButton = new ButtonWidget(Resources.InitializeButtonText,
                                                CreateCommand(ExecuteInitializeCommand),
                                                BuildWidgetParameters(@"btnInitialize"));

            ShutdownButton = new ButtonWidget(Resources.ShutdownButtonText,
                                              CreateCommand(ExecuteShutdownCommand),
                                              BuildWidgetParameters(@"btnShutdown"));
        }
Example #2
0
        /// <summary>
        ///     Initializes a new instance of the
        ///     <see cref="AlfredModule" />
        ///     class.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when one or more required arguments are null.
        /// </exception>
        /// <param name="container"> The container. </param>
        public AlfredTimeModule([NotNull] IObjectContainer container)
            : base(container)
        {
            if (container == null) { throw new ArgumentNullException(nameof(container)); }

            CurrentDateWidget = new TextWidget(BuildWidgetParameters(@"lblCurrentDate"));
            CurrentTimeWidget = new TextWidget(BuildWidgetParameters(@"lblCurrentTime"));

            AlertWidget = new WarningWidget(BuildWidgetParameters(@"warnAlert"))
            {
                IsVisible = false,
                Text = Resources.AlfredTimeModule_AlfredTimeModule_BedtimeNagMessage
            };

            AlertHour = 21;
            AlertMinute = 30;
            AlertDurationInHours = 4;
            IsAlertEnabled = true;

            CurrentTime = DateTime.MinValue;
        }
        /// <summary>
        ///     Handles initialization events
        /// </summary>
        /// <param name="alfred"></param>
        protected override void InitializeProtected(IAlfred alfred)
        {
            _widgets.Clear();

            // Read the subsystems from Alfred
            if (AlfredInstance != null)
            {
                foreach (var item in AlfredInstance.Subsystems)
                {
                    var widget = BuildSubsystemWidget(item);

                    _widgets.Add(widget);

                    Register(widget);
                }
            }

            // We'll want to display a fallback for no subsystems
            if (_widgets.Count == 0)
            {
                var noSubsystemsDetected =
                    Resources.AlfredSubSystemListModule_NoSubsystemsDetected.NonNull();

                Log("Subsystems.Initialize", noSubsystemsDetected, LogLevel.Warning);

                var widget = new TextWidget(noSubsystemsDetected,
                                            BuildWidgetParameters(@"lblNoSubsystems"));
                _widgets.Add(widget);

                Register(widget);
            }
        }
        private TextWidget BuildSubsystemWidget([NotNull] IAlfredSubsystem subsystem)
        {
            var id = string.Format(Locale, @"lblSubsystem{0}", subsystem.Id);
            var widget = new TextWidget(BuildWidgetParameters(id)) { DataContext = subsystem };
            UpdateWidgetText(widget, subsystem);

            return widget;
        }
        /// <summary>
        ///     Adds a widget for an <see cref="IAlfredPage"/>.
        /// </summary>
        /// <param name="page"> The page. </param>
        private void AddPageWidget([NotNull] IAlfredPage page)
        {
            var lblId = string.Format(Locale, @"lblPage{0}", page.Id);
            var widget = new TextWidget(BuildWidgetParameters(lblId)) { DataContext = page };

            UpdateWidgetText(widget, page);

            _widgets.Add(widget);

            Register(widget);
        }
        /// <summary>
        ///     Adds a no items detected <see cref="TextWidget"/>.
        /// </summary>
        private void AddNoItemsWidget()
        {
            var noItemsDetected = Resources.NoPagesDetected.NonNull();

            Log("Pages.Initialize", noItemsDetected, LogLevel.Warning);

            var widget = new TextWidget(noItemsDetected, BuildWidgetParameters(@"lblNoItems"));
            _widgets.Add(widget);

            Register(widget);
        }
Example #7
0
        public void RegisteringWidgetAtInitializeAndShutdownLeavesOneCopyInListAtReinitialize()
        {
            var testModule = new AlfredTestModule(Container);

            var textWidget = new TextWidget(BuildWidgetParams());
            testModule.WidgetsToRegisterOnInitialize.Add(textWidget);
            testModule.WidgetsToRegisterOnShutdown.Add(textWidget);

            _alfred.Register(_subsystem);
            _subsystem.AddAutoRegisterPage(_page);
            _page.Register(testModule);

            _alfred.Initialize();
            _alfred.Update();
            _alfred.Shutdown();
            _alfred.Initialize();
            _alfred.Update();

            Assert.IsNotNull(testModule.Widgets, "testModule.Widgets was null");
            Assert.AreEqual(1,
                            testModule.Widgets.Count(),
                            "Widgets were not properly cleared from list after re-initialize");
        }
Example #8
0
        public void RegisteringAWidgetMultipleTimesThrowsAnException()
        {
            var testModule = new AlfredTestModule(Container);

            var textWidget = new TextWidget(BuildWidgetParams());
            testModule.WidgetsToRegisterOnInitialize.Add(textWidget);
            testModule.WidgetsToRegisterOnInitialize.Add(textWidget);

            _alfred.Register(_subsystem);
            _subsystem.AddAutoRegisterPage(_page);
            _page.Register(testModule);

            _alfred.Initialize();
        }
Example #9
0
        public void TextWidgetTextTests()
        {
            var widget = new TextWidget(BuildWidgetParams()) { Text = TestString };

            Assert.AreEqual(TestString, widget.Text);
        }
Example #10
0
        public void TextWidgetConstructorTextTests()
        {
            var widget = new TextWidget(TestString, BuildWidgetParams());

            Assert.AreEqual(TestString, widget.Text);
        }