상속: 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
 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
        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
 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
        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
        public ITikCommand CreateCommandAndParameters(string commandText, params string[] parameterNamesAndValues)
        {
            var result = new ApiCommand(this, commandText);
            result.AddParameterAndValues(parameterNamesAndValues);

            return result;
        }
예제 #13
0
        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
 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();
     }
 }