Stock trader ri wpf

Author: DPZ On: 10.06.2017

Developer's Guide to Microsoft Prism Library 5. Prism includes a sample called a reference implementation, which is a composite application that is based on a real-world scenario. This intentionally incomplete application illustrates the composite application baseline architecture. Within the application, you will see solutions for common, and recurrent, challenges that developers face when creating composite applications. We solve many of the challenges using design patterns such as Model-View-ViewModel MVVM , Composite View, Event Aggregator, Plug-In, and Dependency Injection that embody important architectural design principles such as separation of concerns and loose coupling.

Prism helps you to create a modular application design and build applications using loosely coupled components that can evolve independently but that can be easily and seamlessly integrated into the overall application.

The reference implementation is not a real-world application; however, it is based on real-world challenges customers are facing. When you look at this application, do not look at it as a reference point for building a stock trader application—instead, look at is as a reference for building a composite application.

When looking at this application, it may seem inappropriate to implement it in the way it was implemented. For example, you might question why there are so many modules, and it may seem overly complex. The focus of Prism is to address challenges around building composite applications.

For this reason, certain scenarios are used in the reference implementation to emphasize those challenges. The following illustration shows the desktop version of the Stock Trader Reference Implementation Stock Trader RI.

You can use the reference implementation in different ways. You can step through a running example that demonstrates application-specific code built on reusable guidance. You can also copy sections of the source code that implement any particular guidance into your own applications. The reference implementation was developed using a "test driven" approach and includes automated unit tests for most of its components.

You can modify the reference implementation and use the unit tests to verify its functionality. The reference implementation for the Prism 5. The Stock Trader RI requires Visual Studio or later and the. The reference implementation is compatible with Blend for Visual Studio To run the Stock Trader RI In Windows Explorer, double-click the following shortcut file to open the solution in Visual Studio: The features of the Stock Trader reference implementation are covered in greater detail later in the Scenarios section.

The following steps provide a quick introduction to the basic features. The Stock Trader RI includes a separate solution that includes acceptance tests. The acceptance tests describe how the reference implementation should perform when you follow a series of steps.

You can use the acceptance tests to explore the functional behavior of the application in a variety of scenarios. You should see the Stock Trader RI shell window and the tests automatically interact with the application. At the end of the test pass, you should see that all tests have passed. The Stock Trader RI illustrates a fictitious, but realistic financial investments scenario. Contoso Financial Investments CFI is a fictional financial organization that is modeled after real financial organizations.

CFI is building a new composite application to be used by their stock traders. This topic contains a summary of the scenario and demonstrates the business drivers that led to a series of technical decisions that ultimately result in the use of Prism.

Contoso Financial Investments CFI is a global investment firm with one hundred traders. For the last several years, CFI's lack of maintainability has brought new development on the application to a standstill—this has left the application in maintenance mode. To meet new customer requirements, CFI adopted the Microsoft. NET Framework development platform and branched out, creating additional applications that were each maintained by separate teams in a silo. The idea was that having separately developed applications would actually result in the development effort being more efficient.

Each team developing in their own silo meant that CFI could remove any contention that might arise, and it would pave the way for easily creating new teams. This would allow CFI to scale out their development teams into several locations, including setting up several offshore teams. The harsh reality is that the approach proved to be extremely inefficient on several levels.

stock trader ri wpf

Because each application was developed in a silo, the trader is now required to maintain multiple copies of the same data throughout a growing suite of applications, including StockPortfolio, MarketView, and StockHist.

The data is not identical, but there are elements of the data that are duplicated. To do their jobs, traders constantly jump back and forth between these various applications. To assist with this, CFI employed a "launcher" that quickly launched all the applications from a central place.

The launcher also passed the user's logon credentials to the application to skip the logon screen for each application. The launcher is more of a bandage than anything else.

