Browse code

move to .net 4.5 and fixed cookies problem

ksemenenko authored on 10/07/2015 20:42:46
Showing 17 changed files
... ...
@@ -1,6 +1,8 @@
1 1
 
2
-Microsoft Visual Studio Solution File, Format Version 10.00
3
-# Visual Studio 2008
2
+Microsoft Visual Studio Solution File, Format Version 12.00
3
+# Visual Studio 2013
4
+VisualStudioVersion = 12.0.31101.0
5
+MinimumVisualStudioVersion = 10.0.40219.1
4 6
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatterBotAPI", "ChatterBotAPI\ChatterBotAPI.csproj", "{2E624962-F155-432C-A90A-E1CE75DEE9EA}"
5 7
 EndProject
6 8
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatterBotAPITest", "ChatterBotAPITest\ChatterBotAPITest.csproj", "{DA59F247-C17B-4A92-BB03-CB458C6916F0}"
... ...
@@ -17,14 +19,17 @@ Global
17 19
 		{2E624962-F155-432C-A90A-E1CE75DEE9EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 20
 		{2E624962-F155-432C-A90A-E1CE75DEE9EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 21
 		{2E624962-F155-432C-A90A-E1CE75DEE9EA}.Release|Any CPU.Build.0 = Release|Any CPU
20
-		{4D5C5614-9C76-4464-AB6E-A4349784F123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21
-		{4D5C5614-9C76-4464-AB6E-A4349784F123}.Debug|Any CPU.Build.0 = Debug|Any CPU
22
-		{4D5C5614-9C76-4464-AB6E-A4349784F123}.Release|Any CPU.ActiveCfg = Release|Any CPU
23
-		{4D5C5614-9C76-4464-AB6E-A4349784F123}.Release|Any CPU.Build.0 = Release|Any CPU
24 22
 		{DA59F247-C17B-4A92-BB03-CB458C6916F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 23
 		{DA59F247-C17B-4A92-BB03-CB458C6916F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 24
 		{DA59F247-C17B-4A92-BB03-CB458C6916F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 25
 		{DA59F247-C17B-4A92-BB03-CB458C6916F0}.Release|Any CPU.Build.0 = Release|Any CPU
26
+		{4D5C5614-9C76-4464-AB6E-A4349784F123}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27
+		{4D5C5614-9C76-4464-AB6E-A4349784F123}.Debug|Any CPU.Build.0 = Debug|Any CPU
28
+		{4D5C5614-9C76-4464-AB6E-A4349784F123}.Release|Any CPU.ActiveCfg = Release|Any CPU
29
+		{4D5C5614-9C76-4464-AB6E-A4349784F123}.Release|Any CPU.Build.0 = Release|Any CPU
30
+	EndGlobalSection
31
+	GlobalSection(SolutionProperties) = preSolution
32
+		HideSolutionNode = FALSE
28 33
 	EndGlobalSection
29 34
 	GlobalSection(MonoDevelopProperties) = preSolution
30 35
 		StartupItem = ChatterBotAPITestVB\ChatterBotAPITestVB.vbproj
... ...
@@ -1,6 +1,4 @@
1
-using System;
2
-
3
-/*
1
+ /*
4 2
     ChatterBotAPI
5 3
     Copyright (C) 2011 pierredavidbelanger@gmail.com
6 4
  
... ...
@@ -17,10 +15,11 @@ using System;
17 15
     You should have received a copy of the GNU Lesser General Public License
18 16
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 17
 */
20
-namespace ChatterBotAPI {
21
-	
22
-	public interface ChatterBot {
23
-		
24
-		ChatterBotSession CreateSession();
25
-	}
18
+
19
+namespace ChatterBotAPI
20
+{
21
+    public interface ChatterBot
22
+    {
23
+        ChatterBotSession CreateSession();
24
+    }
26 25
 }
27 26
\ No newline at end of file
... ...
@@ -1,5 +1,5 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3
   <PropertyGroup>
4 4
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 5
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
... ...
@@ -9,7 +9,28 @@
9 9
     <OutputType>Library</OutputType>
10 10
     <RootNamespace>ChatterBotAPI</RootNamespace>
11 11
     <AssemblyName>ChatterBotAPI</AssemblyName>
12
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
12
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13
+    <FileUpgradeFlags>
14
+    </FileUpgradeFlags>
15
+    <UpgradeBackupLocation>
16
+    </UpgradeBackupLocation>
17
+    <OldToolsVersion>3.5</OldToolsVersion>
18
+    <TargetFrameworkProfile />
19
+    <PublishUrl>publish\</PublishUrl>
20
+    <Install>true</Install>
21
+    <InstallFrom>Disk</InstallFrom>
22
+    <UpdateEnabled>false</UpdateEnabled>
23
+    <UpdateMode>Foreground</UpdateMode>
24
+    <UpdateInterval>7</UpdateInterval>
25
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
26
+    <UpdatePeriodically>false</UpdatePeriodically>
27
+    <UpdateRequired>false</UpdateRequired>
28
+    <MapFileExtensions>true</MapFileExtensions>
29
+    <ApplicationRevision>0</ApplicationRevision>
30
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
31
+    <IsWebBootstrapper>false</IsWebBootstrapper>
32
+    <UseApplicationTrust>false</UseApplicationTrust>
33
+    <BootstrapperEnabled>true</BootstrapperEnabled>
13 34
   </PropertyGroup>
14 35
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15 36
     <DebugSymbols>true</DebugSymbols>
... ...
@@ -20,6 +41,7 @@
20 41
     <ErrorReport>prompt</ErrorReport>
21 42
     <WarningLevel>4</WarningLevel>
22 43
     <ConsolePause>false</ConsolePause>
44
+    <Prefer32Bit>false</Prefer32Bit>
23 45
   </PropertyGroup>
24 46
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25 47
     <DebugType>none</DebugType>
... ...
@@ -28,10 +50,20 @@
28 50
     <ErrorReport>prompt</ErrorReport>
29 51
     <WarningLevel>4</WarningLevel>
30 52
     <ConsolePause>false</ConsolePause>
53
+    <Prefer32Bit>false</Prefer32Bit>
31 54
   </PropertyGroup>
32 55
   <ItemGroup>
33 56
     <Reference Include="System" />
34
-    <Reference Include="System.Web" />
57
+    <Reference Include="System.Net.Http" />
58
+    <Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
59
+      <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
60
+      <Private>True</Private>
61
+    </Reference>
62
+    <Reference Include="System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
63
+      <HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
64
+      <Private>True</Private>
65
+    </Reference>
66
+    <Reference Include="System.Net.Http.WebRequest" />
35 67
     <Reference Include="System.Xml" />
36 68
   </ItemGroup>
37 69
   <ItemGroup>
... ...
@@ -45,5 +77,25 @@
45 77
     <Compile Include="Utils.cs" />
46 78
     <Compile Include="Pandorabots.cs" />
47 79
   </ItemGroup>
80
+  <ItemGroup>
81
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
82
+      <Visible>False</Visible>
83
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
84
+      <Install>false</Install>
85
+    </BootstrapperPackage>
86
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
87
+      <Visible>False</Visible>
88
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
89
+      <Install>true</Install>
90
+    </BootstrapperPackage>
91
+  </ItemGroup>
92
+  <ItemGroup>
93
+    <None Include="packages.config" />
94
+  </ItemGroup>
48 95
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
96
+  <Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
97
+  <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
98
+    <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
99
+    <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
100
+  </Target>
49 101
 </Project>
50 102
\ No newline at end of file
... ...
@@ -17,25 +17,29 @@ using System;
17 17
     You should have received a copy of the GNU Lesser General Public License
18 18
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 19
 */
20
-namespace ChatterBotAPI {
21
-	
22
-	public class ChatterBotFactory {
23
-		
24
-		public ChatterBot Create(ChatterBotType type) {
25
-			return Create(type, null);
26
-		}
27 20
 
28
-		public ChatterBot Create(ChatterBotType type, object arg) {
29
-			switch (type) {
30
-			case ChatterBotType.CLEVERBOT:
31
-				return new Cleverbot("http://www.cleverbot.com/webservicemin", 26);
32
-			case ChatterBotType.JABBERWACKY:
33
-				return new Cleverbot("http://jabberwacky.com/webservicemin", 20);
34
-			case ChatterBotType.PANDORABOTS:
35
-				if (arg == null) throw new ApplicationException("PANDORABOTS needs a botid arg");
36
-				return new Pandorabots(arg.ToString());
37
-			}
38
-			return null;
39
-		}
40
-	}
21
+namespace ChatterBotAPI
22
+{
23
+    public class ChatterBotFactory
24
+    {
25
+        public ChatterBot Create(ChatterBotType type)
26
+        {
27
+            return Create(type, null);
28
+        }
29
+
30
+        public ChatterBot Create(ChatterBotType type, object arg)
31
+        {
32
+            switch (type)
33
+            {
34
+                case ChatterBotType.CLEVERBOT:
35
+                    return new Cleverbot("http://www.cleverbot.com/", "http://www.cleverbot.com/webservicemin", 26);
36
+                case ChatterBotType.JABBERWACKY:
37
+                    return new Cleverbot("http://jabberwacky.com", "http://jabberwacky.com/webservicemin", 20);
38
+                case ChatterBotType.PANDORABOTS:
39
+                    if (arg == null) throw new ApplicationException("PANDORABOTS needs a botid arg");
40
+                    return new Pandorabots(arg.ToString());
41
+            }
42
+            return null;
43
+        }
44
+    }
41 45
 }
42 46
\ No newline at end of file
... ...
@@ -1,6 +1,4 @@
1
-using System;
2
-
3
-/*
1
+ /*
4 2
     ChatterBotAPI
5 3
     Copyright (C) 2011 pierredavidbelanger@gmail.com
6 4
  
... ...
@@ -17,12 +15,12 @@ using System;
17 15
     You should have received a copy of the GNU Lesser General Public License
18 16
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 17
 */
20
-namespace ChatterBotAPI {
21
-	
22
-	public interface ChatterBotSession {
23
-		
24
-		ChatterBotThought Think(ChatterBotThought thought);
25
-		
26
-		string Think(string text);
27
-	}
18
+
19
+namespace ChatterBotAPI
20
+{
21
+    public interface ChatterBotSession
22
+    {
23
+        ChatterBotThought Think(ChatterBotThought thought);
24
+        string Think(string text);
25
+    }
28 26
 }
29 27
\ No newline at end of file
... ...
@@ -1,6 +1,4 @@
1
-using System;
2
-
3
-/*
1
+ /*
4 2
     ChatterBotAPI
5 3
     Copyright (C) 2011 pierredavidbelanger@gmail.com
6 4
  
... ...
@@ -17,12 +15,12 @@ using System;
17 15
     You should have received a copy of the GNU Lesser General Public License
18 16
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 17
 */
20
-namespace ChatterBotAPI {
21
-	
22
-	public class ChatterBotThought {
23
-		
24
-		public string[] Emotions { get; set; }
25
-		
26
-		public string Text { get; set; }
27
-	}
18
+
19
+namespace ChatterBotAPI
20
+{
21
+    public class ChatterBotThought
22
+    {
23
+        public string[] Emotions { get; set; }
24
+        public string Text { get; set; }
25
+    }
28 26
 }
29 27
\ No newline at end of file
... ...
@@ -1,6 +1,4 @@
1
-using System;
2
-
3
-/*
1
+ /*
4 2
     ChatterBotAPI
5 3
     Copyright (C) 2011 pierredavidbelanger@gmail.com
6 4
  
... ...
@@ -17,11 +15,13 @@ using System;
17 15
     You should have received a copy of the GNU Lesser General Public License
18 16
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 17
 */
20
-namespace ChatterBotAPI {
21
-	
22
-	public enum ChatterBotType {
23
-		CLEVERBOT,
24
-		JABBERWACKY,
25
-		PANDORABOTS
26
-	}
18
+
19
+namespace ChatterBotAPI
20
+{
21
+    public enum ChatterBotType
22
+    {
23
+        CLEVERBOT,
24
+        JABBERWACKY,
25
+        PANDORABOTS
26
+    }
27 27
 }
28 28
\ No newline at end of file
... ...
@@ -1,6 +1,5 @@
1
-using System;
2
-
3 1
 using System.Collections.Generic;
2
+using System.Net.Http;
4 3
 
5 4
 /*
6 5
     ChatterBotAPI
... ...
@@ -19,85 +18,98 @@ using System.Collections.Generic;
19 18
     You should have received a copy of the GNU Lesser General Public License
20 19
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 20
 */
22
-namespace ChatterBotAPI {
23
-	
24
-	class Cleverbot: ChatterBot {
25
-		private readonly string url;
26
-		private readonly int endIndex;
27
-		
28
-		public Cleverbot(string url, int endIndex) {
29
-			this.url = url;
30
-			this.endIndex = endIndex;
31
-		}
32
-		
33
-		public ChatterBotSession CreateSession() {
34
-			return new CleverbotSession(url, endIndex);
35
-		}
36
-	}
37
-	
38
-	class CleverbotSession: ChatterBotSession {
39
-		private readonly string url;
40
-		private readonly int endIndex;
41
-		private readonly IDictionary<string, string> vars;
42
-		
43
-		public CleverbotSession(string url, int endIndex) {
44
-			this.url = url;
45
-			this.endIndex = endIndex;
46
-			vars = new Dictionary<string, string>();
47
-			vars["start"] = "y";
48
-			vars["icognoid"] = "wsf";
49
-			vars["fno"] = "0";
50
-			vars["sub"] = "Say";
51
-			vars["islearning"] = "1";
52
-			vars["cleanslate"] = "false";
53
-		}
54
-		
55
-		public ChatterBotThought Think(ChatterBotThought thought) {
56
-			vars["stimulus"] = thought.Text;
57
-			
58
-			string formData = Utils.ParametersToWWWFormURLEncoded(vars);
59
-			string formDataToDigest = formData.Substring(9, endIndex);
60
-			string formDataDigest = Utils.MD5(formDataToDigest);
61
-			vars["icognocheck"] = formDataDigest;
62
-			
63
-			string response = Utils.Post(url, vars);
64
-			
65
-			string[] responseValues = response.Split('\r');
66
-			
67
-			//vars[""] = Utils.StringAtIndex(responseValues, 0); ??
68
-			vars["sessionid"] = Utils.StringAtIndex(responseValues, 1);
69
-			vars["logurl"] = Utils.StringAtIndex(responseValues, 2);
70
-			vars["vText8"] = Utils.StringAtIndex(responseValues, 3);
71
-			vars["vText7"] = Utils.StringAtIndex(responseValues, 4);
72
-			vars["vText6"] = Utils.StringAtIndex(responseValues, 5);
73
-			vars["vText5"] = Utils.StringAtIndex(responseValues, 6);
74
-			vars["vText4"] = Utils.StringAtIndex(responseValues, 7);
75
-			vars["vText3"] = Utils.StringAtIndex(responseValues, 8);
76
-			vars["vText2"] = Utils.StringAtIndex(responseValues, 9);
77
-			vars["prevref"] = Utils.StringAtIndex(responseValues, 10);
78
-			//vars[""] = Utils.StringAtIndex(responseValues, 11); ??
79
-			vars["emotionalhistory"] = Utils.StringAtIndex(responseValues, 12);
80
-			vars["ttsLocMP3"] = Utils.StringAtIndex(responseValues, 13);
81
-			vars["ttsLocTXT"] = Utils.StringAtIndex(responseValues, 14);
82
-			vars["ttsLocTXT3"] = Utils.StringAtIndex(responseValues, 15);
83
-			vars["ttsText"] = Utils.StringAtIndex(responseValues, 16);
84
-			vars["lineRef"] = Utils.StringAtIndex(responseValues, 17);
85
-			vars["lineURL"] = Utils.StringAtIndex(responseValues, 18);
86
-			vars["linePOST"] = Utils.StringAtIndex(responseValues, 19);
87
-			vars["lineChoices"] = Utils.StringAtIndex(responseValues, 20);
88
-			vars["lineChoicesAbbrev"] = Utils.StringAtIndex(responseValues, 21);
89
-			vars["typingData"] = Utils.StringAtIndex(responseValues, 22);
90
-			vars["divert"] = Utils.StringAtIndex(responseValues, 23);
91
-			
92
-			ChatterBotThought responseThought = new ChatterBotThought();
93
-			
94
-			responseThought.Text = Utils.StringAtIndex(responseValues, 16);
95
-			
96
-			return responseThought;
97
-		}
98
-		
99
-		public string Think(string text) {
100
-			return Think(new ChatterBotThought() { Text = text }).Text;
101
-		}
102
-	}
21
+
22
+namespace ChatterBotAPI
23
+{
24
+    internal class Cleverbot : ChatterBot
25
+    {
26
+        private readonly string baseUrl;
27
+        private readonly int endIndex;
28
+        private readonly string url;
29
+
30
+        public Cleverbot(string baseUrl, string url, int endIndex)
31
+        {
32
+            this.baseUrl = baseUrl;
33
+            this.url = url;
34
+            this.endIndex = endIndex;
35
+        }
36
+
37
+        public ChatterBotSession CreateSession()
38
+        {
39
+            return new CleverbotSession(baseUrl, url, endIndex);
40
+        }
41
+    }
42
+
43
+    internal class CleverbotSession : ChatterBotSession
44
+    {
45
+        private readonly string baseUrl;
46
+        private readonly int endIndex;
47
+        private readonly string url;
48
+        private readonly HttpClient client;
49
+        private readonly IDictionary<string, string> vars;
50
+
51
+        public CleverbotSession(string baseUrl, string url, int endIndex)
52
+        {
53
+            this.url = url;
54
+            this.endIndex = endIndex;
55
+            client = Utils.GetHttpClient(baseUrl);
56
+            vars = new Dictionary<string, string>();
57
+            vars["start"] = "y";
58
+            vars["icognoid"] = "wsf";
59
+            vars["fno"] = "0";
60
+            vars["sub"] = "Say";
61
+            vars["islearning"] = "1";
62
+            vars["cleanslate"] = "false";
63
+        }
64
+
65
+        public ChatterBotThought Think(ChatterBotThought thought)
66
+        {
67
+            vars["stimulus"] = thought.Text;
68
+
69
+            var formData = Utils.ParametersToWWWFormURLEncoded(vars);
70
+            var formDataToDigest = formData.Substring(9, endIndex);
71
+            var formDataDigest = Utils.CalculateMD5Hash(formDataToDigest);
72
+            vars["icognocheck"] = formDataDigest;
73
+
74
+            var response = Utils.Post(client, url, vars);
75
+
76
+            var responseValues = response.Split('\r');
77
+
78
+            //vars[""] = Utils.StringAtIndex(responseValues, 0); ??
79
+            vars["sessionid"] = Utils.StringAtIndex(responseValues, 1);
80
+            vars["logurl"] = Utils.StringAtIndex(responseValues, 2);
81
+            vars["vText8"] = Utils.StringAtIndex(responseValues, 3);
82
+            vars["vText7"] = Utils.StringAtIndex(responseValues, 4);
83
+            vars["vText6"] = Utils.StringAtIndex(responseValues, 5);
84
+            vars["vText5"] = Utils.StringAtIndex(responseValues, 6);
85
+            vars["vText4"] = Utils.StringAtIndex(responseValues, 7);
86
+            vars["vText3"] = Utils.StringAtIndex(responseValues, 8);
87
+            vars["vText2"] = Utils.StringAtIndex(responseValues, 9);
88
+            vars["prevref"] = Utils.StringAtIndex(responseValues, 10);
89
+            //vars[""] = Utils.StringAtIndex(responseValues, 11); ??
90
+            vars["emotionalhistory"] = Utils.StringAtIndex(responseValues, 12);
91
+            vars["ttsLocMP3"] = Utils.StringAtIndex(responseValues, 13);
92
+            vars["ttsLocTXT"] = Utils.StringAtIndex(responseValues, 14);
93
+            vars["ttsLocTXT3"] = Utils.StringAtIndex(responseValues, 15);
94
+            vars["ttsText"] = Utils.StringAtIndex(responseValues, 16);
95
+            vars["lineRef"] = Utils.StringAtIndex(responseValues, 17);
96
+            vars["lineURL"] = Utils.StringAtIndex(responseValues, 18);
97
+            vars["linePOST"] = Utils.StringAtIndex(responseValues, 19);
98
+            vars["lineChoices"] = Utils.StringAtIndex(responseValues, 20);
99
+            vars["lineChoicesAbbrev"] = Utils.StringAtIndex(responseValues, 21);
100
+            vars["typingData"] = Utils.StringAtIndex(responseValues, 22);
101
+            vars["divert"] = Utils.StringAtIndex(responseValues, 23);
102
+
103
+            var responseThought = new ChatterBotThought();
104
+
105
+            responseThought.Text = Utils.StringAtIndex(responseValues, 16);
106
+
107
+            return responseThought;
108
+        }
109
+
110
+        public string Think(string text)
111
+        {
112
+            return Think(new ChatterBotThought {Text = text}).Text;
113
+        }
114
+    }
103 115
 }
104 116
\ No newline at end of file
... ...
@@ -1,6 +1,6 @@
1 1
 using System;
2
-
3 2
 using System.Collections.Generic;
3
+using System.Net.Http;
4 4
 
5 5
 /*
6 6
     ChatterBotAPI
... ...
@@ -19,42 +19,52 @@ using System.Collections.Generic;
19 19
     You should have received a copy of the GNU Lesser General Public License
20 20
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 21
 */
22
-namespace ChatterBotAPI {
23
-	
24
-	class Pandorabots: ChatterBot {
25
-		private readonly string botid;
26
-		
27
-		public Pandorabots(string botid) {
28
-			this.botid = botid;
29
-		}
30
-		
31
-		public ChatterBotSession CreateSession() {
32
-			return new PandorabotsSession(botid);
33
-		}
34
-	}
35
-	
36
-	class PandorabotsSession: ChatterBotSession {
37
-		private readonly IDictionary<string, string> vars;
38
-		
39
-		public PandorabotsSession(string botid) {
40
-			vars = new Dictionary<string, string>();
41
-			vars["botid"] = botid;
42
-			vars["custid"] = Guid.NewGuid().ToString();
43
-		}
44
-		
45
-		public ChatterBotThought Think(ChatterBotThought thought) {
46
-			vars["input"] = thought.Text;
47
-			
48
-			string response = Utils.Post("http://www.pandorabots.com/pandora/talk-xml", vars);
49
-			
50
-			ChatterBotThought responseThought = new ChatterBotThought();
51
-			responseThought.Text = Utils.XPathSearch(response, "//result/that/text()");
52
-			
53
-			return responseThought;
54
-		}
55
-		
56
-		public string Think(string text) {
57
-			return Think(new ChatterBotThought() { Text = text }).Text;
58
-		}
59
-	}
22
+
23
+namespace ChatterBotAPI
24
+{
25
+    internal class Pandorabots : ChatterBot
26
+    {
27
+        private readonly string botid;
28
+
29
+        public Pandorabots(string botid)
30
+        {
31
+            this.botid = botid;
32
+        }
33
+
34
+        public ChatterBotSession CreateSession()
35
+        {
36
+            return new PandorabotsSession(botid);
37
+        }
38
+    }
39
+
40
+    internal class PandorabotsSession : ChatterBotSession
41
+    {
42
+        private readonly IDictionary<string, string> vars;
43
+        private readonly HttpClient client;
44
+
45
+        public PandorabotsSession(string botid)
46
+        {
47
+            vars = new Dictionary<string, string>();
48
+            vars["botid"] = botid;
49
+            vars["custid"] = Guid.NewGuid().ToString();
50
+            client = Utils.GetHttpClient(String.Empty);
51
+        }
52
+
53
+        public ChatterBotThought Think(ChatterBotThought thought)
54
+        {
55
+            vars["input"] = thought.Text;
56
+
57
+            var response = Utils.Post(client, "http://www.pandorabots.com/pandora/talk-xml", vars);
58
+
59
+            var responseThought = new ChatterBotThought();
60
+            responseThought.Text = Utils.XPathSearch(response, "//result/that/text()");
61
+
62
+            return responseThought;
63
+        }
64
+
65
+        public string Think(string text)
66
+        {
67
+            return Think(new ChatterBotThought {Text = text}).Text;
68
+        }
69
+    }
60 70
 }
61 71
\ No newline at end of file
... ...
@@ -1,11 +1,10 @@
1 1
 using System;
2
-
3 2
 using System.Collections.Generic;
4 3
 using System.IO;
5 4
 using System.Net;
5
+using System.Net.Http;
6 6
 using System.Text;
7
-using System.Web;
8
-using System.Web.Security;
7
+using System.Threading.Tasks;
9 8
 using System.Xml.XPath;
10 9
 
11 10
 /*
... ...
@@ -25,55 +24,102 @@ using System.Xml.XPath;
25 24
     You should have received a copy of the GNU Lesser General Public License
26 25
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
27 26
 */
28
-namespace ChatterBotAPI {
29
-	
30
-	static class Utils {
31
-		
32
-		public static string ParametersToWWWFormURLEncoded(IDictionary<string, string> parameters) {
33
-			string wwwFormUrlEncoded = null;
34
-			foreach (string parameterKey in parameters.Keys) {
35
-				string parameterValue = parameters[parameterKey];
36
-				string parameter = string.Format("{0}={1}", HttpUtility.UrlEncode(parameterKey), HttpUtility.UrlEncode(parameterValue));
37
-				if (wwwFormUrlEncoded == null) {
38
-					wwwFormUrlEncoded = parameter;
39
-				} else {
40
-					wwwFormUrlEncoded = string.Format("{0}&{1}", wwwFormUrlEncoded, parameter);
41
-				}
42
-			}
43
-			return wwwFormUrlEncoded;
44
-		}
45
-		
46
-		public static string MD5(string input) {
47
-			return FormsAuthentication.HashPasswordForStoringInConfigFile(input, "MD5");
48
-		}
49
-		
50
-		public static string Post(string url, IDictionary<string, string> parameters) {
51
-			string postData = ParametersToWWWFormURLEncoded(parameters);
52
-			byte[] postDataBytes = Encoding.ASCII.GetBytes(postData);
53
-			
54
-			WebRequest webRequest = WebRequest.Create(url);
55
-			webRequest.Method = "POST";
56
-			webRequest.ContentType = "application/x-www-form-urlencoded";
57
-			webRequest.ContentLength = postDataBytes.Length;
58
-			
59
-			Stream outputStream = webRequest.GetRequestStream();
60
-			outputStream.Write(postDataBytes, 0, postDataBytes.Length);
61
-			outputStream.Close();
62
-			
63
-			WebResponse webResponse = webRequest.GetResponse();
64
-			StreamReader responseStreamReader = new StreamReader(webResponse.GetResponseStream());
65
-			return responseStreamReader.ReadToEnd().Trim();
66
-		}
67
-		
68
-		public static string XPathSearch(string input, string expression) {
69
-			XPathDocument document = new XPathDocument(new MemoryStream(Encoding.ASCII.GetBytes(input)));
70
-			XPathNavigator navigator = document.CreateNavigator();
71
-			return navigator.SelectSingleNode(expression).Value.Trim();
72
-		}
73
-		
74
-		public static string StringAtIndex(string[] strings, int index) {
75
-			if (index >= strings.Length) return "";
76
-			return strings[index];
77
-		}
78
-	}
27
+
28
+namespace ChatterBotAPI
29
+{
30
+    internal static class Utils
31
+    {
32
+
33
+        public async static Task<HttpClient> GetHttpClientAsync(string baseUrl)
34
+        {
35
+            var client = new HttpClient();
36
+            client.DefaultRequestHeaders.Add("UserAgent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0;");
37
+            client.DefaultRequestHeaders.Add("Accept-Language", "en-US");
38
+
39
+
40
+            if (!string.IsNullOrEmpty(baseUrl))
41
+            {
42
+                await client.GetAsync(new Uri(baseUrl));
43
+            }
44
+
45
+            return client;
46
+        }
47
+
48
+        public static HttpClient GetHttpClient(string baseUrl)
49
+        {
50
+            var result = GetHttpClientAsync(baseUrl);
51
+
52
+            result.Wait();
53
+            return result.Result;
54
+        }
55
+
56
+        public static string ParametersToWWWFormURLEncoded(IDictionary<string, string> parameters)
57
+        {
58
+            string wwwFormUrlEncoded = null;
59
+            foreach (var parameterKey in parameters.Keys)
60
+            {
61
+                var parameterValue = parameters[parameterKey];
62
+                var parameter = string.Format("{0}={1}", WebUtility.UrlEncode(parameterKey),
63
+                    WebUtility.UrlEncode(parameterValue));
64
+                if (wwwFormUrlEncoded == null)
65
+                {
66
+                    wwwFormUrlEncoded = parameter;
67
+                }
68
+                else
69
+                {
70
+                    wwwFormUrlEncoded = string.Format("{0}&{1}", wwwFormUrlEncoded, parameter);
71
+                }
72
+            }
73
+            return wwwFormUrlEncoded;
74
+        }
75
+
76
+        public static async Task<string> PostAsync(HttpClient client, string url, IDictionary<string, string> parameters)
77
+        {
78
+            var result =  await client.PostAsync(new Uri(url),
79
+                        new StringContent(ParametersToWWWFormURLEncoded(parameters), Encoding.UTF8, "application/x-www-form-urlencoded"));
80
+
81
+
82
+            var conetnt = await result.Content.ReadAsStringAsync();
83
+
84
+
85
+            return conetnt.Trim();
86
+        }
87
+
88
+        public static string Post(HttpClient client, string url, IDictionary<string, string> parameters)
89
+        {
90
+            var result = PostAsync(client, url, parameters);
91
+
92
+            result.Wait();
93
+            return result.Result;
94
+        }
95
+
96
+        public static string XPathSearch(string input, string expression)
97
+        {
98
+            var document = new XPathDocument(new MemoryStream(Encoding.ASCII.GetBytes(input)));
99
+            var navigator = document.CreateNavigator();
100
+            return navigator.SelectSingleNode(expression).Value.Trim();
101
+        }
102
+
103
+        public static string StringAtIndex(string[] strings, int index)
104
+        {
105
+            if (index >= strings.Length) return "";
106
+            return strings[index];
107
+        }
108
+
109
+        public static string CalculateMD5Hash(string input)
110
+        {
111
+            // step 1, calculate MD5 hash from input
112
+            var md5 = System.Security.Cryptography.MD5.Create();
113
+            var inputBytes = Encoding.ASCII.GetBytes(input);
114
+            var hash = md5.ComputeHash(inputBytes);
115
+
116
+            // step 2, convert byte array to hex string
117
+            var sb = new StringBuilder();
118
+            for (var i = 0; i < hash.Length; i++)
119
+            {
120
+                sb.Append(hash[i].ToString("X2"));
121
+            }
122
+            return sb.ToString();
123
+        }
124
+    }
79 125
 }
80 126
\ No newline at end of file
81 127
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<packages>
3
+  <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net45" />
4
+  <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
5
+  <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net45" />
6
+</packages>
0 7
\ No newline at end of file
... ...
@@ -1,5 +1,5 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3
   <PropertyGroup>
4 4
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 5
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
... ...
@@ -9,7 +9,28 @@
9 9
     <OutputType>Exe</OutputType>
10 10
     <RootNamespace>ChatterBotAPITest</RootNamespace>
11 11
     <AssemblyName>ChatterBotAPITest</AssemblyName>
12
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
12
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13
+    <FileUpgradeFlags>
14
+    </FileUpgradeFlags>
15
+    <UpgradeBackupLocation>
16
+    </UpgradeBackupLocation>
17
+    <OldToolsVersion>3.5</OldToolsVersion>
18
+    <TargetFrameworkProfile />
19
+    <PublishUrl>publish\</PublishUrl>
20
+    <Install>true</Install>
21
+    <InstallFrom>Disk</InstallFrom>
22
+    <UpdateEnabled>false</UpdateEnabled>
23
+    <UpdateMode>Foreground</UpdateMode>
24
+    <UpdateInterval>7</UpdateInterval>
25
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
26
+    <UpdatePeriodically>false</UpdatePeriodically>
27
+    <UpdateRequired>false</UpdateRequired>
28
+    <MapFileExtensions>true</MapFileExtensions>
29
+    <ApplicationRevision>0</ApplicationRevision>
30
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
31
+    <IsWebBootstrapper>false</IsWebBootstrapper>
32
+    <UseApplicationTrust>false</UseApplicationTrust>
33
+    <BootstrapperEnabled>true</BootstrapperEnabled>
13 34
   </PropertyGroup>
14 35
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15 36
     <DebugSymbols>true</DebugSymbols>
... ...
@@ -20,6 +41,7 @@
20 41
     <ErrorReport>prompt</ErrorReport>
21 42
     <WarningLevel>4</WarningLevel>
22 43
     <ConsolePause>false</ConsolePause>
44
+    <Prefer32Bit>false</Prefer32Bit>
23 45
   </PropertyGroup>
24 46
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25 47
     <DebugType>none</DebugType>
... ...
@@ -28,6 +50,7 @@
28 50
     <ErrorReport>prompt</ErrorReport>
29 51
     <WarningLevel>4</WarningLevel>
30 52
     <Externalconsole>true</Externalconsole>
53
+    <Prefer32Bit>false</Prefer32Bit>
31 54
   </PropertyGroup>
32 55
   <ItemGroup>
33 56
     <Reference Include="System" />
... ...
@@ -43,4 +66,19 @@
43 66
       <Name>ChatterBotAPI</Name>
44 67
     </ProjectReference>
45 68
   </ItemGroup>
69
+  <ItemGroup>
70
+    <None Include="app.config" />
71
+  </ItemGroup>
72
+  <ItemGroup>
73
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
74
+      <Visible>False</Visible>
75
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
76
+      <Install>false</Install>
77
+    </BootstrapperPackage>
78
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
79
+      <Visible>False</Visible>
80
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
81
+      <Install>true</Install>
82
+    </BootstrapperPackage>
83
+  </ItemGroup>
46 84
 </Project>
47 85
\ No newline at end of file
... ...
@@ -20,28 +20,28 @@ using ChatterBotAPI;
20 20
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 21
 */
22 22
 namespace ChatterBotAPITest {
23
-	
24
-	class MainClass {
25
-		
26
-		public static void Main(string[] args) {
27
-			ChatterBotFactory factory = new ChatterBotFactory();
28
-			
29
-			ChatterBot bot1 = factory.Create(ChatterBotType.CLEVERBOT);
30
-			ChatterBotSession bot1session = bot1.CreateSession();
31
-			
32
-			ChatterBot bot2 = factory.Create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");
33
-			ChatterBotSession bot2session = bot2.CreateSession();
34
-			
35
-			string s = "Hi";
36
-			while (true) {
37
-				
38
-				Console.WriteLine("bot1> " + s);
39
-				
40
-				s = bot2session.Think(s);
41
-				Console.WriteLine("bot2> " + s);
42
-				
43
-				s = bot1session.Think(s);
44
-			}
45
-		}
46
-	}
23
+    
24
+    class MainClass {
25
+        
26
+        public static void Main(string[] args) {
27
+            ChatterBotFactory factory = new ChatterBotFactory();
28
+
29
+            ChatterBot bot1 = factory.Create(ChatterBotType.CLEVERBOT);
30
+            ChatterBotSession bot1session = bot1.CreateSession();
31
+
32
+            ChatterBot bot2 = factory.Create(ChatterBotType.CLEVERBOT, "b0dafd24ee35a477");
33
+            ChatterBotSession bot2session = bot2.CreateSession();
34
+            
35
+            string s = "Hi";
36
+            while (true) {
37
+                
38
+                Console.WriteLine("bot1> " + s);
39
+                
40
+                s = bot2session.Think(s);
41
+                Console.WriteLine("bot2> " + s);
42
+                
43
+                s = bot1session.Think(s);
44
+            }
45
+        }
46
+    }
47 47
 }
48 48
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<configuration>
3
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
... ...
@@ -1,4 +1,5 @@
1 1
 
2
+Imports System
2 3
 Imports ChatterBotAPI
3 4
 
4 5
 '    ChatterBotAPI
... ...
@@ -1,5 +1,5 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 3
   <PropertyGroup>
4 4
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 5
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
... ...
@@ -9,7 +9,28 @@
9 9
     <OutputType>Exe</OutputType>
10 10
     <RootNamespace>ChatterBotAPITestVB</RootNamespace>
11 11
     <AssemblyName>ChatterBotAPITestVB</AssemblyName>
12
-    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
12
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13
+    <FileUpgradeFlags>
14
+    </FileUpgradeFlags>
15
+    <UpgradeBackupLocation>
16
+    </UpgradeBackupLocation>
17
+    <OldToolsVersion>3.5</OldToolsVersion>
18
+    <TargetFrameworkProfile />
19
+    <PublishUrl>publish\</PublishUrl>
20
+    <Install>true</Install>
21
+    <InstallFrom>Disk</InstallFrom>
22
+    <UpdateEnabled>false</UpdateEnabled>
23
+    <UpdateMode>Foreground</UpdateMode>
24
+    <UpdateInterval>7</UpdateInterval>
25
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
26
+    <UpdatePeriodically>false</UpdatePeriodically>
27
+    <UpdateRequired>false</UpdateRequired>
28
+    <MapFileExtensions>true</MapFileExtensions>
29
+    <ApplicationRevision>0</ApplicationRevision>
30
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
31
+    <IsWebBootstrapper>false</IsWebBootstrapper>
32
+    <UseApplicationTrust>false</UseApplicationTrust>
33
+    <BootstrapperEnabled>true</BootstrapperEnabled>
13 34
   </PropertyGroup>
14 35
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15 36
     <DebugSymbols>true</DebugSymbols>
... ...
@@ -19,6 +40,8 @@
19 40
     <DefineDebug>false</DefineDebug>
20 41
     <AdditionalParameters />
21 42
     <ConsolePause>false</ConsolePause>
43
+    <NoWarn>42353,42354,42355</NoWarn>
44
+    <Prefer32Bit>false</Prefer32Bit>
22 45
   </PropertyGroup>
23 46
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
24 47
     <OutputPath>bin\Release</OutputPath>
... ...
@@ -27,6 +50,8 @@
27 50
     <DefineTrace>false</DefineTrace>
28 51
     <AdditionalParameters />
29 52
     <ConsolePause>false</ConsolePause>
53
+    <NoWarn>42353,42354,42355</NoWarn>
54
+    <Prefer32Bit>false</Prefer32Bit>
30 55
   </PropertyGroup>
31 56
   <ItemGroup>
32 57
     <Reference Include="System" />
... ...
@@ -42,4 +67,22 @@
42 67
       <Name>ChatterBotAPI</Name>
43 68
     </ProjectReference>
44 69
   </ItemGroup>
70
+  <ItemGroup>
71
+    <None Include="app.config" />
72
+  </ItemGroup>
73
+  <ItemGroup>
74
+    <Folder Include="My Project\" />
75
+  </ItemGroup>
76
+  <ItemGroup>
77
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
78
+      <Visible>False</Visible>
79
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
80
+      <Install>false</Install>
81
+    </BootstrapperPackage>
82
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
83
+      <Visible>False</Visible>
84
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
85
+      <Install>true</Install>
86
+    </BootstrapperPackage>
87
+  </ItemGroup>
45 88
 </Project>
46 89
\ No newline at end of file
47 90
new file mode 100644
... ...
@@ -0,0 +1,23 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<configuration>
3
+    <system.diagnostics>
4
+        <sources>
5
+            <!-- This section defines the logging configuration for My.Application.Log -->
6
+            <source name="DefaultSource" switchName="DefaultSwitch">
7
+                <listeners>
8
+                    <add name="FileLog"/>
9
+                    <!-- Uncomment the below section to write to the Application Event Log -->
10
+                    <!--<add name="EventLog"/>-->
11
+                </listeners>
12
+            </source>
13
+        </sources>
14
+        <switches>
15
+            <add name="DefaultSwitch" value="Information"/>
16
+        </switches>
17
+        <sharedListeners>
18
+            <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
19
+            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
20
+            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
21
+        </sharedListeners>
22
+    </system.diagnostics>
23
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>