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


C# Connection.OpenConnection方法代码示例

本文整理汇总了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));
            }
        }
开发者ID:rinojk,项目名称:ZipDoc,代码行数:27,代码来源:UserController.cs

示例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();
     }
 }
开发者ID:rinojk,项目名称:ZipDoc,代码行数:13,代码来源:DocumentController.cs

示例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();
     }
 }
开发者ID:rinojk,项目名称:ZipDoc,代码行数:13,代码来源:DocumentController.cs

示例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();
     }
 }
开发者ID:rinojk,项目名称:ZipDoc,代码行数:14,代码来源:DocumentController.cs

示例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();
     }
 }
开发者ID:rinojk,项目名称:ZipDoc,代码行数:22,代码来源:UserController.cs

示例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();
     }
 }
开发者ID:rinojk,项目名称:ZipDoc,代码行数:29,代码来源:DocumentController.cs


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