public bool GetUserAppData(ref UserAppData props, ref string result) { string query = string.Empty; query += "SELECT * FROM userdata WHERE "; query += "\"UserId\" = :Id AND "; query += "\"TagId\" = :TagId"; try { using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) { dbcon.Open(); using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) { cmd.Parameters.AddWithValue("Id", props.UserId.ToString()); cmd.Parameters.AddWithValue (":TagId", props.TagId.ToString()); using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if(reader.HasRows) { reader.Read(); props.DataKey = (string)reader["DataKey"]; props.DataVal = (string)reader["DataVal"]; } else { query += "INSERT INTO userdata VALUES ( "; query += ":UserId,"; query += ":TagId,"; query += ":DataKey,"; query += ":DataVal) "; using (NpgsqlCommand put = new NpgsqlCommand(query, dbcon)) { put.Parameters.AddWithValue("Id", props.UserId.ToString()); put.Parameters.AddWithValue("TagId", props.TagId.ToString()); put.Parameters.AddWithValue("DataKey", props.DataKey.ToString()); put.Parameters.AddWithValue("DataVal", props.DataVal.ToString()); put.ExecuteNonQuery(); } } } } } } catch (Exception e) { m_log.DebugFormat("[PROFILES_DATA]" + ": Requst application data exception {0}", e.Message); result = e.Message; return false; } return true; }
public bool SetUserAppData(UserAppData props, ref string result) { string query = string.Empty; query += "UPDATE userdata SET "; query += "TagId = :TagId, "; query += "DataKey = :DataKey, "; query += "DataVal = :DataVal WHERE "; query += "UserId = :UserId AND "; query += "TagId = :TagId"; try { using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) { cmd.CommandText = query; cmd.Parameters.AddWithValue(":UserId", props.UserId.ToString()); cmd.Parameters.AddWithValue(":TagId", props.TagId.ToString ()); cmd.Parameters.AddWithValue(":DataKey", props.DataKey.ToString ()); cmd.Parameters.AddWithValue(":DataVal", props.DataKey.ToString ()); cmd.ExecuteNonQuery(); } } catch (Exception e) { m_log.DebugFormat("[PROFILES_DATA]" + ": SetUserData exception {0}", e.Message); return false; } return true; }
public bool SetUserAppData(UserAppData props, ref string result) { string query = string.Empty; query += "UPDATE userdata SET "; query += "\"TagId\" = :TagId, "; query += "\"DataKey\" = :DataKey, "; query += "\"DataVal\" = :DataVal WHERE "; query += "\"UserId\" = :UserId AND "; query += "\"TagId\" = :TagId"; try { using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) { dbcon.Open(); using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) { cmd.Parameters.AddWithValue("UserId", props.UserId.ToString()); cmd.Parameters.AddWithValue("TagId", props.TagId.ToString ()); cmd.Parameters.AddWithValue("DataKey", props.DataKey.ToString ()); cmd.Parameters.AddWithValue("DataVal", props.DataKey.ToString ()); cmd.ExecuteNonQuery(); } } } catch (Exception e) { m_log.DebugFormat("[PROFILES_DATA]" + ": SetUserData exception {0}", e.Message); return false; } return true; }
public bool GetUserAppData(ref UserAppData props, ref string result) { IDataReader reader = null; string query = string.Empty; query += "SELECT * FROM `userdata` WHERE "; query += "UserId = :Id AND "; query += "TagId = :TagId"; try { using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand()) { cmd.CommandText = query; cmd.Parameters.AddWithValue(":Id", props.UserId.ToString()); cmd.Parameters.AddWithValue (":TagId", props.TagId.ToString()); using (reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if(reader.Read()) { props.DataKey = (string)reader["DataKey"]; props.DataVal = (string)reader["DataVal"]; } else { query += "INSERT INTO userdata VALUES ( "; query += ":UserId,"; query += ":TagId,"; query += ":DataKey,"; query += ":DataVal) "; using (SqliteCommand put = (SqliteCommand)m_connection.CreateCommand()) { put.Parameters.AddWithValue(":Id", props.UserId.ToString()); put.Parameters.AddWithValue(":TagId", props.TagId.ToString()); put.Parameters.AddWithValue(":DataKey", props.DataKey.ToString()); put.Parameters.AddWithValue(":DataVal", props.DataVal.ToString()); put.ExecuteNonQuery(); } } } } } catch (Exception e) { m_log.DebugFormat("[PROFILES_DATA]" + ": Requst application data exception {0}", e.Message); result = e.Message; return false; } return true; }
public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response) { if(!json.ContainsKey("params")) { response.Error.Code = ErrorCode.ParseError; response.Error.Message = "no parameters supplied"; m_log.DebugFormat ("User App Data Update Request"); return false; } string result = string.Empty; UserAppData props = new UserAppData(); object Props = (object)props; OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); if(Service.SetUserAppData(props, ref result)) { response.Result = OSD.SerializeMembers(props); return true; } response.Error.Code = ErrorCode.InternalError; response.Error.Message = string.Format("{0}", result); return false; }
public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response) { if(!json.ContainsKey("params")) { response.Error.Code = ErrorCode.ParseError; response.Error.Message = "no parameters supplied"; m_log.DebugFormat ("User Application Service URL Request: No Parameters!"); return false; } string result = string.Empty; UserAppData props = new UserAppData(); object Props = (object)props; OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]); if(Service.RequestUserAppData(ref props, ref result)) { OSDMap res = new OSDMap(); res["result"] = OSD.FromString("success"); res["token"] = OSD.FromString (result); response.Result = res; return true; } response.Error.Code = ErrorCode.InternalError; response.Error.Message = string.Format("{0}", result); return false; }
public bool SetUserAppData(UserAppData prop, ref string result) { return true; }
public bool RequestUserAppData(ref UserAppData prop, ref string result) { return ProfilesData.GetUserAppData(ref prop, ref result); }