当前位置: 首页>>代码示例>>C#>>正文


C# Session.Connect方法代码示例

本文整理汇总了C#中Session.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Connect方法的具体用法?C# Session.Connect怎么用?C# Session.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Session的用法示例。


在下文中一共展示了Session.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectShouldThrowProxyExceptionWhenHttpProxyReturnsHttpStatusOtherThan200

        public void ConnectShouldThrowProxyExceptionWhenHttpProxyReturnsHttpStatusOtherThan200()
        {
            var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n"));
                proxyStub.Start();

                using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException ex)
                    {
                        Assert.IsNull(ex.InnerException);
                        Assert.AreEqual("HTTP: Status code 501, \"Custom\"", ex.Message);
                    }
                }
            }
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:25,代码来源:SessionTest.HttpProxy.cs

示例2: ConnectShouldThrowProxyExceptionWhenHttpProxyResponseDoesNotContainStatusLine

        public void ConnectShouldThrowProxyExceptionWhenHttpProxyResponseDoesNotContainStatusLine()
        {
            var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Whatever\r\n"));
                proxyStub.Start();

                using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException ex)
                    {
                        Assert.IsNull(ex.InnerException);
                        Assert.AreEqual("HTTP response does not contain status line.", ex.Message);
                    }
                }
            }
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:25,代码来源:SessionTest.HttpProxy.cs

示例3: CreateSession

		internal Session CreateSession(string sessionName, string serverUrl, MessageSecurityMode securityMode, SecurityPolicy securityPolicy, MessageEncoding messageEncoding, UserIdentity userId)
		{
			Session session = new Session(serverUrl, securityMode, securityPolicy.ToString(), messageEncoding, userId, null);
			session.SessionName = sessionName;
			session.Connect(false, true);
			return session;
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:7,代码来源:Client.cs

示例4: ConnectShouldSkipHeadersWhenHttpProxyReturnsHttpStatus200

        public void ConnectShouldSkipHeadersWhenHttpProxyReturnsHttpStatus200()
        {
            var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n"));
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub"));
                proxyStub.Start();

                using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (SshConnectionException ex)
                    {
                        Assert.IsNull(ex.InnerException);
                        Assert.AreEqual("Server version '666' is not supported.", ex.Message);
                    }
                }
            }
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:28,代码来源:SessionTest.HttpProxy.cs

示例5: Start

        void Start()
        {
            GameObject go = new GameObject("Session");
            session = go.AddComponent<Session>();
            session.onSend += OnSend;
            session.onReceive += OnReceive;
            session.onError += OnError;
            session.Connect("localhost", 4623);

            SendExample1();
            SendExample2();
        }
开发者ID:jungrok5,项目名称:SpiderNET,代码行数:12,代码来源:Main.cs

示例6: Act

 protected virtual void Act()
 {
     try
     {
         using (_session = new Session(_connectionInfo, _serviceFactoryMock.Object))
         {
             _session.Connect();
         }
     }
     catch (SshConnectionException ex)
     {
         _actualException = ex;
     }
 }
开发者ID:delfinof,项目名称:ssh.net,代码行数:14,代码来源:SessionTest_SocketConnected_BadPacketAndDispose.cs

示例7: Connect

		protected void Connect()
		{
			// why does NUnit run the test fixture setup twice?
			if ( session != null )
				return;

			NetworkCredential nc = null;

			// string basicHttpAuthUserName = ConfigurationSettings.AppSettings["BasicHttpAuthUserName"];
			// string basicHttpAuthPassword = ConfigurationSettings.AppSettings["BasicHttpAuthPassword"];
			// if ( ( basicHttpAuthUserName != null ) && ( basicHttpAuthUserName.Length > 0 ) && ( basicHttpAuthPassword != null ) )
			//	nc = new NetworkCredential( basicHttpAuthUserName, basicHttpAuthPassword );

			session = new Session( Url, UserName, Password, nc );

			session.Connect();
		}
开发者ID:mantishub,项目名称:MantisDotNetClient,代码行数:17,代码来源:BaseTestFixture.cs

