internal static SQLiteCommand CreateUser(ConnectionContextSQLite ctx, ref UserAccounts.FCUser user) { var command = new SQLiteCommand(null, ctx.connection, ctx.transaction); SQLiteParameter p = new SQLiteParameter("@name", DbType.String); p.Value = user.name; command.Parameters.Add(p); p = new SQLiteParameter("@pass", DbType.String); p.Value = user.pass; command.Parameters.Add(p); p = new SQLiteParameter("@guid", DbType.String); p.Value = user.g.ToString("B"); command.Parameters.Add(p); // if not exists - create as !Enabled var sb = new StringBuilder( @"INSERT into Users (Name, Pass, Guid, Status, UserCreated, IpCreated) values (@name, @pass, @guid, 0, 1, '192.168.0.0')" // 0 == disabled ); command.CommandText = sb.ToString(); return(command); }
// idYc - each EntryPoint has reference to YieldCurve settings public ResponseEntryPointHistory GetYcHistoricEntryPoints(DateTime settlementDate, YieldCurveDefinition ycDef) { ResponseEntryPointHistory result = new ResponseEntryPointHistory(); try { UserAccounts.FCUser user = (UserAccounts.FCUser)HttpContext.Current.Session["user"]; if (user == null) { result.Error = new CustomException(); result.Error.Message = "Client is not authenticated, will work in Demo read-only mode"; } result = GetEntryPointHistoryList(settlementDate, ycDef.Id); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } result.Error = new CustomException(); result.Error.Message = ex.Message + ex.StackTrace; } return(result); }
// get complete EntryPoint definition by InstrumentId (ep.Instrument.Id) and InstrumentType (ep.Type = {"bond", "swap", "deposit"}) public ResponseEntryPointsByInstrument GetEntryPointByInstrument(Instrument instr) { ResponseEntryPointsByInstrument result = new ResponseEntryPointsByInstrument(); try { UserAccounts.FCUser user = (UserAccounts.FCUser)HttpContext.Current.Session["user"]; if (user == null) { result.Error = new CustomException(); result.Error.Message = "Client is not authenticated, will work in Demo read-only mode"; } result.epList = DataFeed.Repository.GetEntryPointByInstrument(instr); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } result.Error = new CustomException(); result.Error.Message = ex.Message + ex.StackTrace; } return(result); }
public ResponseAddEntryPointHistory AddEntryPointHistory(List <EntryPoint> epl) { ResponseAddEntryPointHistory result = new ResponseAddEntryPointHistory(); try { // Check if invoked from web-form UserAccounts.FCUser user = (UserAccounts.FCUser)HttpContext.Current.Session["user"]; if (user == null) { throw new Exception("Client is not authenticated"); } DataFeed.Repository.AddEntryPointHistory(epl); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } result.Error = new CustomException(); result.Error.Message = ex.Message + ex.StackTrace; } return(result); }
internal static MySqlCommand CheckSignInUser(ConnectionContextMySQL ctx, UserAccounts.FCUser user) { var command = new MySqlCommand(null, ctx.connection, ctx.transaction); MySqlParameter p = new MySqlParameter("@name", MySqlDbType.String); p.Value = user.name; command.Parameters.Add(p); p = new MySqlParameter("@pass", MySqlDbType.String); p.Value = user.pass; command.Parameters.Add(p); // check if exists, check guid, set Enabled if ok var sb = new StringBuilder( @"SELECT Name, Pass, Guid, Status FROM Users WHERE Name = @name AND Pass = @pass" ); if (user.g != Guid.Empty) { sb.Append(" AND Guid = @g"); p = new MySqlParameter("@g", MySqlDbType.String); p.Value = user.g.ToString("B"); command.Parameters.Add(p); } command.CommandText = sb.ToString(); return(command); }
public ResponseGetAllEntryPointsData GetAllEntryPoints(bool isDemo) { ResponseGetAllEntryPointsData result = new ResponseGetAllEntryPointsData(); try { UserAccounts.FCUser user = (UserAccounts.FCUser)HttpContext.Current.Session["user"]; if (user == null) { result.Error = new CustomException(); result.Error.Message = "Client is not authenticated, will work in Demo read-only mode"; isDemo = true; } result.epl = DataFeed.Repository.GetAllEntryPoints(isDemo); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } result.Error = new CustomException(); result.Error.Message = ex.Message + ex.StackTrace; } return(result); }
internal static bool ConfirmUser(ConnectionContextMySQL ctx, UserAccounts.FCUser user) { UserAccounts.FCUser tmp = CheckSignInUser(ctx, user); if (tmp == null || tmp.g == Guid.Empty || tmp.status != UserAccounts.FCUser.eStatus.eDisabled ) { return(false); } // creates or confirms user var command = SqlHelper.ConfirmUser(ctx, user); try { command.ExecuteNonQuery(); command.CommandText = "Commit"; command.ExecuteNonQuery(); } catch (Exception ex) { return(false); } return(true); }
internal static MySqlCommand ConfirmUser(ConnectionContextMySQL ctx, UserAccounts.FCUser user) { var command = new MySqlCommand(null, ctx.connection, ctx.transaction); MySqlParameter p = new MySqlParameter("@name", MySqlDbType.String); p.Value = user.name; command.Parameters.Add(p); p = new MySqlParameter("@pass", MySqlDbType.String); p.Value = user.pass; command.Parameters.Add(p); p = new MySqlParameter("@guid", MySqlDbType.String); p.Value = user.g.ToString("B"); command.Parameters.Add(p); // check if exists, check guid, set Enabled if ok var sb = new StringBuilder( @"UPDATE Users SET Status = 1 WHERE Name = @name AND Pass = @pass AND Guid = @guid" ); command.CommandText = sb.ToString(); return(command); }
// // UserAccounts // internal static SQLiteCommand CheckUser(ConnectionContextSQLite ctx, UserAccounts.FCUser user) { var command = new SQLiteCommand(null, ctx.connection, ctx.transaction); SQLiteParameter p = new SQLiteParameter("@name", DbType.String); p.Value = user.name; command.Parameters.Add(p); // check if exists, check guid, set Enabled if ok var sb = new StringBuilder( @"SELECT Name FROM Users WHERE Name = @name " ); command.CommandText = sb.ToString(); return(command); }
// // User Accounts // internal static bool CreateUser(ConnectionContextSQLite ctx, UserAccounts.FCUser user) { // // Check if already exists with such name // var command = SqlHelperSQLite.CheckUser(ctx, user); string name = string.Empty; using (var reader = command.ExecuteReader()) { while (reader.Read()) { name = reader.IsDBNull(reader.GetOrdinal("Name")) ? "" : reader.GetString(reader.GetOrdinal("Name")); if (string.IsNullOrEmpty(name)) { return(false); } } } // such user already exists if (!string.IsNullOrEmpty(name)) { return(false); } // // creates non-confirmed user // command = SqlHelperSQLite.CreateUser(ctx, ref user); try { command.ExecuteNonQuery(); command.CommandText = "Commit"; command.ExecuteNonQuery(); } catch (Exception ex) { Utilities.Logger.WriteError(String.Format("CreateUser() failed - {0}", ex.Message)); return(false); } return(true); }
public bool LoginUser(string name, string pass) { UserAccounts.FCUser tmp = UserAccounts.Repository.LoginUser(name, pass); if (tmp == null || tmp.status != UserAccounts.FCUser.eStatus.eEnabled) { // can't login return(false); } /* * Guid currentSessionId = new Guid(OperationContext.Current.SessionId); * UserAccounts.FCUser.sActiveUsersDic[sessionId] = tmp; */ HttpContext.Current.Session.Timeout = 60; HttpContext.Current.Session["LoggedIn"] = true; HttpContext.Current.Session["user"] = tmp; return(true); }
/// <summary> /// sql storage connection string /// </summary> //private static string connectionString = null; #endregion #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="SeamContext"/> class. /// Default constructor /// </summary> public ConnectionContextSQLite() { if (HttpContext.Current != null && HttpContext.Current.Session != null) { user = (UserAccounts.FCUser)HttpContext.Current.Session["user"]; } //string connectionString = ConfigurationManager.ConnectionStrings["SQLiteTest"].ConnectionString; if (_connection == null) { string path = AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\"; string db3file = path + "qlc.db3"; string connectionString = string.Format("Data Source={0};Version=3;", db3file); _connection = new SQLiteConnection(connectionString); _connection.Open(); } this.transaction = _connection.BeginTransaction(); this.contextData = null; }
internal static UserAccounts.FCUser LoginUser(ConnectionContextSQLite ctx, string name, string pass) { var command = SqlHelperSQLite.LoginUser(ctx, name, pass); List <UserAccounts.FCUser> users = new List <UserAccounts.FCUser>(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var s = reader.IsDBNull(reader.GetOrdinal("Status")) ? 0 : reader.GetInt32(reader.GetOrdinal("Status")); if (s <= 0) { s = 0; } var g = reader.IsDBNull(reader.GetOrdinal("Guid")) ? "" : reader.GetString(reader.GetOrdinal("Guid")); var tmp = new UserAccounts.FCUser { id = reader.IsDBNull(reader.GetOrdinal("Status")) ? 0 : reader.GetInt32(reader.GetOrdinal("Id")), name = reader.IsDBNull(reader.GetOrdinal("Name")) ? "" : reader.GetString(reader.GetOrdinal("Name")), pass = reader.IsDBNull(reader.GetOrdinal("Pass")) ? "" : reader.GetString(reader.GetOrdinal("Pass")), g = string.IsNullOrEmpty(g) ? Guid.Empty : new Guid(g), status = (UserAccounts.FCUser.eStatus)s }; users.Add(tmp); } } if (users.Count == 1 && users[0].g != Guid.Empty //&& users[0].status != FCUser.eStatus.eDisabled ) { return(users[0]); } return(null); }
internal static UserAccounts.FCUser CheckSignInUser(ConnectionContextMySQL ctx, UserAccounts.FCUser user) { var command = SqlHelper.CheckSignInUser(ctx, user); List <UserAccounts.FCUser> users = new List <UserAccounts.FCUser>(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var s = reader.IsDBNull(reader.GetOrdinal("Status")) ? 0 : reader.GetInt32(reader.GetOrdinal("Status")); if (s <= 0) { s = 0; } var g = reader.IsDBNull(reader.GetOrdinal("Guid")) ? "" : reader.GetString(reader.GetOrdinal("Guid")); var tmp = new UserAccounts.FCUser { name = reader.IsDBNull(reader.GetOrdinal("Name")) ? "" : reader.GetString(reader.GetOrdinal("Name")), pass = reader.IsDBNull(reader.GetOrdinal("Pass")) ? "" : reader.GetString(reader.GetOrdinal("Pass")), g = string.IsNullOrEmpty(g) ? Guid.Empty : new Guid(g), status = (UserAccounts.FCUser.eStatus)s }; users.Add(tmp); } } if (users.Count == 1 && users[0].g != Guid.Empty ) { return(users[0]); } return(null); }
// // User Accounts // internal static bool CreateUser(ConnectionContextMySQL ctx, UserAccounts.FCUser user) { UserAccounts.FCUser tmp = CheckSignInUser(ctx, user); if (tmp != null) { Utilities.Logger.WriteError(String.Format("CreateUser() failed - user already exists: {0}", user.name)); return(false); } // creates or confirms user var command = SqlHelper.CreateUser(ctx, user); try { command.ExecuteNonQuery(); command.CommandText = "Commit"; command.ExecuteNonQuery(); } catch (Exception ex) { Utilities.Logger.WriteError(String.Format("CreateUser() failed - {0}", ex.Message)); return(false); } return(true); }
// // DataFeed: set ASP.NET compatibility mode: <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> // public ResponseInitData InitData() { /* * // Check if invoked from web-form * UserAccounts.FCUser user = (UserAccounts.FCUser)HttpContext.Current.Session["user"]; * if (user == null) * { * // --need wsHttpBinding, which is not supported by Silverlight * * // Otherwise check if invoked by API * Guid sessionId = new Guid(OperationContext.Current.SessionId); * if (!UserAccounts.FCUser.sActiveUsersDic.ContainsKey(sessionId)) * { * // user is not authenticated, demo mode = ON, read-only access * } * else * user = UserAccounts.FCUser.sActiveUsersDic[sessionId]; * } */ ResponseInitData result = new ResponseInitData(); try { if (HttpContext.Current == null || HttpContext.Current.Session == null) { throw new Exception("=== no connection made"); } UserAccounts.FCUser user = (UserAccounts.FCUser)HttpContext.Current.Session["user"]; if (user == null) { result.Error = new CustomException(); result.Error.Message = "Client is not authenticated, will work in Demo read-only mode"; } // needs quantlib class factory GetDayCounterDic(); // shell be before Rate and YieldCurveData, cos those are using DayCounter inside foreach (var v in GetCurrencyDataDic().CurrencyDic.Values) { result.ccyList.Add(v); } foreach (var v in GetRateDataDic().RateDic.Values) { result.instrList.Add(v); } foreach (var v in GetBondDataDic().BondDic.Values) { result.instrList.Add(v); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } result.Error = new CustomException(); result.Error.Message = ex.Message + ex.StackTrace; } return(result); }