Windows Systems Programming: Spring 2004

[ Home | Syllabus | Course Notes | Assignments | Search]


Final Exam 
Revision 1: May 1st (in brown)

Rules of taking this test

  • This will be a take home exam which you will have 1 week to complete. Answers must be submitted no later than midnight Tuesday May 4th.
  • You must work on your own, the only person you can ask for help is Dr. Wild.
  • This is open book, open note, open compiler (that is you can use a compiler to check your answers)
  • You can ask me questions or send e-mail.
  • You must return the test by e-mail.
  • You must sign the honor pledge and either fax or return original to me (even though you e-mail the answers).
    However, you will not get your grade until the honor pledge is turned in.

Honor Pledge: I pledge that I have neither given nor received unauthorized help in taking this exam.
You signature must be delivered to

Dr. Wild
Department of Computer Science
Old Dominion University
Norfolk, VA 23529-0162
FAX 757 6834900

Signature: __________________________________________________________

Printed Name:  __________________________________________________________

 

  1. Modify the web form found here change the form to add three buttons.

    A) Update: this will update the time displayed to the current time. This is needed because the current web form displays the current time when it is first loaded. In order to get a more recent current time, you will use this button.
    B) Start: this is to start an elapsed time timer
    C) Stop: this will stop the elapsed time timer and display the elapsed time
    Thus if the user selects the start button and 5 seconds later selects the stop button, the form will display 5 seconds.
    You must use the session object to solve this problem.
    Your answer should include the entire web application so I can install and run it.

    <%@ Page language="c#" Inherits="TimeClient" %>
    <HTML>
    	<HEAD>
    		<title>Time Client</title>
    	</HEAD>
    	<body>
    		<form id="Form1" method="post" runat="server">
    			<asp:Label id="Label1" runat="server">Web Time Client</asp:Label>
    			<br/>
    			<asp:Label id="Clock" runat="server"/>
    			<br/>
    			<asp:Label id="Elapsed" runat="server"/>
    			<br/>
    			<asp:Button Text="Update Clock Time" OnClick="OnUpdate" RunAt="server" />
    			<br/>
    			Elapsed Time: 
    			<asp:Button Text="Start" OnClick="OnStart" RunAt="server" />
    			<asp:Button Text=" Stop" OnClick="OnStop" RunAt="server" />
    
    		</form>
    	</body>
    </HTML>
    
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    
    public class TimeClient : System.Web.UI.Page
    {
    	protected System.Web.UI.WebControls.Label Clock;
    	protected System.Web.UI.WebControls.Label Elapsed;
    	protected System.Web.UI.WebControls.Label Label1;
    
    	private void Page_Load(object sender, System.EventArgs e)
    	{
    		TimeServiceByHand service = new TimeServiceByHand();
    		Clock.Text = "The time is now is " +  service.GetTime();
    	}
    
            public void OnUpdate (Object sender, EventArgs e)
    	{
    		TimeServiceByHand service = new TimeServiceByHand();
    		Clock.Text = "The time is now is " +  service.GetTime();
    	 }
    	
    	public void OnStart(Object sender, EventArgs e)
    	{
    		Session["Timer"] = DateTime.Now;
    		Elapsed.Text = "";
    	}
    
    	public void OnStop(Object sender, EventArgs e)
    	{
    		DateTime startTime = (DateTime) Session["Timer"];
    		Elapsed.Text = "Elapsed time is  " + 	(int) ((DateTime.Now -  startTime).TotalSeconds);;
    	}
    
    
    
    
    
    }
    
    1. Add three buttons (2)

    2. Add three event handlers for buttons (2)

    3. Update - sets current time using web service (2)

    4. Starts stores start time in session object (5) optional to use web service - since not in seconds

    5. Stop - accesses session object, calculates elapsed and stores on web form (5)

     

  2. Given the following XML schema definition

    <?xml version="1.0"?>
    <xsd:schema id="Guitars" xmlns=""
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="Guitars">
        <xsd:complexType>
          <xsd:choice maxOccurs="unbounded">
            <xsd:element name="Guitar">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="Make" type="xsd:string" />
                  <xsd:element name="Model" type="xsd:string" />
                  <xsd:element name="Year" type="xsd:gYear"
                    minOccurs="0" />
                  <xsd:element name="Color" type="xsd:string"
                    minOccurs="0" />
                  <xsd:element name="Neck" type="xsd:string"
                    minOccurs="0" />
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:choice>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>

    Write an XSL Transformation that will transform the information in an XML file conforming to this schema to a text file in this format

    Guitars.Guitar."elementName"::"textValue"

    where "elementName" is one of "Make, Model, Year, Color, Neck" and "textValue" is the text value of that element.

    1. //// must be consistent on quotes -5    

    2. //// must not include XML directive (output method must be "text") -3

    3. would be nice to be put separate lines (see "&#xA" below)

    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output method="text"/>
    
    <xsl:template match="/">
          <xsl:for-each select="Guitars/Guitar">
             <xsl:text>Guitars.Guitar.Make::</xsl:text>
             <xsl:value-of select="Make"/>
             <xsl:text>&#xA;</xsl:text>
             <xsl:text>Guitars.Guitar.Model::</xsl:text>
             <xsl:value-of select="Model"/>
             <xsl:text>&#xA;</xsl:text>
             <xsl:text>Guitars.Guitar.Year::</xsl:text>
             <xsl:value-of select="Year"/>
             <xsl:text>&#xA;</xsl:text>
             <xsl:text>Guitars.Guitar.Color::</xsl:text>
             <xsl:value-of select="Color"/>
             <xsl:text>&#xA;</xsl:text>
             <xsl:text>Guitars.Guitar.Neck::</xsl:text>
             <xsl:value-of select="Neck"/>
             <xsl:text>&#xA;&#xA;</xsl:text>
          </xsl:for-each>
    </xsl:template>
    
    </xsl:stylesheet>
    

     

  3. There is a difference between a well formed XML document and a valid one. Using the schema in the above question, give an example of an XML file that is

    A) not well formed and not valid //// no end or beginning tag - case differences
    B) well formed but not valid //// no make model duplicate of elements
    C) well formed and valid //// from book
    D) not well formed but valid 

    [Definition: A data object is an XML document if it is well-formed, as defined in this specification. A well-formed XML document MAY in addition be valid if it meets certain further constraints.] http://www.w3.org/TR/REC-xml/ all valid XML documents must first be well formed (-3 for reasonable attempt)

    http://www.spiderpro.com/bu/buxmlm001_val.html To be valid an XML document needs to apply to the following rules:


  4. Change the Calc web service given here to add a new method that adds three numbers at once (because you find you often have to add three numbers and you only want to make one service call). Call this new method "add3". Show the changes (only) that will be made to the "asmx" file, the "wsdl" and the client proxy code.

    //// in the asmx page you write (6 points)
    [WebMethod
            (Description="Computes the sum of three integers")]
        public int add3 (int a, int b, int c)
        {
            return a + b + c;
        }
    //// in the WSDL, changes are (2 points)
    - <s:element name="add3">
    - <s:complexType>
    - <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="a" type="s:int" /> 
      <s:element minOccurs="1" maxOccurs="1" name="b" type="s:int" /> 
      <s:element minOccurs="1" maxOccurs="1" name="c" type="s:int" /> 
      </s:sequence>
      </s:complexType>
      </s:element>
    - <s:element name="add3Response">
    - <s:complexType>
    - <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="add3Result" type="s:int" /> 
      </s:sequence>
      </s:complexType>
      </s:element>
    //// and (2 points)
    - <message name="add3SoapIn">
      <part name="parameters" element="s0:add3" /> 
      </message>
    - <message name="add3SoapOut">
      <part name="parameters" element="s0:add3Response" /> 
      </message>
    
    //// and (2 Points)
    - <operation name="add3">
      <documentation>Computes the sum of three integers</documentation> 
      <input message="s0:add3SoapIn" /> 
      <output message="s0:add3SoapOut" /> 
      </operation>
    
    //// and (2 points)
    - <operation name="add3">
      <soap:operation soapAction="http://tempuri.org/add3" style="document" /> 
    - <input>
      <soap:body use="literal" /> 
      </input>
    - <output>
      <soap:body use="literal" /> 
      </output>
      </operation>
    
    //// in the proxy code (6 points)
    /// <remarks/>
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/add3", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public int add3(int a, int b, int c) {
            object[] results = this.Invoke("add3", new object[] {
                        a,
                        b,
                        c});
            return ((int)(results[0]));
        }
        
        /// <remarks/>
        public System.IAsyncResult Beginadd3(int a, int b, int c, System.AsyncCallback callback, object asyncState) {
            return this.BeginInvoke("add3", new object[] {
                        a,
                        b,
                        c}, callback, asyncState);
        }
        
        /// <remarks/>
        public int Endadd3(System.IAsyncResult asyncResult) {
            object[] results = this.EndInvoke(asyncResult);
            return ((int)(results[0]));
        }
    
    
    
  5. Web service proxies support asynchronous requests (see web client notes).  Change the following example to use a multi-thread solution which gives the same performance in the main thread but only uses the synchronous method of requesting the web service in the secondary thread (ie. no calls to calc.BeginAdd).

    
    CalculatorWebService calc = new CalculatorWebService ();
    IAsyncResult res = calc.BeginAdd (2, 2, null, null);
       .   .   . // do something else while you wait
    //// removed alternate coding
    if (res.IsCompleted) {
         int sum = calc.EndAdd (res); }
     else {     // Try again later }

    //// clarification - the above code is in the main thread and uses asynchronous web services to 


    //// Threaded synchronous solution
    int g_result; //// global variable or data member accessible to both threads
    //// need way to pass result between threads (4)
    //// start thread
    Thread addThread = new Thread (new ThreadStart (AddFunc)); /// (3)
     .   .   . // do something else while you wait
    if (!addThread.IsAlive) { (3)
         int sum = g_result; } (2)
     else {     // Try again later }
     
    static void AddFunc ()    { (2)
    	CalculatorWebService calc = new CalculatorWebService (); (3)
    	g_result = calc.Add (2, 2); // synchronous add (3)
    } //done

     

  6. Given the "NetDraw" remoting example, list, in order, the function/method/service calls, invoked for one client to draw a single stroke and send it to the other clients (you only need to describe the sequence on one of the other clients). Only list the calls that are given here. Assume none of the other clients are doing anything.

     

    1. MyForm.::OnMouseDown (drawing client) (2)

      1. Stroke::Stroke (1)

    2. MyForm::OnMouseMove (drawing client) (2)

      1. Stroke::Add (1)

      2. Stroke::DrawLastSegment (1)

    3. MyForm::OnMouseUp (drawing client) (2)

      1. Paper::DrawStroke (remote singelton object - on server) (2)

        1. NewStroke (event) (posts event to all clients) (1)

        2. MyForm::OnNewStroke (all clients) (2)

          1. Stroke::Add (1)

          2. Stroke::Draw (1)

  7. Which of the student presentations did you find the most interesting and why?

//// graded on the number of presentations attended (+1 for an answer)


Copyright chris wild 1999-2004.
For problems or questions regarding this web contact [Dr. Wild].
Last updated: May 06, 2004.