本文整理汇总了C#中System.Net.Connection.CloseConnection方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.CloseConnection方法的具体用法?C# Connection.CloseConnection怎么用?C# Connection.CloseConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Connection
的用法示例。
在下文中一共展示了Connection.CloseConnection方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public User Register([FromBody] User user)
{
_conn = new Connection(_connectionString);
_conn.OpenConnection();
//Calculate MD5 hash
MD5 md5 = MD5.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(user.Username + user.PasswordHash + DateTime.Now);
byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder tokenString = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
tokenString.Append(hash[i].ToString("X2"));
}
bool result = _conn.Register(user.Username, user.PasswordHash, tokenString.ToString());
_conn.CloseConnection();
if (result)
{
user.Token = tokenString.ToString();
return user;
}
else
{
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Conflict));
}
}
示例2: SearchDocuments
public IEnumerable<Document> SearchDocuments(string token, string pattern)
{
_conn = new Connection(_connectionString);
try
{
_conn.OpenConnection();
return !string.IsNullOrEmpty(_conn.GetUsernameByToken(token)) ? _conn.SearchDocuments(pattern) : null;
}
finally
{
_conn.CloseConnection();
}
}
示例3: Delete
public bool Delete([FromUri] string token, [FromUri] long id)
{
_conn = new Connection(_connectionString);
try
{
_conn.OpenConnection();
return !string.IsNullOrEmpty(_conn.GetUsernameByToken(token)) && _conn.DeleteDocument(id);
}
finally
{
_conn.CloseConnection();
}
}
示例4: GetFtpCredential
public NetworkCredential GetFtpCredential([FromUri] string token)
{
_conn = new Connection(_connectionString);
try
{
_conn.OpenConnection();
string username = _conn.GetUsernameByToken(token);
return !string.IsNullOrEmpty(username) ? _accessCredential : null;
}
finally
{
_conn.CloseConnection();
}
}
示例5: Login
public User Login([FromBody] User user)
{
_conn = new Connection(_connectionString);
try
{
_conn.OpenConnection();
string token = _conn.Login(user.Username, user.PasswordHash);
if (!string.IsNullOrEmpty(token))
{
user.Token = token;
return user;
}
else
{
throw new Exception("Error login");
}
}
finally
{
_conn.CloseConnection();
}
}
示例6: UploadDocument
public Document UploadDocument(string token, string name, long size, string description)
{
_conn = new Connection(_connectionString);
_conn.OpenConnection();
string username = _conn.GetUsernameByToken(token);
try
{
if (!string.IsNullOrEmpty(username))
{
Document doc = new Document()
{
Name = name,
Size = size,
Author = username,
Path = _ftpUri + name,
Description = description
};
return _conn.UploadDocument(doc) ? doc : null;
}
else
{
return null;
}
}
finally
{
_conn.CloseConnection();
}
}
示例7: HandleIncomingMessage
private static void HandleIncomingMessage(PacketHeader header, Connection connection, iRTVOMessage incomingMessage)
{
logger.Log(NLog.LogLevel.Debug,"HandleIncomingMessage: {0}", incomingMessage.ToString());
if (isServer && (incomingMessage.Command == "AUTHENTICATE"))
{
if ((incomingMessage.Arguments == null) || (incomingMessage.Arguments.Count() != 1))
{
logger.Error("HandleIncomingMessage: Wrong arguments to Authenticate from {0}", connection.ConnectionInfo.NetworkIdentifier);
connection.CloseConnection(false,-100);
return;
}
if (String.Compare(_Password, Convert.ToString(incomingMessage.Arguments[0])) != 0)
{
logger.Error("HandleIncomingMessage: Worng Password from {0}", connection.ConnectionInfo.NetworkIdentifier);
connection.CloseConnection(false,-200);
}
logger.Info("Client {0} authenticated.", connection.ConnectionInfo.NetworkIdentifier);
isAuthenticated[connection.ConnectionInfo.NetworkIdentifier] = true;
connection.SendObject("iRTVOMessage", new iRTVOMessage(NetworkComms.NetworkIdentifier, "AUTHENTICATED"));
if (_NewClient != null)
_NewClient(connection.ConnectionInfo.NetworkIdentifier);
return;
}
if (!isServer && (incomingMessage.Command == "AUTHENTICATED"))
{
if (_ClientConnectionEstablished != null)
_ClientConnectionEstablished();
return;
}
if (isServer && (!isAuthenticated.ContainsKey(connection.ConnectionInfo.NetworkIdentifier) || !isAuthenticated[connection.ConnectionInfo.NetworkIdentifier]))
{
logger.Warn("HandleIncomingMessage: Command from unauthorized client {0}",connection.ConnectionInfo.NetworkIdentifier);
connection.CloseConnection(false,-300);
return;
}
iRTVORemoteEvent e = new iRTVORemoteEvent(incomingMessage);
if (_ProcessMessage != null)
{
using ( TimeCall tc = new TimeCall("ProcessMessage") )
_ProcessMessage(e);
}
// Handler signals to abort this connection!
if (e.Cancel)
{
logger.Error("HandleIncomingMessage: ProcessMessage signaled to close client {0}", connection.ConnectionInfo.NetworkIdentifier);
connection.CloseConnection(true, -400);
}
else
{
if (isServer && e.Forward)
ForwardMessage(incomingMessage);
}
}
示例8: fetchInformation
//.........这里部分代码省略.........
}
CharacterRootObject character_information = Newtonsoft.Json.JsonConvert.DeserializeObject<CharacterRootObject>(conn.jsonresponse);
List<CharacterItem> character_item = character_information.items;
character_images = new List<string>();
character_images.Clear();
foreach (CharacterItem item in character_item)
{
if (item.image != null)
character_images.Add(item.image);
}
if (Update == false)
error = conn.Query("get vn tags (id = " + txtID.Text + " )");
else
error = conn.Query("get vn tags (id = " + id + " )");
if (error == 1)
{
MessageBox.Show("Error while requesting information. Response: " + conn.jsonresponse, "Query Error", MessageBoxButtons.OK);
return 0;
}
TagsRootObject tags_information = Newtonsoft.Json.JsonConvert.DeserializeObject<TagsRootObject>(conn.jsonresponse); //deserialize them
List<TagsItem> tags_item = tags_information.items;
if (Update == false)
{
for (int i = 0; i < tags_item[0].tags.Count; i++) //Store them in textbox
{
if (txtTags.Text == "")
nice = "";
else
nice = " ";
txtTags.Text = txtTags.Text + nice + Convert.ToString(tags_item[0].tags[i][0]);
}
}
else
{
VNS[vns_number].tags = "";
for (int i = 0; i < tags_item[0].tags.Count; i++) //Store them in textbox
{
if (VNS[vns_number].tags == "")
nice = "";
else
nice = " ";
VNS[vns_number].tags = VNS[vns_number].tags + nice + Convert.ToString(tags_item[0].tags[i][0]);
}
}
if (plain_tags == null) //Read tag-dump and deserialize it (only once -> needs time!)
plain_tags = JsonConvert.DeserializeObject<List<WrittenTagsRootObject>>(File.ReadAllText(@"tags.json"));
string[] tags;
if (Update == false)
tags = txtTags.Text.Split(' ');
else
tags = VNS[vns_number].tags.Split(' ');
if (Update == false)
txtTags.Text = "";
else
VNS[vns_number].tags = "";
foreach (string tmp in tags) //Change our 'int'-tags into matching 'string'-tags
{
foreach (WrittenTagsRootObject tmp2 in plain_tags)
{
if ((((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "ero") && (chkSexual.Checked == true)) ||
((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "cont") && (chkContent.Checked == true)) ||
((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "tech") && (chkTechnical.Checked == true))) && Update == false)
{
if (txtTags.Text == "")
nice = "";
else
nice = ", ";
txtTags.Text = txtTags.Text + nice + tmp2.name;
}
else if ((((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "ero") && (chkSexual.Checked == true)) ||
((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "cont") && (chkContent.Checked == true)) ||
((Convert.ToInt32(tmp) == tmp2.id) && (tmp2.cat == "tech") && (chkTechnical.Checked == true))) && Update == true)
{
if (VNS[vns_number].tags == "")
nice = "";
else
nice = ", ";
VNS[vns_number].tags = VNS[vns_number].tags + nice + tmp2.name;
}
}
}
conn.CloseConnection();
return vns_number;
}
示例9: RemoveFromConnectionList
// When client closes, this Server should receive packet of string type "Disconnection", report to console and remove IP from ConnectionsList...
public static void RemoveFromConnectionList(PacketHeader header, Connection connection, string Disconnection)
{
// Formulate which client has just disconnected...
disconLastclient = connection.ConnectionInfo.RemoteEndPoint.Address.ToString();
string disconClientName = ConnectionsList.Single(element => element.Contains(disconLastclient));
Console.WriteLine("\n" + disconClientName + " has DISCONNECTED!");
// ...and remove it from ConnectionsList HashSet
ConnectionsList.RemoveWhere(element => element.Contains(disconLastclient));
// Close the connection...
connection.CloseConnection(false);
// Notify remaining clients of the disconnection...
foreach (var item in NetworkComms.GetExistingConnection())
{
item.SendObject("Disconnection", disconLastclient);
}
if (ConnectionsList.Count > 0)
{
Console.WriteLine("\nCurrent Clients:");
foreach (var item in ConnectionsList) { Console.WriteLine(item); };
var currentclients = ConnectionsList.Distinct();
foreach (var item in NetworkComms.GetExistingConnection())
{
item.SendObject("Connection", currentclients);
}
}
if (ConnectionsList.Count == 0)
{
Console.WriteLine("No Connected Clients.");
}
}
示例10: RemoveFromConnectionList_Server
// When client closes, this Server should receive packet of string type "Disconnection", report to console and remove IP from ConnectionsList...
private static void RemoveFromConnectionList_Server(PacketHeader header, Connection connection, string Disconnection)
{
// Formulate which client has just disconnected...
disconLastclient = connection.ConnectionInfo.RemoteEndPoint.Address.ToString();
string disconClientName = ConnectionsList_Server.Single(element => element.Contains(disconLastclient));
// ...and remove it from ConnectionsList HashSet
ConnectionsList_Server.RemoveWhere(element => element.Contains(disconLastclient));
// Close the connection...
connection.CloseConnection(false);
// Notify remaining clients of the disconnection...
foreach (var item in NetworkComms.GetExistingConnection())
{
item.SendObject("Disconnection", disconLastclient);
}
if (ConnectionsList_Server.Count > 0)
{
richTextBox1.AppendText("\nCurrent Clients:" + Environment.NewLine);
foreach (var item in ConnectionsList_Server) { richTextBox1.AppendText(item); };
var currentclients = ConnectionsList_Server.Distinct();
foreach (var item in NetworkComms.GetExistingConnection())
{
item.SendObject("Connection", currentclients);
}
}
if (ConnectionsList_Server.Count == 0)
{
richTextBox1.AppendText("No Connected Clients." + Environment.NewLine);
}
}