Difference between revisions of "OOP Class14"
(→Parallel) |
|||
Line 61: | Line 61: | ||
</csharp> | </csharp> | ||
+ | |||
+ | <!-- | ||
==File IO== | ==File IO== | ||
Line 201: | Line 203: | ||
[[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== | ||
Revision as of 17:02, 6 May 2014
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 <csharp> long count = 200000000; short[] shorts = new short[count]; for (long i = 0; i < count; i++)
{ shorts[i] = 1; }
</pre>
Parallel.For
short[] shortsP = new short[count]; Parallel.For(0, count, i => { shortsP[i] = 1; }); </csharp> Demo http://iam.colum.edu/oop/classsource/class15/AsyncConsoleApplication.zip http://iam.colum.edu/oop/classsource/class15/WindowsFormsApplicationAsync.zipAsync
http://msdn.microsoft.com/en-us/library/hh191443.aspx <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; }</csharp>
<httpRuntime executionTimeout="1200" maxRequestLength="65536" /> </system.web></configuration> </xml>
multipart form <csharp> <form enctype="multipart/form-data" runat="server"> <tr>
<td>Select file to upload:</td> <td> <input id="myfile" type="file" runat="server"></td></tr> <tr>
<td> <input type=button id="btnUploadTheFile" value="Upload" OnServerClick="btnUploadTheFile_Click" runat="server" /> </td></tr> </form> </csharp>
Parse the multipart form and save the file msdn library. System.Web.HtmlInputFile.PostedFile Property
<csharp> void btnUploadTheFile_Click(object Source, EventArgs evArgs) {
//Path to save file string strBaseLocation = ""; if (null != myfile.PostedFile) { // Get the HTTP posted file instance (to simplify the code) HttpPostedFile postedfile = myfile.PostedFile; // Get the filename string filename = new System.IO.FileInfo(postedfile.FileName).Name; string filesize = postedfile.ContentLength.ToString(); try { myfile.PostedFile.SaveAs(strBaseLocation+filename); txtOutput.InnerHtml = "File " + strBaseLocation + filename + " uploaded successfully"; } catch (Exception e) { txtOutput.InnerHtml = "Error saving " + strBaseLocation + filename + ""+ e.ToString();
} //Do some other stuff //maybe like send an email to let admin know file was uploaded }} </csharp>
http://iam.colum.edu/oop/classsource/class14/up.aspx [up.aspx - source] [web.config - source] -->
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