|
@@ -14,6 +14,7 @@ using System.Threading;
|
|
namespace XUnity.AutoTranslator.Plugin.Core.Web
|
|
namespace XUnity.AutoTranslator.Plugin.Core.Web
|
|
{
|
|
{
|
|
public delegate void MyDownloadStringCompletedEventHandler( object sender, MyDownloadStringCompletedEventArgs e );
|
|
public delegate void MyDownloadStringCompletedEventHandler( object sender, MyDownloadStringCompletedEventArgs e );
|
|
|
|
+ public delegate void MyUploadStringCompletedEventHandler( object sender, MyUploadStringCompletedEventArgs e );
|
|
|
|
|
|
public class MyDownloadStringCompletedEventArgs : AsyncCompletedEventArgs
|
|
public class MyDownloadStringCompletedEventArgs : AsyncCompletedEventArgs
|
|
{
|
|
{
|
|
@@ -33,6 +34,24 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ public class MyUploadStringCompletedEventArgs : AsyncCompletedEventArgs
|
|
|
|
+ {
|
|
|
|
+ private string result;
|
|
|
|
+
|
|
|
|
+ internal MyUploadStringCompletedEventArgs( string result, Exception error, bool cancelled, object userState ) : base( error, cancelled, userState )
|
|
|
|
+ {
|
|
|
|
+ this.result = result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public string Result
|
|
|
|
+ {
|
|
|
|
+ get
|
|
|
|
+ {
|
|
|
|
+ base.RaiseExceptionIfNecessary();
|
|
|
|
+ return this.result;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
public class MyAsyncCompletedEventArgs : EventArgs
|
|
public class MyAsyncCompletedEventArgs : EventArgs
|
|
{
|
|
{
|
|
@@ -102,6 +121,7 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
|
|
private static readonly string urlEncodedCType = "application/x-www-form-urlencoded";
|
|
private static readonly string urlEncodedCType = "application/x-www-form-urlencoded";
|
|
|
|
|
|
public event MyDownloadStringCompletedEventHandler DownloadStringCompleted;
|
|
public event MyDownloadStringCompletedEventHandler DownloadStringCompleted;
|
|
|
|
+ public event MyUploadStringCompletedEventHandler UploadStringCompleted;
|
|
|
|
|
|
static MyWebClient()
|
|
static MyWebClient()
|
|
{
|
|
{
|
|
@@ -641,14 +661,14 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
|
|
// }
|
|
// }
|
|
//}
|
|
//}
|
|
|
|
|
|
- //protected virtual void OnUploadStringCompleted( UploadStringCompletedEventArgs args )
|
|
|
|
- //{
|
|
|
|
- // this.CompleteAsync();
|
|
|
|
- // if( this.UploadStringCompleted != null )
|
|
|
|
- // {
|
|
|
|
- // this.UploadStringCompleted( this, args );
|
|
|
|
- // }
|
|
|
|
- //}
|
|
|
|
|
|
+ protected virtual void OnUploadStringCompleted( MyUploadStringCompletedEventArgs args )
|
|
|
|
+ {
|
|
|
|
+ this.CompleteAsync();
|
|
|
|
+ if( this.UploadStringCompleted != null )
|
|
|
|
+ {
|
|
|
|
+ this.UploadStringCompleted( this, args );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
//protected virtual void OnUploadValuesCompleted( UploadValuesCompletedEventArgs args )
|
|
//protected virtual void OnUploadValuesCompleted( UploadValuesCompletedEventArgs args )
|
|
//{
|
|
//{
|
|
@@ -1291,51 +1311,51 @@ namespace XUnity.AutoTranslator.Plugin.Core.Web
|
|
return this.encoding.GetString( bytes );
|
|
return this.encoding.GetString( bytes );
|
|
}
|
|
}
|
|
|
|
|
|
- //public void UploadStringAsync( Uri address, string data )
|
|
|
|
- //{
|
|
|
|
- // this.UploadStringAsync( address, null, data );
|
|
|
|
- //}
|
|
|
|
|
|
+ public void UploadStringAsync( Uri address, string data )
|
|
|
|
+ {
|
|
|
|
+ this.UploadStringAsync( address, null, data );
|
|
|
|
+ }
|
|
|
|
|
|
- //public void UploadStringAsync( Uri address, string method, string data )
|
|
|
|
- //{
|
|
|
|
- // this.UploadStringAsync( address, method, data, null );
|
|
|
|
- //}
|
|
|
|
|
|
+ public void UploadStringAsync( Uri address, string method, string data )
|
|
|
|
+ {
|
|
|
|
+ this.UploadStringAsync( address, method, data, null );
|
|
|
|
+ }
|
|
|
|
|
|
- //public void UploadStringAsync( Uri address, string method, string data, object userToken )
|
|
|
|
- //{
|
|
|
|
- // if( address == null )
|
|
|
|
- // {
|
|
|
|
- // throw new ArgumentNullException( "address" );
|
|
|
|
- // }
|
|
|
|
- // if( data == null )
|
|
|
|
- // {
|
|
|
|
- // throw new ArgumentNullException( "data" );
|
|
|
|
- // }
|
|
|
|
- // MyWebClient client = this;
|
|
|
|
- // lock( client )
|
|
|
|
- // {
|
|
|
|
- // this.CheckBusy();
|
|
|
|
- // this.async = true;
|
|
|
|
- // object[] parameter = new object[] { address, method, data, userToken };
|
|
|
|
- // ThreadPool.QueueUserWorkItem( delegate ( object state )
|
|
|
|
- // {
|
|
|
|
- // object[] objArray = (object[])state;
|
|
|
|
- // try
|
|
|
|
- // {
|
|
|
|
- // string result = this.UploadString( (Uri)objArray[ 0 ], (string)objArray[ 1 ], (string)objArray[ 2 ] );
|
|
|
|
- // this.OnUploadStringCompleted( new UploadStringCompletedEventArgs( result, null, false, objArray[ 3 ] ) );
|
|
|
|
- // }
|
|
|
|
- // catch( ThreadInterruptedException )
|
|
|
|
- // {
|
|
|
|
- // this.OnUploadStringCompleted( new UploadStringCompletedEventArgs( null, null, true, objArray[ 3 ] ) );
|
|
|
|
- // }
|
|
|
|
- // catch( Exception exception )
|
|
|
|
- // {
|
|
|
|
- // this.OnUploadStringCompleted( new UploadStringCompletedEventArgs( null, exception, false, objArray[ 3 ] ) );
|
|
|
|
- // }
|
|
|
|
- // }, parameter );
|
|
|
|
- // }
|
|
|
|
- //}
|
|
|
|
|
|
+ public void UploadStringAsync( Uri address, string method, string data, object userToken )
|
|
|
|
+ {
|
|
|
|
+ if( address == null )
|
|
|
|
+ {
|
|
|
|
+ throw new ArgumentNullException( "address" );
|
|
|
|
+ }
|
|
|
|
+ if( data == null )
|
|
|
|
+ {
|
|
|
|
+ throw new ArgumentNullException( "data" );
|
|
|
|
+ }
|
|
|
|
+ MyWebClient client = this;
|
|
|
|
+ lock( client )
|
|
|
|
+ {
|
|
|
|
+ this.CheckBusy();
|
|
|
|
+ this.async = true;
|
|
|
|
+ object[] parameter = new object[] { address, method, data, userToken };
|
|
|
|
+ ThreadPool.QueueUserWorkItem( delegate ( object state )
|
|
|
|
+ {
|
|
|
|
+ object[] objArray = (object[])state;
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ string result = this.UploadString( (Uri)objArray[ 0 ], (string)objArray[ 1 ], (string)objArray[ 2 ] );
|
|
|
|
+ this.OnUploadStringCompleted( new MyUploadStringCompletedEventArgs( result, null, false, objArray[ 3 ] ) );
|
|
|
|
+ }
|
|
|
|
+ catch( ThreadInterruptedException )
|
|
|
|
+ {
|
|
|
|
+ this.OnUploadStringCompleted( new MyUploadStringCompletedEventArgs( null, null, true, objArray[ 3 ] ) );
|
|
|
|
+ }
|
|
|
|
+ catch( Exception exception )
|
|
|
|
+ {
|
|
|
|
+ this.OnUploadStringCompleted( new MyUploadStringCompletedEventArgs( null, exception, false, objArray[ 3 ] ) );
|
|
|
|
+ }
|
|
|
|
+ }, parameter );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
public byte[] UploadValues( string address, NameValueCollection data )
|
|
public byte[] UploadValues( string address, NameValueCollection data )
|
|
{
|
|
{
|