Added tutorial projects

This commit is contained in:
2021-09-14 12:31:36 +12:00
parent aaed2e6560
commit 544ae9c070
106 changed files with 5249 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
+138
View File
@@ -0,0 +1,138 @@
namespace Tutorial_5
{
partial class CurrentConditionsDisplay
{
/// <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.label3 = new System.Windows.Forms.Label();
this.PressureLabel = new System.Windows.Forms.Label();
this.HumidityLabel = new System.Windows.Forms.Label();
this.TemperatureLabel = new System.Windows.Forms.Label();
this.RegisterButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(174, 59);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(146, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Temperature: ";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(213, 84);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(107, 25);
this.label2.TabIndex = 1;
this.label2.Text = "Humidity: ";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(213, 109);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(110, 25);
this.label3.TabIndex = 2;
this.label3.Text = "Pressure: ";
//
// PressureLabel
//
this.PressureLabel.AutoSize = true;
this.PressureLabel.Location = new System.Drawing.Point(326, 109);
this.PressureLabel.Name = "PressureLabel";
this.PressureLabel.Size = new System.Drawing.Size(110, 25);
this.PressureLabel.TabIndex = 5;
this.PressureLabel.Text = "Pressure: ";
//
// HumidityLabel
//
this.HumidityLabel.AutoSize = true;
this.HumidityLabel.Location = new System.Drawing.Point(326, 84);
this.HumidityLabel.Name = "HumidityLabel";
this.HumidityLabel.Size = new System.Drawing.Size(107, 25);
this.HumidityLabel.TabIndex = 4;
this.HumidityLabel.Text = "Humidity: ";
//
// TemperatureLabel
//
this.TemperatureLabel.AutoSize = true;
this.TemperatureLabel.Location = new System.Drawing.Point(326, 59);
this.TemperatureLabel.Name = "TemperatureLabel";
this.TemperatureLabel.Size = new System.Drawing.Size(146, 25);
this.TemperatureLabel.TabIndex = 3;
this.TemperatureLabel.Text = "Temperature: ";
//
// RegisterButton
//
this.RegisterButton.Location = new System.Drawing.Point(218, 269);
this.RegisterButton.Name = "RegisterButton";
this.RegisterButton.Size = new System.Drawing.Size(297, 42);
this.RegisterButton.TabIndex = 6;
this.RegisterButton.Text = "Register Component";
this.RegisterButton.UseVisualStyleBackColor = true;
this.RegisterButton.Click += new System.EventHandler(this.RegisterButton_Click);
//
// CurrentConditionsDisplay
//
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.RegisterButton);
this.Controls.Add(this.PressureLabel);
this.Controls.Add(this.HumidityLabel);
this.Controls.Add(this.TemperatureLabel);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "CurrentConditionsDisplay";
this.Text = "CurrentConditionsDisplay";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label PressureLabel;
private System.Windows.Forms.Label HumidityLabel;
private System.Windows.Forms.Label TemperatureLabel;
private System.Windows.Forms.Button RegisterButton;
}
}
+51
View File
@@ -0,0 +1,51 @@
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 CurrentConditionsDisplay : Form, IWeatherObserver, IDisplay
{
ISubject subject;
WeatherData weatherData;
private void RegisterButton_Click(object sender, EventArgs e)
{
subject.RegisterObserver(this);
}
double temperature = default, humidity = default, pressure = default;
public void Update(double temperature, double humidity, double pressure)
{
this.temperature = temperature;
this.humidity = humidity;
this.pressure = pressure;
Display();
}
public void UpdateOther()
{
this.temperature = weatherData.GetTemperature();
this.humidity = weatherData.GetHumidity();
this.pressure = weatherData.GetPressure();
}
public void Display()
{
TemperatureLabel.Text = temperature.ToString() + " ℃";
HumidityLabel.Text = humidity.ToString() + " %";
PressureLabel.Text = pressure.ToString() + " kPa";
}
public CurrentConditionsDisplay(ISubject subject)
{
InitializeComponent();
this.subject = subject;
}
}
}
+120
View File
@@ -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>
+245
View File
@@ -0,0 +1,245 @@
namespace Tutorial_5
{
partial class Form1
{
/// <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.TemperatureSlider = new System.Windows.Forms.TrackBar();
this.Temperature = new System.Windows.Forms.Label();
this.TemperatureLabel = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.HumidityLabel = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.HumiditySlider = new System.Windows.Forms.TrackBar();
this.label1 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.PressureLabel = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.PressureSlider = new System.Windows.Forms.TrackBar();
((System.ComponentModel.ISupportInitialize)(this.TemperatureSlider)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.HumiditySlider)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.PressureSlider)).BeginInit();
this.SuspendLayout();
//
// TemperatureSlider
//
this.TemperatureSlider.LargeChange = 10;
this.TemperatureSlider.Location = new System.Drawing.Point(153, 35);
this.TemperatureSlider.Maximum = 100;
this.TemperatureSlider.Minimum = -45;
this.TemperatureSlider.Name = "TemperatureSlider";
this.TemperatureSlider.Size = new System.Drawing.Size(562, 90);
this.TemperatureSlider.TabIndex = 0;
this.TemperatureSlider.Value = 20;
this.TemperatureSlider.ValueChanged += new System.EventHandler(this.SliderChanged);
//
// Temperature
//
this.Temperature.AutoSize = true;
this.Temperature.Location = new System.Drawing.Point(13, 35);
this.Temperature.Name = "Temperature";
this.Temperature.Size = new System.Drawing.Size(134, 25);
this.Temperature.TabIndex = 1;
this.Temperature.Text = "Temperature";
//
// TemperatureLabel
//
this.TemperatureLabel.AutoSize = true;
this.TemperatureLabel.Location = new System.Drawing.Point(721, 35);
this.TemperatureLabel.Name = "TemperatureLabel";
this.TemperatureLabel.Size = new System.Drawing.Size(59, 25);
this.TemperatureLabel.TabIndex = 2;
this.TemperatureLabel.Text = "25 ℃";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(656, 85);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(71, 25);
this.label2.TabIndex = 3;
this.label2.Text = "100 ℃";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(148, 85);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(66, 25);
this.label3.TabIndex = 4;
this.label3.Text = "-45 ℃";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(148, 178);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(49, 25);
this.label4.TabIndex = 9;
this.label4.Text = "0 %";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(656, 178);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(73, 25);
this.label5.TabIndex = 8;
this.label5.Text = "100 %";
//
// HumidityLabel
//
this.HumidityLabel.AutoSize = true;
this.HumidityLabel.Location = new System.Drawing.Point(721, 128);
this.HumidityLabel.Name = "HumidityLabel";
this.HumidityLabel.Size = new System.Drawing.Size(55, 25);
this.HumidityLabel.TabIndex = 7;
this.HumidityLabel.Text = "50%";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(13, 128);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(95, 25);
this.label7.TabIndex = 6;
this.label7.Text = "Humidity";
//
// HumiditySlider
//
this.HumiditySlider.LargeChange = 10;
this.HumiditySlider.Location = new System.Drawing.Point(153, 128);
this.HumiditySlider.Maximum = 100;
this.HumiditySlider.Name = "HumiditySlider";
this.HumiditySlider.Size = new System.Drawing.Size(562, 90);
this.HumiditySlider.TabIndex = 5;
this.HumiditySlider.Value = 20;
this.HumiditySlider.ValueChanged += new System.EventHandler(this.SliderChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(148, 274);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(91, 25);
this.label1.TabIndex = 14;
this.label1.Text = "900 kPa";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(656, 274);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(103, 25);
this.label8.TabIndex = 13;
this.label8.Text = "1100 kPa";
//
// PressureLabel
//
this.PressureLabel.AutoSize = true;
this.PressureLabel.Location = new System.Drawing.Point(721, 224);
this.PressureLabel.Name = "PressureLabel";
this.PressureLabel.Size = new System.Drawing.Size(103, 25);
this.PressureLabel.TabIndex = 12;
this.PressureLabel.Text = "1014 kPa";
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(13, 224);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(98, 25);
this.label10.TabIndex = 11;
this.label10.Text = "Pressure";
//
// PressureSlider
//
this.PressureSlider.LargeChange = 10;
this.PressureSlider.Location = new System.Drawing.Point(153, 224);
this.PressureSlider.Maximum = 1100;
this.PressureSlider.Minimum = 900;
this.PressureSlider.Name = "PressureSlider";
this.PressureSlider.Size = new System.Drawing.Size(562, 90);
this.PressureSlider.TabIndex = 10;
this.PressureSlider.Value = 1014;
this.PressureSlider.ValueChanged += new System.EventHandler(this.SliderChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1061, 548);
this.Controls.Add(this.label1);
this.Controls.Add(this.label8);
this.Controls.Add(this.PressureLabel);
this.Controls.Add(this.label10);
this.Controls.Add(this.PressureSlider);
this.Controls.Add(this.label4);
this.Controls.Add(this.label5);
this.Controls.Add(this.HumidityLabel);
this.Controls.Add(this.label7);
this.Controls.Add(this.HumiditySlider);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.TemperatureLabel);
this.Controls.Add(this.Temperature);
this.Controls.Add(this.TemperatureSlider);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load_1);
((System.ComponentModel.ISupportInitialize)(this.TemperatureSlider)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.HumiditySlider)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.PressureSlider)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TrackBar TemperatureSlider;
private System.Windows.Forms.Label Temperature;
private System.Windows.Forms.Label TemperatureLabel;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label HumidityLabel;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TrackBar HumiditySlider;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label PressureLabel;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TrackBar PressureSlider;
}
}
+43
View File
@@ -0,0 +1,43 @@
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();
}
}
}
+120
View File
@@ -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>
+13
View File
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tutorial_5
{
interface IDisplay
{
void Display();
}
}
+13
View File
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tutorial_5
{
public interface IWeatherObserver
{
void Update(double temperature, double humidity, double pressure);
}
}
+15
View File
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tutorial_5
{
public interface ISubject
{
void RegisterObserver(IWeatherObserver observer);
void DeregisterObserver(IWeatherObserver observer);
void NotifyObservers();
}
}
+23
View File
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Tutorial_5
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
+36
View File
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Tutorial 5")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Tutorial 5")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7256bbb8-354f-467c-8377-f01c4cae956e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+70
View File
@@ -0,0 +1,70 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Tutorial_5.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tutorial_5.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
+117
View File
@@ -0,0 +1,117 @@
<?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.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: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" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</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" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
+29
View File
@@ -0,0 +1,29 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Tutorial_5.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
+7
View File
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
+21
View File
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tutorial_5
{
class ThirdPartyDisplay : IWeatherObserver
{
public void Update(double temperature, double humidity, double pressure)
{
throw new NotImplementedException();
}
void Display()
{
}
}
}
+96
View File
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7256BBB8-354F-467C-8377-F01C4CAE956E}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>Tutorial_5</RootNamespace>
<AssemblyName>Tutorial 5</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CurrentConditionsDisplay.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="CurrentConditionsDisplay.Designer.cs">
<DependentUpon>CurrentConditionsDisplay.cs</DependentUpon>
</Compile>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="IDisplay.cs" />
<Compile Include="IObserver.cs" />
<Compile Include="ISubject.cs" />
<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>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file not shown.
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tutorial_5
{
class WeatherData : ISubject
{
List<IWeatherObserver> observers;
public void DeregisterObserver(IWeatherObserver observer)
{
if (observers.Contains(observer)) observers.Remove(observer);
else Console.Error.WriteLine("{0} does not exist in the observers list.", observer.ToString());
}
public void NotifyObservers()
{
double t = GetTemperature();
double h = GetHumidity();
double p = GetPressure();
foreach (var observer in observers)
{
observer.Update(t,h,p);
}
}
public void RegisterObserver(IWeatherObserver observer)
{
if (observers.Contains(observer)) Console.Error.WriteLine("{0} already exists in the observers list.", observer.ToString());
else observers.Add(observer);
}
public double GetTemperature()
{
return 0.0;
}
public double GetHumidity()
{
return 0.0;
}
public double GetPressure()
{
return 0.0;
}
void MeasurementChanged()
{
NotifyObservers();
}
public WeatherData()
{
observers = new List<IWeatherObserver>();
}
}
}