It did not greatly improve the overall workflow of the traders in that the applications cannot integrate with one another, nor do they support a consistent UI. Because of the lack of integration, getting a consolidated view of all the related data is not an easy task. There is a customer-facing reporting site that can pull from each of the back-end systems to create this "one" view, but it is littered with problems, the least of which is that if the data has not been properly duplicated, the reports do not work.

In addition, entering the duplicate data is extremely time consuming and significantly impacts the number of orders that the trader is processing. Manually entering the data caused many errors in the system. Attempts to automatically synchronize the different systems have been too costly, because the schemas are very different and change frequently.

With all these problems, CFI, like many other businesses, has managed to continue to operate as a profitable business. As customer demand has increased, CFI has invested the necessary funds to expand its services.

It has also consistently grown its trading force whose jobs have become more and more difficult because of the inefficient operating conditions. Recently, however, this inefficiency has increased to the point that the business is starting to lose money:.

Currently, CFI is faced with a new challenge around Service-Oriented Architecture SOA. Fabrikam Web Traders, one of CFI's chief competitors, has offered its customers a rich client desktop experience for managing their portfolios remotely and on-site. The client is able to access Fabrikam's back-end systems through web services. Several large CFI customers are now requesting the same capabilities.

Although there is no immediate threat, in the long term, the business impact can be crippling. If CFI continues with the current strategy and does not both improve its efficiency and adapt to changing market conditions, it will lose business to its competition. The Chief Executive Officer CEO is an opportunist who sees this challenge as an opportunity for CFI to rise to the occasion. Working with the Chief Information Officer CIO and Chief Technology Officer CTO , they devise a three-point strategy for moving CFI forward.

The strategy is as follows:. The CTO has delivered these requirements to the senior architect, who is investigating various options for delivering them. For the architect, this project represents one of the most significant changes in the technology environment of CFI. Work will be spread across several software development teams, with additional development being outsourced.

In the past, cooperation between the development teams has been limited, and development tended to occur on an ad-hoc basis. This was because he identified the following problems that are a result of current development methodology:. The senior architect needs a strategy to realize the architectural vision set forth and to resolve the development challenges identified in the previous section. Prism is a set of assets for building complex WPF applications. Prism enables designing a composite application in the following ways:.

Support for integrating with existing WPF applications is of particular interest to the architect because CFI recently developed several WPF applications to address recent customer needs. He is confident that the guidance will assist him in delivering an effective solution that is robust, reliable, based on proven practices, and that can best use WPF.

After presenting his findings to the CTO, the CTO agrees that Prism will help to deliver an effective solution efficiently and cost-effectively.

He gives approval for the project to proceed. The CFI stock trader application is used for managing a trader's portfolio of investments.

Erreur Google Drive

Using the stock trader application, traders can see their portfolios, view trend data, buy and sell shares, manage items in their watch lists, and view related news. The Stock Trader RI is based on the Prism Library. The following illustration shows the Stock Trader RI Desktop version Solution Explorer.

The Stock Trader RI is a composite application, which is composed of a set of modules that are initialized at run time. The following illustration shows the application's startup process, which includes the initialization of modules. The next sections provide details about each of these steps. A module is a logical unit of separation in the application.

In the Stock Trader RI, each module exists in a separate assembly, but this is not an absolute requirement. The advantage of having this separation is that it makes the application more maintainable and enables distributed teams to work on different modules with minimal overlap on the files being updated in the source control system. The application does not directly insert views from each module into the shell; instead, each module contributes content to the shell view and interacts with other modules.

The final system is composed of the aggregation of the modules' contributions. By using composition, you can create applications with emergent behaviors—this refers to the application being able to scale up in complexity and requirements as it grows. The modules are loosely coupled. This means they do not directly reference each other, which promotes separation of concerns and allows modules to be individually developed, tested, and deployed by different teams.

This is possible through a set of application services that the modules have access to. Modules do not directly reference one another to access these services. In the Stock Trader RI, a dependency injection container referred to as the container injects these services into modules during their initialization the Stock Trader RI uses the MEF container. Modules get initialized during a bootstrapping process by a class named MefBootstrapper.

