示例#1
0
        private static object ComputeConfigDelegateResult(this IDynamicPanelDefinition definition, string delegatePropertyName, object view, object viewModel)
        {
            definition.AssertNotNull(nameof(definition));
            view.AssertParameterNotNull(nameof(view));
            viewModel.AssertParameterNotNull(nameof(viewModel));

            var config     = definition.GetConfig();
            var configType = config.GetType().GetGenericArguments().Single();

            var del = config.GetType().GetProperty(delegatePropertyName).GetValue(config).SafeCast <Delegate>();

            if (configType == definition.View || configType == definition.IView)
            {
                return(del.DynamicInvoke(view));
            }

            else if (configType == definition.ViewModel || configType == definition.IViewModel)
            {
                return(del.DynamicInvoke(viewModel));
            }

            else
            {
                throw new Exception($"Internal Error : DynamicPanelDefinition<{definition.IView.Name}, {definition.View.Name}, {definition.IViewModel.Name}, {definition.ViewModel.Name}> : \n " +
                                    $"DynamicPanelConfiguration Generic Type is not valid and has not been correctly asserted.");
            }
        }
示例#2
0
        internal static IDynamicPanelMetadata GetConfig(this IDynamicPanelDefinition definition)
        {
            definition.AssertNotNull(nameof(definition));

            return(definition.Single(o => o.GetType().IsGenericType&&
                                     o.GetType().GetGenericTypeDefinition() == typeof(DynamicPanelConfiguration <>)));
        }
示例#3
0
        internal static PanelPlacement GetPlacement(this IDynamicPanelDefinition definition)
        {
            definition.AssertNotNull(nameof(definition));

            var config = definition.GetConfig();

            return(config.GetType().GetProperty("Placement").GetValue(config).SafeCast <PanelPlacement>());
        }
示例#4
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>());
        }
示例#5
0
 public void RegisterDynamicPanelDefinition(IDynamicPanelDefinition definition)
 {
     AssertDynamicPanelDefinition(definition);
     Container.RegisterType(definition.IViewModel, definition.ViewModel);
     dynamicPanelDefinitions.Add(definition);
 }
示例#6
0
 public bool IsRegistered(IDynamicPanelDefinition definition)
 {
     definition.AssertParameterNotNull(nameof(definition));
     return(DynamicPanelDefinitions.Contains(definition));
 }
示例#7
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.");
            }
        }
示例#8
0
 public DynamicPanelManager(IObjectInitializationService initSvc, IDynamicPanelDefinition definition)
     : base(initSvc)
 {
     Definition         = definition;
     ViewModelSelection = Definition.GetSelectionBinding(Container);
 }
示例#9
0
 internal static Type GetSelectionBindingRawType(this IDynamicPanelDefinition definition)
 {
     definition.AssertNotNull(nameof(definition));
     return(definition.GetSelectionBindingType().GetBaseTypeGenericArgument(typeof(MultipleSelection <>)));
 }
示例#10
0
 internal static Type GetSelectionBindingType(this IDynamicPanelDefinition definition)
 {
     definition.AssertNotNull(nameof(definition));
     return(definition.OfType <PanelSelectionBinding>().Single().SelectionType);
 }
示例#11
0
 internal static bool ComputeCanFloat(this IDynamicPanelDefinition definition, object view, object viewModel)
 {
     return(definition.ComputeConfigDelegateResult("CanFloat", view, viewModel).SafeCast <bool>());
 }
示例#12
0
 internal static string ComputeTitle(this IDynamicPanelDefinition definition, object view, object viewModel)
 {
     return(definition.ComputeConfigDelegateResult("Title", view, viewModel).SafeCast <string>());
 }