OSDN Git Service

v2.6.1.4-alpha
authorwagashi <wagashi@users.sourceforge.jp>
Mon, 27 Dec 2010 16:56:54 +0000 (01:56 +0900)
committerwagashi <wagashi@users.sourceforge.jp>
Mon, 27 Dec 2010 16:56:54 +0000 (01:56 +0900)
macro.google/PopupTranslateMacro.cs
macro.google/macro.google.csproj
passer/Passer.suo
passer/bin/Release/macro/Lugens.Passer.Macro.Google.dll

index 71444cc..715fe9c 100644 (file)
@@ -4,14 +4,18 @@ using System.Text;
 using System.Globalization;
 using System.Net;
 using System.IO;
 using System.Globalization;
 using System.Net;
 using System.IO;
-using System.Web;
+using System.Web;\r
+using System.Windows.Forms;\r
+using System.Diagnostics;\r
+using System.Threading;
 
 namespace Lugens.Passer.Macro.Google
 {
     public class PopupTranslateMacro : IMacro
     {
         string str;
 
 namespace Lugens.Passer.Macro.Google
 {
     public class PopupTranslateMacro : IMacro
     {
         string str;
-        string pair;
+        string pair;\r
+        ManualResetEvent allDone = new ManualResetEvent(false);\r
 
         event MacroEventHandler macroCompletedEvent;
 
 
         event MacroEventHandler macroCompletedEvent;
 
@@ -66,52 +70,64 @@ namespace Lugens.Passer.Macro.Google
 
 
         public void ExecuteAsync(string str, string[] args)
 
 
         public void ExecuteAsync(string str, string[] args)
-        {
-            this.str = str;
-            if (args == null)
-                this.pair = "en%7Cja";
-            else if (args.Length == 1)
-                this.pair = args[0] + "%7Cja";
-            else
-                this.pair = args[0] + "%7C" + args[1];
-
-            WebRequest webReq = HttpWebRequest.Create("http://ajax.googleapis.com/ajax/services/language/translate");
-            webReq.Method = "POST";
-            webReq.ContentType = "application/x-www-form-urlencoded";
-
-            AsyncCallback writeCallBack = new AsyncCallback(WriteCallBack);
-            IAsyncResult r = webReq.BeginGetRequestStream(writeCallBack, webReq);
-            r.AsyncWaitHandle.WaitOne();
-
-            AsyncCallback readCallBack = new AsyncCallback(ReadCallBack);
-            IAsyncResult rAr = webReq.BeginGetResponse(readCallBack, webReq);
+        {\r
+            try\r
+            {\r
+                this.str = str;\r
+                if (args == null)\r
+                    this.pair = "en%7Cja";\r
+                else if (args.Length == 1)\r
+                    this.pair = args[0] + "%7Cja";\r
+                else\r
+                    this.pair = args[0] + "%7C" + args[1];\r
+\r
+                WebRequest webReq = HttpWebRequest.Create("http://ajax.googleapis.com/ajax/services/language/translate");\r
+                webReq.Method = "POST";\r
+                webReq.ContentType = "application/x-www-form-urlencoded";\r
+\r
+                AsyncCallback writeCallBack = new AsyncCallback(WriteCallBack);\r
+                IAsyncResult r = webReq.BeginGetRequestStream(writeCallBack, webReq);\r
+                allDone.WaitOne();\r
+\r
+                AsyncCallback readCallBack = new AsyncCallback(ReadCallBack);\r
+                IAsyncResult rAr = webReq.BeginGetResponse(readCallBack, webReq);\r
+            }\r
+            catch (Exception e)\r
+            {\r
+                MessageBox.Show(e.Message);\r
+            }
         }
 
         private void ReadCallBack(IAsyncResult ar)
         }
 
         private void ReadCallBack(IAsyncResult ar)
-        {
-            HttpWebRequest req = (HttpWebRequest)ar.AsyncState;
-            HttpWebResponse response = (HttpWebResponse)req.EndGetResponse(ar);
-            StreamReader sr = new StreamReader(response.GetResponseStream());
-            string str = sr.ReadToEnd();
-            string result = "";
-            sr.Close();
-
-            try
-            {
-                int index = str.IndexOf("\"translatedText\"");
-                if (index != -1)
-                {
-                    index += "\"translatedText\"".Length;
-                    int sIndex = str.IndexOf('"', index);
-                    int eIndex = str.IndexOf('"', sIndex + 1);
-
-                    result = str.Substring(sIndex + 1, eIndex - sIndex - 1);
-                    result = result.Replace("\\u003d", "\u003d").Replace("\\u0026", "\u0026");
-                    result = HttpUtility.HtmlDecode(result);
-                }
-            }
-            catch (Exception) { }
-
+        {\r
+            string result = "";\r
+            try\r
+            {\r
+                HttpWebRequest req = (HttpWebRequest)ar.AsyncState;\r
+                HttpWebResponse response = (HttpWebResponse)req.EndGetResponse(ar);\r
+                StreamReader sr = new StreamReader(response.GetResponseStream());\r
+                string str = sr.ReadToEnd();\r
+                sr.Close();\r
+\r
+                int index = str.IndexOf("\"translatedText\"");\r
+                if (index != -1)\r
+                {\r
+                    index += "\"translatedText\"".Length;\r
+                    int sIndex = str.IndexOf('"', index);\r
+                    int eIndex = str.IndexOf('"', sIndex + 1);\r
+\r
+                    result = str.Substring(sIndex + 1, eIndex - sIndex - 1);\r
+                    result = result.Replace("\\u003d", "\u003d").Replace("\\u0026", "\u0026");\r
+                    result = HttpUtility.HtmlDecode(result);\r
+                }\r
+            }\r
+            catch (Exception e)\r
+            {\r
+                result = e.Message;\r
+                macroCompletedEvent(result);\r
+                return;\r
+            }\r
+\r
             if (macroCompletedEvent != null)
                 macroCompletedEvent(result);
         }
             if (macroCompletedEvent != null)
                 macroCompletedEvent(result);
         }
@@ -122,7 +138,8 @@ namespace Lugens.Passer.Macro.Google
             StreamWriter sw = new StreamWriter(req.EndGetRequestStream(ar));
             string parameters = "v=1.0&langpair=" + this.pair + "&q=" + HttpUtility.UrlEncode(this.str);
             sw.Write(parameters);
             StreamWriter sw = new StreamWriter(req.EndGetRequestStream(ar));
             string parameters = "v=1.0&langpair=" + this.pair + "&q=" + HttpUtility.UrlEncode(this.str);
             sw.Write(parameters);
-            sw.Close();
+            sw.Close();\r
+            allDone.Set();\r
         }
 
         public bool Test()
         }
 
         public bool Test()
index 23583e6..ef8ece7 100644 (file)
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>9.0.30729</ProductVersion>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectGuid>{54C23C22-8DDB-46D6-B6FB-65D1DF1BB26D}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>Lugens.Passer.Macro.Google</RootNamespace>
-    <AssemblyName>Lugens.Passer.Macro.Google</AssemblyName>
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <FileUpgradeFlags>
-    </FileUpgradeFlags>
-    <OldToolsVersion>3.5</OldToolsVersion>
-    <UpgradeBackupLocation />
-    <TargetFrameworkProfile />
-    <PublishUrl>publish\</PublishUrl>
-    <Install>true</Install>
-    <InstallFrom>Disk</InstallFrom>
-    <UpdateEnabled>false</UpdateEnabled>
-    <UpdateMode>Foreground</UpdateMode>
-    <UpdateInterval>7</UpdateInterval>
-    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
-    <UpdatePeriodically>false</UpdatePeriodically>
-    <UpdateRequired>false</UpdateRequired>
-    <MapFileExtensions>true</MapFileExtensions>
-    <ApplicationRevision>0</ApplicationRevision>
-    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
-    <IsWebBootstrapper>false</IsWebBootstrapper>
-    <UseApplicationTrust>false</UseApplicationTrust>
-    <BootstrapperEnabled>true</BootstrapperEnabled>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <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' ">
-    <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.Data" />
-    <Reference Include="System.Web" />
-    <Reference Include="System.Xml" />
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="PopupTranslateMacro.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="app.config" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\passer\Passer.csproj">
-      <Project>{A51E566C-9BBE-4579-986B-31CD2E71FAE8}</Project>
-      <Name>Passer</Name>
-    </ProjectReference>
-  </ItemGroup>
-  <ItemGroup>
-    <BootstrapperPackage Include=".NETFramework,Version=v4.0">
-      <Visible>False</Visible>
-      <ProductName>Microsoft .NET Framework 4 %28x86 および x64%29</ProductName>
-      <Install>true</Install>
-    </BootstrapperPackage>
-    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
-      <Visible>False</Visible>
-      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
-      <Install>false</Install>
-    </BootstrapperPackage>
-    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
-      <Visible>False</Visible>
-      <ProductName>.NET Framework 3.5 SP1</ProductName>
-      <Install>false</Install>
-    </BootstrapperPackage>
-    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
-      <Visible>False</Visible>
-      <ProductName>Windows インストーラー 3.1</ProductName>
-      <Install>true</Install>
-    </BootstrapperPackage>
-  </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
+    <ProductVersion>9.0.30729</ProductVersion>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectGuid>{54C23C22-8DDB-46D6-B6FB-65D1DF1BB26D}</ProjectGuid>\r
+    <OutputType>Library</OutputType>\r
+    <AppDesignerFolder>Properties</AppDesignerFolder>\r
+    <RootNamespace>Lugens.Passer.Macro.Google</RootNamespace>\r
+    <AssemblyName>Lugens.Passer.Macro.Google</AssemblyName>\r
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r
+    <FileAlignment>512</FileAlignment>\r
+    <FileUpgradeFlags>\r
+    </FileUpgradeFlags>\r
+    <OldToolsVersion>3.5</OldToolsVersion>\r
+    <UpgradeBackupLocation />\r
+    <TargetFrameworkProfile />\r
+    <PublishUrl>publish\</PublishUrl>\r
+    <Install>true</Install>\r
+    <InstallFrom>Disk</InstallFrom>\r
+    <UpdateEnabled>false</UpdateEnabled>\r
+    <UpdateMode>Foreground</UpdateMode>\r
+    <UpdateInterval>7</UpdateInterval>\r
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>\r
+    <UpdatePeriodically>false</UpdatePeriodically>\r
+    <UpdateRequired>false</UpdateRequired>\r
+    <MapFileExtensions>true</MapFileExtensions>\r
+    <ApplicationRevision>0</ApplicationRevision>\r
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>\r
+    <IsWebBootstrapper>false</IsWebBootstrapper>\r
+    <UseApplicationTrust>false</UseApplicationTrust>\r
+    <BootstrapperEnabled>true</BootstrapperEnabled>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
+    <DebugSymbols>true</DebugSymbols>\r
+    <DebugType>full</DebugType>\r
+    <Optimize>false</Optimize>\r
+    <OutputPath>bin\Debug\</OutputPath>\r
+    <DefineConstants>DEBUG;TRACE</DefineConstants>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
+    <DebugType>pdbonly</DebugType>\r
+    <Optimize>true</Optimize>\r
+    <OutputPath>bin\Release\</OutputPath>\r
+    <DefineConstants>TRACE</DefineConstants>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Reference Include="System" />\r
+    <Reference Include="System.Data" />\r
+    <Reference Include="System.Web" />\r
+    <Reference Include="System.Windows.Forms" />\r
+    <Reference Include="System.Xml" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="PopupTranslateMacro.cs" />\r
+    <Compile Include="Properties\AssemblyInfo.cs" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <None Include="app.config" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\passer\Passer.csproj">\r
+      <Project>{A51E566C-9BBE-4579-986B-31CD2E71FAE8}</Project>\r
+      <Name>Passer</Name>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <BootstrapperPackage Include=".NETFramework,Version=v4.0">\r
+      <Visible>False</Visible>\r
+      <ProductName>Microsoft .NET Framework 4 %28x86 および x64%29</ProductName>\r
+      <Install>true</Install>\r
+    </BootstrapperPackage>\r
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">\r
+      <Visible>False</Visible>\r
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>\r
+      <Install>false</Install>\r
+    </BootstrapperPackage>\r
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">\r
+      <Visible>False</Visible>\r
+      <ProductName>.NET Framework 3.5 SP1</ProductName>\r
+      <Install>false</Install>\r
+    </BootstrapperPackage>\r
+    <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">\r
+      <Visible>False</Visible>\r
+      <ProductName>Windows インストーラー 3.1</ProductName>\r
+      <Install>true</Install>\r
+    </BootstrapperPackage>\r
+  </ItemGroup>\r
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
   <!-- 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>
   <!-- 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>
-  -->
+  -->\r
 </Project>
\ No newline at end of file
 </Project>
\ No newline at end of file
index be64610..2b700d0 100644 (file)
Binary files a/passer/Passer.suo and b/passer/Passer.suo differ
index 8d0ded4..727de0b 100644 (file)
Binary files a/passer/bin/Release/macro/Lugens.Passer.Macro.Google.dll and b/passer/bin/Release/macro/Lugens.Passer.Macro.Google.dll differ