Inheritance: ITikCommand
コード例 #1
0
        //private void LoginInternal(string user, string password)
        //{
        //    switch (_loginProcessVersion)
        //    {
        //        case LoginProcessVersion.Version1:
        //            Login_v1(user, password, true);
        //            break;
        //        case LoginProcessVersion.Version2:
        //            Login_v2(user, password);
        //            break;
        //        default:
        //            throw new NotImplementedException(string.Format("Unsuported login process version {0}", _loginProcessVersion));
        //    }
        //}

        //private void Login_v1(string user, string password, bool allowLoginProcessVersion2Fallback)
        //{
        //    //Get login hash
        //    string responseHash;
        //    try
        //    {
        //        ApiCommand readLoginHashCommand = new ApiCommand(this, "/login");
        //        responseHash = readLoginHashCommand.ExecuteScalar();
        //    }
        //    catch(TikCommandException) //TODO catch specific exception / message
        //    {
        //        if (allowLoginProcessVersion2Fallback)
        //        {
        //            Login_v2(user, password); // try it via newer login process
        //            return;
        //        }
        //        else
        //            throw;
        //    }

        //    //login connection
        //    string hashedPass = ApiConnectionHelper.EncodePassword(password, responseHash);
        //    ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
        //        new ApiCommandParameter("name", user), new ApiCommandParameter("response", hashedPass));
        //    loginCommand.ExecuteNonQuery();
        //}

        //private void Login_v2(string user, string password)
        //{
        //    //login connection
        //    ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
        //        new ApiCommandParameter("name", user), new ApiCommandParameter("password", password));
        //    loginCommand.ExecuteNonQuery();
        //}

        private void Login_v3(string user, string password)
        {
            try
            {
                ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                                                         new ApiCommandParameter("name", user), new ApiCommandParameter("password", password)); //parameters will be ignored with old login protocol

                var responseHashOrNull = loginCommand.ExecuteScalarOrDefault();

                //old login protocol
                if (!string.IsNullOrEmpty(responseHashOrNull))
                {
                    //login connection
                    string     hashedPass    = ApiConnectionHelper.EncodePassword(password, responseHashOrNull);
                    ApiCommand loginCommand2 = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                                                              new ApiCommandParameter("name", user), new ApiCommandParameter("response", hashedPass));
                    loginCommand2.ExecuteNonQuery();
                }
            }
            catch (TikCommandTrapException ex)
            {
                if (ex.Message == "cannot log in")
                {
                    throw new TikConnectionLoginException();
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #2
0
        private void Login_v1(string user, string password, bool allowLoginProcessVersion2Fallback)
        {
            //Get login hash
            string responseHash;

            try
            {
                ApiCommand readLoginHashCommand = new ApiCommand(this, "/login");
                responseHash = readLoginHashCommand.ExecuteScalar();
            }
            catch (TikCommandException) //TODO catch specific exception / message
            {
                if (allowLoginProcessVersion2Fallback)
                {
                    Login_v2(user, password); // try it via newer login process
                    return;
                }
                else
                {
                    throw;
                }
            }

            //login connection
            string     hashedPass   = ApiConnectionHelper.EncodePassword(password, responseHash);
            ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                                                     new ApiCommandParameter("name", user), new ApiCommandParameter("response", hashedPass));

            loginCommand.ExecuteNonQuery();
        }
コード例 #3
0
 private bool CancelInternal(bool joinLoadingThread, int milisecondsTimeout)
 {
     if (_isRuning && _runningTag >= 0)
     {
         ApiCommand cancellCommand = new ApiCommand(_connection, "/cancel", new ApiCommandParameter(TikSpecialProperties.Tag, _runningTag.ToString()));  //REMARKS: =tag=1234 and not =.tag=1234
         cancellCommand.ExecuteNonQuery();
         if (joinLoadingThread)
         {
             Thread loadingThread = _asyncLoadingThread;
             if (loadingThread != null)
             {
                 if (milisecondsTimeout > 0)
                 {
                     return(loadingThread.Join(milisecondsTimeout));
                 }
                 else
                 {
                     loadingThread.Join();
                     return(true);
                 }
             }
         }
     }
     return(true);
 }
コード例 #4
0
 private bool CancelInternal(bool joinLoadingThread, int milisecondsTimeout)
 {
     if (_isRuning && _asynchronouslyRunningTag >= 0)
     {
         ApiCommand cancellCommand = new ApiCommand(_connection, "/cancel",
                                                    new ApiCommandParameter("tag", _asynchronouslyRunningTag.ToString(), TikCommandParameterFormat.NameValue),                    // tag we are cancelling: REMARKS: =tag=1234 and not =.tag=1234
                                                    new ApiCommandParameter(TikSpecialProperties.Tag, "c_" + _asynchronouslyRunningTag.ToString(), TikCommandParameterFormat.Tag) //tag of cancell command itself
                                                    );
         cancellCommand.ExecuteNonQuery();
         if (joinLoadingThread)
         {
             Thread loadingThread = _asyncLoadingThread;
             if (loadingThread != null)
             {
                 if (milisecondsTimeout > 0)
                 {
                     return(loadingThread.Join(milisecondsTimeout));
                 }
                 else
                 {
                     loadingThread.Join();
                     return(true);
                 }
             }
         }
     }
     return(true);
 }
コード例 #5
0
        public ITikCommand CreateCommandAndParameters(string commandText, params string[] parameterNamesAndValues)
        {
            var result = new ApiCommand(this, commandText);

            result.AddParameterAndValues(parameterNamesAndValues);

            return(result);
        }
コード例 #6
0
        private void Login_v2(string user, string password)
        {
            //login connection
            ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                                                     new ApiCommandParameter("name", user), new ApiCommandParameter("password", password));

            loginCommand.ExecuteNonQuery();
        }
