Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Microsoft Visual C++ .NET Professional Projects - Premier Press

.pdf
Скачиваний:
180
Добавлен:
24.05.2014
Размер:
26 Мб
Скачать
☆

910 Project 10 NETWORKING AND REMOTING IN VC++ .NET

pLblQNum->set_TextAlign(ContentAlignment::MiddleLeft);

}

if (pRadioOpt1->get_Visible())

{

int nResult = m_pQuizServer->GetAnswer(m_nQNum - 1);

bool bCorrect = false;

 

 

switch(nResult)

 

 

Y

{

 

 

 

L

case 1:

 

 

F

if (pRadioOpt1->get_Checked())

 

 

bCorrect = true;

 

M

 

break;

 

 

 

 

 

case 2:

 

 

 

if (pRadioOpt2->get_Checked())

 

 

bCorrect = true;

E

 

break;

T

 

 

case 3:

A

 

if (pRadioOpt3->get Checked()) bCorrect = true;

break;

}

if ( bCorrect )

{

MessageBox::Show(“Correct Answer”, “Result”); m_nCorrect++;

}

else

{

MessageBox::Show(“Incorrect Answer”, “Result”);

}

}

if (!bButttonReset)

{

bButttonReset = true; pRadioOpt1->Visible = true; pRadioOpt2->Visible = true; pRadioOpt3->Visible = true;

Team-Fly®

IMPLEMENTING REMOTING

Chapter 31

911

}

 

 

 

 

 

 

if (m_nQNum > 10)

 

 

 

{

 

 

 

//It’s only a 10 question Quiz

 

 

 

String* pStrTemp;

 

 

 

pStrTemp = “Your score is “;

 

 

 

if (m_nCorrect < 5)

 

 

 

pStrTemp = String::Concat(pStrTemp, m_nCorrect.ToString(), “ out of 10. “, “\nYou need to improve your GK.”);

else if (m_nCorrect > 5 && m_nCorrect < 7)

pStrTemp = String::Concat(pStrTemp, m_nCorrect.ToString(), “ out of 10. “, “\nGood work!”);

else

pStrTemp = String::Concat(pStrTemp, m_nCorrect.ToString(), “ out of 10. “, “\nExcellent job!”);

MessageBox::Show(pStrTemp, “Score”);

m_nQNum = 1; m_nCorrect = 0; bButttonReset = false;

pBtnSubmit->Text = “&Start”; pLblQNum->Visible = false; pRadioOpt1->Visible = false; pRadioOpt2->Visible = false; pRadioOpt3->Visible = false;

String* pstrWelcome = m_pQuizServer->DoWelcome(“ BUDDY!”);

pstrWelcome = String::Concat(pstrWelcome, “\nPlease press Start button to start the Quiz.”);

pLblQuestion->Text = pstrWelcome; return;

}

//Uncheck all the radio buttons for the next question pRadioOpt1->set_Checked(false); pRadioOpt2->set_Checked(false);

912 Project 10 NETWORKING AND REMOTING IN VC++ .NET

pRadioOpt3->set_Checked(false);

// Check for the Answer - Correct or not

String* pStrTemp;

pStrTemp = “Question No. “;

pStrTemp = String::Concat(pStrTemp, m_nQNum.ToString()); pLblQNum->Text = pStrTemp;

//Query For Next Question from the server

String* pstrQuestion = m_pQuizServer->GetNextQuestion(m_nQNum); pLblQuestion->Text = pstrQuestion;

for (int i=1; i<4; i++)

{

String* pstrOpt = m_pQuizServer->GetOptions(m_nQNum, i); if (i == 1)

pRadioOpt1->Text = pstrOpt; else if (i == 2) pRadioOpt2->Text = pstrOpt; else if (i == 3) pRadioOpt3->Text = pstrOpt;

}

m_nQNum++;

}

//Handles the Exit button

void OnExitButtonClick(Object *sender, EventArgs *e)

{

Close();

}

};

//This is the entry point for this application int _tmain(void)

{

//TODO: Please replace the sample code below with your own.

IMPLEMENTING REMOTING

Chapter 31

913

 

 

 

 

Application::Run(new CQuizForm());

return 0;

}

Testing

To test the application, you need to execute the RemoteServer application and then execute the RemoteClient application. Click on the Start button to start the quiz. Try answering the question that appears and click on the Submit button to get the next question. Figure 31-1 displays the interface of the client application.

FIGURE 31-1 The RemoteClient application

Summary

In this chapter, you have implemented a client/server application that uses .NET Remoting. The goal of Remoting is to enable coupling between two remote applications and is the .NET replacement of DCOM.

This page intentionally left blank

PARTXIIAppendixes

This page intentionally left blank

Appendix A

The .NET Vision

and Goals

The past few years have seen the development of a plethora of proprietary software technologies. This has posed challenges for developers to develop and integrate applications and businesses to operate on. As a result, a common platform is needed that allows developers to concentrate on their work rather than bother about compatibility-related issues. Such a platform that integrates with the Internet would open unexplored avenues for business propagation. In response to the need for such a platform, Microsoft has developed the .NET Framework. Here, I’ll talk about the .NET vision and also about the design goals for develop-

ing effective business solutions using the .NET platform.

With references to .NET in newspapers, magazines, seminars, discussions, and talk shows, .NET seems to be everywhere. But what is .NET? So much emphasis on the new technology must have left you wondering just what .NET means and how you will be impacted by it. If despite the hullabaloo created about .NET you are still wondering what .NET is all about, this appendix seeks to answer most of your queries.

In this appendix, you will learn about the .NET vision and the design goals for using the .NET platform to develop solutions for the current business scenario.

The Vision Explained

The emergence of a multitude of technologies for developing applications, in turn, multiplied the challenges faced by the organizations to integrate these applications with the existing infrastructure. These requirements formed the prerequisite for the development of .NET. Microsoft’s .NET vision was to develop a common platform that provides a highly integrated and flexible base for developers and businesses. This vision aimed at the conglomeration of the Microsoft technologies to develop, deploy, and support multitier distributed applications.

Although the Windows DNA architecture was designed to facilitate the creation of distributed Web applications, it could not be used to create loosely coupled applications. Therefore, with a view to facilitate the creation of loosely coupled applications, the architecture was modified into .NET. In other words, .NET was

THE .NET VISION AND GOALS Appendix A 919

designed to provide a logical approach to developing flexible and scalable applications.

Some other benefits that the .NET Framework has to offer are the following:

A standards-based support for processing XML.

Support for the globalization and localization of resources.

A uniform platform that provides the services necessary to create enter- prise-class Web applications.

A URL-addressable resource that programmatically returns information to clients requesting it.

Ability to build components that efficiently manage data from multiple data sources and support disconnected scenarios.

Ability to interact with COM components, .NET Framework services, external type libraries, and many operating system services.

Ability to use the COM+ Services including transactions, object pooling, and queued components.

Ability to pass objects by value or by reference between distributed applications.

A programming interface to many of the protocols found on the network, such as HTTP, DNS, TCP, and UDP.

Control access to operations and resources based on policy and a set of configurable rules to determine which permissions to grant to code, based on the code’s domain, user, and assembly.

A rich programming framework for creating Win32 client applications.

Lower total cost of ownership by enabling powerful enterprise-class management of systems, applications, and devices.

Access to Active Directory from managed code.

To provide these benefits, the .NET Framework implements a distributed application model according to which a loosely coupled application is divided into three different layers or tiers:

Presentation layer

Business logic/application layer

Data access and storage layer

In the subsequent sections, I will discuss these layers in more detail.