2013-10-12 21:33:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Contributors, http://opensimulator.org/
|
|
|
|
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of the OpenSimulator Project nor the
|
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Data;
|
|
|
|
using System.Reflection;
|
|
|
|
using OpenSim.Data;
|
|
|
|
using OpenSim.Framework;
|
|
|
|
using OpenMetaverse;
|
|
|
|
using OpenMetaverse.StructuredData;
|
|
|
|
using log4net;
|
|
|
|
using Npgsql;
|
|
|
|
|
|
|
|
namespace OpenSim.Data.PGSQL
|
|
|
|
{
|
|
|
|
public class UserProfilesData: IProfilesData
|
|
|
|
{
|
|
|
|
static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
2014-10-15 13:08:25 +00:00
|
|
|
|
|
|
|
protected PGSQLManager m_database;
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
#region Properites
|
|
|
|
string ConnectionString
|
|
|
|
{
|
|
|
|
get; set;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual Assembly Assembly
|
|
|
|
{
|
|
|
|
get { return GetType().Assembly; }
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion Properties
|
|
|
|
|
|
|
|
#region class Member Functions
|
|
|
|
public UserProfilesData(string connectionString)
|
|
|
|
{
|
|
|
|
ConnectionString = connectionString;
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
|
|
|
|
Migration m = new Migration(dbcon, Assembly, "UserProfiles");
|
|
|
|
m.Update();
|
2014-10-15 13:08:25 +00:00
|
|
|
m_database = new PGSQLManager(ConnectionString);
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion Member Functions
|
|
|
|
|
|
|
|
#region Classifieds Queries
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the classified records.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>
|
|
|
|
/// Array of classified records
|
|
|
|
/// </returns>
|
|
|
|
/// <param name='creatorId'>
|
|
|
|
/// Creator identifier.
|
|
|
|
/// </param>
|
|
|
|
public OSDArray GetClassifiedRecords(UUID creatorId)
|
|
|
|
{
|
|
|
|
OSDArray data = new OSDArray();
|
|
|
|
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
string query = @"SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = :Id";
|
2013-10-12 21:33:45 +00:00
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", creatorId));
|
2013-10-12 21:33:45 +00:00
|
|
|
using( NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
|
|
|
while (reader.Read())
|
|
|
|
{
|
|
|
|
OSDMap n = new OSDMap();
|
|
|
|
UUID Id = UUID.Zero;
|
|
|
|
|
|
|
|
string Name = null;
|
|
|
|
try
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
Id = DBGuid.FromDB(reader["classifieduuid"]);
|
2013-10-12 21:33:45 +00:00
|
|
|
Name = Convert.ToString(reader["name"]);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: UserAccount exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
n.Add("classifieduuid", OSD.FromUUID(Id));
|
|
|
|
n.Add("name", OSD.FromString(Name));
|
|
|
|
data.Add(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result)
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query = @"WITH upsert AS (
|
|
|
|
UPDATE classifieds SET
|
|
|
|
classifieduuid = :ClassifiedId, creatoruuid = :CreatorId, creationdate = :CreatedDate,
|
|
|
|
expirationdate = :ExpirationDate,category =:Category, name = :Name, description = :Description,
|
|
|
|
parceluuid = :ParcelId, parentestate = :ParentEstate, snapshotuuid = :SnapshotId,
|
|
|
|
simname = :SimName, posglobal = :GlobalPos, parcelname = :ParcelName, classifiedflags = :Flags,
|
|
|
|
priceforlisting = :ListingPrice
|
|
|
|
RETURNING * )
|
|
|
|
INSERT INTO classifieds (classifieduuid,creatoruuid,creationdate,expirationdate,category,name,
|
|
|
|
description,parceluuid,parentestate,snapshotuuid,simname,posglobal,parcelname,classifiedflags,
|
|
|
|
priceforlisting)
|
|
|
|
SELECT
|
|
|
|
:ClassifiedId,:CreatorId,:CreatedDate,:ExpirationDate,:Category,:Name,:Description,
|
|
|
|
:ParcelId,:ParentEstate,:SnapshotId,:SimName,:GlobalPos,:ParcelName,:Flags,:ListingPrice
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
SELECT * FROM upsert )";
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
if(string.IsNullOrEmpty(ad.ParcelName))
|
|
|
|
ad.ParcelName = "Unknown";
|
|
|
|
if(ad.ParcelId == null)
|
|
|
|
ad.ParcelId = UUID.Zero;
|
|
|
|
if(string.IsNullOrEmpty(ad.Description))
|
|
|
|
ad.Description = "No Description";
|
|
|
|
|
|
|
|
DateTime epoch = new DateTime(1970, 1, 1);
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
TimeSpan epochnow = now - epoch;
|
|
|
|
TimeSpan duration;
|
|
|
|
DateTime expiration;
|
|
|
|
TimeSpan epochexp;
|
|
|
|
|
|
|
|
if(ad.Flags == 2)
|
|
|
|
{
|
|
|
|
duration = new TimeSpan(7,0,0,0);
|
|
|
|
expiration = now.Add(duration);
|
|
|
|
epochexp = expiration - epoch;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
duration = new TimeSpan(365,0,0,0);
|
|
|
|
expiration = now.Add(duration);
|
|
|
|
epochexp = expiration - epoch;
|
|
|
|
}
|
|
|
|
ad.CreationDate = (int)epochnow.TotalSeconds;
|
|
|
|
ad.ExpirationDate = (int)epochexp.TotalSeconds;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ClassifiedId", ad.ClassifiedId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("CreatorId", ad.CreatorId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("CreatedDate", (int)ad.CreationDate));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ExpirationDate", (int)ad.ExpirationDate));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Category", ad.Category.ToString()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Name", ad.Name.ToString()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Description", ad.Description.ToString()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ParcelId", ad.ParcelId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ParentEstate", (int)ad.ParentEstate));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("SnapshotId", ad.SnapshotId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("SimName", ad.SimName.ToString()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("GlobalPos", ad.GlobalPos.ToString()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ParcelName", ad.ParcelName.ToString()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Flags", (int)Convert.ToInt32(ad.Flags)));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ListingPrice", (int)Convert.ToInt32(ad.Price)));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: ClassifiedsUpdate exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
result = e.Message;
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
public bool DeleteClassifiedRecord(UUID recordId)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query = @"DELETE FROM classifieds WHERE classifieduuid = :ClasifiedId ;";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ClassifiedId", recordId));
|
2015-01-12 23:39:27 +00:00
|
|
|
cmd.ExecuteNonQuery();
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: DeleteClassifiedRecord exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query += "SELECT * FROM classifieds WHERE ";
|
|
|
|
query += "classifieduuid = :AdId";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("AdId", ad.ClassifiedId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
{
|
|
|
|
if(reader.Read ())
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
ad.CreatorId = DBGuid.FromDB(reader["creatoruuid"]);
|
|
|
|
ad.ParcelId = DBGuid.FromDB(reader["parceluuid"]);
|
|
|
|
ad.SnapshotId = DBGuid.FromDB(reader["snapshotuuid"]);
|
2013-10-12 21:33:45 +00:00
|
|
|
ad.CreationDate = Convert.ToInt32(reader["creationdate"]);
|
|
|
|
ad.ExpirationDate = Convert.ToInt32(reader["expirationdate"]);
|
|
|
|
ad.ParentEstate = Convert.ToInt32(reader["parentestate"]);
|
|
|
|
ad.Flags = (byte)Convert.ToInt16(reader["classifiedflags"]);
|
|
|
|
ad.Category = Convert.ToInt32(reader["category"]);
|
|
|
|
ad.Price = Convert.ToInt16(reader["priceforlisting"]);
|
|
|
|
ad.Name = reader["name"].ToString();
|
|
|
|
ad.Description = reader["description"].ToString();
|
|
|
|
ad.SimName = reader["simname"].ToString();
|
|
|
|
ad.GlobalPos = reader["posglobal"].ToString();
|
|
|
|
ad.ParcelName = reader["parcelname"].ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbcon.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: GetClassifiedInfo exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-09 00:19:48 +00:00
|
|
|
public static UUID GetUUID(object uuidValue)
|
|
|
|
{
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
UUID ret = UUID.Zero;
|
|
|
|
|
|
|
|
UUID.TryParse(uuidValue.ToString(), out ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion Classifieds Queries
|
|
|
|
|
|
|
|
#region Picks Queries
|
|
|
|
public OSDArray GetAvatarPicks(UUID avatarId)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
2015-01-13 18:47:51 +00:00
|
|
|
query += "SELECT pickuuid, name FROM userpicks WHERE ";
|
2013-10-12 21:33:45 +00:00
|
|
|
query += "creatoruuid = :Id";
|
|
|
|
OSDArray data = new OSDArray();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", avatarId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
|
|
|
while (reader.Read())
|
|
|
|
{
|
|
|
|
OSDMap record = new OSDMap();
|
|
|
|
|
2014-10-15 13:08:25 +00:00
|
|
|
record.Add("pickuuid",OSD.FromUUID(DBGuid.FromDB(reader["pickuuid"])));
|
2013-10-12 21:33:45 +00:00
|
|
|
record.Add("name",OSD.FromString((string)reader["name"]));
|
|
|
|
data.Add(record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: GetAvatarPicks exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UserProfilePick GetPickInfo(UUID avatarId, UUID pickId)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
UserProfilePick pick = new UserProfilePick();
|
|
|
|
|
|
|
|
query += "SELECT * FROM userpicks WHERE ";
|
|
|
|
query += "creatoruuid = :CreatorId AND ";
|
|
|
|
query += "pickuuid = :PickId";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("CreatorId", avatarId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("PickId", pickId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
|
|
|
|
string description = (string)reader["description"];
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(description))
|
|
|
|
description = "No description given.";
|
|
|
|
|
2014-10-15 13:08:25 +00:00
|
|
|
pick.PickId = DBGuid.FromDB(reader["pickuuid"]);
|
|
|
|
pick.CreatorId = DBGuid.FromDB(reader["creatoruuid"]);
|
|
|
|
pick.ParcelId = DBGuid.FromDB(reader["parceluuid"]);
|
|
|
|
pick.SnapshotId = DBGuid.FromDB(reader["snapshotuuid"]);
|
|
|
|
pick.GlobalPos = (string)reader["posglobal"].ToString();
|
|
|
|
pick.TopPick = Convert.ToBoolean(reader["toppick"]);
|
|
|
|
pick.Enabled = Convert.ToBoolean(reader["enabled"]);
|
|
|
|
pick.Name = reader["name"].ToString ();
|
|
|
|
pick.Desc = reader["description"].ToString();
|
|
|
|
pick.User = reader["user"].ToString();
|
|
|
|
pick.OriginalName = reader["originalname"].ToString();
|
|
|
|
pick.SimName = reader["simname"].ToString();
|
2013-10-12 21:33:45 +00:00
|
|
|
pick.SortOrder = (int)reader["sortorder"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dbcon.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: GetPickInfo exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return pick;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool UpdatePicksRecord(UserProfilePick pick)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
|
2014-10-15 13:08:25 +00:00
|
|
|
query = @"WITH upsert AS (
|
|
|
|
UPDATE userpicks SET
|
|
|
|
pickuuid = :PickId, creatoruuid = :CreatorId, toppick = :TopPick, parceluuid = :ParcelId,
|
|
|
|
name = :Name, description = :Desc, snapshotuuid = :SnapshotId, ""user"" = :User,
|
|
|
|
originalname = :Original, simname = :SimName, posglobal = :GlobalPos,
|
|
|
|
sortorder = :SortOrder, enabled = :Enabled
|
|
|
|
RETURNING * )
|
|
|
|
INSERT INTO userpicks (pickuuid,creatoruuid,toppick,parceluuid,name,description,
|
|
|
|
snapshotuuid,""user"",originalname,simname,posglobal,sortorder,enabled)
|
|
|
|
SELECT
|
|
|
|
:PickId,:CreatorId,:TopPick,:ParcelId,:Name,:Desc,:SnapshotId,:User,
|
|
|
|
:Original,:SimName,:GlobalPos,:SortOrder,:Enabled
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
SELECT * FROM upsert )";
|
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("PickId", pick.PickId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("CreatorId", pick.CreatorId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("TopPick", pick.TopPick));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ParcelId", pick.ParcelId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Name", pick.Name));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Desc", pick.Desc));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("SnapshotId", pick.SnapshotId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("User", pick.User));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Original", pick.OriginalName));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("SimName",pick.SimName));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("GlobalPos", pick.GlobalPos));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("SortOrder", pick.SortOrder));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Enabled", pick.Enabled));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: UpdateAvatarNotes exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DeletePicksRecord(UUID pickId)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query += "DELETE FROM userpicks WHERE ";
|
|
|
|
query += "pickuuid = :PickId";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("PickId", pickId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: DeleteUserPickRecord exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
#endregion Picks Queries
|
|
|
|
|
|
|
|
#region Avatar Notes Queries
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
public bool GetAvatarNotes(ref UserProfileNotes notes)
|
|
|
|
{ // WIP
|
|
|
|
string query = string.Empty;
|
|
|
|
|
2015-01-13 18:50:34 +00:00
|
|
|
query += "SELECT notes FROM usernotes WHERE ";
|
2013-10-12 21:33:45 +00:00
|
|
|
query += "useruuid = :Id AND ";
|
|
|
|
query += "targetuuid = :TargetId";
|
|
|
|
OSDArray data = new OSDArray();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", notes.UserId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("TargetId", notes.TargetId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
|
|
|
reader.Read();
|
|
|
|
notes.Notes = OSD.FromString((string)reader["notes"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: GetAvatarNotes exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
bool remove;
|
|
|
|
|
2015-01-09 00:19:48 +00:00
|
|
|
if (string.IsNullOrEmpty(note.Notes))
|
2013-10-12 21:33:45 +00:00
|
|
|
{
|
|
|
|
remove = true;
|
|
|
|
query += "DELETE FROM usernotes WHERE ";
|
|
|
|
query += "useruuid=:UserId AND ";
|
|
|
|
query += "targetuuid=:TargetId";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
remove = false;
|
2014-10-15 13:08:25 +00:00
|
|
|
|
|
|
|
query = @"WITH upsert AS (
|
|
|
|
UPDATE usernotes SET notes = :Notes, useruuid = :UserId, targetuuid = :TargetId RETURNING * )
|
|
|
|
INSERT INTO usernotes (notes,useruuid,targetuuid)
|
|
|
|
SELECT :Notes,:UserId,:TargetId
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
SELECT * FROM upsert
|
|
|
|
)";
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
|
|
|
if(!remove)
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Notes", note.Notes));
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("TargetId", note.TargetId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("UserId", note.UserId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: UpdateAvatarNotes exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
|
|
|
return true;
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
#endregion Avatar Notes Queries
|
|
|
|
|
|
|
|
#region Avatar Properties
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
public bool GetAvatarProperties(ref UserProfileProperties props, ref string result)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query += "SELECT * FROM userprofile WHERE ";
|
|
|
|
query += "useruuid = :Id";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", props.UserId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
2014-10-15 13:31:39 +00:00
|
|
|
// m_log.DebugFormat("[PROFILES_DATA]" +
|
|
|
|
// ": Getting data for {0}.", props.UserId);
|
2013-10-12 21:33:45 +00:00
|
|
|
reader.Read();
|
2014-10-15 13:08:25 +00:00
|
|
|
props.WebUrl = (string)reader["profileURL"].ToString();
|
|
|
|
props.ImageId = DBGuid.FromDB(reader["profileImage"]);
|
2013-10-12 21:33:45 +00:00
|
|
|
props.AboutText = (string)reader["profileAboutText"];
|
2014-10-15 13:08:25 +00:00
|
|
|
props.FirstLifeImageId = DBGuid.FromDB(reader["profileFirstImage"]);
|
2013-10-12 21:33:45 +00:00
|
|
|
props.FirstLifeText = (string)reader["profileFirstText"];
|
2014-10-15 13:08:25 +00:00
|
|
|
props.PartnerId = DBGuid.FromDB(reader["profilePartner"]);
|
2013-10-12 21:33:45 +00:00
|
|
|
props.WantToMask = (int)reader["profileWantToMask"];
|
|
|
|
props.WantToText = (string)reader["profileWantToText"];
|
|
|
|
props.SkillsMask = (int)reader["profileSkillsMask"];
|
|
|
|
props.SkillsText = (string)reader["profileSkillsText"];
|
|
|
|
props.Language = (string)reader["profileLanguages"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-15 13:31:39 +00:00
|
|
|
//m_log.DebugFormat("[PROFILES_DATA]" +
|
|
|
|
// ": No data for {0}", props.UserId);
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
props.WebUrl = string.Empty;
|
|
|
|
props.ImageId = UUID.Zero;
|
|
|
|
props.AboutText = string.Empty;
|
|
|
|
props.FirstLifeImageId = UUID.Zero;
|
|
|
|
props.FirstLifeText = string.Empty;
|
|
|
|
props.PartnerId = UUID.Zero;
|
|
|
|
props.WantToMask = 0;
|
|
|
|
props.WantToText = string.Empty;
|
|
|
|
props.SkillsMask = 0;
|
|
|
|
props.SkillsText = string.Empty;
|
|
|
|
props.Language = string.Empty;
|
|
|
|
props.PublishProfile = false;
|
|
|
|
props.PublishMature = false;
|
|
|
|
|
|
|
|
query = "INSERT INTO userprofile (";
|
|
|
|
query += "useruuid, ";
|
2014-10-15 13:08:25 +00:00
|
|
|
query += "\"profilePartner\", ";
|
|
|
|
query += "\"profileAllowPublish\", ";
|
|
|
|
query += "\"profileMaturePublish\", ";
|
|
|
|
query += "\"profileURL\", ";
|
|
|
|
query += "\"profileWantToMask\", ";
|
|
|
|
query += "\"profileWantToText\", ";
|
|
|
|
query += "\"profileSkillsMask\", ";
|
|
|
|
query += "\"profileSkillsText\", ";
|
|
|
|
query += "\"profileLanguages\", ";
|
|
|
|
query += "\"profileImage\", ";
|
|
|
|
query += "\"profileAboutText\", ";
|
|
|
|
query += "\"profileFirstImage\", ";
|
|
|
|
query += "\"profileFirstText\") VALUES (";
|
2013-10-12 21:33:45 +00:00
|
|
|
query += ":userId, ";
|
|
|
|
query += ":profilePartner, ";
|
|
|
|
query += ":profileAllowPublish, ";
|
|
|
|
query += ":profileMaturePublish, ";
|
|
|
|
query += ":profileURL, ";
|
|
|
|
query += ":profileWantToMask, ";
|
|
|
|
query += ":profileWantToText, ";
|
|
|
|
query += ":profileSkillsMask, ";
|
|
|
|
query += ":profileSkillsText, ";
|
|
|
|
query += ":profileLanguages, ";
|
|
|
|
query += ":profileImage, ";
|
|
|
|
query += ":profileAboutText, ";
|
|
|
|
query += ":profileFirstImage, ";
|
|
|
|
query += ":profileFirstText)";
|
|
|
|
|
|
|
|
dbcon.Close();
|
|
|
|
dbcon.Open();
|
|
|
|
|
|
|
|
using (NpgsqlCommand put = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:31:39 +00:00
|
|
|
//m_log.DebugFormat("[PROFILES_DATA]" +
|
|
|
|
// ": Adding new data for {0}", props.UserId);
|
2014-10-15 13:08:25 +00:00
|
|
|
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("userId", props.UserId));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profilePartner", props.PartnerId));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileAllowPublish", props.PublishProfile));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileMaturePublish", props.PublishMature));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileURL", props.WebUrl));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileWantToMask", props.WantToMask));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileWantToText", props.WantToText));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileSkillsMask", props.SkillsMask));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileSkillsText", props.SkillsText));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileLanguages", props.Language));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileImage", props.ImageId));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileAboutText", props.AboutText));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileFirstImage", props.FirstLifeImageId));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("profileFirstText", props.FirstLifeText));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
put.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: GetAvatarProperties exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
result = e.Message;
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query += "UPDATE userprofile SET ";
|
2015-01-13 21:53:28 +00:00
|
|
|
query += "\"profileURL\"=:profileURL, ";
|
|
|
|
query += "\"profileImage\"=:image, ";
|
|
|
|
query += "\"profileAboutText\"=:abouttext,";
|
|
|
|
query += "\"profileFirstImage\"=:firstlifeimage,";
|
|
|
|
query += "\"profileFirstText\"=:firstlifetext ";
|
|
|
|
query += "WHERE \"useruuid\"=:uuid";
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("profileURL", props.WebUrl));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("image", props.ImageId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("abouttext", props.AboutText));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("firstlifeimage", props.FirstLifeImageId));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("firstlifetext", props.FirstLifeText));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("uuid", props.UserId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: AgentPropertiesUpdate exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
#endregion Avatar Properties
|
|
|
|
|
|
|
|
#region Avatar Interests
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
public bool UpdateAvatarInterests(UserProfileProperties up, ref string result)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query += "UPDATE userprofile SET ";
|
2015-01-13 21:53:18 +00:00
|
|
|
query += "\"profileWantToMask\"=:WantMask, ";
|
|
|
|
query += "\"profileWantToText\"=:WantText,";
|
|
|
|
query += "\"profileSkillsMask\"=:SkillsMask,";
|
|
|
|
query += "\"profileSkillsText\"=:SkillsText, ";
|
|
|
|
query += "\"profileLanguages\"=:Languages ";
|
|
|
|
query += "WHERE \"useruuid\"=:uuid";
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("WantMask", up.WantToMask));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("WantText", up.WantToText));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("SkillsMask", up.SkillsMask));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("SkillsText", up.SkillsText));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Languages", up.Language));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("uuid", up.UserId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-13 18:42:04 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: UpdateAvatarInterests exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
result = e.Message;
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
#endregion Avatar Interests
|
|
|
|
|
|
|
|
public OSDArray GetUserImageAssets(UUID avatarId)
|
|
|
|
{
|
|
|
|
OSDArray data = new OSDArray();
|
2015-01-13 21:53:04 +00:00
|
|
|
string query = "SELECT \"snapshotuuid\" FROM {0} WHERE \"creatoruuid\" = :Id";
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
|
2015-01-13 21:53:04 +00:00
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(string.Format (query,"\"classifieds\""), dbcon))
|
2013-10-12 21:33:45 +00:00
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", avatarId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
|
|
|
while (reader.Read())
|
|
|
|
{
|
2015-01-14 00:00:02 +00:00
|
|
|
data.Add(new OSDString(reader["snapshotuuid"].ToString()));
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dbcon.Close();
|
|
|
|
dbcon.Open();
|
|
|
|
|
2015-01-13 21:53:04 +00:00
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(string.Format (query,"\"userpicks\""), dbcon))
|
2013-10-12 21:33:45 +00:00
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", avatarId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
|
|
|
while (reader.Read())
|
|
|
|
{
|
2015-01-14 00:00:02 +00:00
|
|
|
data.Add(new OSDString(reader["snapshotuuid"].ToString()));
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dbcon.Close();
|
|
|
|
dbcon.Open();
|
|
|
|
|
2015-01-13 21:53:04 +00:00
|
|
|
query = "SELECT \"profileImage\", \"profileFirstImage\" FROM \"userprofile\" WHERE \"useruuid\" = :Id";
|
2013-10-12 21:33:45 +00:00
|
|
|
|
2015-01-13 21:53:04 +00:00
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(string.Format (query,"\"userpicks\""), dbcon))
|
2013-10-12 21:33:45 +00:00
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", avatarId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
|
|
|
while (reader.Read())
|
|
|
|
{
|
2015-01-14 00:00:02 +00:00
|
|
|
data.Add(new OSDString(reader["profileImage"].ToString()));
|
|
|
|
data.Add(new OSDString(reader["profileFirstImage"].ToString()));
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-14 00:00:02 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: GetUserImageAssets exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
#region User Preferences
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-12-06 07:52:13 +00:00
|
|
|
public bool GetUserPreferences(ref UserPreferences pref, ref string result)
|
2013-10-12 21:33:45 +00:00
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query += "SELECT imviaemail,visible,email FROM ";
|
|
|
|
query += "usersettings WHERE ";
|
|
|
|
query += "useruuid = :Id";
|
|
|
|
|
|
|
|
OSDArray data = new OSDArray();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", pref.UserId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
using (NpgsqlDataReader reader = cmd.ExecuteReader())
|
|
|
|
{
|
|
|
|
if(reader.HasRows)
|
|
|
|
{
|
|
|
|
reader.Read();
|
2013-12-06 07:52:13 +00:00
|
|
|
bool.TryParse((string)reader["imviaemail"], out pref.IMViaEmail);
|
|
|
|
bool.TryParse((string)reader["visible"], out pref.Visible);
|
2014-11-26 00:27:15 +00:00
|
|
|
pref.EMail = (string)reader["email"];
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
using (NpgsqlCommand put = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2015-01-13 23:52:52 +00:00
|
|
|
put.Parameters.Add(m_database.CreateParameter("Id", pref.UserId));
|
2013-10-12 21:33:45 +00:00
|
|
|
query = "INSERT INTO usersettings VALUES ";
|
|
|
|
query += "(:Id,'false','false', '')";
|
2015-01-12 23:39:27 +00:00
|
|
|
|
|
|
|
put.ExecuteNonQuery();
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: GetUserPreferences exception ", e);
|
2013-12-06 07:52:13 +00:00
|
|
|
result = e.Message;
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-12-06 07:52:13 +00:00
|
|
|
return true;
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
2013-12-06 07:52:13 +00:00
|
|
|
|
|
|
|
public bool UpdateUserPreferences(ref UserPreferences pref, ref string result)
|
2013-10-12 21:33:45 +00:00
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
2013-12-06 07:52:13 +00:00
|
|
|
query += "UPDATE usersettings SET ";
|
2013-10-12 21:33:45 +00:00
|
|
|
query += "imviaemail=:ImViaEmail, ";
|
2014-11-23 19:25:48 +00:00
|
|
|
query += "visible=:Visible, ";
|
2014-11-26 00:27:15 +00:00
|
|
|
query += "email=:Email ";
|
2013-10-12 21:33:45 +00:00
|
|
|
query += "WHERE useruuid=:uuid";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2015-01-13 21:40:49 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("ImViaEmail", pref.IMViaEmail));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Visible", pref.Visible));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("EMail", pref.EMail.ToString().ToLower()));
|
2015-01-13 21:13:57 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("uuid", pref.UserId));
|
2015-01-12 23:39:27 +00:00
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-13 18:42:04 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: UpdateUserPreferences exception ", e);
|
2013-12-06 07:52:13 +00:00
|
|
|
result = e.Message;
|
2013-10-12 21:33:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
#endregion User Preferences
|
|
|
|
|
|
|
|
#region Integration
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
public bool GetUserAppData(ref UserAppData props, ref string result)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query += "SELECT * FROM userdata WHERE ";
|
2015-01-13 21:52:43 +00:00
|
|
|
query += "\"UserId\" = :Id AND ";
|
|
|
|
query += "\"TagId\" = :TagId";
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("Id", props.UserId));
|
2015-01-13 20:15:37 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("TagId", props.TagId));
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2015-01-13 20:33:36 +00:00
|
|
|
put.Parameters.Add(m_database.CreateParameter("UserId", props.UserId));
|
2014-10-15 13:08:25 +00:00
|
|
|
put.Parameters.Add(m_database.CreateParameter("TagId", props.TagId));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("DataKey", props.DataKey.ToString()));
|
|
|
|
put.Parameters.Add(m_database.CreateParameter("DataVal", props.DataVal.ToString()));
|
2015-01-12 23:39:27 +00:00
|
|
|
|
|
|
|
put.ExecuteNonQuery();
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: GetUserAppData exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
result = e.Message;
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool SetUserAppData(UserAppData props, ref string result)
|
|
|
|
{
|
|
|
|
string query = string.Empty;
|
|
|
|
|
|
|
|
query += "UPDATE userdata SET ";
|
2015-01-13 21:50:11 +00:00
|
|
|
query += "\"TagId\" = :TagId, ";
|
|
|
|
query += "\"DataKey\" = :DataKey, ";
|
|
|
|
query += "\"DataVal\" = :DataVal WHERE ";
|
|
|
|
query += "\"UserId\" = :UserId AND ";
|
|
|
|
query += "\"TagId\" = :TagId";
|
2013-10-12 21:33:45 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString))
|
|
|
|
{
|
|
|
|
dbcon.Open();
|
|
|
|
using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon))
|
|
|
|
{
|
2014-10-15 13:08:25 +00:00
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("UserId", props.UserId.ToString()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("TagId", props.TagId.ToString ()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("DataKey", props.DataKey.ToString ()));
|
|
|
|
cmd.Parameters.Add(m_database.CreateParameter("DataVal", props.DataKey.ToString ()));
|
2015-01-12 23:39:27 +00:00
|
|
|
|
|
|
|
cmd.ExecuteNonQuery();
|
2013-10-12 21:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2015-01-09 00:19:48 +00:00
|
|
|
m_log.Error("[PROFILES_DATA]: SetUserData exception ", e);
|
2013-10-12 21:33:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
|
2013-10-12 21:33:45 +00:00
|
|
|
#endregion Integration
|
|
|
|
}
|
2015-01-09 00:19:48 +00:00
|
|
|
}
|