本文整理汇总了C#中System.Net.Connection.OpenConnection方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.OpenConnection方法的具体用法?C# Connection.OpenConnection怎么用?C# Connection.OpenConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Connection
的用法示例。
在下文中一共展示了Connection.OpenConnection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}