Пример #1
0
        public void SetItems_ListChangedIsRaisedAfterBehaviors()
        {
            var actionLog = new StringBuilder();

            var changeListener = new TestChangeListener();

            var ownerProperty = PropertyStub
                                .WithBehaviors(changeListener)
                                .Build();

            var ownerVM = ViewModelStub
                          .WithProperties(ownerProperty)
                          .Build();

            var collection = new VMCollection <IViewModel>(ownerVM, ownerProperty);

            changeListener.HandleChange += delegate {
                actionLog.Append("ChangeHandlerBehavior ");
            };

            collection.ListChanged += delegate {
                actionLog.Append("ListChanged ");
            };

            IVMCollection <IViewModel> c = collection;

            c.ReplaceItems(new[] { ViewModelStub.Build(), ViewModelStub.Build() }, null);

            Assert.AreEqual("ChangeHandlerBehavior ListChanged ", actionLog.ToString());
        }
        public void Setup()
        {
            BehaviorStub = new ModificationCollectionBehaviorStub();
            var owner = new Mock <IViewModel> {
                DefaultValue = DefaultValue.Mock
            };

            Collection = new VMCollection <IViewModel>(
                owner.Object,
                PropertyStub.WithBehaviors(BehaviorStub).Build()
                );
        }
Пример #3
0
        public EditorViewModel( IKeyboardContext ctx, IPluginConfigAccessor config )
        {
            DisplayName = "";

            _ctx = ctx;
            _config = config;
            _zoneCache = new Dictionary<ILayoutZone, LayoutZoneViewModel>();

            SelectedHolder = _ctx.CurrentKeyboard.CurrentLayout;
            Zones = new VMCollection<LayoutZoneViewModel, ILayoutZone>( _ctx.CurrentKeyboard.CurrentLayout.LayoutZones, FindOrCreate );

            _ctx.CurrentKeyboardChanged += new EventHandler<CurrentKeyboardChangedEventArgs>( OnCurrentKeyboardChanged );
            _config.ConfigChanged += new EventHandler<ConfigChangedEventArgs>( OnLayoutConfigChanged );
        }
Пример #4
0
        public VMIAssembly( VMIContextViewModel ctx, IAssemblyInfo assembly )
            : base(ctx, null)
        {
            _assemblyInfo = assembly;
            Assembly = assembly.AssemblyName;
            if( !assembly.HasError )
                Label = assembly.AssemblyName.Name;
            else
                Label = assembly.AssemblyFileName;
            OnError = assembly.HasError;

            DetailsTemplateName = "AssemblyDetails";

            Plugins = new VMCollection<VMAlias<VMIPlugin>, IPluginInfo>( assembly.Plugins, ( info ) => { return new VMAlias<VMIPlugin>( VMIContext.FindOrCreate( info ), this ); } );
            Services = new VMCollection<VMAlias<VMIService>, IServiceInfo>( assembly.Services, ( info ) => { return new VMAlias<VMIService>( VMIContext.FindOrCreate( info ), this ); } );
        }
 protected virtual bool SelectElementInCollection(T selectElement)
 {
     if (VMCollection == null)
     {
         throw new Exception("Collection is not define!");
     }
     if (selectElement == null)
     {
         SetCurrentElement(null, isSelectedAfterCollectionInitialize: true);
         return(true);
     }
     else
     {
         var elementFromCollection = VMCollection.Where(i => selectElement.Equals(i)).FirstOrDefault();
         SetCurrentElement(elementFromCollection, isSelectedAfterCollectionInitialize: true);
         return(elementFromCollection != null);
     }
 }
Пример #6
0
        public void GetItemProperties_ReturnsPropertyDescriptorCollection()
        {
            var itemTypeDescriptorBehavior = new TypeDescriptorProviderBehavior();

            var itemDescriptor = DescriptorStub
                                 .WithBehaviors(itemTypeDescriptorBehavior)
                                 .Build();

            var ownerProperty = PropertyStub
                                .WithBehaviors(new ItemDescriptorProviderBehavior(itemDescriptor))
                                .Build();

            var ownerVM = ViewModelStub
                          .WithProperties(ownerProperty)
                          .Build();

            var collection = new VMCollection <IViewModel>(ViewModelStub.Build(), ownerProperty);

            Assert.AreSame(itemTypeDescriptorBehavior.PropertyDescriptors, collection.GetItemProperties(null));
        }
