本文整理汇总了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);
}
}
}
}
示例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);
}
}
}
}
示例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;
}
示例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);
}
}
}
}
示例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();
}
示例6: Act
protected virtual void Act()
{
try
{
using (_session = new Session(_connectionInfo, _serviceFactoryMock.Object))
{
_session.Connect();
}
}
catch (SshConnectionException ex)
{
_actualException = ex;
}
}
示例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();
}
示例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);
}
示例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));
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
}
示例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);
}
};
}
示例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);
}
}
示例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;
}