protected ProjectBase(string location, string title)
        {
            Location = location;
            Title    = title;

            Id = UniqueIdentifierHelper.GetUniqueIdentifier(GetType());
        }
Пример #2
0
 public Notification()
 {
     Id         = UniqueIdentifierHelper.GetUniqueIdentifier <Notification>();
     ShowTime   = TimeSpan.FromSeconds(5);
     IsClosable = true;
     Priority   = NotificationPriority.Normal;
     Level      = NotificationLevel.Normal;
 }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LogicBase"/> class.
        /// </summary>
        /// <param name="targetControl">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="targetControl"/> 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(FrameworkElement targetControl, Type viewModelType, IViewModel viewModel = null)
        {
            Argument.IsNotNull("targetControl", targetControl);
            Argument.IsNotNull("viewModelType", viewModelType);
            Argument.ImplementsInterface("viewModelType", viewModelType, typeof(IViewModel));

            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <LogicBase>();

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

            TargetControl = targetControl;
            ViewModelType = viewModelType;
            ViewModel     = viewModel;

#if SL4 || SL5
            TargetControl.FixUILanguageBug();
#endif

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

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

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

#if NET
            TargetControl.Loaded += OnTargetControlLoadedInternal;
#else
            // Note: in non-WPF, use LayoutUpdated instead of Loaded because the order is down => top instead of top => down
            _frameworkElementLoadedManager.AddElement(TargetControl, () => OnTargetControlLoadedInternal(null, new RoutedEventArgs()));
#endif

            TargetControl.Unloaded += OnTargetControlUnloadedInternal;

#if WIN81
            // TODO: make the same for WIN80. There is no DataContextChanged event in WIN80.
            TargetControl.DataContextChanged += (sender, args) => OnTargetControlDataContextChanged(sender, new DependencyPropertyValueChangedEventArgs("DataContext", FrameworkElement.DataContextProperty, null, args.NewValue));
#endif

            // This also subscribes to DataContextChanged, don't double subscribe
            var dependencyPropertiesToSubscribe = DetermineInterestingDependencyProperties();
            foreach (var dependencyPropertyToSubscribe in dependencyPropertiesToSubscribe)
            {
                TargetControl.SubscribeToDependencyProperty(dependencyPropertyToSubscribe.PropertyName, OnTargetControlPropertyChangedInternal);
            }

#if NET
            IsTargetControlLoaded = TargetControl.IsLoaded;
#endif

            Log.Debug("Constructed behavior '{0}' for '{1}'", GetType().Name, TargetControl.GetType().Name);
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitOfWork" /> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="tag">The tag to uniquely identify this unit of work. If <c>null</c>, a unique id will be generated.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="context" /> is <c>null</c>.</exception>
        public UnitOfWork(DbContext context, string tag = null)
        {
            Argument.IsNotNull("context", context);

            _serviceLocator = ServiceLocator.Default;
            _typeFactory    = _serviceLocator.ResolveType <ITypeFactory>();

            DbContext = context;
            Tag       = tag ?? UniqueIdentifierHelper.GetUniqueIdentifier <UnitOfWork>().ToString(CultureInfo.InvariantCulture);
        }
Пример #5
0
        public SnapshotManager(ISnapshotStorageService snapshotStorageService, IServiceLocator serviceLocator)
        {
            Argument.IsNotNull(() => snapshotStorageService);
            Argument.IsNotNull(() => serviceLocator);

            _snapshotStorageService = snapshotStorageService;
            _serviceLocator         = serviceLocator;

            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <SnapshotManager>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WarningAndErrorValidator"/> class.
        /// </summary>
        public WarningAndErrorValidator()
        {
            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <WarningAndErrorValidator>();

#if NET
            Focusable = false;
#endif

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaElementThreadInfo"/> class.
        /// </summary>
        /// <param name="hostVisual">The host visual.</param>
        /// <param name="createVisual">The function responsible fro creating the visual that will run on the separate UI thread.</param>
        /// <param name="thread">The thread.</param>
        public MediaElementThreadInfo(HostVisual hostVisual, Func <Visual> createVisual, Thread thread)
        {
            Argument.IsNotNull(nameof(hostVisual), hostVisual);
            Argument.IsNotNull(nameof(createVisual), createVisual);
            Argument.IsNotNull(nameof(thread), thread);

            Id           = UniqueIdentifierHelper.GetUniqueIdentifier(typeof(MediaElementThreadInfo));
            HostVisual   = hostVisual;
            CreateVisual = createVisual;
            Thread       = thread;

            thread.Name = $"Media Element Thread: {Id}";
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WarningAndErrorValidator"/> class.
        /// </summary>
        public WarningAndErrorValidator()
        {
            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <WarningAndErrorValidator>();

#if NET || NETCORE
            Focusable = false;
#endif

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;

            this.HideValidationAdorner();
        }
Пример #9
0
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        protected ViewModelBase()
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            UniqueIdentifier          = UniqueIdentifierHelper.GetUniqueIdentifier(GetType());
            ViewModelConstructionTime = DateTime.Now;

            AuditingHelper.RegisterViewModel(this);

            _viewModelCommandManager = ViewModelCommandManager.Create(this);
            _viewModelCommandManager.AddHandler((viewModel, propertyName, command, commandParameter) =>
                                                _catelCommandExecuted.SafeInvoke(this, new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName)));

            ViewModelManager.RegisterViewModelInstance(this);
        }
Пример #10
0
        public IRepository GetSerializableRepository(string name, string source, PackageOperationType operationType, Func <IPackageRepository> packageRepositoryFactory, bool renew = false)
        {
            Argument.IsNotNullOrEmpty(() => name);
            Argument.IsNotNull(() => packageRepositoryFactory);

            var key = GetKey(operationType, name);

            if (_keyIdDictionary.TryGetValue(key, out var id))
            {
                return(!renew
                    ? _idTupleDictionary[id].Item1
                    : CreateSerializableRepository(id, name, source, operationType, packageRepositoryFactory));
            }

            id = UniqueIdentifierHelper.GetUniqueIdentifier <RepositoryCacheService>();
            _keyIdDictionary.Add(key, id);

            return(CreateSerializableRepository(id, name, source, operationType, packageRepositoryFactory));
        }
Пример #11
0
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        protected ViewModelBase()
        {
            if (Catel.Environment.IsInDesignMode)
            {
                return;
            }

            UniqueIdentifier          = UniqueIdentifierHelper.GetUniqueIdentifier(GetType());
            ViewModelConstructionTime = DateTime.Now;

            AuditingHelper.RegisterViewModel(this);

            _viewModelCommandManager = ViewModelCommandManager.Create(this);
            _viewModelCommandManager.AddHandler((viewModel, propertyName, command, commandParameter) =>
                                                _catelCommandExecuted.SafeInvoke(this, new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName)));

            ServiceLocator     = IoCConfiguration.DefaultServiceLocator;
            DependencyResolver = ServiceLocator.ResolveType <IDependencyResolver>();
            RegisterViewModelServices(ServiceLocator);

            ViewModelManager.RegisterViewModelInstance(this);
        }
Пример #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);
        }
 public Notification()
 {
     Id         = UniqueIdentifierHelper.GetUniqueIdentifier <Notification>();
     ShowTime   = TimeSpan.FromSeconds(5);
     IsClosable = true;
 }
