Модераторы: Partizan, gambit

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Application Architecture for .NET 
:(
    Опции темы
Medved
Дата 19.1.2006, 14:06 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 7209
Регистрация: 15.9.2002
Где: Kazakhstan, Astan a

Репутация: 3
Всего: 154



Буду рад любой помощи в переводе изложенного материала на русский язык.


--------------------
http://extreme.sport-express.ru/
...и неважно сколько падал, важно сколько ты вставал...
PM MAIL WWW ICQ Skype GTalk   Вверх
VisualProgrammerNET
Дата 19.1.2006, 14:28 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Почётный халявщик
**


Профиль
Группа: Участник
Сообщений: 461
Регистрация: 30.10.2005
Где: Зеленоград

Репутация: 4
Всего: 6



А переводить надо и все те материалы, что под ссылками? Или картинки и подписи только?


--------------------
3 ГОДА НА user posted image 
PM MAIL ICQ   Вверх
Medved
Дата 19.1.2006, 14:37 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 7209
Регистрация: 15.9.2002
Где: Kazakhstan, Astan a

Репутация: 3
Всего: 154



Да что угодно. Когда я делал выборку, старался использовать минимум английского текста. Было бы неплохо, если бы кто-нибудь что-нибудь дополнил.


--------------------
http://extreme.sport-express.ru/
...и неважно сколько падал, важно сколько ты вставал...
PM MAIL WWW ICQ Skype GTalk   Вверх
Medved
Дата 19.1.2006, 21:29 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 7209
Регистрация: 15.9.2002
Где: Kazakhstan, Astan a

Репутация: 3
Всего: 154



Smart Client - Composite UI Application Block
http://msdn.microsoft.com/library/en-us/dn....asp?frame=true

The following diagram shows these two layers in the architecture of a .NET-based distributed application.
user posted image

Figure 1: Component layers found in distributed applications and services built with .NET

Figure 2 shows an example of the kind of rich user interface applications that the Composite UI Application Block can help you to produce. Meanwhile, the QuickStarts and a simple walkthrough example that demonstrates the fundamentals of the framework will help you to understand the structure and principles of the Composite UI Application Block. These examples and the related documentation are installed with the CAB framework.

user posted image

Figure 2: Sample call center application


Design of the Composite UI Application Block

Model-View-Controller (MVC)
http://msdn.microsoft.com/library/default....html/DesMVC.asp

Дополнительный материал:
Java библиотека - Триада MVC в действии
Delphi. Практика применения паттернов проектирования
  • Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).
  • View. The view manages the display of information.
  • Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.
Figure 3 depicts the structural relationship between the three objects.
user posted image

Figure 3: MVC class structure


MVP patterns

user posted image

Figure 4: Comparison of the MVC and MVP patterns


Design for Modularity

Figure 5 shows how these components interoperate.
user posted image

Figure 5: Components typically found in a Composite UI Application Block application


Design of the WorkItem

The design of the Composite UI Application Block primarily supports applications built using a consistent set of patterns. One of the default patterns is the Model-View-Controller (MVC) pattern. These types of applications generally consist of:
  • Initialization code.
  • State shared between components in the use case.
  • Controller classes that act on the state and other resources.
  • View classes that interact with their controller and read state.
  • Disposal code.
Figure 6 shows how the WorkItem supports the other components and interactions that generally form the basis for a Composite UI Application Block application.

user posted image

Figure 6: Composite UI Application Block application


Event Broker

user posted image

Figure 7: The Event Broker System


Threat Model

user posted image

Figure 8: The CAB start-up and service loading sequence


user posted image

Figure 9: Asynchronous execution of event subscriptions


Subsystems of the Composite UI Application Block

The Composite UI Application Block consists of a number of subsystems that interoperate to provide the functionality that the application block provides. Figure 10 shows the grouping of these subsystems.

user posted image

Figure 10: Subsystems of the Composite UI Application Block


--------------------
http://extreme.sport-express.ru/
...и неважно сколько падал, важно сколько ты вставал...
PM MAIL WWW ICQ Skype GTalk   Вверх
Medved
Дата 19.1.2006, 22:51 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Завсегдатай
Сообщений: 7209
Регистрация: 15.9.2002
Где: Kazakhstan, Astan a

Репутация: 3
Всего: 154



"Hello World"

The sample application used in this walkthrough implements the common "Hello World" scenario, which allows you to focus on the application's design and architecture.

Physical Architecture

In this example, simple code in a separate module implements the model. In response to the view loading, the presenter within this module obtains the results from the model, and updates the view.
Communication between the view and the presenter is through a defined interface. Using interfaces establishes a contract between the participants, which forces the appropriate separation and reduces dependency.