Пример #7
0
        public VMIService( VMIContextViewModel ctx, IServiceInfo service, VMIBase parent )
            : base(ctx, parent)
        {
            _service = service;
            Label = service.ServiceFullName;
            if( !service.HasError && service.Implementations.Count == 0 )
                ErrorMessage = "No implementation";
            else
                ErrorMessage = _service.ErrorMessage;
            OnError = ErrorMessage != null;

            if( service.IsDynamicService )
                Assembly = service.AssemblyInfo.AssemblyName;

            DetailsTemplateName = "ServiceDetails";

            _pluginRunner = VMIContext.Context.GetService<PluginRunner>( true );
            _pluginRunner.ApplyDone += new EventHandler<ApplyDoneEventArgs>( OnApplyDone );

            _allReferencingPlugins = new Dictionary<VMIPlugin, RunningRequirement>();
            ImplementedBy = new VMCollection<VMAlias<VMIPlugin>, IPluginInfo>( _service.Implementations, ( info ) => { return new VMAlias<VMIPlugin>( VMIContext.FindOrCreate( info ), null ); } );
        }
Пример #8
0
        public VMIContextViewModel( IContext context, IPluginConfigAccessor config, ILogService logService, IHelpService helpService )
        {
            DisplayName = "Object explorer";

            Context = context;
            Config = config;
            HelpService = helpService;

            InitializeCommands();

            _plugins = new Dictionary<IPluginInfo, VMIPlugin>();
            _allServices = new Dictionary<IServiceInfo, VMIService>();
            _dynamicServices = new Dictionary<IServiceInfo, VMIService>();
            _serviceRefs = new Dictionary<IServiceReferenceInfo, VMIService>();
            _assemblies = new Dictionary<IAssemblyInfo, VMIAssembly>();

            _pluginRunner = Context.GetService<PluginRunner>( true );
            _pluginRunner.ApplyDone += new EventHandler<ApplyDoneEventArgs>( OnApplyDone );

            NotificationService = context.GetService<INotificationService>();

            Assemblies = new VMCollection<VMIAssembly, IAssemblyInfo>( PluginRunner.Discoverer.AllAssemblies, FindOrCreate );
            Plugins = new VMCollection<VMIPlugin, IPluginInfo>( PluginRunner.Discoverer.AllPlugins.OrderBy( p => p.PublicName ), FindOrCreate );
            AllServices = new VMCollection<VMIService, IServiceInfo>( PluginRunner.Discoverer.AllServices, FindOrCreate );
            DynamicServices = new VMCollection<VMIService, IServiceInfo>( PluginRunner.Discoverer.AllServices.Where( p => p.IsDynamicService ), FindOrCreateDynamic );
            Categories = new ObservableCollection<VMIFolder>();

            _vmLogConfig = new VMLogConfig( this, logService );
            _vmLogConfig.Initialize();

            OsInfo = new VMOSInfo( this );

            VMApplicationInfo = new VMApplicationInfo( this );

            Dictionary<string, List<IPluginInfo>> categoryFolders = new Dictionary<string, List<IPluginInfo>>();
            foreach( IPluginInfo plugin in PluginRunner.Discoverer.AllPlugins )
            {
                foreach( string categ in plugin.Categories )
                {
                    List<IPluginInfo> col;
                    if( !categoryFolders.TryGetValue( categ, out col ) )
                    {
                        col = new List<IPluginInfo>();
                        col.Add( plugin );
                        categoryFolders.Add( categ, col );
                    }
                    else
                    {
                        col.Add( plugin );
                    }
                }
            }
            foreach( KeyValuePair<string, List<IPluginInfo>> item in categoryFolders )
            {
                VMCollection<VMAlias<VMIPlugin>, IPluginInfo> collection = new VMCollection<VMAlias<VMIPlugin>, IPluginInfo>( item.Value, ( info ) => { return new VMAlias<VMIPlugin>( FindOrCreate( info ), null ); } );
                VMIFolder folder = new VMIFolder( collection, item.Key );
                Categories.Add( folder );
            }
        }
Пример #9
0
        public VMIService( VMIContextViewModel ctx, IServiceReferenceInfo service, VMIBase parent )
            : base(ctx, parent)
        {
            _serviceRef = service;
            _service = service.Reference;
            Label = service.Reference.ServiceFullName;
            OnError = service.HasError;

            if( service.Reference.IsDynamicService )
                Assembly = service.Reference.AssemblyInfo.AssemblyName;

            _pluginRunner = VMIContext.Context.GetService<PluginRunner>( true );
            _pluginRunner.ApplyDone += new EventHandler<ApplyDoneEventArgs>( OnApplyDone );

            DetailsTemplateName = "ServiceRefDetails";
            _owner = new VMIPlugin( ctx, service.Owner, this );
            _reference = new VMIService( ctx, service.Reference, this );

            _allReferencingPlugins = new Dictionary<VMIPlugin,RunningRequirement>();
            ImplementedBy = new VMCollection<VMAlias<VMIPlugin>, IPluginInfo>( _service.Implementations, ( info ) => { return new VMAlias<VMIPlugin>( VMIContext.FindOrCreate( info ), this ); } );
        }
