Esempio n. 1
0
        public async Task <bool> LoadAsync()
        {
            Log.Debug($"[{Scope}] Loading snapshots");

            var loadingAsync = LoadingAsync;

            if (loadingAsync != null)
            {
                var cancelEventArgs = new CancelEventArgs();
                await loadingAsync(this, cancelEventArgs);

                if (cancelEventArgs.Cancel)
                {
                    Log.Info("Loading canceled by LoadingAsync event");
                    return(false);
                }
            }

            var snapshots = await _snapshotStorageService.LoadSnapshotsAsync();

            lock (_snapshots)
            {
                _snapshots.Clear();
                _snapshots.AddRange(snapshots);
            }

            Loaded.SafeInvoke(this);

            Log.Info($"[{Scope}] Loaded '{snapshots.Count()}' snapshots");

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when the fragment is resumed.
        /// </summary>
        public override void OnResume()
        {
            base.OnResume();

            Loaded.SafeInvoke(this);

            InitializeBindingContext();
        }
Esempio n. 3
0
 public void Load(string fileName = null)
 {
     if (TryLoad(fileName))
     {
         Loaded.SafeInvoke(this);
         Updated.SafeInvoke(this);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Called when the view is loaded.
        /// </summary>
        protected override void OnResume()
        {
            base.OnResume();

            RaiseViewModelChanged();

            Loaded.SafeInvoke(this);

            InitializeBindingContext();
        }
Esempio n. 5
0
        public void Load(string fileName = null)
        {
            if (!TryLoad(fileName))
            {
                throw Log.ErrorAndCreateException <FileLoadException>("Unable to load filters from file '{0}'", GetFileName(fileName));
            }

            Loaded.SafeInvoke(this);
            Updated.SafeInvoke(this);
        }
Esempio n. 6
0
        /// <summary>
        /// Called when the view is loaded.
        /// </summary>
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            RaiseViewModelChanged();

            Loaded.SafeInvoke(this);

            InitializeBindingContext();
        }
Esempio n. 7
0
        /// <summary>
        /// Called when the framework element is loaded.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        public void OnLoaded(object sender, EventArgs e)
        {
            if (IsLoaded)
            {
                return;
            }

            IsLoaded = true;

            Loaded.SafeInvoke(this);
        }
Esempio n. 8
0
            private void ElementLoaded(object sender, RoutedEventArgs args)
            {
                sender.DoIf <object, FrameworkElement>(e =>
                {
                    _controlsLoaded[e] = true;
                    e.Loaded          -= ElementLoaded;
                });

                if (!_initialized && _controlsLoaded.Values.All(i => i))
                {
                    _initialized = true;
                    Loaded.SafeInvoke();
                }
            }
Esempio n. 9
0
        public async Task <bool> LoadAsync(string fileName = null)
        {
            using (await _lockObject.LockAsync())
            {
                if (TryLoad(fileName))
                {
                    Loaded.SafeInvoke(this);
                    Updated.SafeInvoke(this);

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 10
0
        public async Task <bool> LoadAsync(string fileName = null)
        {
            using (await _lockObject.LockAsync())
            {
                if (TryLoad(fileName))
                {
                    foreach (var filterScheme in FilterSchemes.Schemes.ToList())
                    {
                        await filterScheme.EnsureIntegrityAsync();
                    }

                    Loaded.SafeInvoke(this);
                    Updated.SafeInvoke(this);

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogicBase"/> class.
        /// </summary>
        /// <param name="targetView">The target control.</param>
        /// <param name="viewModelType">Type of the view model.</param>
        /// <param name="viewModel">The view model.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="targetView"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> does not implement interface <see cref="IViewModel"/>.</exception>
        protected LogicBase(IView targetView, Type viewModelType = null, IViewModel viewModel = null)
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            Argument.IsNotNull("targetView", targetView);

            if (viewModelType == null)
            {
                viewModelType = (viewModel != null) ? viewModel.GetType() : _viewModelLocator.ResolveViewModel(targetView.GetType());
                if (viewModelType == null)
                {
                    throw Log.ErrorAndCreateException <NotSupportedException>("The view model of the view '{0}' could not be resolved. Make sure to customize the IViewModelLocator or register the view and view model manually", TargetViewType?.Name);
                }
            }

            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <LogicBase>();

            Log.Debug($"Constructing behavior '{GetType().Name}' for '{targetView.GetType().Name}' with unique id '{UniqueIdentifier}'");

            TargetView    = targetView;
            ViewModelType = viewModelType;
            ViewModel     = viewModel;

            ViewModelBehavior = (viewModel != null) ? LogicViewModelBehavior.Injected : LogicViewModelBehavior.Dynamic;

            if (ViewModel != null)
            {
                SetDataContext(ViewModel);
            }

            Log.Debug("Subscribing to view events");

            ViewLoadManager.AddView(this);

            if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewLoading", OnViewLoadedManagerLoadingInternal, false) == null)
            {
                Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewLoading', going to subscribe without weak events");

                ViewLoadManager.ViewLoading += OnViewLoadedManagerLoadingInternal;
            }

            if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewLoaded", OnViewLoadedManagerLoadedInternal, false) == null)
            {
                Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewLoaded', going to subscribe without weak events");

                ViewLoadManager.ViewLoaded += OnViewLoadedManagerLoadedInternal;
            }

            if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewUnloading", OnViewLoadedManagerUnloadingInternal, false) == null)
            {
                Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewUnloading', going to subscribe without weak events");

                ViewLoadManager.ViewUnloading += OnViewLoadedManagerUnloadingInternal;
            }

            if (this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewUnloaded", OnViewLoadedManagerUnloadedInternal, false) == null)
            {
                Log.Debug("Failed to use weak events to subscribe to 'ViewLoadManager.ViewUnloaded', going to subscribe without weak events");

                ViewLoadManager.ViewUnloaded += OnViewLoadedManagerUnloadedInternal;
            }

            // Required so the ViewLoadManager can handle the rest
            targetView.Loaded   += (sender, e) => Loaded.SafeInvoke(this);
            targetView.Unloaded += (sender, e) => Unloaded.SafeInvoke(this);

            TargetView.DataContextChanged += OnTargetViewDataContextChanged;

            Log.Debug("Subscribing to view properties");

            // This also subscribes to DataContextChanged, don't double subscribe
            var viewPropertiesToSubscribe = DetermineInterestingViewProperties();

            foreach (var viewPropertyToSubscribe in viewPropertiesToSubscribe)
            {
                TargetView.SubscribeToPropertyChanged(viewPropertyToSubscribe, OnTargetViewPropertyChanged);
            }

            Log.Debug($"Constructed behavior '{GetType().Name}' for '{TargetViewType?.Name}'");
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogicBase"/> class.
        /// </summary>
        /// <param name="targetView">The target control.</param>
        /// <param name="viewModelType">Type of the view model.</param>
        /// <param name="viewModel">The view model.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="targetView"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> does not implement interface <see cref="IViewModel"/>.</exception>
        protected LogicBase(IView targetView, Type viewModelType = null, IViewModel viewModel = null)
        {
            Argument.IsNotNull("targetView", targetView);

            if (viewModelType == null)
            {
                viewModelType = (viewModel != null) ? viewModel.GetType() : _viewModelLocator.ResolveViewModel(targetView.GetType());
                if (viewModelType == null)
                {
                    var error = string.Format("The view model of the view '{0}' could not be resolved. Make sure to customize the IViewModelLocator or register the view and view model manually", targetView.GetType().GetSafeFullName());
                    Log.Error(error);
                    throw new NotSupportedException(error);
                }
            }

            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <LogicBase>();

            Log.Debug("Constructing behavior '{0}' for '{1}' with unique id '{2}'", GetType().Name, targetView.GetType().Name, UniqueIdentifier);

            TargetView    = targetView;
            ViewModelType = viewModelType;
            ViewModel     = viewModel;

#if SL5
            Catel.Windows.FrameworkElementExtensions.FixUILanguageBug((System.Windows.FrameworkElement)TargetView);
#endif

            ViewModelBehavior = (viewModel != null) ? LogicViewModelBehavior.Injected : LogicViewModelBehavior.Dynamic;

            if (ViewModel != null)
            {
                SetDataContext(ViewModel);
            }

            // Very impoortant to exit here in design mode
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            Log.Debug("Subscribing to view events");

            ViewLoadManager.AddView(this);
            this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewLoading", OnViewLoadedManagerLoading);
            this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewLoaded", OnViewLoadedManagerLoaded);
            this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewUnloading", OnViewLoadedManagerUnloading);
            this.SubscribeToWeakGenericEvent <ViewLoadEventArgs>(ViewLoadManager, "ViewUnloaded", OnViewLoadedManagerUnloaded);

            // Required so the ViewLoadManager can handle the rest
            targetView.Loaded   += (sender, e) => Loaded.SafeInvoke(this);
            targetView.Unloaded += (sender, e) => Unloaded.SafeInvoke(this);

            TargetView.DataContextChanged += OnTargetViewDataContextChanged;

            Log.Debug("Subscribing to view properties");

            // This also subscribes to DataContextChanged, don't double subscribe
            var viewPropertiesToSubscribe = DetermineInterestingViewProperties();
            foreach (var viewPropertyToSubscribe in viewPropertiesToSubscribe)
            {
                TargetView.SubscribeToPropertyChanged(viewPropertyToSubscribe, OnTargetViewPropertyChanged);
            }

            Log.Debug("Constructed behavior '{0}' for '{1}'", GetType().Name, TargetView.GetType().Name);
        }