Exemple #1
0
        internal static IMultipleSelection GetSelectionBinding(this IDynamicPanelDefinition definition, IUnityContainer container)
        {
            definition.AssertNotNull(nameof(definition));
            definition.AssertParameterNotNull(nameof(container));

            var selectionType   = definition.GetSelectionBindingType();
            var eventAggregator = container.Resolve <IEventAggregator>();

            return(eventAggregator.GetEvent(selectionType).SafeCast <IMultipleSelection>());
        }
Exemple #2
0
 public bool IsRegistered(IDynamicPanelDefinition definition)
 {
     definition.AssertParameterNotNull(nameof(definition));
     return(DynamicPanelDefinitions.Contains(definition));
 }
Exemple #3
0
        private void AssertDynamicPanelDefinition(IDynamicPanelDefinition definition)
        {
            definition.AssertParameterNotNull(nameof(definition));

            definition.IView.AssertNotNull($"IDynamicPanelDefinition.IView");
            definition.View.AssertNotNull($"IDynamicPanelDefinition.View");
            definition.IViewModel.AssertNotNull($"IDynamicPanelDefinition.IViewModel");
            definition.ViewModel.AssertNotNull($"IDynamicPanelDefinition.ViewModel");

            if (!definition.View.IsClass ||
                !definition.View.IsSubclassOf(typeof(UserControl)) ||
                definition.View.GetConstructors().Count() != 1 ||
                definition.View.GetConstructors().Single().GetParameters().Any())
            {
                throw new Exception($"Error : {definition.View.Name} must be a class inheriting from user control with an empty constructor.");
            }

            if (!definition.View.Implements(definition.IView))
            {
                throw new Exception($"Error : {definition.View.Name} does not implement {definition.IView.Name}.");
            }

            if (!definition.ViewModel.Implements(definition.IViewModel))
            {
                throw new Exception($"Error : {definition.ViewModel.Name} does not implement {definition.IViewModel.Name}.");
            }

            if (!definition.ViewModel.Implements(typeof(IIdentifiable)))
            {
                throw new Exception($"Error : {definition.ViewModel.Name} does not implement IIdentifiable. This is required for the serialization of the" +
                                    $"active panel layout collection.");
            }

            if (DynamicPanelDefinitions.Any(def => def.View == definition.View))
            {
                throw new Exception($"Error! A DynamicPanelDefinitions with the associated {definition.View.Name} View has already been registered.");
            }
            if (DynamicPanelDefinitions.Any(def => def.IView == definition.IView))
            {
                throw new Exception($"Error! A DynamicPanelDefinitions with the associated View interface {definition.IView.Name} has already been registered.");
            }
            if (DynamicPanelDefinitions.Any(def => def.ViewModel == definition.ViewModel))
            {
                throw new Exception($"Error! A DynamicPanelDefinitions with the associated ViewModel : {definition.ViewModel.Name} has already been registered.");
            }
            if (DynamicPanelDefinitions.Any(def => def.IViewModel == definition.IViewModel))
            {
                throw new Exception($"Error! A DynamicPanelDefinitions with the associated ViewModel interface : {definition.IViewModel.Name} has already been registered.");
            }

            MetadataAsserter.AssertMetadataCollection <IDynamicPanelDefinition, IDynamicPanelMetadata>(definition, $"DynamicPanelDefinition<{definition.IView.Name}, {definition.View.Name}, {definition.IViewModel.Name}, {definition.ViewModel.Name}>");

            var config = definition.Single(o => o.GetType().IsGenericType&& o.GetType().GetGenericTypeDefinition() == typeof(DynamicPanelConfiguration <>));
            var configGenericParamType = config.GetType().GetGenericArguments().Single();

            if (!(configGenericParamType == definition.View ||
                  configGenericParamType == definition.IView ||
                  configGenericParamType == definition.ViewModel ||
                  configGenericParamType == definition.IViewModel))
            {
                throw new Exception($"Error : DynamicPanelDefinition<{definition.IView.Name}, {definition.View.Name}, {definition.IViewModel.Name}, {definition.ViewModel.Name}> : \n" +
                                    $"The DynamicPanelConfiguration Generic Parameter must be of one of the following types : {definition.IView.Name}, {definition.View.Name}, {definition.IViewModel.Name}, {definition.ViewModel.Name}");
            }

            var selectionBindingType = definition.GetSelectionBindingRawType();

            if (!(selectionBindingType == definition.ViewModel || selectionBindingType == definition.IViewModel))
            {
                throw new Exception($"Error : DynamicPanelDefinition<{definition.IView.Name}, {definition.View.Name}, {definition.IViewModel.Name}, {definition.ViewModel.Name}> : \n " +
                                    $"The PanelSelectionBinding type does not match the viewModel Type.");
            }
        }