Difference between revisions of "OOP Class14"
esse quam videri
(20 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | [[Category: | + | [[Category:IAM Classes]] |
− | == | + | ==Parallel== |
+ | http://msdn.microsoft.com/en-us/library/dd460713(v=vs.110).aspx | ||
+ | |||
+ | samples: http://code.msdn.microsoft.com/windowsdesktop/Samples-for-Parallel-b4b76364 | ||
+ | |||
+ | for | ||
+ | <syntaxhighlight lang="csharp"> | ||
+ | int count = 20; | ||
+ | int[] ints = new int[count]; | ||
+ | for (int i = 0; i < count; i++) | ||
+ | { | ||
+ | shorts[i] = 1; | ||
+ | } | ||
+ | |||
+ | //sample Parallel.For | ||
+ | int[] intP = new int[count]; | ||
+ | Parallel.For(0, count, i => | ||
+ | { | ||
+ | intP[i] = 1; | ||
+ | }); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Demo | ||
+ | |||
+ | http://iam.colum.edu/oop/classsource/class15/AsyncConsoleApplication.zip | ||
+ | |||
+ | http://iam.colum.edu/oop/classsource/class15/WindowsFormsApplicationAsync.zip | ||
+ | |||
+ | ==Async== | ||
+ | http://msdn.microsoft.com/en-us/library/hh191443.aspx | ||
+ | <syntaxhighlight lang="csharp"> | ||
+ | private void buttonBlock_Click(object sender, EventArgs e) | ||
+ | { | ||
+ | textBox1.Text = DoLongCount(); | ||
+ | } | ||
+ | |||
+ | //Async call to async method | ||
+ | private async void buttonAsync_Click(object sender, EventArgs e) | ||
+ | { | ||
+ | textBox1.Text = await DoLongAsyncCount(); | ||
+ | } | ||
+ | |||
+ | private string DoLongCount() | ||
+ | { | ||
+ | System.Threading.Thread.Sleep(1000); | ||
+ | Count++; | ||
+ | return "count is " + Count; | ||
+ | } | ||
+ | |||
+ | //Async Task | ||
+ | private async Task<string> DoLongAsyncCount() | ||
+ | { | ||
+ | await Task.Delay(1000); | ||
+ | Count++; | ||
+ | return "count is " + Count; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | <!-- | ||
+ | ==File IO== | ||
+ | |||
+ | ===write file=== | ||
+ | <syntaxhighlight lang="csharp"> string fileName = "test.txt"; | ||
+ | string folderPath = "c:\\user\\"; | ||
+ | |||
+ | FileStream fs; | ||
+ | |||
+ | //Make sure the the File exists if not create it if so open it | ||
+ | if (!(File.Exists(folderPath + fileName))) | ||
+ | { | ||
+ | fs = File.Create(folderPath + fileName); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | fs = new FileStream( folderPath + fileName , FileMode.Open, FileAccess.ReadWrite ); | ||
+ | } | ||
+ | |||
+ | StreamWriter sw = new StreamWriter(fs); //use streamwriter to write to file | ||
+ | |||
+ | sw.Write("Hello World!!!"); | ||
+ | sw.Close(); //close writer | ||
+ | fs.Close(); //close file stream</syntaxhighlight> | ||
+ | |||
+ | http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/hellowrite.cs | ||
+ | |||
+ | ===read file=== | ||
+ | <syntaxhighlight lang="csharp"> StreamReader sr = new StreamReader(fs); | ||
+ | while( sr.Peek() > -1 ) | ||
+ | { | ||
+ | Console.WriteLine(sr.ReadLine()); | ||
+ | } | ||
+ | sr.Close();</syntaxhighlight> | ||
+ | |||
+ | http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/echoFile.cs | ||
+ | |||
+ | ===File Counter=== | ||
+ | |||
+ | http://iam.colum.edu/oop/classsource/class14/hitCounter.aspx | ||
+ | [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/hitCounter.aspx - source]] | ||
===Send Mail=== | ===Send Mail=== | ||
− | <csharp><% @Page Language="C#" %> | + | <syntaxhighlight lang="csharp"><% @Page Language="C#" %> |
<% @Import Namespace="System.Web.Mail" %> | <% @Import Namespace="System.Web.Mail" %> | ||
<% | <% | ||
Line 17: | Line 116: | ||
SmtpMail.SmtpServer = "localhost"; | SmtpMail.SmtpServer = "localhost"; | ||
SmtpMail.Send(strFrom, strTo, strSubject, strBody); | SmtpMail.Send(strFrom, strTo, strSubject, strBody); | ||
− | %></ | + | %></syntaxhighlight> |
http://iam.colum.edu/oop/classsource/class14/mail.aspx | http://iam.colum.edu/oop/classsource/class14/mail.aspx | ||
[[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/mail.aspx -source]] | [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/mail.aspx -source]] | ||
Line 41: | Line 140: | ||
enableVersionHeader="[true|false]" - outputs X-AspNet-Version header with each request | enableVersionHeader="[true|false]" - outputs X-AspNet-Version header with each request | ||
--> | --> | ||
+ | <!-- | ||
<httpRuntime | <httpRuntime | ||
executionTimeout="1200" | executionTimeout="1200" | ||
Line 50: | Line 150: | ||
multipart form | multipart form | ||
− | <csharp> | + | <syntaxhighlight lang="csharp"> |
<form enctype="multipart/form-data" runat="server"> | <form enctype="multipart/form-data" runat="server"> | ||
<tr> | <tr> | ||
Line 64: | Line 164: | ||
</tr> | </tr> | ||
</form> | </form> | ||
− | </ | + | </syntaxhighlight> |
Parse the multipart form and save the file msdn library. System.Web.HtmlInputFile.PostedFile Property | Parse the multipart form and save the file msdn library. System.Web.HtmlInputFile.PostedFile Property | ||
− | <csharp> | + | <syntaxhighlight lang="csharp"> |
void btnUploadTheFile_Click(object Source, EventArgs evArgs) | void btnUploadTheFile_Click(object Source, EventArgs evArgs) | ||
{ | { | ||
//Path to save file | //Path to save file | ||
− | string strBaseLocation = " | + | string strBaseLocation = ""; |
if (null != myfile.PostedFile) | if (null != myfile.PostedFile) | ||
Line 97: | Line 197: | ||
} | } | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
http://iam.colum.edu/oop/classsource/class14/up.aspx | http://iam.colum.edu/oop/classsource/class14/up.aspx | ||
[[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/up.aspx up.aspx - source]] | [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/up.aspx up.aspx - source]] | ||
[[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/web.config web.config - source]] | [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/web.config web.config - source]] | ||
− | + | --> | |
==Final Review== | ==Final Review== | ||
− | + | [[OOP Final Review]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | *Be very familiar with c# syntax | |
− | + | **Basic object types (int, bool, string) | |
− | + | **Conditional and Branching statements | |
+ | **Arrays and Generics ie List | ||
+ | *Understand Classes and Inheritance. | ||
+ | *Use some advanced class features such as abstract classes and virtual methods that are overridden | ||
− | + | *Understand class relationships | |
+ | **Is A | ||
+ | **Has A | ||
+ | **Uses A | ||
+ | *Understand Encapsulation, Abstraction and Polymorphism | ||
+ | **Abstraction | ||
+ | :Each class should abstract its behavior in order to increase usability, reuse, and organization. | ||
+ | **Encapsulation | ||
+ | :Each class should contain all of the properties and methods it needs. It should only expose what is necessary to outside classes. | ||
+ | **Polymorphism | ||
+ | :many forms, same code interface but interchangeable classes | ||
+ | *Be able to read and create UML Diagrams | ||
+ | *Be able to recognize and use simple design patters | ||
− | + | The final will be consist of two sections the writtens section and the practical section. The practical section will be open everything excpet open mouth (yes open note open book open web). You will not be ablt to use any of theese resources during the written section. |
Latest revision as of 16:32, 10 June 2019
Parallel
http://msdn.microsoft.com/en-us/library/dd460713(v=vs.110).aspx
samples: http://code.msdn.microsoft.com/windowsdesktop/Samples-for-Parallel-b4b76364
for
int count = 20;
int[] ints = new int[count];
for (int i = 0; i < count; i++)
{
shorts[i] = 1;
}
//sample Parallel.For
int[] intP = new int[count];
Parallel.For(0, count, i =>
{
intP[i] = 1;
});
Demo
http://iam.colum.edu/oop/classsource/class15/AsyncConsoleApplication.zip
http://iam.colum.edu/oop/classsource/class15/WindowsFormsApplicationAsync.zip
Async
http://msdn.microsoft.com/en-us/library/hh191443.aspx
private void buttonBlock_Click(object sender, EventArgs e)
{
textBox1.Text = DoLongCount();
}
//Async call to async method
private async void buttonAsync_Click(object sender, EventArgs e)
{
textBox1.Text = await DoLongAsyncCount();
}
private string DoLongCount()
{
System.Threading.Thread.Sleep(1000);
Count++;
return "count is " + Count;
}
//Async Task
private async Task<string> DoLongAsyncCount()
{
await Task.Delay(1000);
Count++;
return "count is " + Count;
}
Final Review
- Be very familiar with c# syntax
- Basic object types (int, bool, string)
- Conditional and Branching statements
- Arrays and Generics ie List
- Understand Classes and Inheritance.
- Use some advanced class features such as abstract classes and virtual methods that are overridden
- Understand class relationships
- Is A
- Has A
- Uses A
- Understand Encapsulation, Abstraction and Polymorphism
- Abstraction
- Each class should abstract its behavior in order to increase usability, reuse, and organization.
- Encapsulation
- Each class should contain all of the properties and methods it needs. It should only expose what is necessary to outside classes.
- Polymorphism
- many forms, same code interface but interchangeable classes
- Be able to read and create UML Diagrams
- Be able to recognize and use simple design patters
The final will be consist of two sections the writtens section and the practical section. The practical section will be open everything excpet open mouth (yes open note open book open web). You will not be ablt to use any of theese resources during the written section.