user posted image

Figure 17 The result of running the completed application
    There are two projects in the completed Visual Studio solution:
  • ShellApplication is the main shell for the application. It contains the form that acts as the container for all the use cases in the application. This form includes the container controls that define the overall layout of the SmartParts. The SmartParts are implemented in and displayed by the separate module.
  • MyModule is the module that contains the WorkItem that represents the use case, and the SmartPart that represents the view part of the MVP pattern. It also contains the presenter that updates the view within the shell where it is displayed. In this simple case, where the module locally generates the data to display, it also acts as the model.

user posted image

Figure 11: The components in the completed example application


Stage 1: Creating the Shell and the Form

Your first task is to create the project that acts as the main shell for the application.

Figure 12 shows the architecture of the application you have created so far. As the application starts and you call the Run method in your Main routine, the CAB creates the ShellForm form and the root ShellWorkItem.

user posted image

Figure 12: The components at the end of Stage 1

To create the shell and form
1. Create a new C# Windows Forms application. Name the new application ShellApplication.
2. In the Solution Explorer window, rename Form1.cs to ShellForm.cs.

To add references to the core classes
1. In the Solution Explorer window, right-click References and then click Add Reference.
Цитата

Microsoft.Practices.CompositeUI.dll
Microsoft.Practices.CompositeUI.WinForms.dll
Microsoft.Practices.ObjectBuilder.dll

2. In the New Item dialog, select Class and name it ShellWorkItem.cs.
3. In the new class file, add the following using statement for the namespace:
Код

using Microsoft.Practices.CompositeUI;

4. Edit the ShellWorkItem class declaration so that it is public, and inherits from WorkItem:
Код

public class ShellWorkItem : WorkItem
{
}


To initialize and display the form from within the root WorkItem
1. In the Solution Explorer window, rename the file Program.cs to ShellApplication.cs and open it.
2. Edit the existing using statement for the WinForms namespace to use the CompositeUI.WinForms namespace classes:
Код

using Microsoft.Practices.CompositeUI.WinForms;

3. Replace the static class ShellApplication with a public class that inherits from FormShellApplication, and which instructs the CAB to load the ShellForm form into the ShellWorkItem:
Код

public class ShellApplication : FormShellApplication<ShellWorkItem, ShellForm>
{
}

4. Add the [STAThread] attribute to the static Main method in this class. This method executes when the application starts, and it must instantiate your ShellApplication class and call the Run method. The FormShellApplication class inherits from the CabApplication class, which contains the Run method implementation:
Код

[STAThread]
static void Main()
{
  new ShellApplication().Run();
}



Stage 2: Creating and Loading the Module

In this stage, you add the module that provides the view to display on the ShellForm form.

user posted image

Figure 13: The components at the end of Stage 2

To add the module that provide the view
1. Right-click the top-level Solution 'Shell Application' entry in the Solution Explorer window, click Add, then click New Project.
2. Select the Class Library project type and name it MyModule.

In this example, the new module contains a child WorkItem.

To add references to the core classes
1. Add Reference.
Цитата

Microsoft.Practices.CompositeUI.dll
Microsoft.Practices.CompositeUI.WinForms.dll
Microsoft.Practices.ObjectBuilder.dll

2. In the New Item dialog for the MyModule project, select Class and name it MyWorkItem.cs.
3. Add the following using statement for the namespace to your new class file:
Код

using Microsoft.Practices.CompositeUI;

4. Edit the MyWorkItem class declaration so that it is public and inherits from WorkItem:
Код

public class MyWorkItem : WorkItem { }


To add a class to your project
1. Rename the file Class1.cs to MyModuleInit.cs. This is the file Visual Studio added to your new project.
2. In the MyModuleInit.cs file, add the following using statements for the three namespaces you will reference classes from:
Код

using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.Services;
using System.Windows.Forms;

3. Edit the class declaration to inherit from ModuleInit as shown here:
Код

public class MyModuleInit : ModuleInit

4. Add the following variable to reference the WorkItemTypeCatalogService (using the IWorkItemTypeCatalogService interface) so that you can access it to register your WorkItem:
Код

private IWorkItemTypeCatalogService myCatalogService;

5. Add the following public property to the class that sets the value of the myCatalogService variable. Use the [ServiceDependency] attribute on this property so that the dependency injection feature of the underlying ObjectBuilder utility will create an instance of the service and pass back a reference to it:
Код

[ServiceDependency]
public IWorkItemTypeCatalogService myWorkItemCatalog

  set { myCatalogService = value; }
}

