Inheritance: INotifyPropertyChanged
        private static void OnRemoveWidgetCommandExecute(Widget widget)
        {
            var fixedProject = widget as FixedBudgetMonitorWidget;
            if (fixedProject != null)
            {
                bool? result = QuestionBoxService.Show(
                    "Remove Widget",
                    "Are you sure you want to remove the Fixed Budget Project Widget '{0}'?\n\nOnce removed, it cannot be undone. All assigned transactions will be remain in the project bucket. Any unsaved edits will also be committed.",
                    fixedProject.Id);
                if (result == null || result == false)
                {
                    return;
                }
            }

            DashboardService.RemoveUserDefinedWidget((IUserDefinedWidget) widget);
        }
        private void UpdateWidget(Widget widget)
        {
            if (widget.Dependencies == null || !widget.Dependencies.Any())
            {
                widget.Update();
                return;
            }

            var parameters = new object[widget.Dependencies.Count()];
            int index = 0;
            foreach (Type dependencyType in widget.Dependencies)
            {
                if (!this.availableDependencies.ContainsKey(dependencyType))
                {
                    // If you get an exception here first check the InitialiseSupportedDependenciesArray method.
                    throw new NotSupportedException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            "The requested dependency {0} for the widget {1} is not supported.",
                            dependencyType.Name,
                            widget.Name));
                }

                parameters[index++] = this.availableDependencies[dependencyType];
            }

            widget.Update(parameters);
        }
 private void OnWidgetCommandExecuted(Widget widget)
 {
     MessengerInstance.Send(new WidgetActivatedMessage(widget));
 }
 private static bool WidgetCommandCanExecute(Widget widget)
 {
     return widget.Clickable;
 }
        private static WidgetState CreateWidgetState(Widget widget)
        {
            var multiInstanceWidget = widget as IMultiInstanceWidget;
            if (multiInstanceWidget != null)
            {
                return new MultiInstanceWidgetState
                {
                    Id = multiInstanceWidget.Id,
                    Visible = multiInstanceWidget.Visibility,
                    WidgetType = multiInstanceWidget.WidgetType.FullName,
                };
            }

            return new WidgetState
            {
                Visible = widget.Visibility,
                WidgetType = widget.GetType().FullName,
            };
        }
        private Widget UpdateWidgetCollectionWithNewAddition(Widget baseWidget)
        {
            var widgetGroup = WidgetGroups.FirstOrDefault(group => @group.Heading == baseWidget.Category);
            if (widgetGroup == null)
            {
                widgetGroup = new WidgetGroup
                {
                    Heading = baseWidget.Category,
                    Widgets = new ObservableCollection<Widget>()
                };
                WidgetGroups.Add(widgetGroup);
            }

            widgetGroup.Widgets.Add(baseWidget);
            UpdateAllWidgets();
            return baseWidget;
        }
        private void UpdateWidget(Widget widget)
        {
            if (widget.Dependencies == null || widget.Dependencies.None())
            {
                widget.Update();
                return;
            }

            var parameters = new object[widget.Dependencies.Count()];
            var index = 0;
            foreach (var dependencyType in widget.Dependencies)
            {
                try
                {
                    parameters[index++] = this.monitoringServices.RetrieveDependency(dependencyType);
                }
                catch (NotSupportedException ex)
                {
                    // If you get an exception here first check the MonitorableDependencies.ctor method.
                    throw new NotSupportedException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            "The requested dependency {0} for the widget {1} is not supported.",
                            dependencyType.Name,
                            widget.Name), ex);
                }
            }

            widget.Update(parameters);
        }
        private async void ScheduledWidgetUpdate(Widget widget)
        {
            Debug.Assert(widget.RecommendedTimeIntervalUpdate != null);
            this.logger.LogInfo(
                l => l.Format(
                    "Scheduling \"{0}\" widget to update every {1} minutes.",
                    widget.Name,
                    widget.RecommendedTimeIntervalUpdate.Value.TotalMinutes));

            // Run the scheduling on a different thread.
            await Task.Run(
                async () =>
                {
                    while (true)
                    {
                        await Task.Delay(widget.RecommendedTimeIntervalUpdate.Value);
                        this.logger.LogInfo(
                            l => l.Format(
                                "Scheduled Update for \"{0}\" widget. Will run again after {1} minutes.",
                                widget.Name,
                                widget.RecommendedTimeIntervalUpdate.Value.TotalMinutes));
                        UpdateWidget(widget);
                    }
                    // ReSharper disable once FunctionNeverReturns - intentional timer tick infinite loop
                });
        }
        private static WidgetPersistentState CreateWidgetState(Widget widget)
        {
            var multiInstanceWidget = widget as IUserDefinedWidget;
            if (multiInstanceWidget != null)
            {
                var surprisePaymentWidget = multiInstanceWidget as SurprisePaymentWidget;
                if (surprisePaymentWidget == null)
                {
                    return new MultiInstanceWidgetState
                    {
                        Id = multiInstanceWidget.Id,
                        Visible = multiInstanceWidget.Visibility,
                        WidgetType = multiInstanceWidget.WidgetType.FullName
                    };
                }

                return new SurprisePaymentWidgetPersistentState
                {
                    Id = surprisePaymentWidget.Id,
                    Visible = surprisePaymentWidget.Visibility,
                    WidgetType = surprisePaymentWidget.WidgetType.FullName,
                    PaymentStartDate = surprisePaymentWidget.StartPaymentDate,
                    Frequency = surprisePaymentWidget.Frequency
                };
            }

            return new WidgetPersistentState
            {
                Visible = widget.Visibility,
                WidgetType = widget.GetType().FullName
            };
        }
 public WidgetActivatedMessage(Widget widget)
 {
     Widget = widget;
 }
 public WidgetRepositoryChangedEventArgs(Widget widgetRemoved)
 {
     WidgetRemoved = widgetRemoved;
 }