public void GetBytes2() { NpgsqlCommand command = new NpgsqlCommand("select '\\001\\002\\003'::bytea;", TheConnection); NpgsqlDataReader dr = command.ExecuteReader(); dr.Read(); Byte[] result = new Byte[3]; Int64 a = dr.GetBytes(0, 0, result, 0, 0); Int64 b = dr.GetBytes(0, 0, result, 0, 1); Int64 c = dr.GetBytes(0, 0, result, 0, 2); Int64 d = dr.GetBytes(0, 0, result, 0, 3); Assert.AreEqual(1, result[0]); Assert.AreEqual(2, result[1]); Assert.AreEqual(3, result[2]); Assert.AreEqual(0, a); Assert.AreEqual(1, b); Assert.AreEqual(2, c); Assert.AreEqual(3, d); dr.Close(); }
public PlayerMissions getMission(long pId, int mission1, int mission2, int mission3, int mission4) { if (pId == 0) { return(null); } PlayerMissions mission = null; try { using (NpgsqlConnection connection = SQLjec.getInstance().conn()) { NpgsqlCommand command = connection.CreateCommand(); connection.Open(); command.Parameters.AddWithValue("@owner", pId); command.CommandText = "SELECT * FROM player_missions WHERE owner_id=@owner"; command.CommandType = CommandType.Text; NpgsqlDataReader data = command.ExecuteReader(); while (data.Read()) { mission = new PlayerMissions { actualMission = data.GetInt32(1), card1 = data.GetInt32(2), card2 = data.GetInt32(3), card3 = data.GetInt32(4), card4 = data.GetInt32(5), mission1 = mission1, mission2 = mission2, mission3 = mission3, mission4 = mission4, }; data.GetBytes(6, 0, mission.list1, 0, 40); data.GetBytes(7, 0, mission.list2, 0, 40); data.GetBytes(8, 0, mission.list3, 0, 40); data.GetBytes(9, 0, mission.list4, 0, 40); mission.UpdateSelectedCard(); } command.Dispose(); data.Close(); connection.Dispose(); connection.Close(); } return(mission); } catch (Exception ex) { SaveLog.fatal(ex.ToString()); Printf.b_danger("[MissionManager.getMission] Erro fatal!"); return(null); } }
List <LayerPatch> ISimulationDataTerrainStorageInterface.this[UUID regionID] { get { var patches = new List <LayerPatch>(); using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); using (var cmd = new NpgsqlCommand("SELECT \"PatchID\", \"TerrainData\" FROM terrains WHERE \"RegionID\" = @regionid", connection)) { cmd.Parameters.AddParameter("@regionid", regionID); cmd.CommandTimeout = 3600; using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { var patch = new LayerPatch { ExtendedPatchID = (uint)(int)dbReader["PatchID"], Serialization = dbReader.GetBytes("TerrainData") }; patches.Add(patch); } } } } return(patches); } }
public static byte[] GetBytes(this NpgsqlDataReader reader, int index, int maxLength = 4096) { byte[] buffer = new byte[maxLength]; var length = reader.GetBytes(index, 0, buffer, 0, buffer.Length); return(buffer.Part(0, (int)length)); }
bool ISimulationDataPhysicsConvexStorageInterface.TryGetValue(ObjectPart.PrimitiveShape primShape, out PhysicsConvexShape shape) { using (var conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new NpgsqlCommand("SELECT \"ConvexData\" FROM primphysics WHERE \"ShapeKey\"=@id LIMIT 1", conn)) { cmd.Parameters.AddParameter("@id", primShape.Serialization); using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { if (dbReader.Read()) { shape = new PhysicsConvexShape { SerializedData = dbReader.GetBytes("ConvexData") }; return(true); } } } } shape = null; return(false); }
bool ISimulationDataTerrainStorageInterface.TryGetDefault(UUID regionID, List <LayerPatch> list) { using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); using (var cmd = new NpgsqlCommand("SELECT PatchID, TerrainData FROM defaultterrains WHERE RegionID = @regionid", connection)) { cmd.Parameters.AddParameter("@regionid", regionID); cmd.CommandTimeout = 3600; using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { var patch = new LayerPatch { ExtendedPatchID = (uint)(int)dbReader["PatchID"], Serialization = dbReader.GetBytes("TerrainData") }; list.Add(patch); } } } } return(list.Count != 0); }
bool ISimulationDataPhysicsConvexStorageInterface.TryGetValue(UUID meshid, PrimitivePhysicsShapeType physicsShape, out PhysicsConvexShape shape) { using (var conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new NpgsqlCommand("SELECT \"ConvexData\" FROM meshphysics WHERE \"MeshID\"=@id AND \"PhysicsShape\"=@stype LIMIT 1", conn)) { cmd.Parameters.AddParameter("@id", meshid); cmd.Parameters.AddParameter("@stype", physicsShape); using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { if (dbReader.Read()) { shape = new PhysicsConvexShape { SerializedData = dbReader.GetBytes("ConvexData") }; return(true); } } } } shape = null; return(false); }
public override bool TryGetValue(GridVector location, int zoomlevel, out MaptileData data) { data = default(MaptileData); using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); using (var cmd = new NpgsqlCommand("SELECT * FROM maptiles WHERE \"LocX\" = @locx AND \"LocY\" = @locy AND \"ZoomLevel\" = @zoomlevel LIMIT 1", connection)) { cmd.Parameters.AddParameter("@locx", location.X); cmd.Parameters.AddParameter("@locy", location.Y); cmd.Parameters.AddParameter("@zoomlevel", zoomlevel); using (NpgsqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { data = new MaptileData(); data.Location.X = (uint)(int)reader["LocX"]; data.Location.Y = (uint)(int)reader["LocY"]; data.LastUpdate = reader.GetDate("LastUpdate"); data.ContentType = (string)reader["ContentType"]; data.ZoomLevel = (int)reader["ZoomLevel"]; data.Data = reader.GetBytes("Data"); return(true); } } } } return(false); }
public void GetBytes() { NpgsqlCommand command = new NpgsqlCommand("select field_bytea from tablef where field_serial = 1;", _conn); NpgsqlDataReader dr = command.ExecuteReader(); dr.Read(); Byte[] result = new Byte[2]; Int64 a = dr.GetBytes(0, 0, result, 0, 2); Int64 b = dr.GetBytes(0, result.Length, result, 0, 2); Assert.AreEqual('S', (Char)result[0]); Assert.AreEqual('.', (Char)result[1]); Assert.AreEqual(2, a); Assert.AreEqual(0, b); }
public void GetBytesSequential() { NpgsqlCommand command = new NpgsqlCommand("select field_bytea from tablef where field_serial = 1;", TheConnection); using (NpgsqlDataReader dr = command.ExecuteReader(CommandBehavior.SequentialAccess)) { dr.Read(); Byte[] result = new Byte[2]; Int64 a = dr.GetBytes(0, 0, result, 0, 2); Int64 b = dr.GetBytes(0, result.Length, result, 0, 2); Assert.AreEqual('S', (Char)result[0]); Assert.AreEqual('.', (Char)result[1]); Assert.AreEqual(2, a); Assert.AreEqual(0, b); } }
private ObjectPartInventoryItem ObjectPartInventoryItemFromDbReader(NpgsqlDataReader dbReader) { var item = new ObjectPartInventoryItem(dbReader.GetUUID("InventoryID")) { AssetID = dbReader.GetUUID("AssetID"), AssetType = dbReader.GetEnum <AssetType>("AssetType"), CreationDate = dbReader.GetDate("CreationDate"), Creator = dbReader.GetUGUI("Creator"), Description = (string)dbReader["Description"], Flags = dbReader.GetEnum <InventoryFlags>("Flags"), Group = dbReader.GetUGI("Group"), IsGroupOwned = (bool)dbReader["GroupOwned"], InventoryType = dbReader.GetEnum <InventoryType>("InventoryType"), LastOwner = dbReader.GetUGUI("LastOwner"), Name = (string)dbReader["Name"], Owner = dbReader.GetUGUI("Owner"), ParentFolderID = dbReader.GetUUID("PrimID"), NextOwnerAssetID = dbReader.GetUUID("NextOwnerAssetID"), ExperienceID = dbReader.GetUEI("ExperienceID"), CollisionFilter = new ObjectPartInventoryItem.CollisionFilterParam { DbSerialization = dbReader.GetBytes("CollisionFilterData") }, }; item.Permissions.Base = dbReader.GetEnum <InventoryPermissionsMask>("BasePermissions"); item.Permissions.Current = dbReader.GetEnum <InventoryPermissionsMask>("CurrentPermissions"); item.Permissions.EveryOne = dbReader.GetEnum <InventoryPermissionsMask>("EveryOnePermissions"); item.Permissions.Group = dbReader.GetEnum <InventoryPermissionsMask>("GroupPermissions"); item.Permissions.NextOwner = dbReader.GetEnum <InventoryPermissionsMask>("NextOwnerPermissions"); item.SaleInfo.Type = dbReader.GetEnum <InventoryItem.SaleInfoData.SaleType>("SaleType"); item.SaleInfo.Price = (int)dbReader["SalePrice"]; item.SaleInfo.PermMask = dbReader.GetEnum <InventoryPermissionsMask>("SalePermMask"); var grantinfo = new ObjectPartInventoryItem.PermsGranterInfo(); if (((string)dbReader["PermsGranter"]).Length != 0) { try { grantinfo.PermsGranter = dbReader.GetUGUI("PermsGranter"); } catch { /* no action required */ } } grantinfo.PermsMask = dbReader.GetEnum <ScriptPermissions>("PermsMask"); grantinfo.DebitPermissionKey = dbReader.GetUUID("DebitPermissionKey"); item.PermsGranter = grantinfo; return(item); }
private RegionSettings ToRegionSettings(NpgsqlDataReader reader) => new RegionSettings { BlockTerraform = (bool)reader["BlockTerraform"], BlockFly = (bool)reader["BlockFly"], AllowDamage = (bool)reader["AllowDamage"], RestrictPushing = (bool)reader["RestrictPushing"], AllowLandResell = (bool)reader["AllowLandResell"], AllowLandJoinDivide = (bool)reader["AllowLandJoinDivide"], BlockShowInSearch = (bool)reader["BlockShowInSearch"], AgentLimit = (int)reader["AgentLimit"], ObjectBonus = (double)reader["ObjectBonus"], DisableScripts = (bool)reader["DisableScripts"], DisableCollisions = (bool)reader["DisableCollisions"], BlockFlyOver = (bool)reader["BlockFlyOver"], Sandbox = (bool)reader["Sandbox"], TerrainTexture1 = reader.GetUUID("TerrainTexture1"), TerrainTexture2 = reader.GetUUID("TerrainTexture2"), TerrainTexture3 = reader.GetUUID("TerrainTexture3"), TerrainTexture4 = reader.GetUUID("TerrainTexture4"), TelehubObject = reader.GetUUID("TelehubObject"), Elevation1NW = (double)reader["Elevation1NW"], Elevation2NW = (double)reader["Elevation2NW"], Elevation1NE = (double)reader["Elevation1NE"], Elevation2NE = (double)reader["Elevation2NE"], Elevation1SE = (double)reader["Elevation1SE"], Elevation2SE = (double)reader["Elevation2SE"], Elevation1SW = (double)reader["Elevation1SW"], Elevation2SW = (double)reader["Elevation2SW"], WaterHeight = (double)reader["WaterHeight"], TerrainRaiseLimit = (double)reader["TerrainRaiseLimit"], TerrainLowerLimit = (double)reader["TerrainLowerLimit"], SunPosition = (double)reader["SunPosition"], IsSunFixed = (bool)reader["IsSunFixed"], UseEstateSun = (bool)reader["UseEstateSun"], BlockDwell = (bool)reader["BlockDwell"], ResetHomeOnTeleport = (bool)reader["ResetHomeOnTeleport"], AllowLandmark = (bool)reader["AllowLandmark"], AllowDirectTeleport = (bool)reader["AllowDirectTeleport"], MaxBasePrims = (int)reader["MaxBasePrims"], WalkableCoefficientsSerialization = reader.GetBytes("WalkableCoefficientsData") };
public override bool TryGetValue(UUID key, out AssetData asset) { asset = null; using (var conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new NpgsqlCommand("SELECT * FROM assetrefs INNER JOIN assetdata ON assetrefs.\"hash\" = assetdata.\"hash\" AND assetrefs.\"assetType\" = assetdata.\"assetType\" WHERE \"id\" = @id LIMIT 1", conn)) { cmd.Parameters.AddParameter("@id", key); using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { if (!dbReader.Read()) { return(false); } asset = new AssetData { ID = dbReader.GetUUID("id"), Data = dbReader.GetBytes("data"), Type = dbReader.GetEnum <AssetType>("assetType"), Name = (string)dbReader["name"], CreateTime = dbReader.GetDate("create_time"), AccessTime = dbReader.GetDate("access_time"), Flags = dbReader.GetEnum <AssetFlags>("asset_flags"), Temporary = (bool)dbReader["temporary"] }; } } if (DateTime.UtcNow - asset.AccessTime > TimeSpan.FromHours(1)) { /* update access_time */ using (var cmd = new NpgsqlCommand("UPDATE assetrefs SET access_time = @access WHERE \"id\" = @id", conn)) { cmd.Parameters.AddParameter("@access", Date.GetUnixTime()); cmd.Parameters.AddParameter("@id", key); cmd.ExecuteNonQuery(); } } return(true); } }
bool ISimulationDataEnvControllerStorageInterface.TryGetValue(UUID regionID, out byte[] settings) { using (var conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new NpgsqlCommand("SELECT \"SerializedData\" FROM environmentcontroller WHERE \"RegionID\" = @regionid LIMIT 1", conn)) { cmd.Parameters.AddParameter("@regionid", regionID); using (NpgsqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { settings = reader.GetBytes("SerializedData"); return(true); } } } } settings = null; return(false); }
bool IAssetDataServiceInterface.TryGetValue(UUID key, out Stream s) { using (var conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new NpgsqlCommand("SELECT \"data\" FROM assetrefs INNER JOIN assetdata ON assetrefs.\"hash\" = assetdata.\"hash\" AND assetrefs.\"assetType\" = assetdata.\"assetType\" WHERE \"id\"=@id", conn)) { cmd.Parameters.AddParameter("@id", key); using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { if (dbReader.Read()) { s = new MemoryStream(dbReader.GetBytes("data")); return(true); } } } } s = null; return(false); }
public override List <GridInstantMessage> GetOfflineIMs(UUID principalID) { var ims = new List <GridInstantMessage>(); using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); using (var cmd = new NpgsqlCommand("SELECT * FROM offlineim WHERE \"ToAgentID\" = @id", connection)) { cmd.Parameters.AddParameter("@id", principalID); using (NpgsqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { var im = new GridInstantMessage { ID = (ulong)(long)reader["ID"], FromAgent = reader.GetUGUIWithName("FromAgent"), FromGroup = reader.GetUGI("FromGroup"), ToAgent = reader.GetUGUI("ToAgentID"), Dialog = reader.GetEnum <GridInstantMessageDialog>("Dialog"), IsFromGroup = (bool)reader["IsFromGroup"], Message = (string)reader["Message"], IMSessionID = reader.GetUUID("IMSessionID"), Position = reader.GetVector3("Position"), BinaryBucket = reader.GetBytes("BinaryBucket"), ParentEstateID = (uint)(int)reader["ParentEstateID"], RegionID = reader.GetUUID("RegionID"), Timestamp = reader.GetDate("Timestamp"), IsOffline = true }; ims.Add(im); } } } } return(ims); }
bool ISimulationDataEnvSettingsStorageInterface.TryGetValue(UUID regionID, out WindLightSettings settings) { using (var conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new NpgsqlCommand("SELECT \"EnvironmentSettings\" FROM environmentsettings WHERE \"RegionID\" = @regionid LIMIT 1", conn)) { cmd.Parameters.AddParameter("@regionid", regionID); using (NpgsqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { using (var ms = new MemoryStream(reader.GetBytes("EnvironmentSettings"))) { settings = WindLightSettings.Deserialize(ms); return(true); } } } } } settings = null; return(false); }
bool ISimulationDataScriptStateStorageInterface.TryGetValue(UUID regionID, UUID primID, UUID itemID, out byte[] state) { using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); using (var cmd = new NpgsqlCommand("SELECT \"ScriptState\" FROM scriptstates WHERE \"RegionID\" = @regionid AND \"PrimID\" = @primid AND \"ItemID\" = @itemid LIMIT 1", connection)) { cmd.Parameters.AddParameter("@regionid", regionID); cmd.Parameters.AddParameter("@primid", primID); cmd.Parameters.AddParameter("@itemid", itemID); using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { if (dbReader.Read()) { state = dbReader.GetBytes("ScriptState"); return(true); } } } } state = null; return(false); }
public bool Get(string name, ref byte[] v) { try { int ord = reader.GetOrdinal(name); if (!reader.IsDBNull(ord)) { int len; if ((len = (int)reader.GetBytes(ord, 0, null, 0, 0)) > 0) { v = new byte[len]; reader.GetBytes(ord, 0, v, 0, len); // read data into the buffer return(true); } } } catch { } return(false); }
ParcelInfo ISimulationDataParcelStorageInterface.this[UUID regionID, UUID parcelID] { get { using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); using (var cmd = new NpgsqlCommand("SELECT * FROM parcels WHERE \"RegionID\" = @regionid AND \"ParcelID\" = @parcelid LIMIT 1", connection)) { cmd.Parameters.AddParameter("@regionid", regionID); cmd.Parameters.AddParameter("@parcelid", parcelID); using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { if (!dbReader.Read()) { throw new KeyNotFoundException(); } var pi = new ParcelInfo((int)dbReader["BitmapWidth"], (int)dbReader["BitmapHeight"]) { Area = (int)dbReader["Area"], AuctionID = (uint)(int)dbReader["AuctionID"], AuthBuyer = dbReader.GetUGUI("AuthBuyer"), Category = dbReader.GetEnum <ParcelCategory>("Category"), ClaimDate = dbReader.GetDate("ClaimDate"), ClaimPrice = (int)dbReader["ClaimPrice"], ID = dbReader.GetUUID("ParcelID"), Group = dbReader.GetUGI("Group"), GroupOwned = (bool)dbReader["IsGroupOwned"], Description = (string)dbReader["Description"], Flags = dbReader.GetEnum <ParcelFlags>("Flags"), LandingType = dbReader.GetEnum <TeleportLandingType>("LandingType"), LandingPosition = dbReader.GetVector3("LandingPosition"), LandingLookAt = dbReader.GetVector3("LandingLookAt"), Name = (string)dbReader["Name"], LocalID = (int)dbReader["LocalID"], MediaID = dbReader.GetUUID("MediaID"), Owner = dbReader.GetUGUI("Owner"), SnapshotID = dbReader.GetUUID("SnapshotID"), SalePrice = (int)dbReader["SalePrice"], OtherCleanTime = (int)dbReader["OtherCleanTime"], MediaAutoScale = (bool)dbReader["MediaAutoScale"], MediaType = (string)dbReader["MediaType"], MediaWidth = (int)dbReader["MediaWidth"], MediaHeight = (int)dbReader["MediaHeight"], MediaLoop = (bool)dbReader["MediaLoop"], ObscureMedia = (bool)dbReader["ObscureMedia"], ObscureMusic = (bool)dbReader["ObscureMusic"], MediaDescription = (string)dbReader["MediaDescription"], RentPrice = (int)dbReader["RentPrice"], AABBMin = dbReader.GetVector3("AABBMin"), AABBMax = dbReader.GetVector3("AABBMax"), ParcelPrimBonus = (double)dbReader["ParcelPrimBonus"], PassPrice = (int)dbReader["PassPrice"], PassHours = (double)dbReader["PassHours"], ActualArea = (int)dbReader["ActualArea"], BillableArea = (int)dbReader["BillAbleArea"], Status = dbReader.GetEnum <ParcelStatus>("Status"), SeeAvatars = (bool)dbReader["SeeAvatars"], AnyAvatarSounds = (bool)dbReader["AnyAvatarSounds"], GroupAvatarSounds = (bool)dbReader["GroupAvatarSounds"], IsPrivate = (bool)dbReader["IsPrivate"] }; pi.LandBitmap.DataNoAABBUpdate = dbReader.GetBytes("Bitmap"); var uri = (string)dbReader["MusicURI"]; if (!string.IsNullOrEmpty(uri)) { pi.MusicURI = new URI(uri); } uri = (string)dbReader["MediaURI"]; if (!string.IsNullOrEmpty(uri)) { pi.MediaURI = new URI(uri); } return(pi); } } } } }
public void EnumerateUsedAssets(Action <UUID> action) { using (var conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new NpgsqlCommand("SELECT DISTINCT \"AssetId\" FROM primitems", conn)) { using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { action(dbReader.GetUUID("AssetId")); } } } using (var cmd = new NpgsqlCommand("SELECT \"EnvironmentSettings\" FROM environmentsettings", conn)) { using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { WindLightSettings settings; using (MemoryStream ms = new MemoryStream(dbReader.GetBytes("EnvironmentSettings"))) { settings = WindLightSettings.Deserialize(ms); } if (settings.WaterSettings.NormalMap != UUID.Zero) { action(settings.WaterSettings.NormalMap); } } } } using (var cmd = new NpgsqlCommand("SELECT DISTINCT \"NormalMapTexture\" FROM lightshare", conn)) { using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { UUID id = dbReader.GetUUID("NormalMapTexture"); if (id != UUID.Zero) { action(id); } } } } using (var cmd = new NpgsqlCommand("SELECT DISTINCT \"TerrainTexture1\", \"TerrainTexture2\", \"TerrainTexture3\", \"TerrainTexture4\" FROM regionsettings", conn)) { using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { UUID id; id = dbReader.GetUUID("TerrainTexture1"); if (id != UUID.Zero) { action(id); } id = dbReader.GetUUID("TerrainTexture2"); if (id != UUID.Zero) { action(id); } id = dbReader.GetUUID("TerrainTexture3"); if (id != UUID.Zero) { action(id); } id = dbReader.GetUUID("TerrainTexture4"); if (id != UUID.Zero) { action(id); } } } } using (var cmd = new NpgsqlCommand("SELECT \"PrimitiveShapeData\", \"ParticleSystem\", \"TextureEntryBytes\", \"ProjectionData\", \"LoopedSoundData\", \"ImpactSoundData\" FROM prims", conn)) { using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) { while (dbReader.Read()) { var shape = new ObjectPart.PrimitiveShape { Serialization = dbReader.GetBytes("PrimitiveShapeData") }; var particleSystem = new ParticleSystem(dbReader.GetBytes("ParticleSystem"), 0); var te = new TextureEntry(dbReader.GetBytes("TextureEntryBytes")); var proj = new ProjectionParam { DbSerialization = dbReader.GetBytes("ProjectionData") }; var sound = new SoundParam { Serialization = dbReader.GetBytes("LoopedSoundData") }; var colsound = new CollisionSoundParam { Serialization = dbReader.GetBytes("ImpactSoundData") }; if (shape.SculptMap != UUID.Zero) { action(shape.SculptMap); } foreach (UUID refid in particleSystem.References) { if (refid != UUID.Zero) { action(refid); } } foreach (UUID refid in te.References) { if (refid != UUID.Zero) { action(refid); } } if (proj.ProjectionTextureID != UUID.Zero) { action(proj.ProjectionTextureID); } if (sound.SoundID != UUID.Zero) { action(sound.SoundID); } if (colsound.ImpactSound != UUID.Zero) { action(colsound.ImpactSound); } } } } } }
/// <summary> /// Populates a byte array with the value of a column, given its zero-based ordinal. /// </summary> /// <param name="i"></param> /// <returns></returns> public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) { return(_rdr.GetBytes(i, fieldOffset, buffer, bufferoffset, length)); }
public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length) { return(source.GetBytes(ordinal, dataOffset, buffer, bufferOffset, length)); }
public long PurgeUnusedAssets() { long purged; try { using (var conn = new NpgsqlConnection(m_ConnectionString)) { conn.Open(); m_PurgeState = "PURGE_REFS"; using (var cmd = new NpgsqlCommand("DELETE FROM assetrefs WHERE \"usesprocessed\" = true AND \"access_time\" < @access_time AND NOT EXISTS (SELECT NULL FROM assetsinuse WHERE \"usesid\" = assetrefs.\"id\" LIMIT 1)", conn)) { ulong now = Date.GetUnixTime() - 2 * 24 * 3600; cmd.Parameters.AddParameter("@access_time", now); purged = cmd.ExecuteNonQuery(); } m_PurgeState = "PURGE_USES"; int removed = 1000; int execres; do { m_ProcessingPurge = removed; UUID id; UUID usesid; using (var cmd = new NpgsqlCommand("SELECT id, usesid FROM assetsinuse WHERE NOT EXISTS (SELECT NULL FROM assetrefs WHERE assetsinuse.\"id\" = assetrefs.\"id\" LIMIT 1) LIMIT 1", conn)) { using (NpgsqlDataReader reader = cmd.ExecuteReader()) { if (!reader.Read()) { break; } id = reader.GetUUID("id"); usesid = reader.GetUUID("usesid"); } } using (var cmd = new NpgsqlCommand("DELETE FROM assetsinuse WHERE id = @id AND usesid = @usesid AND NOT EXISTS (SELECT NULL FROM assetrefs WHERE assetsinuse.\"id\" = assetrefs.\"id\" LIMIT 1)", conn)) { cmd.Parameters.AddParameter("@id", id); cmd.Parameters.AddParameter("@usesid", usesid); execres = cmd.ExecuteNonQuery(); } removed -= execres; Interlocked.Add(ref m_PurgedAssets, execres); } while (removed > 0 && execres > 0); m_PurgeState = "PURGE_DATA"; removed = 1000; do { m_ProcessingPurge = removed; byte[] hash; AssetType assetType; using (var cmd = new NpgsqlCommand("SELECT \"hash\", \"assetType\" FROM assetdata WHERE NOT EXISTS (SELECT NULL FROM assetrefs WHERE assetdata.\"hash\" = assetrefs.\"hash\" AND assetdata.\"assetType\" = assetrefs.\"assetType\" LIMIT 1) LIMIT 1", conn)) { using (NpgsqlDataReader reader = cmd.ExecuteReader()) { if (!reader.Read()) { break; } hash = reader.GetBytes("hash"); assetType = reader.GetEnum <AssetType>("assetType"); } } using (var cmd = new NpgsqlCommand("DELETE FROM assetdata WHERE \"hash\" = @hash AND \"assetType\" = @assettype NOT EXISTS (SELECT NULL FROM assetrefs WHERE assetdata.\"hash\" = assetrefs.\"hash\" AND assetdata.\"assetType\" = assetrefs.\"assetType\" LIMIT 1)", conn)) { cmd.Parameters.AddParameter("@hash", hash); cmd.Parameters.AddParameter("@assettype", assetType); execres = cmd.ExecuteNonQuery(); } removed -= execres; Interlocked.Add(ref m_PurgedAssets, execres); } while (removed > 0 && execres > 0); } } finally { m_PurgeState = "IDLE"; m_ProcessingPurge = 0; } return(purged); }
private ObjectPart ObjectPartFromDbReader(NpgsqlDataReader dbReader) { var objpart = new ObjectPart(dbReader.GetUUID("ID")) { LoadedLinkNumber = (int)dbReader["LinkNumber"], Position = dbReader.GetVector3("Position"), Rotation = dbReader.GetQuaternion("Rotation"), SitText = (string)dbReader["SitText"], SitAnimation = (string)dbReader["SitAnimation"], TouchText = (string)dbReader["TouchText"], Name = (string)dbReader["Name"], Description = (string)dbReader["Description"], SitTargetOffset = dbReader.GetVector3("SitTargetOffset"), SitTargetOrientation = dbReader.GetQuaternion("SitTargetOrientation"), Creator = dbReader.GetUGUI("Creator"), CreationDate = dbReader.GetDate("CreationDate"), RezDate = dbReader.GetDate("RezDate"), Flags = dbReader.GetEnum <PrimitiveFlags>("Flags"), CameraAtOffset = dbReader.GetVector3("CameraAtOffset"), CameraEyeOffset = dbReader.GetVector3("CameraEyeOffset"), PhysicsShapeType = dbReader.GetEnum <PrimitivePhysicsShapeType>("PhysicsShapeType"), PathfindingType = dbReader.GetEnum <PathfindingType>("PathfindingType"), PathfindingCharacterType = dbReader.GetEnum <CharacterType>("PathfindingCharacterType"), WalkableCoefficientAvatar = (double)dbReader["WalkableCoefficientAvatar"], WalkableCoefficientA = (double)dbReader["WalkableCoefficientA"], WalkableCoefficientB = (double)dbReader["WalkableCoefficientB"], WalkableCoefficientC = (double)dbReader["WalkableCoefficientC"], WalkableCoefficientD = (double)dbReader["WalkableCoefficientD"], Material = dbReader.GetEnum <PrimitiveMaterial>("Material"), Size = dbReader.GetVector3("Size"), MediaURL = (string)dbReader["MediaURL"], AngularVelocity = dbReader.GetVector3("AngularVelocity"), PointLight = new PointLightParam { DbSerialization = dbReader.GetBytes("LightData") }, Projection = new ProjectionParam { DbSerialization = dbReader.GetBytes("ProjectionData"), }, Text = new TextParam { Serialization = dbReader.GetBytes("HoverTextData") }, Flexible = new FlexibleParam { DbSerialization = dbReader.GetBytes("FlexibleData") }, Sound = new SoundParam { Serialization = dbReader.GetBytes("LoopedSoundData") }, CollisionSound = new CollisionSoundParam { Serialization = dbReader.GetBytes("ImpactSoundData") }, Shape = new ObjectPart.PrimitiveShape { Serialization = dbReader.GetBytes("PrimitiveShapeData") }, ParticleSystemBytes = dbReader.GetBytes("ParticleSystem"), TextureEntryBytes = dbReader.GetBytes("TextureEntryBytes"), TextureAnimationBytes = dbReader.GetBytes("TextureAnimationBytes"), ScriptAccessPin = (int)dbReader["ScriptAccessPin"], ForceMouselook = (bool)dbReader["ForceMouselook"], BaseMask = dbReader.GetEnum <InventoryPermissionsMask>("BasePermissions"), OwnerMask = dbReader.GetEnum <InventoryPermissionsMask>("CurrentPermissions"), EveryoneMask = dbReader.GetEnum <InventoryPermissionsMask>("EveryOnePermissions"), GroupMask = dbReader.GetEnum <InventoryPermissionsMask>("GroupPermissions"), NextOwnerMask = dbReader.GetEnum <InventoryPermissionsMask>("NextOwnerPermissions"), ClickAction = dbReader.GetEnum <ClickActionType>("ClickAction"), PassCollisionMode = dbReader.GetEnum <PassEventMode>("PassCollisionMode"), PassTouchMode = dbReader.GetEnum <PassEventMode>("PassTouchMode"), Velocity = dbReader.GetVector3("Velocity"), IsSoundQueueing = (bool)dbReader["IsSoundQueueing"], IsAllowedDrop = (bool)dbReader["IsAllowedDrop"], PhysicsDensity = (double)dbReader["PhysicsDensity"], PhysicsFriction = (double)dbReader["PhysicsFriction"], PhysicsRestitution = (double)dbReader["PhysicsRestitution"], PhysicsGravityMultiplier = (double)dbReader["PhysicsGravityMultiplier"], IsVolumeDetect = (bool)dbReader["IsVolumeDetect"], IsPhantom = (bool)dbReader["IsPhantom"], IsPhysics = (bool)dbReader["IsPhysics"], IsRotateZEnabled = (bool)dbReader["IsRotateZEnabled"], IsRotateXEnabled = (bool)dbReader["IsRotateXEnabled"], IsRotateYEnabled = (bool)dbReader["IsRotateYEnabled"], IsSandbox = (bool)dbReader["IsSandbox"], IsBlockGrab = (bool)dbReader["IsBlockGrab"], IsDieAtEdge = (bool)dbReader["IsDieAtEdge"], IsReturnAtEdge = (bool)dbReader["IsReturnAtEdge"], IsBlockGrabObject = (bool)dbReader["IsBlockGrabObject"], SandboxOrigin = dbReader.GetVector3("SandboxOrigin"), ExtendedMesh = new ExtendedMeshParams { DbSerialization = dbReader.GetBytes("ExtendedMeshData") }, IsSitTargetActive = (bool)dbReader["IsSitTargetActive"], IsScriptedSitOnly = (bool)dbReader["IsScriptedSitOnly"], AllowUnsit = (bool)dbReader["AllowUnsit"], IsUnSitTargetActive = (bool)dbReader["IsUnSitTargetActive"], UnSitTargetOffset = dbReader.GetVector3("UnSitTargetOffset"), UnSitTargetOrientation = dbReader.GetQuaternion("UnSitTargetOrientation"), LocalizationSerialization = dbReader.GetBytes("LocalizationData"), Damage = (double)dbReader["Damage"] }; objpart.AnimationController.DbSerialization = dbReader.GetBytes("AnimationData"); objpart.LoadFromVehicleSerialization(dbReader.GetBytes("VehicleData")); using (var ms = new MemoryStream(dbReader.GetBytes("DynAttrs"))) { foreach (KeyValuePair <string, IValue> kvp in (Map)LlsdBinary.Deserialize(ms)) { objpart.DynAttrs.Add(kvp.Key, kvp.Value); } } return(objpart); }