6. Override the Load method of the ModuleInit class so that it registers your module's WorkItem. The code here calls the corresponding method of the base class first, as is usual practice, however the Load method of the ModuleInit class does nothing and so this line could be omitted:
Код

public override void Load()
{
  base.Load();
  myCatalogService.RegisterWorkItem<MyWorkItem>();
}

Note:
In Stage 4 of this walkthrough, you will change this code to use the RootWorkItem to add a child WorkItem. This illustrates some of the different techniques that you can use in CAB applications.

To instruct the CAB to load the new module
1. In the ShellApplication project, open the New Item dialog box and select XML File. Name it ProfileCatalog.xml.
Edit the file as shown in the following code to load the module named MyModule.dll:
Код

<?xml version="1.0" encoding="utf-8" ?>
<SolutionProfile xmlns="http://schemas.microsoft.com/pag/cab-profile">
  <Modules>
    <ModuleInfo AssemblyFile="MyModule.dll" />
  </Modules>
</SolutionProfile>



Stage 3: Adding the TabWorkspace

user posted image

Figure 15. The ShellForm form with the SplitContainer and TabWorkspace controls


user posted image

Figure 14. The components at the end of Stage 3

To add a TabWorkspace to the shell application
1. Open the file ShellForm.cs in the form designer, and resize it to 500 x 300 pixels by dragging the form edges, or by setting the Size property in the Properties window.
2. From the Containers section of the Toolbox, drag a SplitContainer control onto the form. Drag the center splitter so that the two panels are approximately the same width.
3. The CAB workspace controls, such as TabWorkspace and ZoneWorkspace do not appear in the Toolbox by default. Right-click the Toolbox, click Items..., and then click Browse.....
4. In the \Src\CS\CompositeUI.WinForms\bin\Debug\ subfolder of the folder where you installed the CAB files, select the file Microsoft.Practices.CompositeUI.WinForms.dll.
5. Drag a TabWorkspace onto the form and drop it onto the left-hand panel of the SplitContainer control.
6. Right-click the new TabWorkspace control and click Properties. In the Properties window, navigate to the Dock property and set it to Fill. This positions the workspace control to fill the panel, and adds two default tabs to it.
7. Right-click the TabWorkspace control and click Remove Tab. Then repeat this step to remove the second tab. Your form should now look like Figure 15.


Stage 4: Creating and Showing the SmartPart

user posted image

Figure 11: The components at the final stage of building the application

To create an interface for the view and the presenter to communicate
1. Right-click the MyModule project entry in Solution Explorer, click Add, and then click New Item. In the New Item dialog, click Interface and name it IMyView.cs.
Add the public keyword to the interface statement. Then declare the two members of this interface as an event named Load and a string property named Message as shown in the following code:
Код

public interface IMyView
{
  event EventHandler Load;
  string Message { get; set; }
}         

Now you can create the SmartPart user control. In this example, the SmartPart contains a Label control that displays a message in the shell.

user posted image

Figure 16. The completed MyView user control

To create a SmartPart user control
1. Right-click the MyModule project entry in Solution Explorer, and click Add, and then click New Item. In the New Item dialog box, select User Control and name it MyView.cs.
2. Resize the user control in the form designer window to 250 x 250 pixels.
3. Drag a Label control from the Toolbox onto the user control and drop it near the top left corner.
4. In the Properties window for the Label control, change the Font Size property to 10. Your user control should now look like Figure 16.

Within the user control, you must now implement the IMyView interface that you created earlier. This means that the user control must expose a property named Message. Internally, the user control sets the Text property of the Label control to the value of the Message property.

To implement the IMyView interface
1. Right-click the design surface and select View Code. Add the IMyView interface to the class declaration so that the user control class implements this interface:
Код

public partial class MyView : UserControl, IMyView    

2. Right-click IMyView and click Implement Interface, then click Implement Interface in the fly-out menu.
3. Replace the two throw statements that Visual Studio generates with two statements that get and set the value of the Message property:
Код

public string Message
{
  get
  {
    return this.label1.Text;
  }
  set
  {
    this.label1.Text = value;
  }
}    

The next step is to create the class that acts as the presenter in the MVP pattern. It manipulates the SmartPart you just created. The presenter hooks into the Load event of the view and exposes an event handler for this event. The event handler set the Message property of the view.

To create the presenter class
1. In the New Item dialog, select Class and name it MyPresenter.cs.
2. Edit the opening class declaration to make it public, and add a variable of type IMyView to the class to reference the view through the interface that you created for it:
Код

