浏览代码

Avoid code duplication.
Use Session.SilverlightShared from Silverlight (v4) project.

Gert Driesen 11 年之前
父节点
当前提交
ff3bf965c6

+ 4 - 2
Renci.SshClient/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj

@@ -96,6 +96,9 @@
     <Compile Include="..\Renci.SshNet.Silverlight\Session.SilverlightBrowser.cs">
       <Link>Session.SilverlightBrowser.cs</Link>
     </Compile>
+    <Compile Include="..\Renci.SshNet.Silverlight\Session.SilverlightShared.cs">
+      <Link>Session.SilverlightShared.cs</Link>
+    </Compile>
     <Compile Include="..\Renci.SshNet.Silverlight\SftpClient.SilverlightShared.cs">
       <Link>SftpClient.SilverlightShared.cs</Link>
     </Compile>
@@ -889,7 +892,6 @@
     <Compile Include="..\Renci.SshNet\Properties\CommonAssemblyInfo.cs">
       <Link>Properties\CommonAssemblyInfo.cs</Link>
     </Compile>
-    <Compile Include="Session.SilverlightShared.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\Renci.SshNet.snk">
@@ -902,7 +904,7 @@
       <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
         <SilverlightProjectProperties />
       </FlavorProperties>
-      <UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" />
+      <UserProperties ProjectLinkReference="2f5f8c90-0bd1-424f-997c-7bc6280919d1" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
     </VisualStudio>
   </ProjectExtensions>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 0 - 189
Renci.SshClient/Renci.SshNet.Silverlight5/Session.SilverlightShared.cs

@@ -1,189 +0,0 @@
-using System;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
-using System.Threading;
-using Renci.SshNet.Common;
-using Renci.SshNet.Messages.Transport;
-using System.Text;
-
-namespace Renci.SshNet
-{
-    public partial class Session
-    {
-        private readonly AutoResetEvent _autoEvent = new AutoResetEvent(false);
-        private readonly AutoResetEvent _sendEvent = new AutoResetEvent(false);
-        private readonly AutoResetEvent _receiveEvent = new AutoResetEvent(false);
-
-        private bool _isConnected;
-
-        partial void IsSocketConnected(ref bool isConnected)
-        {
-            isConnected = (this._socket != null && this._socket.Connected && _isConnected);
-        }
-
-        partial void SocketConnect(string host, int port)
-        {
-            var ep = new DnsEndPoint(host, port);
-            this._socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-
-            var args = new SocketAsyncEventArgs();
-            args.UserToken = this._socket;
-            args.RemoteEndPoint = ep;
-            args.Completed += OnConnect;
-
-            this._socket.ConnectAsync(args);
-            this._autoEvent.WaitOne(this.ConnectionInfo.Timeout);
-
-            if (args.SocketError != SocketError.Success)
-                throw new SocketException((int)args.SocketError);
-        }
-
-        partial void SocketDisconnect()
-        {
-            this._socket.Close(10000);
-        }
-
-        partial void SocketReadLine(ref string response)
-        {
-            //  TODO:   Improve this function, currently will not work with server that send multiple lines as a first string
-
-            var buffer = new byte[1024];
-
-            var result = new StringBuilder();
-
-            do
-            {
-                var args = new SocketAsyncEventArgs();
-                args.SetBuffer(buffer, 0, buffer.Length);
-                args.UserToken = this._socket;
-                args.RemoteEndPoint = this._socket.RemoteEndPoint;
-                args.Completed += OnReceive;
-                this._socket.ReceiveAsync(args);
-
-                this._receiveEvent.WaitOne(this.ConnectionInfo.Timeout);
-
-                var lastChar = (char)buffer[0];
-                for (var i = 1; i < args.BytesTransferred; i++)
-                {
-                    var newChar = (char)buffer[i];
-                    if (lastChar == '\r' && newChar == '\n')
-                        break;
-
-                    result.Append(lastChar);
-                    lastChar = newChar;
-                }
-
-                if (args.BytesTransferred < buffer.Length)
-                    break;
-
-            } while (true);
-
-            response = result.ToString();
-        }
-
-        partial void SocketRead(int length, ref byte[] buffer)
-        {
-            var receivedTotal = 0;  // how many bytes is already received
-
-            do
-            {
-                var args = new SocketAsyncEventArgs();
-                args.SetBuffer(buffer, receivedTotal, length - receivedTotal);
-                args.UserToken = this._socket;
-                args.RemoteEndPoint = this._socket.RemoteEndPoint;
-                args.Completed += OnReceive;
-                this._socket.ReceiveAsync(args);
-
-                this._receiveEvent.WaitOne(this.ConnectionInfo.Timeout);
-
-                if (args.SocketError == SocketError.WouldBlock ||
-                    args.SocketError == SocketError.IOPending ||
-                    args.SocketError == SocketError.NoBufferSpaceAvailable)
-                {
-                    // socket buffer is probably empty, wait and try again
-                    Thread.Sleep(30);
-                    continue;
-                }
-                else if (args.SocketError != SocketError.Success)
-                {
-                    throw new SocketException((int)args.SocketError);
-                }
-
-                var receivedBytes = args.BytesTransferred;
-
-                if (receivedBytes > 0)
-                {
-                    receivedTotal += receivedBytes;
-                    continue;
-                }
-                throw new SshConnectionException(
-                    "An established connection was aborted by the software in your host machine.",
-                    DisconnectReason.ConnectionLost);
-            } while (receivedTotal < length);
-        }
-
-        partial void SocketWrite(byte[] data)
-        {
-            if (this._isConnected)
-            {
-                var args = new SocketAsyncEventArgs();
-                args.SetBuffer(data, 0, data.Length);
-                args.UserToken = this._socket;
-                args.RemoteEndPoint = this._socket.RemoteEndPoint;
-                args.Completed += OnSend;
-
-                this._socket.SendAsync(args);
-            }
-            else
-                throw new SocketException((int)SocketError.NotConnected);
-
-        }
-
-        private void OnConnect(object sender, SocketAsyncEventArgs e)
-        {
-            this._autoEvent.Set();
-            this._isConnected = (e.SocketError == SocketError.Success);
-        }
-
-        private void OnSend(object sender, SocketAsyncEventArgs e)
-        {
-            this._sendEvent.Set();
-        }
-
-        private void OnReceive(object sender, SocketAsyncEventArgs e)
-        {
-            this._receiveEvent.Set();
-        }
-
-        partial void ExecuteThread(Action action)
-        {
-            ThreadPool.QueueUserWorkItem(o => action());
-        }
-
-        partial void InternalRegisterMessage(string messageName)
-        {
-            lock (this._messagesMetadata)
-            {
-                foreach (var item in from m in this._messagesMetadata where m.Name == messageName select m)
-                {
-                    item.Enabled = true;
-                    item.Activated = true;
-                }
-            }
-        }
-
-        partial void InternalUnRegisterMessage(string messageName)
-        {
-            lock (this._messagesMetadata)
-            {
-                foreach (var item in from m in this._messagesMetadata where m.Name == messageName select m)
-                {
-                    item.Enabled = false;
-                    item.Activated = false;
-                }
-            }
-        }
-
-    }
-}