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