--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.21005.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter10", "Chapter10\Chapter10.csproj", "{33082672-213E-4011-9D0C-0CB052B64E64}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {33082672-213E-4011-9D0C-0CB052B64E64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {33082672-213E-4011-9D0C-0CB052B64E64}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {33082672-213E-4011-9D0C-0CB052B64E64}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {33082672-213E-4011-9D0C-0CB052B64E64}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+ </startup>
+</configuration>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{33082672-213E-4011-9D0C-0CB052B64E64}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Chapter10</RootNamespace>
+ <AssemblyName>Chapter10</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </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.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chapter10
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+
+ /**
+ *
+ * Listing 10.2 Using StreamUtil to copy a web response stream to a file.
+ */
+ Console.WriteLine("Listing 10.2 Using StreamUtil to copy a web response stream to a file.");
+ WebRequest request1 = WebRequest.Create("http://gumartinm.name");
+ using (WebResponse response1 = request1.GetResponse())
+ using (Stream responseStream1 = response1.GetResponseStream())
+ using (FileStream output1 = File.Create("response.dat"))
+ {
+ StreamUtil.Copy(responseStream1, output1);
+ }
+
+ /**
+ *
+ * Listing 10.4 Copying a stream using an extension method.
+ */
+ Console.WriteLine("Listing 10.4 Copying a stream using an extension method.");
+ WebRequest request2 = WebRequest.Create("http://gumartinm.name");
+ using (WebResponse response2 = request2.GetResponse())
+ using (Stream responseStream2 = response2.GetResponseStream())
+ using (FileStream output2 = File.Create("response.dat"))
+ {
+ responseStream2.CopyToExtension(output2);
+ }
+
+ /**
+ *
+ * Listing 10.5 Extension method being called on a null reference.
+ */
+ Console.WriteLine("Listing 10.5 Extension method being called on a null reference.");
+ object y = null;
+ Console.WriteLine(y.IsNull());
+ y = new object();
+ Console.WriteLine(y.IsNull());
+
+ /**
+ *
+ * Listing 10.6 Using Enumerable.Range to print out the numbers 0 to 9.
+ */
+ Console.WriteLine("Listing 10.6 Using Enumerable.Range to print out the numbers 0 to 9.");
+ var collection1 = Enumerable.Range(0, 10);
+ foreach (var element in collection1)
+ {
+ Console.WriteLine(element);
+ }
+
+ /**
+ *
+ * Listing 10.7 Reversing a collection with the Reverse method.
+ */
+ Console.WriteLine("Listing 10.7 Reversing a collection with the Reverse method.");
+ var collection2 = Enumerable.Range(0, 10).Reverse();
+ foreach (var element in collection2)
+ {
+ Console.WriteLine(element);
+ }
+
+ /**
+ *
+ * Listing 10.8 Using the Where method with a lambda expression to find odd numbers.
+ */
+ Console.WriteLine("Listing 10.8 Using the Where method with a lambda expression to find odd numbers.");
+ var collection3 = Enumerable.Range(0, 10).Where(x => x % 2 != 0).Reverse();
+ foreach (var element in collection3)
+ {
+ Console.WriteLine(element);
+ }
+
+ /**
+ *
+ * Listing 10.9 Projection using a lambda expression and an anonymous type.
+ */
+ Console.WriteLine("Listing 10.9 Projection using a lambda expression and an anonymous type.");
+ var collection4 = Enumerable.Range(0, 10)
+ .Where(x => x % 2 != 0)
+ .Reverse()
+ .Select(x => new { Original = x, SquareRoot = Math.Sqrt(x) });
+ foreach(var element in collection4)
+ {
+ Console.WriteLine(element);
+ }
+
+ /**
+ *
+ * Listing 10.10 Ordering a sequence by two properties.
+ */
+ Console.WriteLine("Listing 10.10 Ordering a sequence by two properties.");
+ var collection5 = Enumerable.Range(-5, 11)
+ .Select(x => new { Original = x, Square = x * x })
+ .OrderBy(x => x.Square)
+ .ThenBy(x => x.Original);
+ foreach (var element in collection5)
+ {
+ Console.WriteLine(element);
+ }
+
+ // Wait for key.
+ Console.ReadKey();
+ }
+ }
+
+ public static class StreamUtil
+ {
+ const int BufferSize = 8192;
+
+ public static void Copy(Stream input, Stream output)
+ {
+ byte[] buffer = new byte[BufferSize];
+ int read;
+ while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ output.Write(buffer, 0, read);
+ }
+ }
+
+ public static byte[] ReadFully(Stream input)
+ {
+ using (MemoryStream tempStream = new MemoryStream())
+ {
+ Copy(input, tempStream);
+ return tempStream.ToArray();
+ }
+ }
+ }
+
+ public static class StreamUtilExtension
+ {
+ const int BufferSize = 8192;
+
+ public static void CopyToExtension(this Stream input, Stream output)
+ {
+ byte[] buffer = new byte[BufferSize];
+ int read;
+ while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ output.Write(buffer, 0, read);
+ }
+ }
+
+ public static byte[] ReadFully(this Stream input)
+ {
+ using (MemoryStream tempStream = new MemoryStream())
+ {
+ CopyToExtension(input, tempStream);
+ return tempStream.ToArray();
+ }
+ }
+ }
+
+ public static class NullUtil
+ {
+ public static bool IsNull(this object x)
+ {
+ return x == null;
+ }
+ }
+}
--- /dev/null
+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("Chapter10")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Chapter10")]
+[assembly: AssemblyCopyright("Copyright © 2014")]
+[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("e813db06-46dd-411c-b1a4-2c9f4b7b20e1")]
+
+// 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")]
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+ </startup>
+</configuration>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+ </startup>
+</configuration>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
+ <security>
+ <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
+ <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+</assembly>
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>gumartinm.name » index</title>
+ <link rel="stylesheet" href="/media/main.css" type="text/css" media="screen, projection">
+ <link rel="stylesheet" href="/media/main-print.css" type="text/css" media="print">
+ <!--[if IE]><link rel="stylesheet" href="/media/cache/main-ie.css?1280098410" type="text/css" media="screen, projection"><![endif]-->
+</head>
+<body>
+ <div class="container">
+ <div class="push-4 span-16">
+ <div class="push-1 span-15">
+ <h1>gumartinm.name</h1>
+ <div class="span-10 project-grid">
+ <span class="span-5" style="float: left;">
+ <h2>java</h2>
+ <ul>
+ <li>
+ <a href="https://github.com/gumartinm/JavaForFun/tree/master/Allgemeines/Threads" title="threads examples">threads</a>
+ </li>
+ </ul>
+ </span>
+
+ <span class="span-5" style="float: left;">
+ <h2>android</h2>
+ <ul>
+ <li>
+ <a href="https://github.com/gumartinm/JavaForFun/tree/master/Android/AndroidTetris" title="tetris">simple tetris for android</a>
+ </li>
+ <li>
+ <a href="https://github.com/gumartinm/JavaForFun/tree/master/Android/MobiAdsReloaded" title="mobi ads">mobi ads</a>
+ </li>
+ <li>
+ <a href="https://github.com/gumartinm/AndroidReversiForFun" title="reversi">reversi</a>
+ </li>
+ </ul>
+ </span>
+
+ <span class="span-5" style="float: left;">
+ <h2>symfony</h2>
+ <ul>
+ <li>
+ <a href="http://code.google.com/p/mobiads/" title="mobi ads">mobi ads</a>
+ </li>
+ </ul>
+ </span>
+
+ <span class="span-5" style="float: left;">
+ <h2>java spring</h2>
+ <ul>
+ <li>
+ <a href="https://github.com/gumartinm/JavaForFun/tree/master/SpringJava" title="examples with Spring: Annotations and Aspects">annotations and aspects</a>
+ </li>
+ <li>
+ <a href="https://github.com/gumartinm/SpringWebServicesForFun" title="examples with Spring Web Services">Spring Web Services</a>
+ </li>
+ <li>
+ <a href="https://github.com/gumartinm/JavaForFun/tree/master/MyBatis/MyBatis-Spring" title="examples with MyBatis-Spring">MyBatis-Spring</a>
+ </li>
+ </ul>
+
+ </span>
+
+ <span class="span-5" style="float: left;">
+ <h2>javapos</h2>
+ <ul>
+ <li>
+ <a href="https://github.com/gumartinm/JavaForFun/tree/master/JavaPOS/KeyBoardDriver" title="driver JavaPOS for keyboards. Linux implementation.">KeyBoardDriver</a>
+ </li>
+ </ul>
+ </span>
+
+ <span class="span-5" style="float: left;">
+ <h2>java mybatis</h2>
+ <ul>
+ <li>
+ <a href="https://github.com/gumartinm/JavaForFun/tree/master/MyBatis/MyBatis" title="examples with MyBatis">MyBatis</a>
+ </li>
+ </ul>
+ </span>
+
+ <span class="span-5" style="float: left;">
+ <h2>C</h2>
+ <ul>
+ <li>
+ <a href="https://github.com/gumartinm/JavaTCPFork" title="daemon to fork processes, useful under low memory conditions using Java">JavaFork</a>
+ </li>
+ </ul>
+ </span>
+
+ <span class="span-5" style="float: left;">
+ <h2>C#</h2>
+ <ul>
+ <li>
+ <a href="https://github.com/gumartinm/CSharpForFun/tree/master/CSharpInDepth" title="">C# In Depth</a>
+ </li>
+ </ul>
+ </span>
+
+
+ <p style="clear: left;"><em><span class="inactive">Light color</span> means currently no plans for further development.</em></p>
+ </div>
+
+ <div class="span-5 last">
+ <div style="border-left: 1px solid black; padding-left: 20px;">
+ <h2>contact</h2>
+ <ul>
+ <li><a href="mailto:noemail@noemail.com">e-mail</a></li>
+ <li><a href="http://blog.gumartinm.name/">blog</a></li>
+ <li><a href="https://github.com/gumartinm">github</a></li>
+ <li><a href="http://git.gumartinm.name">git</a></li>
+ </ul>
+ <p>
+ Gustavo Martin Morcuende<br>
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
--- /dev/null
+C:\Users\Gustavo\Source\Repos\CSharpForFun\CSharpInDepth\Chapter10\Chapter10\bin\Debug\Chapter10.exe.config
+C:\Users\Gustavo\Source\Repos\CSharpForFun\CSharpInDepth\Chapter10\Chapter10\bin\Debug\Chapter10.exe
+C:\Users\Gustavo\Source\Repos\CSharpForFun\CSharpInDepth\Chapter10\Chapter10\bin\Debug\Chapter10.pdb
+C:\Users\Gustavo\Source\Repos\CSharpForFun\CSharpInDepth\Chapter10\Chapter10\obj\Debug\Chapter10.csprojResolveAssemblyReference.cache
+C:\Users\Gustavo\Source\Repos\CSharpForFun\CSharpInDepth\Chapter10\Chapter10\obj\Debug\Chapter10.exe
+C:\Users\Gustavo\Source\Repos\CSharpForFun\CSharpInDepth\Chapter10\Chapter10\obj\Debug\Chapter10.pdb