Added Tutorial 9
This commit is contained in:
@@ -13,13 +13,20 @@ namespace Tutorial_5
|
||||
public partial class CurrentConditionsDisplay : Form, IWeatherObserver, IDisplay
|
||||
{
|
||||
ISubject subject;
|
||||
WeatherData weatherData;
|
||||
//WeatherData_old weatherData;
|
||||
private void RegisterButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
subject.RegisterObserver(this);
|
||||
}
|
||||
|
||||
double temperature = default, humidity = default, pressure = default;
|
||||
|
||||
/// <summary>
|
||||
/// Push technique
|
||||
/// </summary>
|
||||
/// <param name="temperature"></param>
|
||||
/// <param name="humidity"></param>
|
||||
/// <param name="pressure"></param>
|
||||
public void Update(double temperature, double humidity, double pressure)
|
||||
{
|
||||
this.temperature = temperature;
|
||||
@@ -30,9 +37,9 @@ namespace Tutorial_5
|
||||
|
||||
public void UpdateOther()
|
||||
{
|
||||
this.temperature = weatherData.GetTemperature();
|
||||
this.humidity = weatherData.GetHumidity();
|
||||
this.pressure = weatherData.GetPressure();
|
||||
//this.temperature = weatherData.GetTemperature();
|
||||
//this.humidity = weatherData.GetHumidity();
|
||||
//this.pressure = weatherData.GetPressure();
|
||||
}
|
||||
|
||||
public void Display()
|
||||
|
||||
Generated
+98
@@ -0,0 +1,98 @@
|
||||
|
||||
namespace Tutorial_5
|
||||
{
|
||||
partial class ForecastDisplay
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.ConditionLabel = new System.Windows.Forms.Label();
|
||||
this.RegisterButton = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.label1.Location = new System.Drawing.Point(100, 9);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(96, 26);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Forecast";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(14, 106);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(104, 13);
|
||||
this.label2.TabIndex = 1;
|
||||
this.label2.Text = "Expected Conditions";
|
||||
//
|
||||
// ConditionLabel
|
||||
//
|
||||
this.ConditionLabel.AutoSize = true;
|
||||
this.ConditionLabel.Location = new System.Drawing.Point(124, 106);
|
||||
this.ConditionLabel.Name = "ConditionLabel";
|
||||
this.ConditionLabel.Size = new System.Drawing.Size(139, 13);
|
||||
this.ConditionLabel.TabIndex = 2;
|
||||
this.ConditionLabel.Text = "______________________";
|
||||
//
|
||||
// RegisterButton
|
||||
//
|
||||
this.RegisterButton.Location = new System.Drawing.Point(85, 231);
|
||||
this.RegisterButton.Name = "RegisterButton";
|
||||
this.RegisterButton.Size = new System.Drawing.Size(136, 23);
|
||||
this.RegisterButton.TabIndex = 3;
|
||||
this.RegisterButton.Text = "Register Observer";
|
||||
this.RegisterButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// ForecastDisplay
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(304, 450);
|
||||
this.Controls.Add(this.RegisterButton);
|
||||
this.Controls.Add(this.ConditionLabel);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "ForecastDisplay";
|
||||
this.Text = "ForecastDisplay";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.Label ConditionLabel;
|
||||
private System.Windows.Forms.Button RegisterButton;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Tutorial_5
|
||||
{
|
||||
public partial class ForecastDisplay : Form
|
||||
{
|
||||
public ForecastDisplay()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Tutorial_5
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
ISubject subject;
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.subject = new WeatherData();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void SliderChanged(object sender, EventArgs e)
|
||||
{
|
||||
subject.NotifyObservers();
|
||||
TemperatureLabel.Text = TemperatureSlider.Value.ToString() + " ℃";
|
||||
HumidityLabel.Text = HumiditySlider.Value.ToString() + " %";
|
||||
PressureLabel.Text = PressureSlider.Value.ToString() + " kPa";
|
||||
}
|
||||
|
||||
private void Form1_Load_1(object sender, EventArgs e)
|
||||
{
|
||||
CurrentConditionsDisplay ccd = new CurrentConditionsDisplay(this.subject);
|
||||
ccd.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace Tutorial_5
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new WeatherData());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,17 @@
|
||||
<Compile Include="CurrentConditionsDisplay.Designer.cs">
|
||||
<DependentUpon>CurrentConditionsDisplay.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Form1.cs">
|
||||
<Compile Include="ForecastDisplay.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
<Compile Include="ForecastDisplay.Designer.cs">
|
||||
<DependentUpon>ForecastDisplay.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WeatherData.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="WeatherData.Designer.cs">
|
||||
<DependentUpon>WeatherData.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="IDisplay.cs" />
|
||||
<Compile Include="IObserver.cs" />
|
||||
@@ -63,12 +69,14 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ThirdPartyDisplay.cs" />
|
||||
<Compile Include="WeatherData.cs" />
|
||||
<EmbeddedResource Include="CurrentConditionsDisplay.resx">
|
||||
<DependentUpon>CurrentConditionsDisplay.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
<EmbeddedResource Include="ForecastDisplay.resx">
|
||||
<DependentUpon>ForecastDisplay.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="WeatherData.resx">
|
||||
<DependentUpon>WeatherData.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace Tutorial_5
|
||||
{
|
||||
partial class Form1
|
||||
partial class WeatherData
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@@ -1,12 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Tutorial_5
|
||||
{
|
||||
class WeatherData : ISubject
|
||||
public partial class WeatherData : Form, ISubject
|
||||
{
|
||||
List<IWeatherObserver> observers;
|
||||
public void DeregisterObserver(IWeatherObserver observer)
|
||||
@@ -15,6 +19,9 @@ namespace Tutorial_5
|
||||
else Console.Error.WriteLine("{0} does not exist in the observers list.", observer.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 'Push' method
|
||||
/// </summary>
|
||||
public void NotifyObservers()
|
||||
{
|
||||
double t = GetTemperature();
|
||||
@@ -23,7 +30,7 @@ namespace Tutorial_5
|
||||
|
||||
foreach (var observer in observers)
|
||||
{
|
||||
observer.Update(t,h,p);
|
||||
observer.Update(t, h, p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,17 +42,17 @@ namespace Tutorial_5
|
||||
|
||||
public double GetTemperature()
|
||||
{
|
||||
return 0.0;
|
||||
return TemperatureSlider.Value;
|
||||
}
|
||||
|
||||
public double GetHumidity()
|
||||
{
|
||||
return 0.0;
|
||||
return HumiditySlider.Value;
|
||||
}
|
||||
|
||||
public double GetPressure()
|
||||
{
|
||||
return 0.0;
|
||||
return PressureSlider.Value;
|
||||
}
|
||||
|
||||
void MeasurementChanged()
|
||||
@@ -55,7 +62,33 @@ namespace Tutorial_5
|
||||
|
||||
public WeatherData()
|
||||
{
|
||||
InitializeComponent();
|
||||
observers = new List<IWeatherObserver>();
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Analagous to the Update() method in Excercise 1
|
||||
/// Pushes data to observers via Subject.NotifyObservers
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SliderChanged(object sender, EventArgs e)
|
||||
{
|
||||
NotifyObservers();
|
||||
TemperatureLabel.Text = TemperatureSlider.Value.ToString() + " ℃";
|
||||
HumidityLabel.Text = HumiditySlider.Value.ToString() + " %";
|
||||
PressureLabel.Text = PressureSlider.Value.ToString() + " kPa";
|
||||
}
|
||||
|
||||
private void Form1_Load_1(object sender, EventArgs e)
|
||||
{
|
||||
CurrentConditionsDisplay ccd = new CurrentConditionsDisplay(this);
|
||||
ccd.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
Reference in New Issue
Block a user