The MefBootstrapper is responsible for starting the core composition services used in an application created with the Prism Library. The following code from the MefBootstrapper class shows how the Module Manager is located from the container.

The Module Manager manages the process of validating the module catalog, retrieving modules if they are remote, loading the modules into the application domain, and calling the IModule. The StockTraderRIBootstrapper class configures the AggregateCatalog in code. In this case, the shell has direct references to all the modules, so the StockTraderRIBootstrapper can directly add them to the AggregateCatalog. The StockTraderRIBootstrapper also adds its own assembly to the catalog so that types exported within the application are available in the container.

During this initialization process, the container will inject instances into types to resolve their dependencies.

The following code shows how the news feed service, region manager, and event aggregator services are injected into the ArticleViewModel constructor. In addition, other types, such as services, are available so they can be accessed either by the same module or other modules in a loosely coupled fashion. A view is any content that a module contributes to the UI. In the Stock Trader RI, views are discovered at run time and added to regions. Regions are classes associated with a control container, such as ContentControl or TabControl.

Views can be registered through declarative attributes, directly in code, or through configuration. The Stock Trader RI uses MEF and the MVVM pattern to demonstrate the use of declarative attributes. Views associate themselves with a region through a custom export attribute, as shown in the following code example.

The AutoPopulateExportedViewsBehavior in the Stock Trader RI infrastructure discovers the views in the container and automatically populates them into the associated region, as shown in the following code example. The Stock Trader RI uses the MVVM pattern to separate UI, presentation logic, and the data model.

Using MVVM allows the view model to be unit tested because it has no direct knowledge of the view. The Prism Library provides the BindableBase class that the view models in the Stock Trader RI use to notify the user interface of property changes. BindableBase makes implementing INotifyPropertyChanged much easier. In the Stock Trader RI, the view and view model are connected through view discovery.

The view is discovered by the AutoPopulateExportedViewsBehavior and instantiated through the container. Because the view declares an import of the view model, the container then instantiates the view model and injects it into the view, as shown in the following code example. For more information about view discovery, see Composing the User Interface. Views can communicate with presenters and services in a loosely coupled fashion by using commands.

The Add To Watch List control, as shown in the following illustration, uses the AddWatchCommand , which is a DelegateCommand , to notify the WatchListService whenever a new watch item is added. Using a DelegateCommand allows the service to delegate the command's Execute method to the service's AddWatch method, as shown in the following code example.

The WatchListService is also injected into the AddWatchViewModel , which exposes the command to the view.

The AddWatchButton in the view then binds to the AddWatchViewModel command through the DataContext. This is using an attached behavior on the Add To Watch List text box, so when the user enters a stock symbol and then presses ENTER , the AddWatchCommand will be invoked, thereby passing the stock symbol to the WatchListService.

For more information about attached behaviors, see Command Behaviors in Advanced MVVM Scenarios. The Event Aggregator pattern channels events from multiple objects through a single object to simplify registration for clients.

In the Prism Library, a variation of the Event Aggregator pattern allows multiple objects to locate and publish or subscribe to events. In the Stock Trader RI, the event aggregator is used to communicate between modules. The subscriber tells the event aggregator to receive notifications on the UI thread. For example, when the user selects a symbol on the Position tab, the PositionSummaryViewModel in the Position module raises an event that specifies the symbol that was selected, as shown in the following code example.

The ArticleViewModel in the News module listens to the event to display the news related to the selected symbol, as shown in the following code example.

Download - UpdateStar - ywegyrayeku.web.fc2.com

The Stock Trader Reference Implementation Stock Trader RI demonstrates how you can address common technical challenges that you face when you build composite applications in WPF. The following table describes the technical challenges that the Stock Trader RI addresses.

The use of regions for placing the views without having to know how the layout is implemented. Compose UI across modules: Shows how a module can have views in different parts of the shell that interact with each other. The News module has an article list view and a popup article reader view that shows the same articles.

