コード例 #1
0
        private void UpdateLoader(BusyInfo info)
        {
            lock (_lockObject)
            {
                info.Depth++;
            }

            if (info.BusyViewModel == null || info.BusyIndicator == null)
            {
                return;
            }

            Type         indicatorType = info.BusyIndicator.GetType();
            PropertyInfo content       = indicatorType.GetProperty("BusyContent");

            if (content == null)
            {
                ContentPropertyAttribute contentProperty = indicatorType.GetAttributes <ContentPropertyAttribute>(true)
                                                           .FirstOrDefault();

                if (contentProperty == null)
                {
                    return;
                }

                content = indicatorType.GetProperty(contentProperty.Name);
            }

            content.SetValue(info.BusyIndicator, info.BusyViewModel, null);
        }
コード例 #2
0
        /// <summary>
        /// Updates the indicator.
        /// </summary>
        /// <param name="info">The info.</param>
        protected virtual void UpdateIndicator(BusyInfo info)
        {
            lock (IndicatorLock)
            {
                info.Depth++;
            }

            if (info.BusyViewModel == null || info.BusyIndicator == null)
            {
                return;
            }

            var indicatorType = info.BusyIndicator.GetType();
            var content       = indicatorType.GetProperty("BusyContent");

            if (content == null)
            {
                var contentProperty = indicatorType.GetAttributes <ContentPropertyAttribute>(true)
                                      .FirstOrDefault();

                if (contentProperty == null)
                {
                    return;
                }

                content = indicatorType.GetProperty(contentProperty.Name);
            }

            content.SetValue(info.BusyIndicator, info.BusyViewModel, null);
        }
コード例 #3
0
        /// <summary>
        /// Called when no busy indicator can be found.
        /// </summary>
        /// <param name="sourceViewModel">The source view model.</param>
        /// <param name="busyViewModel">The busy view model.</param>
        protected virtual void NoBusyIndicatorFound(object sourceViewModel, object busyViewModel)
        {
            var activator = busyViewModel as IActivate;

            if (activator == null)
            {
                return;
            }

            activator.Activated += (s, e) => {
                if (!e.WasInitialized)
                {
                    return;
                }

                var info = new BusyInfo {
                    BusyViewModel = busyViewModel
                };
                Indicators[sourceViewModel] = info;
                UpdateIndicator(info);
            };

            Log.Warn("No busy indicator was found in the UI hierarchy. Using modal dialog.");
            WindowManager.ShowDialog(busyViewModel, null);
        }
コード例 #4
0
 public void HandleBusyInfo(BusyInfo busyInfo)
 {
     if (!string.IsNullOrEmpty(busyInfo.Message))
     {
         IsBusy      = true;
         BusyMessage = busyInfo.Message;
     }
     else
     {
         IsBusy = false;
     }
 }
コード例 #5
0
        /// <summary>
        /// Called when the busy indicator is found.
        /// </summary>
        /// <param name="sourceViewModel">The source view model.</param>
        /// <param name="busyViewModel">The busy view model.</param>
        /// <param name="busyIndicator">The busy indicator.</param>
        protected virtual void BusyIndicatorFound(object sourceViewModel, object busyViewModel, UIElement busyIndicator)
        {
            var info = new BusyInfo {
                BusyIndicator = busyIndicator,
                BusyViewModel = busyViewModel
            };

            Indicators[sourceViewModel] = info;

            ToggleBusyIndicator(info, true);
            UpdateIndicator(info);
        }