Пример #10
0
        public VMIPlugin( VMIContextViewModel ctx, IPluginInfo plugin, VMIBase parent )
            : base(ctx, parent)
        {
            _pluginInfo = plugin;

            Label = plugin.PublicName;
            Assembly = plugin.AssemblyInfo.AssemblyName;
            DetailsTemplateName = "PluginDetails";

            _systemPluginStatus = VMIContext.Context.ConfigManager.SystemConfiguration.PluginsStatus.GetStatus( Id, ConfigPluginStatus.Manual );
            _userPluginStatus = VMIContext.Context.ConfigManager.UserConfiguration.PluginsStatus.GetStatus( Id, ConfigPluginStatus.Manual );

            _pluginRunner = VMIContext.Context.GetService<PluginRunner>( true );
            _pluginRunner.ApplyDone += new EventHandler<ApplyDoneEventArgs>( OnApplyDone );

            VMIContext.Context.ConfigManager.UserConfiguration.LiveUserConfiguration.Changed += new EventHandler<LiveUserConfigurationChangedEventArgs>( OnLiveUserConfigurationChanged );
            VMIContext.Context.ConfigManager.SystemConfiguration.PluginsStatus.Changed += new EventHandler<PluginStatusCollectionChangedEventArgs>( OnSystemPluginStatusChanged );
            VMIContext.Context.ConfigManager.UserConfiguration.PluginsStatus.Changed += new EventHandler<PluginStatusCollectionChangedEventArgs>( OnUserPluginStatusChanged );

            VMIContext.Context.ConfigManager.UserConfiguration.PropertyChanged += new PropertyChangedEventHandler( OnUserConfigurationChanged );
            VMIContext.Context.ConfigManager.SystemConfiguration.PropertyChanged += new PropertyChangedEventHandler( OnSystemConfigurationChanged );

            CreateCommands();

            IList<IPluginInfo> editableBy = new List<IPluginInfo>();
            foreach( IPluginConfigAccessorInfo p in plugin.EditableBy )
                editableBy.Add( p.Plugin );
            _canEdit = new List<IPluginInfo>();
            foreach( IPluginConfigAccessorInfo p in _pluginInfo.EditorsInfo )
                _canEdit.Add( p.EditedSource );
            IList<IPluginInfo> required = new List<IPluginInfo>();

            _vmRequirementLayers = new List<VMIPluginRequirementLayer>();
            foreach( RequirementLayer layer in RequirementLayers )
            {
                _vmRequirementLayers.Add( new VMIPluginRequirementLayer( this, layer ) );
            }

            ServiceRefs = new VMCollection<VMAlias<VMIService>, IServiceReferenceInfo>( plugin.ServiceReferences, ( info ) => { return new VMAlias<VMIService>( VMIContext.FindOrCreate( info ), this ); } );
            CanEdit = new VMCollection<VMAlias<VMIPlugin>, IPluginInfo>( new CKReadOnlyListOnIList<IPluginInfo>( _canEdit ), ( info ) => { return new VMAlias<VMIPlugin>( VMIContext.FindOrCreate( info ), this ); } );
            EditableBy = new VMCollection<VMAlias<VMIPlugin>, IPluginInfo>( new CKReadOnlyListOnIList<IPluginInfo>( editableBy ), ( info ) => { return new VMAlias<VMIPlugin>( VMIContext.FindOrCreate( info ), this ); } );
        }
Пример #11
0
        void OnCurrentKeyboardChanged( object sender, CurrentKeyboardChangedEventArgs e )
        {
            if( e.Previous != null ) e.Previous.CurrentLayoutChanged -= new EventHandler<KeyboardCurrentLayoutChangedEventArgs>( OnCurrentLayoutChanged );
            if( e.Current != null )
            {
                e.Current.CurrentLayoutChanged += new EventHandler<KeyboardCurrentLayoutChangedEventArgs>( OnCurrentLayoutChanged );

                _zoneCache.Clear();
                Zones.Refresh();
                Zones = new VMCollection<LayoutZoneViewModel, ILayoutZone>( _ctx.CurrentKeyboard.CurrentLayout.LayoutZones, FindOrCreate );
                ToggleCurrentKeyboardAsHolder();
                NotifyOfPropertyChange( () => Zones );
                Refresh();
            }
        }