我试图创建一个winforms应用程序来连接到bopup IM服务器。提供的示例是在Visual Basic中,我试图确定如何使用C#。
原件:
Sub Main()
Dim Err As String
Dim ResultCode As UInteger
Client = New CSCLIENTLib.ServerClientVB
Console.WriteLine("This sample console application is written on Microsoft Visual Basic 2012 and demonstrates how to use Bopup IM Client SDK version 1.0.")
Console.WriteLine("Copyright(C) 2012-2015 B Labs. All right reserved.")
Console.WriteLine()
Console.WriteLine("*** CONNECTING TO IM SERVER ***")
Console.WriteLine()
Console.WriteLine()
Console.WriteLine("> Enter IP address or computer name of Bopup Communication Server:")
Dim server = Console.ReadLine()
Console.WriteLine()
Console.WriteLine("> Enter a numeric value to indicate Authentication Mode to use for connection with the IM server:")
Console.WriteLine("0 - Simple")
Console.WriteLine("1 - Windows Authentication")
Console.WriteLine("2 - Login/password")
Dim authentication = Console.ReadLine()
Console.WriteLine()
Console.WriteLine("> Enter account name under which you want to connect to the IM server:")
Dim account = Console.ReadLine()
Dim password As String = vbNull
If (authentication = VBAuthenticationMode.Windows Or
authentication = VBAuthenticationMode.Password) Then
Console.WriteLine()
Console.WriteLine("> Enter password for the account:")
password = Console.ReadLine()
End If
Try
Client.Initialize(server, 0, VBClientType.Messenger, vbNull, ResultCode)
Client.OpenSession(authentication, account, password, vbNull, vbNull, vbNull, vbNull, ResultCode)
Console.WriteLine()
Console.WriteLine("> Connected to the IM server!")
Catch ex As Exception
Console.WriteLine(ex.ToString)
Client.GetEventDescription(ResultCode, Err)
Console.WriteLine("Error occured: {0}", Err)
Console.WriteLine()
Console.WriteLine("Press Enter to exit")
Console.ReadLine()
Environment.Exit(0)
End Try
Dim operation
Do
Console.WriteLine()
Console.WriteLine("> Enter a numeric value to perform specific operation to the IM server:")
Console.WriteLine("0 - Display current user account information")
Console.WriteLine("1 - Retrieve a list of available contacts")
Console.WriteLine("2 - Retrieve a list of assigned messaging groups")
Console.WriteLine("3 - Display IM server version")
Console.WriteLine("4 - Display current IM session ID")
Console.WriteLine("5 - Close IM session and disconnect from the server")
operation = Console.ReadLine()
If (operation = "0") Then
ShowAccountInfo(account)
ElseIf (operation = "1") Then
ShowContacts()
ElseIf (operation = "2") Then
ShowGroups()
ElseIf (operation = "3") Then
ShowServerVersion()
ElseIf (operation = "4") Then
ShowSessionId()
End If
Loop While (operation <> "5")
Console.WriteLine()
Console.WriteLine("Disconnecting from the IM server and shutting down the client...")
Try
Client.CloseSession()
Console.WriteLine()
Console.WriteLine("> Disconnected")
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try
Console.WriteLine()
Console.WriteLine("Press Enter to exit")
Console.ReadLine()
End Sub
我的尝试:
static void Main(string[] args)
{
string Err;
uint ResultCode;
Client = new CSCLIENTLib.ServerClientVB();
Console.WriteLine("This sample console application is written on Microsoft Visual Basic 2012 and demonstrates how to use Bopup IM Client SDK version 1.0.");
Console.WriteLine("Copyright(C) 2012-2015 B Labs. All right reserved.");
Console.WriteLine();
Console.WriteLine("*** CONNECTING TO IM SERVER ***");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("> Enter IP address or computer name of Bopup Communication Server:");
var server = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("> Enter a numeric value to indicate Authentication Mode to use for connection with the IM server:");
Console.WriteLine("0 - Simple");
Console.WriteLine("1 - Windows Authentication");
Console.WriteLine("2 - Login/password");
var authentication = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("> Enter account name under which you want to connect to the IM server:");
var account = Console.ReadLine();
string password = null;
if ((authentication == CSCLIENTLib.VBAuthenticationMode.Windows | authentication == VBAuthenticationMode.Password))
{
Console.WriteLine();
Console.WriteLine("> Enter password for the account:");
password = Console.ReadLine();
}
try
{
Client.Initialize(server, 0, VBClientType.Messenger, CSCLIENTLib.Constants.vbNull, ResultCode);
Client.OpenSession(authentication, account, password, Constants.vbNull, Constants.vbNull, Constants.vbNull, Constants.vbNull, ResultCode);
Console.WriteLine();
Console.WriteLine("> Connected to the IM server!");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Client.GetEventDescription(ResultCode, Err);
Console.WriteLine("Error occured: {0}", Err);
Console.WriteLine();
Console.WriteLine("Press Enter to exit");
Console.ReadLine();
Environment.Exit(0);
}
var operation;
do
{
Console.WriteLine();
Console.WriteLine("> Enter a numeric value to perform specific operation to the IM server:");
Console.WriteLine("0 - Display current user account information");
Console.WriteLine("1 - Retrieve a list of available contacts");
Console.WriteLine("2 - Retrieve a list of assigned messaging groups");
Console.WriteLine("3 - Display IM server version");
Console.WriteLine("4 - Display current IM session ID");
Console.WriteLine("5 - Close IM session and disconnect from the server");
operation = Console.ReadLine();
if ((operation == "0"))
ShowAccountInfo(account);
else if ((operation == "1"))
ShowContacts();
else if ((operation == "2"))
ShowGroups();
else if ((operation == "3"))
ShowServerVersion();
else if ((operation == "4"))
ShowSessionId();
}
while ((operation != "5"));
Console.WriteLine();
Console.WriteLine("Disconnecting from the IM server and shutting down the client...");
try
{
Client.CloseSession();
Console.WriteLine();
Console.WriteLine("> Disconnected");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine();
Console.WriteLine("Press Enter to exit");
Console.ReadLine();
}
我收到了一些我不确定如何解决的错误。第一个是&#39;身份验证== CSCLIENTLib.VBAuthentication.Windows&#39;它说&#39;运算符==不能应用于类型字符串和CSCLIENTLib.VBAuthentication / CSClientLib.VBPassword的opperands
Client.Initialize有一个参数CSCLIENTLib.Constants.vbNull,IDE告诉我它不存在..我缺少什么?