コード例 #7
0
ファイル: ApiCommand.cs プロジェクト: LeonardoMtnez/tik4net
 public void Cancel()
 {
     if (_isRuning && _runningTag >= 0)
     {
         ApiCommand cancellCommand = new ApiCommand(_connection, "/cancel", new ApiCommandParameter(TikSpecialProperties.Tag, _runningTag.ToString())); //REMARKS: =tag=1234 and not =.tag=1234
         cancellCommand.ExecuteNonQuery();
     }
 }
コード例 #8
0
ファイル: ApiConnection.cs プロジェクト: DaveSchmid/tik4net
        private void LoginOld(string user, string password)
        {
            //Get login hash
            ApiCommand readLoginHashCommand = new ApiCommand(this, "/login");
            string     responseHash         = readLoginHashCommand.ExecuteScalar();

            //login connection
            string     hashedPass   = ApiConnectionHelper.EncodePassword(password, responseHash);
            ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                                                     new ApiCommandParameter("name", user), new ApiCommandParameter("response", hashedPass));

            loginCommand.ExecuteNonQuery();
        }
コード例 #9
0
        public void Open(string host, int port, string user, string password)
        {
            //open connection
            _tcpConnection = new TcpClient();
            _tcpConnection.Connect(host, port);
            _tcpConnectionStream = _tcpConnection.GetStream();

            //Get login hash
            ApiCommand readLoginHashCommand = new ApiCommand(this, "/login");
            string     responseHash         = readLoginHashCommand.ExecuteScalar();

            //login connection
            string     hashedPass   = ApiConnectionHelper.EncodePassword(password, responseHash);
            ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                                                     new ApiCommandParameter("name", user), new ApiCommandParameter("response", hashedPass));

            loginCommand.ExecuteNonQuery();

            _isOpened = true;
        }
コード例 #10
0
ファイル: ApiCommand.cs プロジェクト: D-Bullock/tik4net
 private bool CancelInternal(bool joinLoadingThread, int milisecondsTimeout)
 {
     if (_isRuning && _runningTag >= 0)
     {
          ApiCommand cancellCommand = new ApiCommand(_connection, "/cancel", new ApiCommandParameter(TikSpecialProperties.Tag, _runningTag.ToString())); //REMARKS: =tag=1234 and not =.tag=1234
          cancellCommand.ExecuteNonQuery();
         if (joinLoadingThread)
         {
             Thread loadingThread = _asyncLoadingThread;
             if (loadingThread != null)
             {
                 if (milisecondsTimeout > 0)
                     return loadingThread.Join(milisecondsTimeout);
                 else
                 {
                     loadingThread.Join();
                     return true;
                 }
             }
         }
     }
     return true;
 }
コード例 #11
0
ファイル: ApiConnection.cs プロジェクト: Hispanion/tik4net
        public void Open(string host, int port, string user, string password)
        {
            //open connection
            _tcpConnection = new TcpClient();
            _tcpConnection.Connect(host, port);
            _tcpConnectionStream = _tcpConnection.GetStream();

            //Get login hash
            ApiCommand readLoginHashCommand = new ApiCommand(this, "/login");
            string responseHash = readLoginHashCommand.ExecuteScalar();

            //login connection
            string hashedPass = ApiConnectionHelper.EncodePassword(password, responseHash);
            ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                new ApiCommandParameter("name", user), new ApiCommandParameter("response", hashedPass));
            loginCommand.ExecuteNonQuery();

            _isOpened = true;
        }
コード例 #12
0
ファイル: ApiConnection.cs プロジェクト: Hispanion/tik4net
        public ITikCommand CreateCommandAndParameters(string commandText, params string[] parameterNamesAndValues)
        {
            var result = new ApiCommand(this, commandText);
            result.AddParameterAndValues(parameterNamesAndValues);

            return result;
        }
コード例 #13
0
ファイル: ApiConnection.cs プロジェクト: D-Bullock/tik4net
        private void Login(string user, string password)
        {
            //Get login hash
            ApiCommand readLoginHashCommand = new ApiCommand(this, "/login");
            string responseHash = readLoginHashCommand.ExecuteScalar();

            //login connection
            string hashedPass = ApiConnectionHelper.EncodePassword(password, responseHash);
            ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                new ApiCommandParameter("name", user), new ApiCommandParameter("response", hashedPass));
            loginCommand.ExecuteNonQuery();
        }
コード例 #14
0
ファイル: ApiCommand.cs プロジェクト: Hispanion/tik4net
 public void Cancel()
 {
     if (_isRuning && _runningTag >= 0)
     {
         ApiCommand cancellCommand = new ApiCommand(_connection, "/cancel", new ApiCommandParameter(TikSpecialProperties.Tag, _runningTag.ToString())); //REMARKS: =tag=1234 and not =.tag=1234
         cancellCommand.ExecuteNonQuery();
     }
 }