Shows the Command pattern. The command to buy or sell a stock is a delegate command. Each row in the list uses the same command instance but with a different parameter corresponding to the stock. This decouples the invoker from the receiver and shows passing additional data with the command. Buy and Sell command invokers in PositionSummaryView and handlers in OrdersController. Use composite commands to broadcast all of the commands. The Submit All or Cancel All commands execute all the individual instances of the Submit or Cancel commands.

Publish and Subscribe to events across decoupled modules. Publisher and Subscriber have no contract other than the event type. Show relevant news content: When the user selects a position in the position list, the communication to the news module uses the EventAggregator service.

The consumers of the market feed service subscribe to an event to be notified when new feeds are available; the consumers then update the model behind the UI. Services are also used to communicate between modules.

Code Samples Using the Prism Library for WPF

Services are more contractual and flexible than commands. The use of a bootstrapper to initialize the application with global services. Created bootstrapper with MEF and configuring global services, such as logging and defining the module catalog. The Stock Trader RI includes unit tests within the solution. Unit tests verify whether individual units of source code work as expected. The acceptance tests describe how the application should perform when you follow a series of steps; you can use the acceptance tests to explore the functional behavior of the application in a variety of scenarios.

You should see the reference implementation window and the tests automatically interact with the application. At the end of the test run, you should see that all tests have passed.

Downloads Visual Studio SDKs Trial software Free downloads Office resources SharePoint Server resources SQL Server Express resources Windows Server resources Programs Subscriptions Overview Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Samples Retired content.

The content you requested has been removed. Prism Prism 5 - Developer's Guide to Microsoft Prism Library 5. Code Samples Stock Trader Reference Implementation. Stock Trader Reference Implementation. Collapse the table of content. This documentation is archived and is not being maintained. Stock Trader Reference Implementation Using the Prism Library 5.

Prism Stock Trader RI Features Logical Architecture Implementation View How the Stock Trader RI Works Modules Services and Containers Bootstrapping the Application Configuring the Aggregate Catalog Module Loading Views View Registration in the Container Model-View-ViewModel Commands Event Aggregator Technical Challenges Unit and Acceptance Tests Outcome More Information. For an introduction to dependency injection and Inversion of Control, see the article, Loosen Up - Tame Your Software Dependencies for More Flexible Apps , by James Kovacs in MSDN Magazine.

Add new AssemblyCatalog typeof StockTraderRIBootstrapper. Add new AssemblyCatalog typeof StockTraderRICommands. Add new AssemblyCatalog typeof MarketModule. Add new AssemblyCatalog typeof PositionModule.

Add new AssemblyCatalog typeof WatchModule. Add new AssemblyCatalog typeof NewsModule. Each module class for example, NewsModule in the reference implementation is empty. The use of MEF allows for discovery of types using declarative attributes, so there is not any work to be done during module initialization.

If a module needed to do additional work when it is loaded, the module class should then implement IModule and perform this initialization in the Initialize method.

The ModuleManager would then discover, load, and initialize that module. Shared ] public class ArticleViewModel: In the Stock Trader RI, views are usually user controls. However, data templates in WPF are an alternative approach to rendering a view.

ResearchRegion ] [PartCreationPolicy CreationPolicy. Shared ] public partial class ArticleView: The DelegateCommand is one kind of command that the Prism Library provides. For more information about commands in Prism, see Commands in Implementing the MVVM Pattern. The notification of the event is on the UI thread to safely update the UI and avoid a WPF exception.

Next Topic Previous Topic Home Community. Is this page helpful? We appreciate your feedback. Dev centers Windows Office Visual Studio Microsoft Azure More Learning resources Microsoft Virtual Academy Channel 9 MSDN Magazine.

Community Forums Blogs Codeplex. Programs BizSpark for startups Microsoft Imagine for students. Shows how a composite view communicates with its child view.

Rating 4,4 stars - 360 reviews
inserted by FC2 system