示例8: LibSshNetConnection

        public LibSshNetConnection(string host, string username, string password)
        {
            Session = new Session();
            Session.SetOption(SshOption.Host, host);
            Session.SetOption(SshOption.Port, 22);
            Session.SetOption(SshOption.User, username);
            //			Session.SetOption(SshOption.CiphersCS, "aes256-cbc");
            Session.Connect();

            Session.PasswordAuth(password);

            Pty = new Channel(Session);
            Pty.RequestPty("xterm", 160, 40);
            Pty.RequestShell();

            stream = new LibSshNetStream(this);
        }
开发者ID:npcook,项目名称:terminal,代码行数:17,代码来源:libsshnetConnection.cs

示例9: ConnectShouldWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNotNullAndNotEmpty

        public void ConnectShouldWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNotNullAndNotEmpty()
        {
            var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n"));
                proxyStub.Start();

                var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon");
                using (var session = new Session(connectionInfo, _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException)
                    {
                    }
                }

                var expectedProxyAuthorizationHeader = CreateProxyAuthorizationHeader(connectionInfo);
                Assert.IsNotNull(proxyStub.HttpRequest.Headers.SingleOrDefault(p => p == expectedProxyAuthorizationHeader));
            }
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:27,代码来源:SessionTest.HttpProxy.cs

示例10: SessionConnect

 private void SessionConnect()
 {
     if (_session == null) {
         _session = new Session(_activity, Configuration.Config.API_KEY, Configuration.Config.SESSION_ID);
         _session.SetSessionListener(this);
         _session.Connect(Configuration.Config.TOKEN);
     }
 }
开发者ID:ericgla,项目名称:XamarinOpenTok,代码行数:8,代码来源:OpenTokViewRenderer.cs

示例11: ConnectShouldWriteConnectMethodToHttpProxy

        public void ConnectShouldWriteConnectMethodToHttpProxy()
        {
            var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123);
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);

            using (var proxyStub = new HttpProxyStub(proxyEndPoint))
            {
                proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n"));
                proxyStub.Start();

                using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (ProxyException)
                    {
                    }
                }

                Assert.AreEqual(string.Format("CONNECT {0} HTTP/1.0", serverEndPoint), proxyStub.HttpRequest.RequestLine);
            }
        }
开发者ID:delfinof,项目名称:ssh.net,代码行数:25,代码来源:SessionTest.HttpProxy.cs

示例12: ConnectShouldThrowSshOperationExceptionWhenServerDoesNotRespondWithinConnectionTimeout

        public void ConnectShouldThrowSshOperationExceptionWhenServerDoesNotRespondWithinConnectionTimeout()
        {
            var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
            var timeout = TimeSpan.FromMilliseconds(500);
            Socket clientSocket = null;

            using (var serverStub = new AsyncSocketListener(serverEndPoint))
            {
                serverStub.Connected += socket =>
                    {
                        socket.Send(Encoding.ASCII.GetBytes("\r\n"));
                        socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n"));
                        clientSocket = socket;
                    };
                serverStub.Start();

                using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromMilliseconds(500)), _serviceFactoryMock.Object))
                {
                    try
                    {
                        session.Connect();
                        Assert.Fail();
                    }
                    catch (SshOperationTimeoutException ex)
                    {
                        Assert.IsNull(ex.InnerException);
                        Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds), ex.Message);

                        Assert.IsNotNull(clientSocket);
                        Assert.IsTrue(clientSocket.Connected);

                        // shut down socket
                        clientSocket.Shutdown(SocketShutdown.Send);
                    }
                }
            }
        }
开发者ID:REALTOBIZ,项目名称:SSH.NET,代码行数:37,代码来源:SessionTest.cs

