├── .editorconfig ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── Sandbox ├── README.md └── WinForms │ ├── CommandBinderSample │ ├── App.config │ ├── Bootstraper.cs │ ├── CommandBinderSample.csproj │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── Shell.Designer.cs │ ├── Shell.cs │ ├── Shell.resx │ ├── View.Designer.cs │ ├── View.cs │ ├── View.resx │ ├── ViewModel.cs │ └── packages.config │ └── Hello World │ ├── HelloWorldModule │ ├── HelloWorldModule.cs │ ├── HelloWorldModule.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config │ └── HeloWorldUnity │ ├── App.config │ ├── Bootstraper.cs │ ├── HeloWorldUnity.csproj │ ├── Program.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ ├── Shell.Designer.cs │ ├── Shell.cs │ ├── Shell.resx │ └── packages.config └── Source ├── Prism.Tests ├── Events │ ├── BackgroundEventSubscriptionFixture.cs │ ├── DataEventArgsFixture.cs │ ├── DelegateReferenceFixture.cs │ ├── DispatcherEventSubscriptionFixture.cs │ ├── EventAggregatorFixture.cs │ ├── EventBaseFixture.cs │ ├── EventSubscriptionFixture.cs │ ├── MockDelegateReference.cs │ └── PubSubEventFixture.cs ├── Logging │ ├── DebugLoggerFixture.cs │ └── EmptyLoggerFixture.cs ├── Mocks │ ├── Commands │ │ └── DelegateCommandMock.cs │ ├── ViewModels │ │ ├── MockValidatingViewModel.cs │ │ └── MockViewModel.cs │ └── Views │ │ ├── Mock.cs │ │ └── MockView.cs ├── Mvvm │ ├── BindableBaseFixture.cs │ ├── CompositeCommandFixture.cs │ ├── DelegateCommandFixture.cs │ ├── ErrorsContainerFixture.cs │ ├── PropertySupportFixture.cs │ └── ViewModelLocationProviderFixture.cs ├── Prism.Tests.csproj ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Prism ├── Commands │ ├── CompositeCommand.cs │ ├── DelegateCommand.cs │ └── DelegateCommandBase.cs ├── Events │ ├── BackgroundEventSubscription.cs │ ├── DataEventArgs.cs │ ├── DelegateReference.cs │ ├── DispatcherEventSubscription.cs │ ├── EventAggregator.cs │ ├── EventBase.cs │ ├── EventSubscription.cs │ ├── IDelegateReference.cs │ ├── IEventAggregator.cs │ ├── IEventSubscription.cs │ ├── PubSubEvent.cs │ ├── SubscriptionToken.cs │ └── ThreadOption.cs ├── IActiveAware.cs ├── Logging │ ├── Category.cs │ ├── DebugLogger.cs │ ├── EmptyLogger.cs │ ├── ILoggerFacade.cs │ └── Priority.cs ├── Mvvm │ ├── BindableBase.cs │ ├── ErrorsContainer.cs │ ├── PropertySupport.cs │ └── ViewModelLocationProvider.cs ├── Prism.csproj └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── PrismLibrary.sln ├── PrismLibrary_Core.sln ├── PrismLibrary_WinForms.sln ├── WinForms ├── Prism.Unity.WinForms │ ├── GlobalSuppressions.cs │ ├── Prism.Unity.WinForms.csproj │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ └── Resources.resx │ ├── Regions │ │ └── UnityRegionNavigationContentLoader.cs │ ├── UnityBootstrapper.cs │ ├── UnityBootstrapperExtension.cs │ ├── UnityContainerHelper.cs │ ├── UnityExtensions.cs │ ├── UnityServiceLocatorAdapter.cs │ └── packages.config ├── Prism.WinForms.Tests │ ├── App.config │ ├── BootstrapperFixture.cs │ ├── CollectionChangedTracker.cs │ ├── CollectionExtensionsFixture.cs │ ├── CompilerHelper.Desktop.cs │ ├── ExceptionAssert.cs │ ├── ExceptionExtensionsFixture.cs │ ├── ListDictionaryFixture.cs │ ├── Logging │ │ ├── TextLoggerFixture.cs │ │ └── TraceLoggerFixture.Desktop.cs │ ├── Mocks │ │ ├── MockAsyncModuleTypeLoader.cs │ │ ├── MockClickableObject.cs │ │ ├── MockCommand.cs │ │ ├── MockConfigurationStore.Desktop.cs │ │ ├── MockContainerAdapter.cs │ │ ├── MockDelegateReference.cs │ │ ├── MockDependencyObject.cs │ │ ├── MockFrameworkElement.cs │ │ ├── MockHostAwareRegionBehavior.cs │ │ ├── MockInteractionRequestAwareElement.cs │ │ ├── MockLogger.cs │ │ ├── MockModuleTypeLoader.cs │ │ ├── MockPresentationRegion.cs │ │ ├── MockRegion.cs │ │ ├── MockRegionAdapter.cs │ │ ├── MockRegionBehavior.cs │ │ ├── MockRegionBehaviorCollection.cs │ │ ├── MockRegionManager.cs │ │ ├── MockRegionManagerAccessor.cs │ │ ├── MockServiceLocator.cs │ │ ├── MockSortableViews.cs │ │ ├── MockViewsCollection.cs │ │ ├── Modules │ │ │ ├── MockAbstractModule.cs │ │ │ ├── MockAttributedModule.cs │ │ │ ├── MockDependantModule.cs │ │ │ ├── MockDependencyModule.cs │ │ │ ├── MockExposingTypeFromGacAssemblyModule.cs │ │ │ ├── MockModuleA.cs │ │ │ ├── MockModuleReferencedAssembly.cs │ │ │ ├── MockModuleReferencingAssembly.cs │ │ │ ├── MockModuleReferencingOtherModule.cs │ │ │ └── MockModuleThrowingException.cs │ │ ├── ViewModels │ │ │ └── MockViewModel.cs │ │ └── Views │ │ │ ├── Mock.cs │ │ │ └── MockView.cs │ ├── Modularity │ │ ├── AssemblyResolverFixture.Desktop.cs │ │ ├── ConfigurationModuleCatalogFixture.Desktop.cs │ │ ├── ConfigurationStoreFixture.Desktop.cs │ │ ├── DirectoryModuleCatalogFixture.Desktop.cs │ │ ├── FileModuleTypeLoaderFixture.Desktop.cs │ │ ├── ModuleAttributeFixture.Desktop.cs │ │ ├── ModuleCatalogFixture.cs │ │ ├── ModuleCatalogXaml │ │ │ └── SimpleModuleCatalog.xaml │ │ ├── ModuleDependencySolverFixture.cs │ │ ├── ModuleInfoGroupExtensionsFixture.cs │ │ ├── ModuleInfoGroupFixture.cs │ │ ├── ModuleInitializerFixture.cs │ │ ├── ModuleManagerFixture.cs │ │ └── NotAValidDotNetDll.txt.dll │ ├── Prism.WinForms.Tests.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ServiceLocatorExtensionsFixture.cs │ └── packages.config └── Prism.WinForms │ ├── Bootstrapper.cs │ ├── Commands │ ├── ButtonBinder.cs │ ├── CommandBinder.cs │ ├── CommandManager.cs │ ├── ICommandBinder.cs │ └── MenuItemCommandBinder.cs │ ├── Common │ ├── CallbackHelper.cs │ └── ListDictionary.cs │ ├── Events │ └── WeakDelegatesManager.cs │ ├── Extensions │ ├── CollectionExtensions.cs │ ├── ExceptionExtensions.cs │ └── ServiceLocatorExtensions.cs │ ├── Logging │ ├── TextLogger.cs │ └── TraceLogger.cs │ ├── Modularity │ ├── AssemblyResolver.Desktop.cs │ ├── ConfigurationModuleCatalog.Desktop.cs │ ├── ConfigurationStore.Desktop.cs │ ├── CyclicDependencyFoundException.Desktop.cs │ ├── CyclicDependencyFoundException.cs │ ├── DirectoryModuleCatalog.Desktop.cs │ ├── DuplicateModuleException.Desktop.cs │ ├── DuplicateModuleException.cs │ ├── FileModuleTypeLoader.Desktop.cs │ ├── IAssemblyResolver.Desktop.cs │ ├── IConfigurationStore.Desktop.cs │ ├── IModule.cs │ ├── IModuleCatalog.cs │ ├── IModuleCatalogItem.cs │ ├── IModuleInitializer.cs │ ├── IModuleManager.cs │ ├── IModuleTypeLoader.cs │ ├── InitializationMode.cs │ ├── LoadModuleCompletedEventArgs.cs │ ├── ModularityException.Desktop.cs │ ├── ModularityException.cs │ ├── ModuleAttribute.Desktop.cs │ ├── ModuleCatalog.cs │ ├── ModuleConfigurationElement.Desktop.cs │ ├── ModuleConfigurationElementCollection.Desktop.cs │ ├── ModuleDependencyAttribute.Desktop.cs │ ├── ModuleDependencyCollection.Desktop.cs │ ├── ModuleDependencyConfigurationElement.Desktop.cs │ ├── ModuleDependencySolver.cs │ ├── ModuleDownloadProgressChangedEventArgs.cs │ ├── ModuleInfo.Desktop.cs │ ├── ModuleInfo.cs │ ├── ModuleInfoGroup.cs │ ├── ModuleInfoGroupExtensions.cs │ ├── ModuleInitializeException.Desktop.cs │ ├── ModuleInitializeException.cs │ ├── ModuleInitializer.cs │ ├── ModuleManager.Desktop.cs │ ├── ModuleManager.cs │ ├── ModuleNotFoundException.Desktop.cs │ ├── ModuleNotFoundException.cs │ ├── ModuleState.cs │ ├── ModuleTypeLoaderNotFoundException.Desktop.cs │ ├── ModuleTypeLoaderNotFoundException.cs │ ├── ModuleTypeLoadingException.Desktop.cs │ ├── ModuleTypeLoadingException.cs │ └── ModulesConfigurationSection.Desktop.cs │ ├── Prism.WinForms.csproj │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx │ └── packages.config └── nuspecs ├── CreatePrismNuGetPackages.ps1 ├── Prism.Unity.WinForms.nuspec └── Prism.WinForms.nuspec /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | end_of_line = CRLF 8 | 9 | [*.cs] 10 | indent_style = space 11 | indent_size = 4 12 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prism.WinForms 2 | 3 | Reduced version of Prism.WPF that works in Windows.Forms. 4 | 5 | ### Includes: 6 | * Unity bootstraper 7 | * Modularity 8 | 9 | ## What is Prism ? 10 | 11 | Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in WPF, Windows 10 UWP, and Xamarin Forms. Separate releases are available for each platform and those will be developed on independent timelines. Prism provides an implementation of a collection of design patterns that are helpful in writing well-structured and maintainable XAML applications, including MVVM, dependency injection, commands, EventAggregator, and others. Prism's core functionality is a shared code base in a Portable Class Library targeting these platforms. Those things that need to be platform specific are implemented in the respective libraries for the target platform. Prism also provides great integration of these patterns with the target platform. For example, Prism for UWP and Xamarin Forms allows you to use an abstraction for navigation that is unit testable, but that layers on top of the platform concepts and APIs for navigation so that you can fully leverage what the platform itself has to offer, but done in the MVVM way. 12 | 13 | Prism 6 is a fully open source version of the Prism guidance originally produced by Microsoft patterns & practices. The core team members were all part of the p&p team that developed Prism 1 through 5, and the effort has now been turned over to the open source community to keep it alive and thriving to support the .NET community. There are thousands of companies who have adopted previous versions of Prism for WPF, Silverlight, and Windows Runtime, and we hope they will continue to move along with us as we continue to evolve and enhance the framework to keep pace with current platform capabilities and requirements. 14 | 15 | For more info visit the [Prism][3] repository in github. 16 | 17 | ## Requeriments 18 | 19 | * [Prism.Core][1] 20 | * [Unity Container][2] 21 | 22 | [1]: https://www.nuget.org/packages/Prism.Core/ 23 | [2]: https://www.nuget.org/packages/Unity/ 24 | [3]: https://github.com/PrismLibrary/Prism 25 | 26 | -------------------------------------------------------------------------------- /Sandbox/README.md: -------------------------------------------------------------------------------- 1 | # Development samples 2 | 3 | All samples under this repository are minimal samples created to test Prism in a real application during development. This enables the team to proof and validate more complex functionality (e.g. navigation) without the need to create new NuGet packages during development. 4 | 5 | These samples are no replacement for the unit test suite that covers the code base. 6 | 7 | # Stable samples 8 | 9 | More complete samples showing how to use Prism 6 for your application development will be posted in separate repositories under the [PrismLibrary GitHub organization](https://github.com/PrismLibrary). These samples are based on public released NuGet packages and are thus more stable than the development samples. 10 | 11 | * [WPF](https://github.com/PrismLibrary/Prism-Samples-Wpf) 12 | * [Xamarin Forms](https://github.com/PrismLibrary/Prism-Samples-Forms) 13 | * [Windows 10 UWP](https://github.com/PrismLibrary/Prism-Samples-Windows) 14 | 15 | 16 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/Bootstraper.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | using Prism.Modularity; 3 | using Prism.Unity; 4 | using Microsoft.Practices.Unity; 5 | 6 | namespace CommandBinderSample 7 | { 8 | internal class Bootstraper: UnityBootstrapper 9 | { 10 | protected override Form CreateShell() 11 | { 12 | return this.Container.Resolve(); 13 | } 14 | 15 | protected override void ConfigureModuleCatalog() 16 | { 17 | base.ConfigureModuleCatalog(); 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace CommandBinderSample 5 | { 6 | static class Program 7 | { 8 | [STAThread] 9 | static void Main() 10 | { 11 | Application.EnableVisualStyles(); 12 | Application.SetCompatibleTextRenderingDefault(false); 13 | 14 | Bootstraper b = new Bootstraper(); 15 | b.Run(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CommandBinderSample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CommandBinderSample")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9f00a1e3-eee5-4d1b-a74c-01b2f5879eb0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CommandBinderSample.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CommandBinderSample.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace CommandBinderSample.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/Shell.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace CommandBinderSample 2 | { 3 | partial class Shell 4 | { 5 | /// 6 | /// Variable del diseñador necesaria. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Limpiar los recursos que se estén usando. 12 | /// 13 | /// true si los recursos administrados se deben desechar; false en caso contrario. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Código generado por el Diseñador de Windows Forms 24 | 25 | /// 26 | /// Método necesario para admitir el Diseñador. No se puede modificar 27 | /// el contenido de este método con el editor de código. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.view1 = new CommandBinderSample.View(); 32 | this.SuspendLayout(); 33 | // 34 | // view1 35 | // 36 | this.view1.Dock = System.Windows.Forms.DockStyle.Fill; 37 | this.view1.Location = new System.Drawing.Point(0, 0); 38 | this.view1.Name = "view1"; 39 | this.view1.Size = new System.Drawing.Size(284, 262); 40 | this.view1.TabIndex = 0; 41 | // 42 | // Shell 43 | // 44 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 45 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 46 | this.ClientSize = new System.Drawing.Size(284, 262); 47 | this.Controls.Add(this.view1); 48 | this.Name = "Shell"; 49 | this.Text = "Shell"; 50 | this.ResumeLayout(false); 51 | 52 | } 53 | 54 | #endregion 55 | 56 | private View view1; 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/Shell.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | 3 | namespace CommandBinderSample 4 | { 5 | public partial class Shell : Form 6 | { 7 | public Shell() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/View.cs: -------------------------------------------------------------------------------- 1 | using Prism.Commands; 2 | using System.Windows.Forms; 3 | 4 | namespace CommandBinderSample 5 | { 6 | public partial class View : UserControl 7 | { 8 | CommandManager commandManager = new CommandManager(); 9 | ViewModel viewModel; 10 | 11 | public View() 12 | { 13 | InitializeComponent(); 14 | 15 | viewModel = new ViewModel(); 16 | 17 | statusLabel.DataBindings.Add("Text", viewModel, "Status"); 18 | 19 | commandManager.Bind(viewModel.Command1, toolStrip1); 20 | commandManager.Bind(viewModel.Command2, toolStrip2); 21 | 22 | commandManager.Bind(viewModel.Command1, button1); 23 | commandManager.Bind(viewModel.Command2, button2); 24 | 25 | checkBox1.CheckedChanged += (o, e) => viewModel.Command1Enabled = checkBox1.Checked; 26 | checkBox2.CheckedChanged += (o, e) => viewModel.Command2Enabled = checkBox2.Checked; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/ViewModel.cs: -------------------------------------------------------------------------------- 1 | using Prism.Commands; 2 | using Prism.Mvvm; 3 | 4 | namespace CommandBinderSample 5 | { 6 | internal class ViewModel : BindableBase 7 | { 8 | public DelegateCommand Command1 { get; private set; } 9 | public DelegateCommand Command2 { get; private set; } 10 | 11 | 12 | private string _status; 13 | public string Status 14 | { 15 | get { return _status; } 16 | set { SetProperty(ref _status, value); } 17 | } 18 | 19 | 20 | private bool _command1Enabled; 21 | public bool Command1Enabled 22 | { 23 | get { return _command1Enabled; } 24 | set { SetProperty(ref _command1Enabled, value); 25 | Command1.RaiseCanExecuteChanged(); 26 | } 27 | } 28 | 29 | private bool _command2Enabled; 30 | public bool Command2Enabled 31 | { 32 | get { return _command2Enabled; } 33 | set 34 | { 35 | SetProperty(ref _command2Enabled, value); 36 | Command2.RaiseCanExecuteChanged(); 37 | } 38 | } 39 | 40 | 41 | public ViewModel() 42 | { 43 | Command1 = new DelegateCommand(Write1, () => Command1Enabled); 44 | Command2 = new DelegateCommand(Write2, () => Command2Enabled); 45 | } 46 | 47 | private void Write1() 48 | { 49 | Status = "Command1 executed!!!"; 50 | } 51 | 52 | private void Write2() 53 | { 54 | Status = "Command2 executed!!!"; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sandbox/WinForms/CommandBinderSample/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HelloWorldModule/HelloWorldModule.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.Design; 2 | using Prism.Modularity; 3 | using Microsoft.Practices.Unity; 4 | namespace HelloWorldModule 5 | { 6 | public class HelloWorldModule : IModule 7 | { 8 | private readonly IUnityContainer _container; 9 | 10 | public HelloWorldModule(IUnityContainer container) 11 | { 12 | _container = container; 13 | } 14 | 15 | public void Initialize() 16 | { 17 | _container.RegisterType(); 18 | } 19 | } 20 | 21 | public interface IHelloService 22 | { 23 | string SayHello(); 24 | } 25 | 26 | public class HelloService : IHelloService 27 | { 28 | public string SayHello() 29 | { 30 | return "Hello"; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HelloWorldModule/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // La información general de un ensamblado se controla mediante el siguiente 6 | // conjunto de atributos. Cambie estos valores de atributo para modificar la información 7 | // asociada con un ensamblado. 8 | [assembly: AssemblyTitle("HelloWorldModule")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Esteban Espuña")] 12 | [assembly: AssemblyProduct("HelloWorldModule")] 13 | [assembly: AssemblyCopyright("Copyright © Esteban Espuña 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles 18 | // para los componentes COM. Si necesita obtener acceso a un tipo de este ensamblado desde 19 | // COM, establezca el atributo ComVisible en true en este tipo. 20 | [assembly: ComVisible(false)] 21 | 22 | // El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. 23 | [assembly: Guid("7e741828-4cfa-4c22-834e-1904e66d56e7")] 24 | 25 | // La información de versión de un ensamblado consta de los cuatro valores siguientes: 26 | // 27 | // Versión principal 28 | // Versión secundaria 29 | // Número de compilación 30 | // Revisión 31 | // 32 | // Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión 33 | // mediante el carácter '*', como se muestra a continuación: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HelloWorldModule/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/Bootstraper.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | using Prism.Modularity; 3 | using Prism.Unity; 4 | using Microsoft.Practices.Unity; 5 | 6 | namespace HeloWorldUnity 7 | { 8 | internal class Bootstraper: UnityBootstrapper 9 | { 10 | protected override Form CreateShell() 11 | { 12 | return this.Container.Resolve(); 13 | } 14 | 15 | protected override void ConfigureModuleCatalog() 16 | { 17 | base.ConfigureModuleCatalog(); 18 | 19 | ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog; 20 | moduleCatalog.AddModule(typeof(HelloWorldModule.HelloWorldModule)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace HeloWorldUnity 5 | { 6 | static class Program 7 | { 8 | [STAThread] 9 | static void Main() 10 | { 11 | Application.EnableVisualStyles(); 12 | Application.SetCompatibleTextRenderingDefault(false); 13 | 14 | Bootstraper b = new Bootstraper(); 15 | b.Run(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // La información general de un ensamblado se controla mediante el siguiente 6 | // conjunto de atributos. Cambie estos valores de atributo para modificar la información 7 | // asociada con un ensamblado. 8 | [assembly: AssemblyTitle("HeloWorldUnity")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Esteban Espuña")] 12 | [assembly: AssemblyProduct("HeloWorldUnity")] 13 | [assembly: AssemblyCopyright("Copyright © Esteban Espuña 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles 18 | // para los componentes COM. Si necesita obtener acceso a un tipo de este ensamblado desde 19 | // COM, establezca el atributo ComVisible en true en este tipo. 20 | [assembly: ComVisible(false)] 21 | 22 | // El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. 23 | [assembly: Guid("5eddd609-ce60-497c-9656-6e9761612a33")] 24 | 25 | // La información de versión de un ensamblado consta de los cuatro valores siguientes: 26 | // 27 | // Versión principal 28 | // Versión secundaria 29 | // Número de compilación 30 | // Revisión 31 | // 32 | // Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión 33 | // mediante el carácter '*', como se muestra a continuación: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Este código fue generado por una herramienta. 4 | // Versión de runtime: 4.0.30319.42000 5 | // 6 | // Los cambios de este archivo pueden provocar un comportamiento inesperado y se perderán si 7 | // el código se vuelve a generar. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace HeloWorldUnity.Properties 12 | { 13 | 14 | 15 | /// 16 | /// Clase de recurso fuertemente tipado para buscar cadenas traducidas, etc. 17 | /// 18 | // StronglyTypedResourceBuilder generó automáticamente esta clase 19 | // a través de una herramienta como ResGen o Visual Studio. 20 | // Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen 21 | // con la opción /str o recompile su proyecto de VS. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Devuelve la instancia ResourceManager almacenada en caché utilizada por esta clase. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HeloWorldUnity.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Invalida la propiedad CurrentUICulture del subproceso actual para todas las 56 | /// búsquedas de recursos usando esta clase de recursos fuertemente tipados. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace HeloWorldUnity.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/Shell.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace HeloWorldUnity 2 | { 3 | partial class Shell 4 | { 5 | /// 6 | /// Variable del diseñador necesaria. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Limpiar los recursos que se estén usando. 12 | /// 13 | /// true si los recursos administrados se deben desechar; false en caso contrario. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Código generado por el Diseñador de Windows Forms 24 | 25 | /// 26 | /// Método necesario para admitir el Diseñador. No se puede modificar 27 | /// el contenido de este método con el editor de código. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.HelloLabel = new System.Windows.Forms.Label(); 32 | this.SuspendLayout(); 33 | // 34 | // HelloLabel 35 | // 36 | this.HelloLabel.Dock = System.Windows.Forms.DockStyle.Fill; 37 | this.HelloLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 38 | this.HelloLabel.Location = new System.Drawing.Point(0, 0); 39 | this.HelloLabel.Name = "HelloLabel"; 40 | this.HelloLabel.Size = new System.Drawing.Size(284, 262); 41 | this.HelloLabel.TabIndex = 0; 42 | this.HelloLabel.Text = "This label shoud say hello"; 43 | this.HelloLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 44 | // 45 | // Shell 46 | // 47 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 48 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 49 | this.ClientSize = new System.Drawing.Size(284, 262); 50 | this.Controls.Add(this.HelloLabel); 51 | this.Name = "Shell"; 52 | this.Text = "Shell"; 53 | this.ResumeLayout(false); 54 | 55 | } 56 | 57 | #endregion 58 | 59 | private System.Windows.Forms.Label HelloLabel; 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/Shell.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using HelloWorldModule; 4 | using Microsoft.Practices.Unity; 5 | 6 | namespace HeloWorldUnity 7 | { 8 | public partial class Shell : Form 9 | { 10 | public Shell() 11 | { 12 | InitializeComponent(); 13 | this.Load += Shell_Load; 14 | } 15 | 16 | [Dependency] 17 | public IHelloService HelloService { get; set; } 18 | 19 | private void Shell_Load(object sender, EventArgs e) 20 | { 21 | this.HelloLabel.Text = HelloService.SayHello(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sandbox/WinForms/Hello World/HeloWorldUnity/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Events/BackgroundEventSubscriptionFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using Xunit; 4 | using Prism.Events; 5 | 6 | namespace Prism.Tests.Events 7 | { 8 | public class BackgroundEventSubscriptionFixture 9 | { 10 | [Fact] 11 | public void ShouldReceiveDelegateOnDifferentThread() 12 | { 13 | ManualResetEvent completeEvent = new ManualResetEvent(false); 14 | SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); 15 | SynchronizationContext calledSyncContext = null; 16 | Action action = delegate 17 | { 18 | calledSyncContext = SynchronizationContext.Current; 19 | completeEvent.Set(); 20 | }; 21 | 22 | IDelegateReference actionDelegateReference = new MockDelegateReference() { Target = action }; 23 | IDelegateReference filterDelegateReference = new MockDelegateReference() { Target = (Predicate)delegate { return true; } }; 24 | 25 | var eventSubscription = new BackgroundEventSubscription(actionDelegateReference, filterDelegateReference); 26 | 27 | 28 | var publishAction = eventSubscription.GetExecutionStrategy(); 29 | 30 | Assert.NotNull(publishAction); 31 | 32 | publishAction.Invoke(null); 33 | 34 | completeEvent.WaitOne(5000); 35 | 36 | Assert.NotEqual(SynchronizationContext.Current, calledSyncContext); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Events/DataEventArgsFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Xunit; 3 | using Prism.Events; 4 | 5 | namespace Prism.Tests.Events 6 | { 7 | public class DataEventArgsFixture 8 | { 9 | [Fact] 10 | public void CanPassData() 11 | { 12 | DataEventArgs e = new DataEventArgs(32); 13 | Assert.Equal(32, e.Value); 14 | } 15 | 16 | [Fact] 17 | public void IsEventArgs() 18 | { 19 | DataEventArgs dea = new DataEventArgs(""); 20 | EventArgs ea = dea as EventArgs; 21 | Assert.NotNull(ea); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Source/Prism.Tests/Events/DispatcherEventSubscriptionFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using Xunit; 4 | using Prism.Events; 5 | 6 | namespace Prism.Tests.Events 7 | { 8 | public class DispatcherEventSubscriptionFixture 9 | { 10 | [Fact] 11 | public void ShouldCallInvokeOnDispatcher() 12 | { 13 | DispatcherEventSubscription eventSubscription = null; 14 | 15 | IDelegateReference actionDelegateReference = new MockDelegateReference() 16 | { 17 | Target = (Action)(arg => 18 | { 19 | return; 20 | }) 21 | }; 22 | 23 | IDelegateReference filterDelegateReference = new MockDelegateReference 24 | { 25 | Target = (Predicate)(arg => true) 26 | }; 27 | var mockSyncContext = new MockSynchronizationContext(); 28 | 29 | eventSubscription = new DispatcherEventSubscription(actionDelegateReference, filterDelegateReference, mockSyncContext); 30 | 31 | eventSubscription.GetExecutionStrategy().Invoke(new object[0]); 32 | 33 | Assert.True(mockSyncContext.InvokeCalled); 34 | } 35 | 36 | [Fact] 37 | public void ShouldPassParametersCorrectly() 38 | { 39 | IDelegateReference actionDelegateReference = new MockDelegateReference() 40 | { 41 | Target = 42 | (Action)(arg1 => 43 | { 44 | return; 45 | }) 46 | }; 47 | IDelegateReference filterDelegateReference = new MockDelegateReference 48 | { 49 | Target = (Predicate)(arg => true) 50 | }; 51 | 52 | var mockSyncContext = new MockSynchronizationContext(); 53 | 54 | DispatcherEventSubscription eventSubscription = new DispatcherEventSubscription(actionDelegateReference, filterDelegateReference, mockSyncContext); 55 | 56 | var executionStrategy = eventSubscription.GetExecutionStrategy(); 57 | Assert.NotNull(executionStrategy); 58 | 59 | object argument1 = new object(); 60 | 61 | executionStrategy.Invoke(new[] { argument1 }); 62 | 63 | Assert.Same(argument1, mockSyncContext.InvokeArg); 64 | } 65 | } 66 | 67 | internal class MockSynchronizationContext : SynchronizationContext 68 | { 69 | public bool InvokeCalled; 70 | public object InvokeArg; 71 | 72 | public override void Post(SendOrPostCallback d, object state) 73 | { 74 | InvokeCalled = true; 75 | InvokeArg = state; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Events/EventAggregatorFixture.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using Prism.Events; 3 | 4 | namespace Prism.Tests.Events 5 | { 6 | public class EventAggregatorFixture 7 | { 8 | [Fact] 9 | public void GetReturnsSingleInstancesOfSameEventType() 10 | { 11 | var eventAggregator = new EventAggregator(); 12 | var instance1 = eventAggregator.GetEvent(); 13 | var instance2 = eventAggregator.GetEvent(); 14 | 15 | Assert.Same(instance2, instance1); 16 | } 17 | 18 | public class MockEventBase : EventBase { } 19 | } 20 | } -------------------------------------------------------------------------------- /Source/Prism.Tests/Events/MockDelegateReference.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | using System; 5 | using Prism.Events; 6 | 7 | namespace Prism.Tests.Events 8 | { 9 | class MockDelegateReference : IDelegateReference 10 | { 11 | public Delegate Target { get; set; } 12 | 13 | public MockDelegateReference() 14 | { 15 | 16 | } 17 | 18 | public MockDelegateReference(Delegate target) 19 | { 20 | Target = target; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Source/Prism.Tests/Logging/DebugLoggerFixture.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using Prism.Logging; 3 | 4 | namespace Prism.Tests.Logging 5 | { 6 | public class DebugLoggerFixture 7 | { 8 | [Fact] 9 | public void LogShouldNotFail() 10 | { 11 | ILoggerFacade logger = new DebugLogger(); 12 | logger.Log(null, Category.Debug, Priority.Medium); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Source/Prism.Tests/Logging/EmptyLoggerFixture.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using Prism.Logging; 3 | 4 | namespace Prism.Tests.Logging 5 | { 6 | public class EmptyLoggerFixture 7 | { 8 | [Fact] 9 | public void LogShouldNotFail() 10 | { 11 | ILoggerFacade logger = new EmptyLogger(); 12 | 13 | logger.Log(null, Category.Debug, Priority.Medium); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Source/Prism.Tests/Mocks/Commands/DelegateCommandMock.cs: -------------------------------------------------------------------------------- 1 | using Prism.Commands; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Prism.Tests.Mocks.Commands 9 | { 10 | public class DelegateCommandMock : DelegateCommandBase 11 | { 12 | public DelegateCommandMock(Action executeMethod) : 13 | base(executeMethod, (o) => true) 14 | { 15 | 16 | } 17 | 18 | public DelegateCommandMock(Action executeMethod, Func canExecuteMethod) : 19 | base(executeMethod, canExecuteMethod) 20 | { 21 | 22 | } 23 | 24 | public static DelegateCommandMock FromAsyncHandler(Func executeMethod) 25 | { 26 | return new DelegateCommandMock(executeMethod); 27 | } 28 | 29 | public static DelegateCommandMock FromAsyncHandler(Func executeMethod, Func canExecuteMethod) 30 | { 31 | return new DelegateCommandMock(executeMethod, canExecuteMethod); 32 | } 33 | 34 | private DelegateCommandMock(Func executeMethod) : 35 | base(executeMethod, (o) => true) 36 | { 37 | 38 | } 39 | 40 | private DelegateCommandMock(Func executeMethod, Func canExecuteMethod) : 41 | base(executeMethod, canExecuteMethod) 42 | { 43 | 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Mocks/ViewModels/MockValidatingViewModel.cs: -------------------------------------------------------------------------------- 1 | using Prism.Mvvm; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Prism.Tests.Mocks.ViewModels 10 | { 11 | public class MockValidatingViewModel : BindableBase, INotifyDataErrorInfo 12 | { 13 | ErrorsContainer _errorsContainer; 14 | 15 | private int mockProperty; 16 | public int MockProperty 17 | { 18 | get 19 | { 20 | return this.mockProperty; 21 | } 22 | 23 | set 24 | { 25 | this.SetProperty(ref mockProperty, value); 26 | 27 | if (mockProperty < 0) 28 | _errorsContainer.SetErrors(() => MockProperty, new string[] { "value cannot be less than 0" }); 29 | } 30 | } 31 | 32 | internal void ClearMockPropertyErrors() 33 | { 34 | _errorsContainer.ClearErrors(() => MockProperty); 35 | } 36 | 37 | internal void SetMockPropertyErrorsWithNullCollection() 38 | { 39 | _errorsContainer.SetErrors(() => MockProperty, null); 40 | } 41 | 42 | public MockValidatingViewModel() 43 | { 44 | _errorsContainer = new ErrorsContainer(OnErrorsChanged); 45 | } 46 | 47 | public event System.EventHandler ErrorsChanged; 48 | public void OnErrorsChanged(string propertyName) 49 | { 50 | var handler = ErrorsChanged; 51 | } 52 | 53 | public System.Collections.IEnumerable GetErrors(string propertyName) 54 | { 55 | return _errorsContainer.GetErrors(propertyName); 56 | } 57 | 58 | public bool HasErrors 59 | { 60 | get { return _errorsContainer.HasErrors; } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Mocks/ViewModels/MockViewModel.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Mvvm; 4 | using System.ComponentModel; 5 | 6 | namespace Prism.Tests.Mocks.ViewModels 7 | { 8 | public class MockViewModel : BindableBase 9 | { 10 | private int mockProperty; 11 | 12 | public int MockProperty 13 | { 14 | get 15 | { 16 | return this.mockProperty; 17 | } 18 | 19 | set 20 | { 21 | this.SetProperty(ref mockProperty, value); 22 | } 23 | } 24 | 25 | internal void InvokeOnPropertyChanged() 26 | { 27 | this.OnPropertyChanged(() => this.MockProperty); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Mocks/Views/Mock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Prism.Tests.Mocks.Views 8 | { 9 | public class Mock 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Mocks/Views/MockView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Prism.Tests.Mocks.Views 8 | { 9 | public class MockView 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Mvvm/BindableBaseFixture.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using Prism.Tests.Mocks.ViewModels; 3 | 4 | namespace Prism.Tests.Mvvm 5 | { 6 | public class BindableBaseFixture 7 | { 8 | [Fact] 9 | public void SetPropertyMethodShouldSetTheNewValue() 10 | { 11 | int value = 10; 12 | MockViewModel mockViewModel = new MockViewModel(); 13 | 14 | Assert.Equal(mockViewModel.MockProperty, 0); 15 | 16 | mockViewModel.MockProperty = value; 17 | Assert.Equal(mockViewModel.MockProperty, value); 18 | } 19 | 20 | [Fact] 21 | public void SetPropertyMethodShouldNotSetTheNewValue() 22 | { 23 | int value = 10; 24 | MockViewModel mockViewModel = new MockViewModel(); 25 | mockViewModel.MockProperty = 10; 26 | 27 | bool invoked = false; 28 | mockViewModel.PropertyChanged += (o, e) => { if (e.PropertyName.Equals("MockProperty")) invoked = true; }; 29 | mockViewModel.MockProperty = value; 30 | 31 | Assert.False(invoked); 32 | Assert.Equal(mockViewModel.MockProperty, value); 33 | } 34 | 35 | [Fact] 36 | public void SetPropertyMethodShouldRaisePropertyRaised() 37 | { 38 | bool invoked = false; 39 | MockViewModel mockViewModel = new MockViewModel(); 40 | 41 | mockViewModel.PropertyChanged += (o, e) => { if (e.PropertyName.Equals("MockProperty")) invoked = true; }; 42 | mockViewModel.MockProperty = 10; 43 | 44 | Assert.True(invoked); 45 | } 46 | 47 | [Fact] 48 | public void OnPropertyChangedShouldExtractPropertyNameCorrectly() 49 | { 50 | bool invoked = false; 51 | MockViewModel mockViewModel = new MockViewModel(); 52 | 53 | mockViewModel.PropertyChanged += (o, e) => { if (e.PropertyName.Equals("MockProperty")) invoked = true; }; 54 | mockViewModel.InvokeOnPropertyChanged(); 55 | 56 | Assert.True(invoked); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Mvvm/PropertySupportFixture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Prism.Mvvm; 3 | using Xunit; 4 | 5 | namespace Prism.Tests.Mvvm 6 | { 7 | public class PropertySupportFixture 8 | { 9 | [Fact] 10 | public virtual void WhenExtractingNameFromAValidPropertyExpression_ThenPropertyNameReturned() 11 | { 12 | var propertyName = PropertySupport.ExtractPropertyName(() => this.InstanceProperty); 13 | Assert.Equal("InstanceProperty", propertyName); 14 | } 15 | 16 | [Fact] 17 | public void WhenExpressionRepresentsAStaticProperty_ThenExceptionThrown() 18 | { 19 | Assert.Throws(() => PropertySupport.ExtractPropertyName(() => StaticProperty)); 20 | } 21 | 22 | [Fact] 23 | public void WhenExpressionIsNull_ThenAnExceptionIsThrown() 24 | { 25 | Assert.Throws(() => PropertySupport.ExtractPropertyName(null)); 26 | } 27 | 28 | [Fact] 29 | public void WhenExpressionRepresentsANonMemberAccessExpression_ThenAnExceptionIsThrown() 30 | { 31 | Assert.Throws(() => PropertySupport.ExtractPropertyName(() => GetHashCode())); 32 | } 33 | 34 | [Fact] 35 | public void WhenExpressionRepresentsANonPropertyMemberAccessExpression_ThenAnExceptionIsThrown() 36 | { 37 | Assert.Throws(() => PropertySupport.ExtractPropertyName(() => InstanceField)); 38 | } 39 | 40 | public static int StaticProperty { get; set; } 41 | public int InstanceProperty { get; set; } 42 | public int InstanceField; 43 | public static int SetOnlyStaticProperty { set { } } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/Prism.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Prism.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Prism.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a95cb7df-f667-44c7-9cac-750ba459a15d")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/Prism.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Source/Prism/Events/BackgroundEventSubscription.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | using System.Threading; 5 | using System; 6 | using System.Threading.Tasks; 7 | 8 | namespace Prism.Events 9 | { 10 | /// 11 | /// Extends to invoke the delegate in a background thread. 12 | /// 13 | /// The type to use for the generic and types. 14 | public class BackgroundEventSubscription : EventSubscription 15 | { 16 | /// 17 | /// Creates a new instance of . 18 | /// 19 | /// A reference to a delegate of type . 20 | /// A reference to a delegate of type . 21 | /// When or are . 22 | /// When the target of is not of type , 23 | /// or the target of is not of type . 24 | public BackgroundEventSubscription(IDelegateReference actionReference, IDelegateReference filterReference) 25 | : base(actionReference, filterReference) 26 | { 27 | } 28 | 29 | /// 30 | /// Invokes the specified in an asynchronous thread by using a . 31 | /// 32 | /// The action to execute. 33 | /// The payload to pass while invoking it. 34 | public override void InvokeAction(Action action, TPayload argument) 35 | { 36 | //ThreadPool.QueueUserWorkItem( (o) => action(argument) ); 37 | Task.Run(() => action(argument)); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Source/Prism/Events/DataEventArgs.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | using System; 5 | 6 | namespace Prism.Events 7 | { 8 | /// 9 | /// Generic arguments class to pass to event handlers that need to receive data. 10 | /// 11 | /// The type of data to pass. 12 | public class DataEventArgs : EventArgs 13 | { 14 | private readonly TData _value; 15 | 16 | /// 17 | /// Initializes the DataEventArgs class. 18 | /// 19 | /// Information related to the event. 20 | public DataEventArgs(TData value) 21 | { 22 | _value = value; 23 | } 24 | 25 | /// 26 | /// Gets the information related to the event. 27 | /// 28 | /// Information related to the event. 29 | public TData Value 30 | { 31 | get { return _value; } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Source/Prism/Events/DelegateReference.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | using System; 5 | using System.Reflection; 6 | 7 | namespace Prism.Events 8 | { 9 | /// 10 | /// Represents a reference to a that may contain a 11 | /// to the target. This class is used 12 | /// internally by the Prism Library. 13 | /// 14 | public class DelegateReference : IDelegateReference 15 | { 16 | private readonly Delegate _delegate; 17 | private readonly WeakReference _weakReference; 18 | private readonly MethodInfo _method; 19 | private readonly Type _delegateType; 20 | 21 | /// 22 | /// Initializes a new instance of . 23 | /// 24 | /// The original to create a reference for. 25 | /// If the class will create a weak reference to the delegate, allowing it to be garbage collected. Otherwise it will keep a strong reference to the target. 26 | /// If the passed is not assignable to . 27 | public DelegateReference(Delegate @delegate, bool keepReferenceAlive) 28 | { 29 | if (@delegate == null) 30 | throw new ArgumentNullException("delegate"); 31 | 32 | if (keepReferenceAlive) 33 | { 34 | this._delegate = @delegate; 35 | } 36 | else 37 | { 38 | _weakReference = new WeakReference(@delegate.Target); 39 | _method = @delegate.GetMethodInfo(); 40 | _delegateType = @delegate.GetType(); 41 | } 42 | } 43 | 44 | /// 45 | /// Gets the (the target) referenced by the current object. 46 | /// 47 | /// if the object referenced by the current object has been garbage collected; otherwise, a reference to the referenced by the current object. 48 | public Delegate Target 49 | { 50 | get 51 | { 52 | if (_delegate != null) 53 | { 54 | return _delegate; 55 | } 56 | else 57 | { 58 | return TryGetDelegate(); 59 | } 60 | } 61 | } 62 | 63 | private Delegate TryGetDelegate() 64 | { 65 | if (_method.IsStatic) 66 | { 67 | return _method.CreateDelegate(_delegateType, null); 68 | } 69 | object target = _weakReference.Target; 70 | if (target != null) 71 | { 72 | return _method.CreateDelegate(_delegateType, target); 73 | } 74 | return null; 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Source/Prism/Events/DispatcherEventSubscription.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | using System; 5 | using System.Threading; 6 | 7 | namespace Prism.Events 8 | { 9 | /// 10 | /// Extends to invoke the delegate 11 | /// in a specific . 12 | /// 13 | /// The type to use for the generic and types. 14 | public class DispatcherEventSubscription : EventSubscription 15 | { 16 | private readonly SynchronizationContext syncContext; 17 | 18 | /// 19 | /// Creates a new instance of . 20 | /// 21 | ///A reference to a delegate of type . 22 | ///A reference to a delegate of type . 23 | ///The synchronization context to use for UI thread dispatching. 24 | ///When or are . 25 | ///When the target of is not of type , 26 | ///or the target of is not of type . 27 | public DispatcherEventSubscription(IDelegateReference actionReference, IDelegateReference filterReference, SynchronizationContext context) 28 | : base(actionReference, filterReference) 29 | { 30 | syncContext = context; 31 | } 32 | 33 | /// 34 | /// Invokes the specified asynchronously in the specified . 35 | /// 36 | /// The action to execute. 37 | /// The payload to pass while invoking it. 38 | public override void InvokeAction(Action action, TPayload argument) 39 | { 40 | syncContext.Post((o) => action((TPayload)o), argument); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Source/Prism/Events/EventAggregator.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Threading; 6 | 7 | namespace Prism.Events 8 | { 9 | /// 10 | /// Implements . 11 | /// 12 | public class EventAggregator : IEventAggregator 13 | { 14 | private readonly Dictionary events = new Dictionary(); 15 | // Captures the sync context for the UI thread when constructed on the UI thread 16 | // in a platform agnositc way so it can be used for UI thread dispatching 17 | private readonly SynchronizationContext syncContext = SynchronizationContext.Current; 18 | 19 | /// 20 | /// Gets the single instance of the event managed by this EventAggregator. Multiple calls to this method with the same returns the same event instance. 21 | /// 22 | /// The type of event to get. This must inherit from . 23 | /// A singleton instance of an event object of type . 24 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] 25 | public TEventType GetEvent() where TEventType : EventBase, new() 26 | { 27 | lock (events) 28 | { 29 | EventBase existingEvent = null; 30 | 31 | if (!events.TryGetValue(typeof(TEventType), out existingEvent)) 32 | { 33 | TEventType newEvent = new TEventType(); 34 | newEvent.SynchronizationContext = syncContext; 35 | events[typeof(TEventType)] = newEvent; 36 | 37 | return newEvent; 38 | } 39 | else 40 | { 41 | return (TEventType)existingEvent; 42 | } 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Source/Prism/Events/IDelegateReference.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | using System; 5 | 6 | namespace Prism.Events 7 | { 8 | /// 9 | /// Represents a reference to a . 10 | /// 11 | public interface IDelegateReference 12 | { 13 | /// 14 | /// Gets the referenced object. 15 | /// 16 | /// A instance if the target is valid; otherwise . 17 | Delegate Target { get; } 18 | } 19 | } -------------------------------------------------------------------------------- /Source/Prism/Events/IEventAggregator.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | namespace Prism.Events 6 | { 7 | /// 8 | /// Defines an interface to get instances of an event type. 9 | /// 10 | public interface IEventAggregator 11 | { 12 | /// 13 | /// Gets an instance of an event type. 14 | /// 15 | /// The type of event to get. 16 | /// An instance of an event object of type . 17 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] 18 | TEventType GetEvent() where TEventType : EventBase, new(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/Prism/Events/IEventSubscription.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | using System; 5 | 6 | namespace Prism.Events 7 | { 8 | /// 9 | /// Defines a contract for an event subscription to be used by . 10 | /// 11 | public interface IEventSubscription 12 | { 13 | /// 14 | /// Gets or sets a that identifies this . 15 | /// 16 | /// A token that identifies this . 17 | SubscriptionToken SubscriptionToken { get; set; } 18 | 19 | /// 20 | /// Gets the execution strategy to publish this event. 21 | /// 22 | /// An with the execution strategy, or if the is no longer valid. 23 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] 24 | Action GetExecutionStrategy(); 25 | } 26 | } -------------------------------------------------------------------------------- /Source/Prism/Events/ThreadOption.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | namespace Prism.Events 6 | { 7 | /// 8 | /// Specifies on which thread a subscriber will be called. 9 | /// 10 | public enum ThreadOption 11 | { 12 | /// 13 | /// The call is done on the same thread on which the was published. 14 | /// 15 | PublisherThread, 16 | 17 | /// 18 | /// The call is done on the UI thread. 19 | /// 20 | UIThread, 21 | 22 | /// 23 | /// The call is done asynchronously on a background thread. 24 | /// 25 | BackgroundThread 26 | } 27 | } -------------------------------------------------------------------------------- /Source/Prism/IActiveAware.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Prism 4 | { 5 | /// 6 | /// Interface that defines if the object instance is active 7 | /// and notifies when the activity changes. 8 | /// 9 | public interface IActiveAware 10 | { 11 | /// 12 | /// Gets or sets a value indicating whether the object is active. 13 | /// 14 | /// if the object is active; otherwise . 15 | bool IsActive { get; set; } 16 | 17 | /// 18 | /// Notifies that the value for property has changed. 19 | /// 20 | event EventHandler IsActiveChanged; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/Prism/Logging/Category.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Prism.Logging 5 | { 6 | /// 7 | /// Defines values for the categories used by . 8 | /// 9 | public enum Category 10 | { 11 | /// 12 | /// Debug category. 13 | /// 14 | Debug, 15 | 16 | /// 17 | /// Exception category. 18 | /// 19 | Exception, 20 | 21 | /// 22 | /// Informational category. 23 | /// 24 | Info, 25 | 26 | /// 27 | /// Warning category. 28 | /// 29 | Warn 30 | } 31 | } -------------------------------------------------------------------------------- /Source/Prism/Logging/DebugLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Globalization; 4 | using Prism.Properties; 5 | 6 | namespace Prism.Logging 7 | { 8 | /// 9 | /// Implementation of that logs into a message into the Debug.Listeners collection. 10 | /// 11 | public class DebugLogger : ILoggerFacade 12 | { 13 | /// 14 | /// Write a new log entry with the specified category and priority. 15 | /// 16 | /// Message body to log. 17 | /// Category of the entry. 18 | /// The priority of the entry. 19 | public void Log(string message, Category category, Priority priority) 20 | { 21 | string messageToLog = String.Format(CultureInfo.InvariantCulture, Resources.DefaultDebugLoggerPattern, DateTime.Now, 22 | category.ToString().ToUpper(), message, priority); 23 | 24 | Debug.WriteLine(messageToLog); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Source/Prism/Logging/EmptyLogger.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Prism.Logging 5 | { 6 | /// 7 | /// Implementation of that does nothing. This 8 | /// implementation is useful when the application does not need logging 9 | /// but there are infrastructure pieces that assume there is a logger. 10 | /// 11 | public class EmptyLogger : ILoggerFacade 12 | { 13 | /// 14 | /// This method does nothing. 15 | /// 16 | /// Message body to log. 17 | /// Category of the entry. 18 | /// The priority of the entry. 19 | public void Log(string message, Category category, Priority priority) 20 | { 21 | 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Source/Prism/Logging/ILoggerFacade.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Prism.Logging 5 | { 6 | /// 7 | /// Defines a simple logger façade to be used by the Prism Library. 8 | /// 9 | public interface ILoggerFacade 10 | { 11 | /// 12 | /// Write a new log entry with the specified category and priority. 13 | /// 14 | /// Message body to log. 15 | /// Category of the entry. 16 | /// The priority of the entry. 17 | void Log(string message, Category category, Priority priority); 18 | } 19 | } -------------------------------------------------------------------------------- /Source/Prism/Logging/Priority.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Prism.Logging 5 | { 6 | /// 7 | /// Defines values for the priorities used by . 8 | /// 9 | public enum Priority 10 | { 11 | /// 12 | /// No priority specified. 13 | /// 14 | None = 0, 15 | 16 | /// 17 | /// High priority entry. 18 | /// 19 | High = 1, 20 | 21 | /// 22 | /// Medium priority entry. 23 | /// 24 | Medium, 25 | 26 | /// 27 | /// Low priority entry. 28 | /// 29 | Low 30 | } 31 | } -------------------------------------------------------------------------------- /Source/Prism/Mvvm/BindableBase.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.ComponentModel; 5 | using System.Linq.Expressions; 6 | using System.Runtime.CompilerServices; 7 | 8 | namespace Prism.Mvvm 9 | { 10 | /// 11 | /// Implementation of to simplify models. 12 | /// 13 | public abstract class BindableBase : INotifyPropertyChanged 14 | { 15 | /// 16 | /// Occurs when a property value changes. 17 | /// 18 | public event PropertyChangedEventHandler PropertyChanged; 19 | 20 | /// 21 | /// Checks if a property already matches a desired value. Sets the property and 22 | /// notifies listeners only when necessary. 23 | /// 24 | /// Type of the property. 25 | /// Reference to a property with both getter and setter. 26 | /// Desired value for the property. 27 | /// Name of the property used to notify listeners. This 28 | /// value is optional and can be provided automatically when invoked from compilers that 29 | /// support CallerMemberName. 30 | /// True if the value was changed, false if the existing value matched the 31 | /// desired value. 32 | protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null) 33 | { 34 | if (object.Equals(storage, value)) return false; 35 | 36 | storage = value; 37 | this.OnPropertyChanged(propertyName); 38 | 39 | return true; 40 | } 41 | 42 | /// 43 | /// Notifies listeners that a property value has changed. 44 | /// 45 | /// Name of the property used to notify listeners. This 46 | /// value is optional and can be provided automatically when invoked from compilers 47 | /// that support . 48 | protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null) 49 | { 50 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 51 | } 52 | 53 | /// 54 | /// Raises this object's PropertyChanged event. 55 | /// 56 | /// The type of the property that has a new value 57 | /// A Lambda expression representing the property that has a new value. 58 | protected virtual void OnPropertyChanged(Expression> propertyExpression) 59 | { 60 | var propertyName = PropertySupport.ExtractPropertyName(propertyExpression); 61 | this.OnPropertyChanged(propertyName); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Source/Prism/Mvvm/PropertySupport.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Linq.Expressions; 5 | using System.Reflection; 6 | using Prism.Properties; 7 | 8 | namespace Prism.Mvvm 9 | { 10 | /// 11 | /// Provides support for extracting property information based on a property expression. 12 | /// 13 | public static class PropertySupport 14 | { 15 | /// 16 | /// Extracts the property name from a property expression. 17 | /// 18 | /// The object type containing the property specified in the expression. 19 | /// The property expression (e.g. p => p.PropertyName) 20 | /// The name of the property. 21 | /// Thrown if the is null. 22 | /// Thrown when the expression is:
23 | /// Not a
24 | /// The does not represent a property.
25 | /// Or, the property is static. 26 | ///
27 | public static string ExtractPropertyName(Expression> propertyExpression) 28 | { 29 | if (propertyExpression == null) 30 | throw new ArgumentNullException("propertyExpression"); 31 | 32 | return ExtractPropertyNameFromLambda(propertyExpression); 33 | } 34 | 35 | /// 36 | /// Extracts the property name from a LambdaExpression. 37 | /// 38 | /// The LambdaExpression 39 | /// The name of the property. 40 | /// Thrown if the is null. 41 | /// Thrown when the expression is:
42 | /// The does not represent a property.
43 | /// Or, the property is static. 44 | ///
45 | internal static string ExtractPropertyNameFromLambda(LambdaExpression expression) 46 | { 47 | if (expression == null) 48 | throw new ArgumentNullException("expression"); 49 | 50 | var memberExpression = expression.Body as MemberExpression; 51 | if (memberExpression == null) 52 | throw new ArgumentException(Resources.PropertySupport_NotMemberAccessExpression_Exception, "expression"); 53 | 54 | var property = memberExpression.Member as PropertyInfo; 55 | if (property == null) 56 | throw new ArgumentException(Resources.PropertySupport_ExpressionNotProperty_Exception, "expression"); 57 | 58 | var getMethod = property.GetMethod; 59 | if (getMethod.IsStatic) 60 | throw new ArgumentException(Resources.PropertySupport_StaticExpression_Exception, "expression"); 61 | 62 | return memberExpression.Member.Name; 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Source/Prism/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Resources; 3 | using System.Reflection; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Prism")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Prism")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | [assembly: NeutralResourcesLanguage("en")] 17 | [assembly: CLSCompliant(true)] 18 | 19 | [assembly: AssemblyVersion("6.1")] 20 | [assembly: AssemblyFileVersion("6.1.0")] 21 | [assembly: AssemblyInformationalVersion("6.1")] 22 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.Unity.WinForms/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | // This file is used by Code Analysis to maintain SuppressMessage 4 | // attributes that are applied to this project. 5 | // Project-level suppressions either have no target or are given 6 | // a specific target and scoped to a namespace, type, member, etc. 7 | // 8 | // To add a suppression to this file, right-click the message in the 9 | // Error List, point to "Suppress Message(s)", and click 10 | // "In Project Suppression File". 11 | // You do not need to add suppressions to this file manually. 12 | 13 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames")] 14 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "Microsoft.Practices.Prism.UnityExtensions")] 15 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Practices.Prism.UnityExtensions.UnityBootstrapper.#RegisterTypeIfMissing(System.Type,System.Type,System.Boolean)")] 16 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.Unity.WinForms/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyTitle("Prism.Unity.WinForms")] 5 | [assembly: AssemblyDescription("")] 6 | [assembly: AssemblyConfiguration("")] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("Prism.Unity.WinForms")] 9 | [assembly: AssemblyCopyright("Copyright © 2015")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: ComVisible(false)] 14 | 15 | [assembly: Guid("55f29d50-841b-4d6c-8210-a0ed06ca0c40")] 16 | 17 | [assembly: AssemblyVersion("1.0.0.1")] 18 | [assembly: AssemblyFileVersion("1.0.0.1")] 19 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.Unity.WinForms/Regions/UnityRegionNavigationContentLoader.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Regions; 4 | using Microsoft.Practices.ServiceLocation; 5 | using Microsoft.Practices.Unity; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace Prism.Unity.Regions 13 | { 14 | /// 15 | /// Specialization of the default RegionNavigationContentLoader that queries the corresponding 16 | /// to obtain the name of the view's type registered for the contract name. 17 | /// 18 | public class UnityRegionNavigationContentLoader : RegionNavigationContentLoader 19 | { 20 | private IUnityContainer container; 21 | 22 | /// 23 | /// Initializes a new instance of the class. 24 | /// 25 | /// used to create the instance of the view from its . 26 | /// where the views are registered. 27 | public UnityRegionNavigationContentLoader(IServiceLocator serviceLocator, IUnityContainer container) 28 | : base(serviceLocator) 29 | { 30 | this.container = container; 31 | } 32 | 33 | /// 34 | /// Returns the set of candidates that may satisfiy this navigation request. 35 | /// 36 | /// The region containing items that may satisfy the navigation request. 37 | /// The candidate navigation target. 38 | /// An enumerable of candidate objects from the 39 | protected override IEnumerable GetCandidatesFromRegion(IRegion region, string candidateNavigationContract) 40 | { 41 | if (candidateNavigationContract == null || candidateNavigationContract.Equals(string.Empty)) 42 | throw new ArgumentNullException("candidateNavigationContract"); 43 | 44 | IEnumerable contractCandidates = base.GetCandidatesFromRegion(region, candidateNavigationContract); 45 | 46 | if (!contractCandidates.Any()) 47 | { 48 | //First try friendly name registration. If not found, try type registration 49 | var matchingRegistration = this.container.Registrations.Where(r => candidateNavigationContract.Equals(r.Name, StringComparison.Ordinal)).FirstOrDefault(); 50 | if (matchingRegistration == null) 51 | { 52 | matchingRegistration = this.container.Registrations.Where(r => candidateNavigationContract.Equals(r.RegisteredType.Name, StringComparison.Ordinal)).FirstOrDefault(); 53 | } 54 | if (matchingRegistration == null) return new object[0]; 55 | 56 | string typeCandidateName = matchingRegistration.MappedToType.FullName; 57 | 58 | contractCandidates = base.GetCandidatesFromRegion(region, typeCandidateName); 59 | } 60 | 61 | return contractCandidates; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.Unity.WinForms/UnityBootstrapperExtension.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using Microsoft.Practices.ObjectBuilder2; 5 | using Microsoft.Practices.Unity; 6 | 7 | namespace Prism.Unity 8 | { 9 | /// 10 | /// Implements a that checks if a specific type was registered with the container. 11 | /// 12 | public class UnityBootstrapperExtension : UnityContainerExtension 13 | { 14 | /// 15 | /// Evaluates if a specified type was registered in the container. 16 | /// 17 | /// The container to check if the type was registered in. 18 | /// The type to check if it was registered. 19 | /// if the was registered with the container. 20 | /// 21 | /// In order to use this extension, you must first call 22 | /// and specify as the extension type. 23 | /// 24 | public static bool IsTypeRegistered(IUnityContainer container, Type type) 25 | { 26 | UnityBootstrapperExtension extension = container.Configure(); 27 | if (extension == null) 28 | { 29 | //Extension was not added to the container. 30 | return false; 31 | } 32 | IBuildKeyMappingPolicy policy = extension.Context.Policies.Get(new NamedTypeBuildKey(type)); 33 | return policy != null; 34 | } 35 | 36 | /// 37 | ///Initializes the container with this extension's functionality. 38 | /// 39 | protected override void Initialize() 40 | { 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.Unity.WinForms/UnityContainerHelper.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using Microsoft.Practices.Unity; 5 | 6 | namespace Prism.Unity 7 | { 8 | /// 9 | /// Extensions methods to extend and facilitate the usage of . 10 | /// 11 | public static class UnityContainerHelper 12 | { 13 | /// 14 | /// Returns whether a specified type has a type mapping registered in the container. 15 | /// 16 | /// The to check for the type mapping. 17 | /// The type to check if there is a type mapping for. 18 | /// if there is a type mapping registered for . 19 | /// In order to use this extension method, you first need to add the 20 | /// extension to the . 21 | /// 22 | public static bool IsTypeRegistered(this IUnityContainer container, Type type) 23 | { 24 | return UnityBootstrapperExtension.IsTypeRegistered(container, type); 25 | } 26 | 27 | /// 28 | /// Utility method to try to resolve a service from the container avoiding an exception if the container cannot build the type. 29 | /// 30 | /// The cointainer that will be used to resolve the type. 31 | /// The type to resolve. 32 | /// The instance of built up by the container. 33 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")] 34 | public static T TryResolve(this IUnityContainer container) 35 | { 36 | object result = TryResolve(container, typeof(T)); 37 | if (result != null) 38 | { 39 | return (T)result; 40 | } 41 | return default(T); 42 | } 43 | 44 | /// 45 | /// Utility method to try to resolve a service from the container avoiding an exception if the container cannot build the type. 46 | /// 47 | /// The cointainer that will be used to resolve the type. 48 | /// The type to resolve. 49 | /// The instance of built up by the container. 50 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")] 51 | public static object TryResolve(this IUnityContainer container, Type typeToResolve) 52 | { 53 | try 54 | { 55 | return container.Resolve(typeToResolve); 56 | } 57 | catch 58 | { 59 | return null; 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.Unity.WinForms/UnityExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Practices.Unity; 2 | using System; 3 | 4 | namespace Prism.Unity 5 | { 6 | public static class UnityExtensions 7 | { 8 | /// 9 | /// Registers an object for navigation. 10 | /// 11 | /// The Type of the object to register 12 | /// The unique name to register with the object. 13 | public static void RegisterTypeForNavigation(this IUnityContainer container, string name = null) 14 | { 15 | Type type = typeof(T); 16 | string viewName = string.IsNullOrWhiteSpace(name) ? type.Name : name; 17 | container.RegisterType(typeof(object), type, viewName); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.Unity.WinForms/UnityServiceLocatorAdapter.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Microsoft.Practices.ServiceLocation; 6 | using Microsoft.Practices.Unity; 7 | 8 | namespace Prism.Unity 9 | { 10 | /// 11 | /// Defines a adapter for the interface to be used by the Prism Library. 12 | /// 13 | public class UnityServiceLocatorAdapter : ServiceLocatorImplBase 14 | { 15 | private readonly IUnityContainer _unityContainer; 16 | 17 | /// 18 | /// Initializes a new instance of . 19 | /// 20 | /// The that will be used 21 | /// by the and methods. 22 | public UnityServiceLocatorAdapter(IUnityContainer unityContainer) 23 | { 24 | _unityContainer = unityContainer; 25 | } 26 | 27 | /// 28 | /// Resolves the instance of the requested service. 29 | /// 30 | /// Type of instance requested. 31 | /// Name of registered service you want. May be null. 32 | /// The requested service instance. 33 | protected override object DoGetInstance(Type serviceType, string key) 34 | { 35 | return _unityContainer.Resolve(serviceType, key); 36 | } 37 | 38 | /// 39 | /// Resolves all the instances of the requested service. 40 | /// 41 | /// Type of service requested. 42 | /// Sequence of service instance objects. 43 | protected override IEnumerable DoGetAllInstances(Type serviceType) 44 | { 45 | return _unityContainer.ResolveAll(serviceType); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.Unity.WinForms/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 |
5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/CollectionChangedTracker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Specialized; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Prism.WinForms.Tests 9 | { 10 | public class CollectionChangedTracker 11 | { 12 | private readonly List eventList = new List(); 13 | 14 | public CollectionChangedTracker(INotifyCollectionChanged collection) 15 | { 16 | collection.CollectionChanged += OnCollectionChanged; 17 | } 18 | 19 | public IEnumerable ActionsFired { get { return this.eventList.Select(e => e.Action); } } 20 | public IEnumerable NotifyEvents { get { return this.eventList; } } 21 | 22 | private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 23 | { 24 | this.eventList.Add(e); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/CollectionExtensionsFixture.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections.Generic; 4 | using System.Collections.ObjectModel; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | 7 | namespace Prism.WinForms.Tests 8 | { 9 | [TestClass] 10 | public class CollectionExtensionsFixture 11 | { 12 | [TestMethod] 13 | public void CanAddRangeToCollection() 14 | { 15 | Collection col = new Collection(); 16 | List itemsToAdd = new List{"1", "2"}; 17 | 18 | col.AddRange(itemsToAdd); 19 | 20 | Assert.AreEqual(2, col.Count); 21 | Assert.AreEqual("1", col[0]); 22 | Assert.AreEqual("2", col[1]); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/ExceptionAssert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | 4 | namespace Prism.WinForms.Tests 5 | { 6 | public static class ExceptionAssert 7 | { 8 | public static void Throws(Action action) 9 | where TException : Exception 10 | { 11 | Throws(typeof(TException), action); 12 | } 13 | 14 | public static void Throws(Type expectedExceptionType, Action action) 15 | { 16 | try 17 | { 18 | action(); 19 | } 20 | catch (Exception ex) 21 | { 22 | Assert.IsInstanceOfType(ex, expectedExceptionType); 23 | return; 24 | } 25 | 26 | Assert.Fail("No exception thrown. Expected exception type of {0}.", expectedExceptionType.Name); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Logging/TextLoggerFixture.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.IO; 5 | using System.Text; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using Prism.Logging; 8 | 9 | namespace Prism.WinForms.Tests.Logging 10 | { 11 | [TestClass] 12 | public class TextLoggerFixture 13 | { 14 | [TestMethod] 15 | [ExpectedException(typeof(ArgumentNullException))] 16 | public void NullTextWriterThrows() 17 | { 18 | ILoggerFacade logger = new TextLogger(null); 19 | } 20 | 21 | [TestMethod] 22 | public void ShouldWriteToTextWriter() 23 | { 24 | TextWriter writer = new StringWriter(); 25 | ILoggerFacade logger = new TextLogger(writer); 26 | 27 | logger.Log("Test", Category.Debug, Priority.Low); 28 | StringAssert.Contains(writer.ToString(), "Test"); 29 | StringAssert.Contains(writer.ToString(), "DEBUG"); 30 | StringAssert.Contains(writer.ToString(), "Low"); 31 | } 32 | 33 | [TestMethod] 34 | public void ShouldDisposeWriterOnDispose() 35 | { 36 | MockWriter writer = new MockWriter(); 37 | IDisposable logger = new TextLogger(writer); 38 | 39 | Assert.IsFalse(writer.DisposeCalled); 40 | logger.Dispose(); 41 | Assert.IsTrue(writer.DisposeCalled); 42 | } 43 | } 44 | 45 | internal class MockWriter : TextWriter 46 | { 47 | public bool DisposeCalled; 48 | public override Encoding Encoding 49 | { 50 | get { throw new NotImplementedException(); } 51 | } 52 | 53 | protected override void Dispose(bool disposing) 54 | { 55 | DisposeCalled = true; 56 | base.Dispose(disposing); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Logging/TraceLoggerFixture.Desktop.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Diagnostics; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | using Prism.Logging; 6 | 7 | namespace Prism.WinForms.Tests.Logging 8 | { 9 | [TestClass] 10 | public class TraceLoggerFixture 11 | { 12 | TraceListener[] existingListeners; 13 | 14 | [TestInitialize] 15 | public void RemoveExisitingListeners() 16 | { 17 | existingListeners = new TraceListener[Trace.Listeners.Count]; 18 | Trace.Listeners.CopyTo(existingListeners, 0); 19 | Trace.Listeners.Clear(); 20 | } 21 | 22 | [TestCleanup] 23 | public void ReAttachExistingListeners() 24 | { 25 | Trace.Listeners.AddRange(existingListeners); 26 | } 27 | 28 | [TestMethod] 29 | public void ShouldWriteToTraceWriter() 30 | { 31 | var listener = new MockTraceListener(); 32 | Trace.Listeners.Add(listener); 33 | 34 | var traceLogger = new TraceLogger(); 35 | traceLogger.Log("Test debug message", Category.Debug, Priority.Low); 36 | 37 | Assert.AreEqual("Test debug message", listener.LogMessage); 38 | 39 | Trace.Listeners.Remove(listener); 40 | } 41 | 42 | 43 | [TestMethod] 44 | public void ShouldTraceErrorException() 45 | { 46 | var listener = new MockTraceListener(); 47 | Trace.Listeners.Add(listener); 48 | 49 | var traceLogger = new TraceLogger(); 50 | traceLogger.Log("Test exception message", Category.Exception, Priority.Low); 51 | 52 | Assert.AreEqual("Test exception message", listener.ErrorMessage); 53 | 54 | Trace.Listeners.Remove(listener); 55 | } 56 | } 57 | 58 | class MockTraceListener : TraceListener 59 | { 60 | public string LogMessage { get; set; } 61 | public string ErrorMessage { get; set; } 62 | 63 | public override void Write(string message) 64 | { 65 | LogMessage = message; 66 | } 67 | 68 | public override void WriteLine(string message) 69 | { 70 | LogMessage = message; 71 | } 72 | 73 | public override void WriteLine(string message, string category) 74 | { 75 | LogMessage = message; 76 | } 77 | 78 | public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) 79 | { 80 | if (eventType == TraceEventType.Error) 81 | { 82 | ErrorMessage = message; 83 | } 84 | else 85 | { 86 | LogMessage = message; 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockAsyncModuleTypeLoader.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Threading; 5 | using Prism.Modularity; 6 | 7 | namespace Prism.Wpf.Tests.Mocks 8 | { 9 | public class MockAsyncModuleTypeLoader : IModuleTypeLoader 10 | { 11 | private ManualResetEvent callbackEvent; 12 | 13 | public MockAsyncModuleTypeLoader(ManualResetEvent callbackEvent) 14 | { 15 | this.callbackEvent = callbackEvent; 16 | } 17 | 18 | public int SleepTimeOut { get; set; } 19 | 20 | public Exception CallbackArgumentError { get; set; } 21 | 22 | public bool CanLoadModuleType(ModuleInfo moduleInfo) 23 | { 24 | return true; 25 | } 26 | 27 | public void LoadModuleType(ModuleInfo moduleInfo) 28 | { 29 | Thread retrieverThread = new Thread(() => 30 | { 31 | Thread.Sleep(SleepTimeOut); 32 | 33 | this.RaiseLoadModuleCompleted(new LoadModuleCompletedEventArgs(moduleInfo, CallbackArgumentError)); 34 | callbackEvent.Set(); 35 | }); 36 | retrieverThread.Start(); 37 | } 38 | 39 | 40 | public event EventHandler ModuleDownloadProgressChanged; 41 | 42 | private void RaiseLoadModuleProgressChanged(ModuleDownloadProgressChangedEventArgs e) 43 | { 44 | if (this.ModuleDownloadProgressChanged != null) 45 | { 46 | this.ModuleDownloadProgressChanged(this, e); 47 | } 48 | } 49 | 50 | public event EventHandler LoadModuleCompleted; 51 | 52 | private void RaiseLoadModuleCompleted(LoadModuleCompletedEventArgs e) 53 | { 54 | if (this.LoadModuleCompleted != null) 55 | { 56 | this.LoadModuleCompleted(this, e); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockClickableObject.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Windows.Controls.Primitives; 4 | 5 | namespace Prism.Wpf.Tests.Mocks 6 | { 7 | internal class MockClickableObject : ButtonBase 8 | { 9 | public void RaiseClick() 10 | { 11 | OnClick(); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockCommand.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Windows.Input; 5 | 6 | namespace Prism.Wpf.Tests.Mocks 7 | { 8 | internal class MockCommand : ICommand 9 | { 10 | public bool ExecuteCalled { get; set; } 11 | public bool CanExecuteReturnValue = true; 12 | public object ExecuteParameter; 13 | public object CanExecuteParameter; 14 | public int CanExecuteTimesCalled; 15 | 16 | public event EventHandler CanExecuteChanged; 17 | 18 | public void Execute(object parameter) 19 | { 20 | ExecuteCalled = true; 21 | ExecuteParameter = parameter; 22 | } 23 | 24 | public bool CanExecute(object parameter) 25 | { 26 | CanExecuteTimesCalled++; 27 | CanExecuteParameter = parameter; 28 | return CanExecuteReturnValue; 29 | } 30 | 31 | public void RaiseCanExecuteChanged() 32 | { 33 | if (this.CanExecuteChanged != null) 34 | this.CanExecuteChanged(this, EventArgs.Empty); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockConfigurationStore.Desktop.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | 5 | namespace Prism.WinForms.Tests.Mocks 6 | { 7 | public class MockConfigurationStore : IConfigurationStore 8 | { 9 | private ModulesConfigurationSection _section = new ModulesConfigurationSection(); 10 | 11 | public ModuleConfigurationElement[] Modules 12 | { 13 | set { _section.Modules = new ModuleConfigurationElementCollection(value); } 14 | } 15 | 16 | public ModulesConfigurationSection RetrieveModuleConfigurationSection() 17 | { 18 | return _section; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockContainerAdapter.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Microsoft.Practices.ServiceLocation; 6 | 7 | namespace Prism.WinForms.Tests.Mocks 8 | { 9 | internal class MockContainerAdapter : ServiceLocatorImplBase 10 | { 11 | public Dictionary ResolvedInstances = new Dictionary(); 12 | 13 | protected override object DoGetInstance(Type serviceType, string key) 14 | { 15 | object resolvedInstance; 16 | if (!this.ResolvedInstances.ContainsKey(serviceType)) 17 | { 18 | resolvedInstance = Activator.CreateInstance(serviceType); 19 | this.ResolvedInstances.Add(serviceType, resolvedInstance); 20 | } 21 | else 22 | { 23 | resolvedInstance = this.ResolvedInstances[serviceType]; 24 | } 25 | 26 | return resolvedInstance; 27 | } 28 | 29 | protected override IEnumerable DoGetAllInstances(Type serviceType) 30 | { 31 | throw new System.NotImplementedException(); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockDelegateReference.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using Prism.Events; 5 | 6 | namespace Prism.Wpf.Tests.Mocks 7 | { 8 | class MockDelegateReference : IDelegateReference 9 | { 10 | public Delegate Target { get; set; } 11 | 12 | public MockDelegateReference() 13 | { 14 | 15 | } 16 | 17 | public MockDelegateReference(Delegate target) 18 | { 19 | Target = target; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockDependencyObject.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Windows; 4 | 5 | namespace Prism.Wpf.Tests.Mocks 6 | { 7 | public class MockDependencyObject : DependencyObject 8 | { 9 | } 10 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockFrameworkElement.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace Prism.Wpf.Tests.Mocks 4 | { 5 | public class MockFrameworkElement : FrameworkElement 6 | { 7 | public void RaiseLoaded() 8 | { 9 | this.RaiseEvent(new RoutedEventArgs(LoadedEvent)); 10 | } 11 | 12 | public void RaiseUnloaded() 13 | { 14 | this.RaiseEvent(new RoutedEventArgs(UnloadedEvent)); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockHostAwareRegionBehavior.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Windows; 4 | using Prism.Regions; 5 | using Prism.Regions.Behaviors; 6 | 7 | namespace Prism.Wpf.Tests.Mocks 8 | { 9 | public class MockHostAwareRegionBehavior : IHostAwareRegionBehavior 10 | { 11 | public IRegion Region { get; set; } 12 | 13 | public void Attach() 14 | { 15 | 16 | } 17 | 18 | public DependencyObject HostControl { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockInteractionRequestAwareElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using Prism.Interactivity.InteractionRequest; 4 | 5 | namespace Prism.Wpf.Tests.Mocks 6 | { 7 | public class MockInteractionRequestAwareElement : FrameworkElement, IInteractionRequestAware 8 | { 9 | public INotification Notification { get; set; } 10 | 11 | public Action FinishInteraction { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockLogger.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Logging; 4 | 5 | namespace Prism.WinForms.Tests.Mocks 6 | { 7 | internal class MockLogger : ILoggerFacade 8 | { 9 | public string LastMessage; 10 | public Category LastMessageCategory; 11 | public void Log(string message, Category category, Priority priority) 12 | { 13 | LastMessage = message; 14 | LastMessageCategory = category; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockModuleTypeLoader.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Prism.Modularity; 6 | 7 | namespace Prism.WinForms.Tests.Mocks 8 | { 9 | public class MockModuleTypeLoader : IModuleTypeLoader 10 | { 11 | public List LoadedModules = new List(); 12 | public bool canLoadModuleTypeReturnValue = true; 13 | public Exception LoadCompletedError; 14 | 15 | public bool CanLoadModuleType(ModuleInfo moduleInfo) 16 | { 17 | return canLoadModuleTypeReturnValue; 18 | } 19 | 20 | public void LoadModuleType(ModuleInfo moduleInfo) 21 | { 22 | this.LoadedModules.Add(moduleInfo); 23 | this.RaiseLoadModuleCompleted(new LoadModuleCompletedEventArgs(moduleInfo, this.LoadCompletedError)); 24 | } 25 | 26 | public event EventHandler ModuleDownloadProgressChanged; 27 | 28 | public void RaiseLoadModuleProgressChanged(ModuleDownloadProgressChangedEventArgs e) 29 | { 30 | if (this.ModuleDownloadProgressChanged != null) 31 | { 32 | this.ModuleDownloadProgressChanged(this, e); 33 | } 34 | } 35 | 36 | public event EventHandler LoadModuleCompleted; 37 | 38 | public void RaiseLoadModuleCompleted(ModuleInfo moduleInfo, Exception error) 39 | { 40 | this.RaiseLoadModuleCompleted(new LoadModuleCompletedEventArgs(moduleInfo, error)); 41 | } 42 | 43 | public void RaiseLoadModuleCompleted(LoadModuleCompletedEventArgs e) 44 | { 45 | if (this.LoadModuleCompleted != null) 46 | { 47 | this.LoadModuleCompleted(this, e); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockRegion.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.ComponentModel; 5 | using Prism.Regions; 6 | 7 | namespace Prism.Wpf.Tests.Mocks 8 | { 9 | internal class MockRegion : IRegion 10 | { 11 | public event PropertyChangedEventHandler PropertyChanged; 12 | public Func GetViewStringDelegate { get; set; } 13 | 14 | private MockViewsCollection views = new MockViewsCollection(); 15 | 16 | public IViewsCollection Views 17 | { 18 | get { return views; } 19 | } 20 | 21 | public IViewsCollection ActiveViews 22 | { 23 | get { throw new System.NotImplementedException(); } 24 | } 25 | 26 | public object Context 27 | { 28 | get { throw new System.NotImplementedException(); } 29 | set { throw new System.NotImplementedException(); } 30 | } 31 | 32 | public NavigationParameters NavigationParameters 33 | { 34 | get { throw new System.NotImplementedException(); } 35 | set { throw new System.NotImplementedException(); } 36 | } 37 | 38 | public string Name { get; set; } 39 | 40 | public IRegionManager Add(object view) 41 | { 42 | this.views.Add(view); 43 | return null; 44 | } 45 | 46 | public IRegionManager Add(object view, string viewName) 47 | { 48 | return Add(view); 49 | } 50 | 51 | public IRegionManager Add(object view, string viewName, bool createRegionManagerScope) 52 | { 53 | throw new System.NotImplementedException(); 54 | } 55 | 56 | public void Remove(object view) 57 | { 58 | throw new System.NotImplementedException(); 59 | } 60 | 61 | public void Activate(object view) 62 | { 63 | throw new System.NotImplementedException(); 64 | } 65 | 66 | public void Deactivate(object view) 67 | { 68 | throw new System.NotImplementedException(); 69 | } 70 | 71 | public object GetView(string viewName) 72 | { 73 | return GetViewStringDelegate(viewName); 74 | } 75 | 76 | public IRegionManager RegionManager { get; set; } 77 | 78 | public IRegionBehaviorCollection Behaviors 79 | { 80 | get { throw new System.NotImplementedException(); } 81 | } 82 | 83 | public bool Navigate(System.Uri source) 84 | { 85 | throw new System.NotImplementedException(); 86 | } 87 | 88 | 89 | public void RequestNavigate(System.Uri target, System.Action navigationCallback) 90 | { 91 | throw new System.NotImplementedException(); 92 | } 93 | 94 | public void RequestNavigate(System.Uri target, System.Action navigationCallback, NavigationParameters navigationParameters) 95 | { 96 | throw new System.NotImplementedException(); 97 | } 98 | 99 | public IRegionNavigationService NavigationService 100 | { 101 | get { throw new System.NotImplementedException(); } 102 | set { throw new System.NotImplementedException(); } 103 | } 104 | 105 | 106 | public System.Comparison SortComparison 107 | { 108 | get 109 | { 110 | throw new System.NotImplementedException(); 111 | } 112 | set 113 | { 114 | throw new System.NotImplementedException(); 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockRegionAdapter.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections.Generic; 4 | using System.Windows; 5 | using Prism.Regions; 6 | 7 | namespace Prism.Wpf.Tests.Mocks 8 | { 9 | internal class MockRegionAdapter : IRegionAdapter 10 | { 11 | public List CreatedRegions = new List(); 12 | public MockRegionManagerAccessor Accessor; 13 | 14 | 15 | public IRegion Initialize(object regionTarget, string regionName) 16 | { 17 | CreatedRegions.Add(regionName); 18 | 19 | var region = new MockPresentationRegion(); 20 | RegionManager.GetObservableRegion(regionTarget as DependencyObject).Value = region; 21 | 22 | // Fire update regions again. This also happens if a region is created and added to the regionmanager 23 | if (this.Accessor != null) 24 | Accessor.UpdateRegions(); 25 | 26 | return region; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockRegionBehavior.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using Prism.Regions; 5 | 6 | namespace Prism.Wpf.Tests.Mocks 7 | { 8 | public class MockRegionBehavior : IRegionBehavior 9 | { 10 | public IRegion Region 11 | { 12 | get; set; 13 | } 14 | 15 | public Func OnAttach; 16 | 17 | public void Attach() 18 | { 19 | if (OnAttach != null) 20 | OnAttach(); 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockRegionBehaviorCollection.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using Prism.Regions; 6 | 7 | namespace Prism.Wpf.Tests.Mocks 8 | { 9 | internal class MockRegionBehaviorCollection : Dictionary, IRegionBehaviorCollection 10 | { 11 | IEnumerator IEnumerable.GetEnumerator() 12 | { 13 | return GetEnumerator(); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockRegionManagerAccessor.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Windows; 5 | using Prism.Regions; 6 | 7 | namespace Prism.Wpf.Tests.Mocks 8 | { 9 | internal class MockRegionManagerAccessor : IRegionManagerAccessor 10 | { 11 | public Func GetRegionName; 12 | public Func GetRegionManager; 13 | 14 | public event EventHandler UpdatingRegions; 15 | 16 | string IRegionManagerAccessor.GetRegionName(DependencyObject element) 17 | { 18 | return this.GetRegionName(element); 19 | } 20 | 21 | IRegionManager IRegionManagerAccessor.GetRegionManager(DependencyObject element) 22 | { 23 | if (this.GetRegionManager != null) 24 | { 25 | return this.GetRegionManager(element); 26 | } 27 | 28 | return null; 29 | } 30 | 31 | public void UpdateRegions() 32 | { 33 | if (this.UpdatingRegions != null) 34 | { 35 | this.UpdatingRegions(this, EventArgs.Empty); 36 | } 37 | } 38 | 39 | public int GetSubscribersCount() 40 | { 41 | return this.UpdatingRegions != null ? this.UpdatingRegions.GetInvocationList().Length : 0; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockServiceLocator.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using Microsoft.Practices.ServiceLocation; 5 | 6 | namespace Prism.Wpf.Tests.Mocks 7 | { 8 | internal class MockServiceLocator : IServiceLocator 9 | { 10 | public Func GetInstance; 11 | public Func GetService; 12 | 13 | object IServiceLocator.GetInstance(Type serviceType) 14 | { 15 | if (this.GetInstance != null) 16 | return this.GetInstance(serviceType); 17 | 18 | return null; 19 | } 20 | 21 | object IServiceProvider.GetService(Type serviceType) 22 | { 23 | if (this.GetService != null) 24 | return this.GetService(serviceType); 25 | 26 | return null; 27 | } 28 | 29 | System.Collections.Generic.IEnumerable IServiceLocator.GetAllInstances() 30 | { 31 | throw new NotImplementedException(); 32 | } 33 | 34 | System.Collections.Generic.IEnumerable IServiceLocator.GetAllInstances(Type serviceType) 35 | { 36 | throw new NotImplementedException(); 37 | } 38 | 39 | TService IServiceLocator.GetInstance(string key) 40 | { 41 | throw new NotImplementedException(); 42 | } 43 | 44 | TService IServiceLocator.GetInstance() 45 | { 46 | return (TService)GetInstance(typeof(TService)); 47 | } 48 | 49 | object IServiceLocator.GetInstance(Type serviceType, string key) 50 | { 51 | throw new NotImplementedException(); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockSortableViews.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Regions; 4 | 5 | namespace Prism.Wpf.Tests.Mocks 6 | { 7 | [ViewSortHint("01")] 8 | internal class MockSortableView1 9 | { 10 | } 11 | 12 | [ViewSortHint("02")] 13 | internal class MockSortableView2 14 | { 15 | } 16 | 17 | [ViewSortHint("03")] 18 | internal class MockSortableView3 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/MockViewsCollection.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Collections.ObjectModel; 6 | using System.Collections.Specialized; 7 | using Prism.Regions; 8 | 9 | namespace Prism.Wpf.Tests.Mocks 10 | { 11 | class MockViewsCollection : IViewsCollection 12 | { 13 | public ObservableCollection Items = new ObservableCollection(); 14 | 15 | public void Add(object view) 16 | { 17 | this.Items.Add(view); 18 | } 19 | 20 | public bool Contains(object value) 21 | { 22 | return Items.Contains(value); 23 | } 24 | 25 | public IEnumerator GetEnumerator() 26 | { 27 | return Items.GetEnumerator(); 28 | } 29 | 30 | IEnumerator IEnumerable.GetEnumerator() 31 | { 32 | return GetEnumerator(); 33 | } 34 | 35 | public event NotifyCollectionChangedEventHandler CollectionChanged 36 | { 37 | add { Items.CollectionChanged += value; } 38 | remove { Items.CollectionChanged -= value; } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockAbstractModule.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | 5 | namespace Prism.WinForms.Tests.Mocks.Modules 6 | { 7 | public abstract class MockAbstractModule : IModule 8 | { 9 | public void Initialize() 10 | { 11 | } 12 | } 13 | 14 | public class MockInheritingModule : MockAbstractModule 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockAttributedModule.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | 5 | namespace Prism.WinForms.Tests.Mocks.Modules 6 | { 7 | [Module(ModuleName = "TestModule", OnDemand = true)] 8 | public class MockAttributedModule : IModule 9 | { 10 | public void Initialize() 11 | { 12 | throw new System.NotImplementedException(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockDependantModule.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | 5 | namespace Prism.WinForms.Tests.Mocks.Modules 6 | { 7 | [Module(ModuleName = "DependantModule")] 8 | [ModuleDependency("DependencyModule")] 9 | public class DependantModule : IModule 10 | { 11 | public void Initialize() 12 | { 13 | throw new System.NotImplementedException(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockDependencyModule.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | 5 | namespace Prism.WinForms.Tests.Mocks.Modules 6 | { 7 | [Module(ModuleName = "DependencyModule")] 8 | public class DependencyModule : IModule 9 | { 10 | public void Initialize() 11 | { 12 | throw new System.NotImplementedException(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockExposingTypeFromGacAssemblyModule.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using Prism.Modularity; 5 | 6 | namespace Prism.WinForms.Tests.Mocks.Modules 7 | { 8 | public class MockExposingTypeFromGacAssemblyModule : IModule 9 | { 10 | public void Initialize() 11 | { 12 | throw new NotImplementedException(); 13 | } 14 | } 15 | 16 | public class SomeContractReferencingTransactionsAssembly : System.Transactions.IDtcTransaction 17 | { 18 | public void Commit(int retaining, int commitType, int reserved) 19 | { 20 | throw new System.NotImplementedException(); 21 | } 22 | 23 | public void Abort(IntPtr reason, int retaining, int async) 24 | { 25 | throw new System.NotImplementedException(); 26 | } 27 | 28 | public void GetTransactionInfo(IntPtr transactionInformation) 29 | { 30 | throw new System.NotImplementedException(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockModuleA.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | using System; 5 | 6 | namespace Prism.WinForms.Tests.Mocks.Modules 7 | { 8 | public class MockModuleA : IModule 9 | { 10 | public void Initialize() 11 | { 12 | throw new System.NotImplementedException(); 13 | } 14 | } 15 | 16 | public class DummyClass 17 | { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockModuleReferencedAssembly.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace Prism.WinForms.Tests.Mocks.Modules 4 | { 5 | public class MockReferencedModule 6 | { 7 | } 8 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockModuleReferencingAssembly.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | 5 | namespace Prism.WinForms.Tests.Mocks.Modules 6 | { 7 | public class MockModuleReferencingAssembly : IModule 8 | { 9 | public void Initialize() 10 | { 11 | MockReferencedModule instance = new MockReferencedModule(); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockModuleReferencingOtherModule.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | 5 | namespace Prism.WinForms.Tests.Mocks.Modules 6 | { 7 | public class MockModuleReferencingOtherModule : IModule 8 | { 9 | public void Initialize() 10 | { 11 | throw new System.NotImplementedException(); 12 | } 13 | } 14 | 15 | public class MyDummyClass : DummyClass {} 16 | } 17 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Modules/MockModuleThrowingException.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Prism.Modularity; 4 | 5 | namespace Prism.WinForms.Tests.Mocks.Modules 6 | { 7 | public class MockModuleThrowingException : IModule 8 | { 9 | public void Initialize() 10 | { 11 | throw new System.NotImplementedException(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/ViewModels/MockViewModel.cs: -------------------------------------------------------------------------------- 1 | using Prism.Mvvm; 2 | 3 | namespace Prism.WinForms.Tests.Mocks.ViewModels 4 | { 5 | public class MockViewModel : BindableBase 6 | { 7 | private int mockProperty; 8 | 9 | public int MockProperty 10 | { 11 | get 12 | { 13 | return this.mockProperty; 14 | } 15 | 16 | set 17 | { 18 | this.SetProperty(ref mockProperty, value); 19 | } 20 | } 21 | 22 | internal void InvokeOnPropertyChanged() 23 | { 24 | this.OnPropertyChanged(() => this.MockProperty); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Views/Mock.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Forms; 3 | 4 | namespace Prism.WinForms.Tests.Mocks.Views 5 | { 6 | public class Mock : Control 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Mocks/Views/MockView.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Forms; 3 | 4 | namespace Prism.WinForms.Tests.Mocks.Views 5 | { 6 | public class MockView : Control 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Modularity/ConfigurationStoreFixture.Desktop.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Prism.Modularity; 5 | 6 | namespace Prism.WinForms.Tests.Modularity 7 | { 8 | [TestClass] 9 | public class ConfigurationStoreFixture 10 | { 11 | [TestMethod] 12 | public void ShouldRetrieveModuleConfiguration() 13 | { 14 | ConfigurationStore store = new ConfigurationStore(); 15 | var section = store.RetrieveModuleConfigurationSection(); 16 | 17 | Assert.IsNotNull(section); 18 | Assert.IsNotNull(section.Modules); 19 | Assert.AreEqual(1, section.Modules.Count); 20 | Assert.IsNotNull(section.Modules[0].AssemblyFile); 21 | Assert.AreEqual("MockModuleA", section.Modules[0].ModuleName); 22 | Assert.IsNotNull(section.Modules[0].AssemblyFile); 23 | Assert.IsTrue(section.Modules[0].AssemblyFile.Contains(@"MocksModules\MockModuleA.dll")); 24 | Assert.IsNotNull(section.Modules[0].ModuleType); 25 | Assert.IsTrue(section.Modules[0].StartupLoaded); 26 | Assert.AreEqual("Prism.WinForms.Tests.Mocks.Modules.MockModuleA", section.Modules[0].ModuleType); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Modularity/ModuleAttributeFixture.Desktop.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Prism.Modularity; 5 | 6 | namespace Prism.WinForms.Tests.Modularity 7 | { 8 | [TestClass] 9 | public class ModuleAttributeFixture 10 | { 11 | [TestMethod] 12 | public void StartupLoadedDefaultsToTrue() 13 | { 14 | var moduleAttribute = new ModuleAttribute(); 15 | 16 | Assert.AreEqual(false, moduleAttribute.OnDemand); 17 | } 18 | 19 | [TestMethod] 20 | public void CanGetAndSetProperties() 21 | { 22 | var moduleAttribute = new ModuleAttribute(); 23 | moduleAttribute.ModuleName = "Test"; 24 | moduleAttribute.OnDemand = true; 25 | 26 | Assert.AreEqual("Test", moduleAttribute.ModuleName); 27 | Assert.AreEqual(true, moduleAttribute.OnDemand); 28 | } 29 | 30 | [TestMethod] 31 | public void ModuleDependencyAttributeStoresModuleName() 32 | { 33 | var moduleDependencyAttribute = new ModuleDependencyAttribute("Test"); 34 | 35 | Assert.AreEqual("Test", moduleDependencyAttribute.ModuleName); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Modularity/ModuleCatalogXaml/SimpleModuleCatalog.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | ModuleW 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Modularity/ModuleInfoGroupExtensionsFixture.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Linq; 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; 6 | using Prism.Modularity; 7 | 8 | namespace Prism.WinForms.Tests.Modularity 9 | { 10 | /// 11 | /// Summary description for ModuleInfoGroupExtensionsFixture 12 | /// 13 | [TestClass] 14 | public class ModuleInfoGroupExtensionsFixture 15 | { 16 | [TestMethod] 17 | public void ShouldAddModuleToModuleInfoGroup() 18 | { 19 | string moduleName = "MockModule"; 20 | ModuleInfoGroup groupInfo = new ModuleInfoGroup(); 21 | groupInfo.AddModule(moduleName, typeof(MockModule)); 22 | 23 | Assert.AreEqual(1, groupInfo.Count); 24 | Assert.AreEqual(moduleName, groupInfo.ElementAt(0).ModuleName); 25 | } 26 | 27 | [TestMethod] 28 | public void ShouldSetModuleTypeCorrectly() 29 | { 30 | ModuleInfoGroup groupInfo = new ModuleInfoGroup(); 31 | groupInfo.AddModule("MockModule", typeof(MockModule)); 32 | 33 | Assert.AreEqual(1, groupInfo.Count); 34 | Assert.AreEqual(typeof(MockModule).AssemblyQualifiedName, groupInfo.ElementAt(0).ModuleType); 35 | } 36 | 37 | [TestMethod] 38 | [ExpectedException(typeof(ArgumentNullException))] 39 | public void NullTypeThrows() 40 | { 41 | ModuleInfoGroup groupInfo = new ModuleInfoGroup(); 42 | groupInfo.AddModule("NullModule", null); 43 | } 44 | 45 | [TestMethod] 46 | public void ShouldSetDependencies() 47 | { 48 | string dependency1 = "ModuleA"; 49 | string dependency2 = "ModuleB"; 50 | 51 | ModuleInfoGroup groupInfo = new ModuleInfoGroup(); 52 | groupInfo.AddModule("MockModule", typeof(MockModule), dependency1, dependency2); 53 | 54 | Assert.IsNotNull(groupInfo.ElementAt(0).DependsOn); 55 | Assert.AreEqual(2, groupInfo.ElementAt(0).DependsOn.Count); 56 | Assert.IsTrue(groupInfo.ElementAt(0).DependsOn.Contains(dependency1)); 57 | Assert.IsTrue(groupInfo.ElementAt(0).DependsOn.Contains(dependency2)); 58 | } 59 | 60 | [TestMethod] 61 | public void ShouldUseTypeNameIfNoNameSpecified() 62 | { 63 | ModuleInfoGroup groupInfo = new ModuleInfoGroup(); 64 | groupInfo.AddModule(typeof(MockModule)); 65 | 66 | Assert.AreEqual(1, groupInfo.Count); 67 | Assert.AreEqual(typeof(MockModule).Name, groupInfo.ElementAt(0).ModuleName); 68 | } 69 | 70 | 71 | public class MockModule : IModule 72 | { 73 | public void Initialize() 74 | { 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Modularity/ModuleInfoGroupFixture.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | using Prism.Modularity; 5 | 6 | namespace Prism.WinForms.Tests.Modularity 7 | { 8 | [TestClass] 9 | public class ModuleInfoGroupFixture 10 | { 11 | [TestMethod] 12 | public void ShouldForwardValuesToModuleInfo() 13 | { 14 | ModuleInfoGroup group = new ModuleInfoGroup(); 15 | group.Ref = "MyCustomGroupRef"; 16 | ModuleInfo moduleInfo = new ModuleInfo(); 17 | Assert.IsNull(moduleInfo.Ref); 18 | 19 | group.Add(moduleInfo); 20 | 21 | Assert.AreEqual(group.Ref, moduleInfo.Ref); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Modularity/NotAValidDotNetDll.txt.dll: -------------------------------------------------------------------------------- 1 | This is just a text file renamed as a dll for testing non-.NET DLL loading. 2 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Prism.WinForms.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Prism.WinForms.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("9b8ccd16-ebf3-4bd7-81e2-5d2500cccca4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/ServiceLocatorExtensionsFixture.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Microsoft.Practices.ServiceLocation; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | 8 | namespace Prism.WinForms.Tests 9 | { 10 | [TestClass] 11 | public class ServiceLocatorExtensionsFixture 12 | { 13 | [TestMethod] 14 | public void TryResolveShouldReturnNullIfNotFound() 15 | { 16 | IServiceLocator sl = new MockServiceLocator(() => null); 17 | 18 | object value = sl.TryResolve(typeof(ServiceLocatorExtensionsFixture)); 19 | 20 | Assert.IsNull(value); 21 | } 22 | 23 | [TestMethod] 24 | public void ShouldResolveFoundtypes() 25 | { 26 | IServiceLocator sl = new MockServiceLocator(() => new ServiceLocatorExtensionsFixture()); 27 | 28 | object value = sl.TryResolve(typeof(ServiceLocatorExtensionsFixture)); 29 | 30 | Assert.IsNotNull(value); 31 | } 32 | 33 | [TestMethod] 34 | public void GenericTryResolveShouldReturn() 35 | { 36 | IServiceLocator sl = new MockServiceLocator(() => new ServiceLocatorExtensionsFixture()); 37 | 38 | ServiceLocatorExtensionsFixture value = sl.TryResolve(); 39 | 40 | Assert.IsNotNull(value); 41 | } 42 | 43 | internal class MockServiceLocator : ServiceLocatorImplBase 44 | { 45 | public Func ResolveMethod; 46 | 47 | public MockServiceLocator(Func resolveMethod) 48 | { 49 | ResolveMethod = resolveMethod; 50 | } 51 | 52 | protected override object DoGetInstance(Type serviceType, string key) 53 | { 54 | object instance = ResolveMethod(); 55 | 56 | // If the instance was not found, throw exception. 57 | if (instance.GetType() != serviceType) 58 | { 59 | throw new ActivationException("Type not found."); 60 | } 61 | else 62 | { 63 | return instance; 64 | } 65 | } 66 | 67 | protected override IEnumerable DoGetAllInstances(Type serviceType) 68 | { 69 | return null; 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Source/WinForms/Prism.WinForms/Commands/ButtonBinder.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | using System.Windows.Input; 3 | 4 | namespace Prism.Commands 5 | { 6 | public class ButtonBinder : CommandBinder