コード例 #6
0
        public void MarkAsBusy(object sourceViewModel, object busyViewModel)
        {
            sourceViewModel = sourceViewModel ?? _defaultKey;

            if (_loaders.ContainsKey(sourceViewModel))
            {
                BusyInfo info = _loaders[sourceViewModel];
                info.BusyViewModel = busyViewModel;
                UpdateLoader(info);
            }
            else
            {
                UIElement busyIndicator = TryFindBusyIndicator(sourceViewModel);

                if (busyIndicator == null)
                {
                    var notifier = busyViewModel as IActivate;
                    if (notifier == null)
                    {
                        return;
                    }

                    notifier.Activated += (o, e) =>
                    {
                        if (e.WasInitialized)
                        {
                            var info = new BusyInfo {
                                BusyViewModel = busyViewModel
                            };
                            _loaders[sourceViewModel] = info;
                            UpdateLoader(info);
                        }
                    };

                    Log.Warn("No busy indicator with name '" + BusyIndicatorName +
                             "' was found in the UI hierarchy. Using modal.");
                    _windowManager.ShowDialog(busyViewModel, null);
                }
                else
                {
                    var info = new BusyInfo {
                        BusyIndicator = busyIndicator, BusyViewModel = busyViewModel
                    };
                    _loaders[sourceViewModel] = info;
                    ToggleBusyIndicator(info, true);
                    UpdateLoader(info);
                }
            }
        }
コード例 #7
0
        public void MarkAsBusy(object sourceViewModel, object busyViewModel)
        {
            sourceViewModel = sourceViewModel ?? _defaultKey;

            if (_loaders.ContainsKey(sourceViewModel))
            {
                BusyInfo info = _loaders[sourceViewModel];
                info.BusyViewModel = busyViewModel;
                UpdateLoader(info);
            }
            else
            {
                UIElement busyIndicator = TryFindBusyIndicator(sourceViewModel);

                if (busyIndicator == null)
                {
#if WP7
                    var ex = new CaliburnException("No busy indicator with name '" + BusyIndicatorName + "' was found in the UI hierarchy.");
                    Log.Error(ex);
                    throw ex;
#else
                    var notifier = busyViewModel as IActivate;
                    if (notifier == null)
                        return;

                    notifier.Activated += (o, e) =>
                                              {
                                                  if (e.WasInitialized)
                                                  {
                                                      var info = new BusyInfo {BusyViewModel = busyViewModel};
                                                      _loaders[sourceViewModel] = info;
                                                      UpdateLoader(info);
                                                  }
                                              };

                    Log.Warn("No busy indicator with name '" + BusyIndicatorName +
                             "' was found in the UI hierarchy. Using modal.");
                    _windowManager.ShowDialog(busyViewModel, null);
#endif
                }
                else
                {
                    var info = new BusyInfo {BusyIndicator = busyIndicator, BusyViewModel = busyViewModel};
                    _loaders[sourceViewModel] = info;
                    ToggleBusyIndicator(info, true);
                    UpdateLoader(info);
                }
            }
        }
コード例 #8
0
        public void MarkAsBusy(object sourceViewModel, object busyViewModel)
        {
            sourceViewModel = sourceViewModel ?? defaultKey;

            if (loaders.ContainsKey(sourceViewModel))
            {
                var info = loaders[sourceViewModel];
                info.BusyViewModel = busyViewModel;
                UpdateLoader(info);
            }
            else
            {
                var busyIndicator = TryFindBusyIndicator(sourceViewModel);

                if (busyIndicator == null)
                {
                    var activator = busyViewModel as IActivate;
                    if (activator == null)
                        return;

                    activator.Activated += (s,e) =>{
                        if (!e.WasInitialized)
                            return;

                        var info = new BusyInfo { BusyViewModel = busyViewModel };
                        loaders[sourceViewModel] = info;
                        UpdateLoader(info);
                    };

                    Log.Warn("No busy indicator with name '" + BusyIndicatorName + "' was found in the UI hierarchy. Using modal.");
                    windowManager.ShowDialog(busyViewModel, null);
                }
                else
                {
                    var info = new BusyInfo { BusyIndicator = busyIndicator, BusyViewModel = busyViewModel };
                    loaders[sourceViewModel] = info;
                    ToggleBusyIndicator(info, true);
                    UpdateLoader(info);
                }
            }
        }