Пример #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BindingContext"/> class.
        /// </summary>
        public BindingContext()
        {
            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <BindingContext>();

            Log.Debug("Initialized binding context");
        }
Пример #15
0
 public A()
 {
     Id       = UniqueIdentifierHelper.GetUniqueIdentifier <A>();
     SubClass = new B();
 }
Пример #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Batch"/> class.
 /// </summary>
 public Batch()
 {
     UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <Batch>();
 }
Пример #17
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);

            var targetViewType = targetView.GetType();

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

            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, nameof(IViewLoadManager.ViewLoading), OnViewLoadedManagerLoadingInternal, false) is 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, nameof(IViewLoadManager.ViewLoaded), OnViewLoadedManagerLoadedInternal, false) is 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, nameof(IViewLoadManager.ViewUnloading), OnViewLoadedManagerUnloadingInternal, false) is 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, nameof(IViewLoadManager.ViewUnloaded), OnViewLoadedManagerUnloadedInternal, false) is 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?.Invoke(this, EventArgs.Empty);
            targetView.Unloaded += (sender, e) => Unloaded?.Invoke(this, EventArgs.Empty);

            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}'");
        }
Пример #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PoolableBase"/> class.
        /// </summary>
        protected PoolableBase()
        {
            var type = GetType();

            UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier(type);
        }
Пример #19
0
 public PackageOperationContext()
 {
     UniqueIdentifier = UniqueIdentifierHelper.GetUniqueIdentifier <PackageOperationContext>();
     Exceptions       = new List <Exception>();
 }
Пример #20
0
 public B()
 {
     Id = UniqueIdentifierHelper.GetUniqueIdentifier <B>();
 }
Пример #21
0
 public CircularTestModel()
 {
     Name = UniqueIdentifierHelper.GetUniqueIdentifier <CircularTestModel>().ToString();
 }