public class MyPresenter
{
  IMyView view;        

3. Create a constructor for the class. The constructor takes a reference to the view, sets it as the view for this presenter, and subscribes to the Load event of the view:
Код

public MyPresenter(IMyView view)
{
  this.view = view;
  view.Load += new EventHandler(view_Load);
}        

4. Create an event handler for the Load event. This sets the Message property of the Label control:
Код

void view_Load(object sender, EventArgs e)
{
  view.Message = "Hello World from a Module";
}         

In the next stage, you modify the ModuleInit class so that it gets a reference to the WorkItem in the module, and calls the Run method of this WorkItem.

To get a reference to the WorkItem
1. Open the MyModuleInit.cs file and add the following variable immediately after the existing myCatalogService variable declaration. The variable will contain a reference to the root ShellWorkItem:
Код

private WorkItem parentWorkItem;

2. Add a public property to the class. This property sets the value of the parentWorkItem variable. Use the [ServiceDependency] attribute on this property so that the dependency injection feature of the underlying ObjectBuilder utility references the existing WorkItem, and passes back a reference to it:
Код

[ServiceDependency]
public WorkItem ParentWorkItem

  set { parentWorkItem = value; }
}    

3. Modify the Load method that you added during Stage 2. This creates an instance of the module's WorkItem within the context of the root ShellWorkItem using the AddNew method, then calls the Run method of the new WorkItem. You retrieve the Workspace using its name and pass this Workspace to the Run method. In this example, the target is the TabWorkspace named tabWorkspace1 that you placed into the SplitContainer control on the form:
Код

public override void Load()
{
  base.Load();
  MyWorkItem myWorkItem = parentWorkItem.WorkItems.AddNew<MyWorkItem>();
  myWorkItem.Run(parentWorkItem.Workspaces["tabWorkspace1"]);
}         

In the final step, you implement the Run method in the module's WorkItem to create a new instance of the view, instantiate the presenter, and show the view within the TabWorkspace.

To create and show the view
1. Open the file MyWorkItem.cs, and add the following using statement for the namespace that contains the IWorkspace class you will use in your new code:
Код

using Microsoft.Practices.CompositeUI.SmartParts;

2. Create a public Run method that accepts as a parameter a reference to the TabWorkspace. It is a good idea to declare the parameter as of type IWorkspace instead of TabWorkspace. If in future you decide to change the type of workspace used in the shell form, you will not have to change the method declaration:
Код

 public void Run(IWorkspace TabWorkspace)
{
}     

3. Add statements to the Run method that create a new instance of the MyView class (using the AddNew method of the Items collection of this WorkItem), and a new instance of the MyPresenter class. Passing the view instance you just created to the presenter connects them together:
Код

IMyView view = this.Items.AddNew<MyView>();
MyPresenter presenter = new MyPresenter(view);    

4. Add statements to the Run method that add the new presenter to the current WorkItem, and call the Show method of the TabWorkspace to display the view:
Код

this.Items.Add(presenter);
TabWorkspace.Show(view);    




user posted image

Figure 11: The components in the completed example application

Figure 11 repeats the schematic that you saw near the start of this walkthrough. It shows all of the components in the completed application. At run time, the application initializes and loads the main form (ShellForm). It then loads the module (MyModule) that is specified in the ProfileCatalog.xml file. The module registers its WorkItem (MyWorkItem) with the RootWorkItem that is exposed by the shell, and calls the Run method.
The Run method of the module's WorkItem creates a new instance of the user control (MyView) and the presenter (MyPresenter). It adds the presenter to the module's WorkItem, and shows the MyView user control in the TabWorkspace. The module handles the Load event of the MyView user control and sets the Message property of the user control, which displays the message in the Label control.


--------------------
http://extreme.sport-express.ru/
...и неважно сколько падал, важно сколько ты вставал...
PM MAIL WWW ICQ Skype GTalk   Вверх
Ответ в темуСоздание новой темы Создание опроса
Прежде чем создать тему, посмотрите сюда:
mr.DUDA
THandle

Используйте теги [code=csharp][/code] для подсветки кода. Используйтe чекбокс "транслит" если у Вас нет русских шрифтов.
Что делать если Вам помогли, но отблагодарить помощника плюсом в репутацию Вы не можете(не хватает сообщений)? Пишите сюда, или отправляйте репорт. Поставим :)
Так же не забывайте отмечать свой вопрос решенным, если он таковым является :)


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, mr.DUDA, THandle.

 
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Общие вопросы по .NET и C# | Следующая тема »


 




[ Время генерации скрипта: 0.1288 ]   [ Использовано запросов: 21 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.