コード例 #9
0
        public void MarkAsBusy(object sourceViewModel, object busyViewModel)
        {
            sourceViewModel = sourceViewModel ?? _defaultKey;

            if (_loaders.ContainsKey(sourceViewModel))
            {
                BusyInfo info = _loaders[sourceViewModel];
                info.BusyViewModel = busyViewModel;
                UpdateLoader(info);
            }
            else
            {
                UIElement busyIndicator = TryFindBusyIndicator(sourceViewModel);

                if (busyIndicator == null)
                {
                    var notifier = busyViewModel as IActivate;
                    if (notifier == null)
                        return;

                    notifier.Activated += (o, e) =>
                    {
                        if (e.WasInitialized)
                        {
                            var info = new BusyInfo { BusyViewModel = busyViewModel };
                            _loaders[sourceViewModel] = info;
                            UpdateLoader(info);
                        }
                    };

                    _windowManager.ShowDialog(busyViewModel, null);
                }
                else
                {
                    var info = new BusyInfo { BusyIndicator = busyIndicator, BusyViewModel = busyViewModel };
                    _loaders[sourceViewModel] = info;
                    ToggleBusyIndicator(info, true);
                    UpdateLoader(info);
                }
            }
        }
コード例 #10
0
        public void MarkAsNotBusy(object sourceViewModel)
        {
            sourceViewModel = sourceViewModel ?? _defaultKey;

            if (!_loaders.ContainsKey(sourceViewModel))
            {
                return;
            }

            BusyInfo info = _loaders[sourceViewModel];

            lock (_lockObject)
            {
                info.Depth--;

                if (info.Depth == 0)
                {
                    _loaders.Remove(sourceViewModel);
                    ToggleBusyIndicator(info, false);
                }
            }
        }
コード例 #11
0
 private void ToggleBusyIndicator(BusyInfo info, bool isBusy)
 {
     if (info.BusyIndicator != null)
     {
         PropertyInfo busyProperty = info.BusyIndicator.GetType().GetProperty("IsBusy");
         if (busyProperty != null)
         {
             busyProperty.SetValue(info.BusyIndicator, isBusy, null);
         }
         else
         {
             info.BusyIndicator.Visibility = isBusy ? Visibility.Visible : Visibility.Collapsed;
         }
     }
     else if (!isBusy)
     {
         MethodInfo close = info.BusyViewModel.GetType().GetMethod("Close", Type.EmptyTypes);
         if (close != null)
         {
             close.Invoke(info.BusyViewModel, null);
         }
     }
 }
コード例 #12
0
 private static void ToggleBusyIndicator(BusyInfo info, bool isBusy)
 {
     if (info.BusyIndicator != null)
     {
         var busyProperty = info.BusyIndicator.GetType().GetProperty("IsBusy");
         if (busyProperty != null)
             busyProperty.SetValue(info.BusyIndicator, isBusy, null);
         else info.BusyIndicator.Visibility = isBusy ? Visibility.Visible : Visibility.Collapsed;
     }
     else if (!isBusy)
     {
         var close = info.BusyViewModel.GetType().GetMethod("Close", Type.EmptyTypes);
         if (close != null)
             close.Invoke(info.BusyViewModel, null);
     }
 }
コード例 #13
0
        private static void UpdateLoader(BusyInfo info)
        {
            if (info.BusyViewModel == null || info.BusyIndicator == null)
                return;

            var indicatorType = info.BusyIndicator.GetType();
            var content = indicatorType.GetProperty("BusyContent");

            if (content == null)
            {
                var contentProperty = indicatorType.GetAttributes<ContentPropertyAttribute>(true)
                    .FirstOrDefault();

                if (contentProperty == null)
                    return;

                content = indicatorType.GetProperty(contentProperty.Name);
            }
            content.SetValue(info.BusyIndicator, info.BusyViewModel, null);
        }
コード例 #14
0
        private void UpdateLoader(BusyInfo info)
        {
            lock (_lockObject)
            {
                info.Depth++;
            }

            if (info.BusyViewModel == null || info.BusyIndicator == null)
                return;

            Type indicatorType = info.BusyIndicator.GetType();
            PropertyInfo content = indicatorType.GetProperty("BusyContent");

            if (content == null)
            {
                ContentPropertyAttribute contentProperty = indicatorType.GetAttributes<ContentPropertyAttribute>(true)
                    .FirstOrDefault();

                if (contentProperty == null)
                    return;

                content = indicatorType.GetProperty(contentProperty.Name);
            }

            content.SetValue(info.BusyIndicator, info.BusyViewModel, null);
        }