示例13: OscarPlugin

 public OscarPlugin(string host, string port)
     : base(host, port)
 {
     Config.SupportReceipts = true;
     OscarSessions = new Dictionary<string, Session>();
     LoggedIn += (sender, login) =>
         {
             var newSession = new Session(login.LoginPayload.legacyName, login.LoginPayload.password);
             OscarSessions.Add(login.LoginPayload.user, newSession);
             newSession.Messaging.MessageReceived += message =>
                 {
                     var currentUser = OscarSessions.FirstOrDefault(k => k.Value == newSession).Key;
                     if (currentUser == null) return;
                     var convMessage = new ConversationMessage
                         {
                             userName = currentUser,
                             buddyName = message.Contact.Uin,
                             message = message.Text
                         };
                     SendMessage(WrapperMessage.Type.TYPE_CONV_MESSAGE, convMessage);
                 };
             newSession.Connected += (o, args) =>
                 {
                     var currentUser = OscarSessions.FirstOrDefault(k => k.Value == newSession).Key;
                     if (currentUser == null) return;
                     var connected = new Connected {user = currentUser};
                     SendMessage(WrapperMessage.Type.TYPE_CONNECTED, connected);
                 };
             newSession.ContactList.ContactSignedOn += contact => ContactChanged(newSession, contact);
             newSession.ContactList.ContactSignedOff += contact => ContactChanged(newSession, contact);
             newSession.ContactList.ContactRemoved += contact => ContactChanged(newSession, contact);
             newSession.ContactList.ContactAdded += contact => ContactChanged(newSession, contact);
             newSession.ContactList.ContactStatusChanged += contact => ContactChanged(newSession, contact);
             newSession.ContactList.ContactListReceived +=
                 (o, args) => newSession.ContactList.Contacts.ForEach(c => ContactChanged(newSession, c));
             newSession.Connect();
         };
     LoggedOut += (sender, logout) =>
         {
             if (!OscarSessions.ContainsKey(logout.LogoutPayload.user)) return;
             OscarSessions[logout.LogoutPayload.user].Disconnect();
             OscarSessions[logout.LogoutPayload.user].Dispose();
             OscarSessions.Remove(logout.LogoutPayload.user);
         };
     ConversationMessage += (sender, message) =>
         {
             var session = OscarSessions[message.ConversationMessagePayload.userName];
             var contact = session.ContactList.Contacts.FirstOrDefault(
                 c => c.Uin.Equals(message.ConversationMessagePayload.buddyName));
             if (contact == null) return;
             /*var datetime =
                 (new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddSeconds(
                     long.Parse(message.ConversationMessagePayload.timestamp));*/
             session.Messaging.Send(new Message(contact, MessageType.Outgoing,
                                                //datetime,
                                                message.ConversationMessagePayload.message));
             if (!string.IsNullOrEmpty(message.ConversationMessagePayload.id))
             {
                 var ack = new ConversationMessage
                     {
                         id = message.ConversationMessagePayload.id,
                         userName = message.ConversationMessagePayload.userName,
                         buddyName = message.ConversationMessagePayload.buddyName,
                         message = ""
                     };
                 SendMessage(WrapperMessage.Type.TYPE_CONV_MESSAGE_ACK, ack);
             }
         };
 }
开发者ID:vitalyster,项目名称:networkplugin-csharp,代码行数:69,代码来源:OscarPlugin.cs

示例14: SessionConnect

 private void SessionConnect()
 {
     if (mSession == null) {
         mSession = new Session(this, Configuration.Config.API_KEY, Configuration.Config.SESSION_ID);
         mSession.SetSessionListener(this);
         mSession.Connect(Configuration.Config.TOKEN);
     }
 }
开发者ID:ericgla,项目名称:XamarinOpenTok,代码行数:8,代码来源:ConferenceActivity.cs

示例15: Connect

        public static bool Connect(int serverType, string serverName, string user, string pass, string database,
            bool writeDbConfigFile)
        {
            var sConnectionString = GetConnectionString(serverType, serverName, user, pass, database);

            XpoDefault.ConnectionString = sConnectionString;
            try
            {
                var s = new Session();
                s.Connect();
                s.Disconnect();

                // Kết nối thành công thì lưu xuống file dbConfig.con
                if (writeDbConfigFile)
                {
                    var dbConfigPath = Application.StartupPath + @"\DatabaseConfig.con";
                    WriteDatabaseConfig(dbConfigPath, serverType, serverName, user, pass, database);
                }
            }
            catch (Exception ex)
            {
                EasyDialog.ShowErrorDialog("Không kết nối được CSDL (" + ex.Message + ")");
                return false;
            }

            return true;
        }
开发者ID:congnguyendl,项目名称:CnAppMedic,代码行数:27,代码来源:Connector.cs


注:本文中的Session.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。