// This is needed for .NET serialization!!!
 // Do NOT "Optimize" away!
 public AssetBase()
 {
     m_metadata = new AssetMetadata();
     m_metadata.FullID = UUID.Zero;
     m_metadata.ID = UUID.Zero.ToString();
     m_metadata.Type = (sbyte)AssetType.Unknown;
 }
Example #2
0
 public AssetBase(UUID assetID, string name, sbyte assetType, string creatorID)
 {
     m_metadata = new AssetMetadata();
     m_metadata.FullID = assetID;
     m_metadata.Name = name;
     m_metadata.Type = assetType;
 }
        public AssetBase(UUID assetID, string name, sbyte assetType)
        {
            if (assetType == (sbyte)AssetType.Unknown)
            {
                System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
            }

            m_metadata = new AssetMetadata();
            m_metadata.FullID = assetID;
            m_metadata.Name = name;
            m_metadata.Type = assetType;
        }
        public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata)
        {
            metadata = null;
            BackendResponse ret;

            if (metadataStorage.TryGetValue(assetID, out metadata))
                ret = BackendResponse.Success;
            else
                ret = BackendResponse.NotFound;

            server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
            return ret;
        }
Example #5
0
        public AssetBase(UUID assetID, string name, sbyte assetType)
        {
            if (assetType == (sbyte)AssetType.Unknown)
            {
                System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);
                m_log.ErrorFormat("[ASSETBASE]: Creating asset '{0}' ({1}) with an unknown asset type\n{2}",
                    name, assetID, trace.ToString());
            }

            m_metadata = new AssetMetadata();
            m_metadata.FullID = assetID;
            m_metadata.Name = name;
            m_metadata.Type = assetType;
        }
        public BackendResponse TryFetchMetadata(UUID assetID, out AssetMetadata metadata)
        {
            metadata = null;
            BackendResponse ret;

            AssetBase asset = m_assetProvider.FetchAsset(assetID);

            if (asset == null) ret = BackendResponse.NotFound;
            else
            {
                metadata = asset.Metadata;
                ret = BackendResponse.Success;
            }

            m_server.MetricsProvider.LogAssetMetadataFetch(EXTENSION_NAME, ret, assetID, DateTime.Now);
            return ret;
        }
        /// <summary>
        ///   Add asset metadata xml
        /// </summary>
        /// <param name = "xml"></param>
        public void AddAssetMetadata(string xml)
        {
            m_metadata = new Dictionary<string, AssetMetadata>();

            StringReader sr = new StringReader(xml);
            XmlTextReader reader = new XmlTextReader(sr);

            reader.ReadStartElement("assets");
            reader.Read();

            while (reader.Name.Equals("asset"))
            {
                reader.Read();

                AssetMetadata metadata = new AssetMetadata();

                string filename = reader.ReadElementString("filename");
                MainConsole.Instance.DebugFormat("[DEARCHIVER]: Reading node {0}", filename);

                metadata.Name = reader.ReadElementString("name");
                metadata.Description = reader.ReadElementString("description");
                metadata.AssetType = Convert.ToSByte(reader.ReadElementString("asset-type"));

                m_metadata[filename] = metadata;

                // Read asset end tag
                reader.ReadEndElement();

                reader.Read();
            }

            MainConsole.Instance.DebugFormat("[DEARCHIVER]: Resolved {0} items of asset metadata", m_metadata.Count);

            ResolvePendingAssetData();
        }
        /// <summary>
        /// Returns a list of AssetMetadata objects. The list is a subset of
        /// the entire data set offset by <paramref name="start" /> containing
        /// <paramref name="count" /> elements.
        /// </summary>
        /// <param name="start">The number of results to discard from the total data set.</param>
        /// <param name="count">The number of rows the returned list should contain.</param>
        /// <returns>A list of AssetMetadata objects.</returns>
        public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
        {
            List<AssetMetadata> retList = new List<AssetMetadata>(count);
            string sql = @"WITH OrderedAssets AS
                (
                    SELECT id, name, description, assetType, temporary, creatorid,
                    RowNumber = ROW_NUMBER() OVER (ORDER BY id)
                    FROM assets 
                ) 
                SELECT * 
                FROM OrderedAssets
                WHERE RowNumber BETWEEN @start AND @stop;";

            using (SqlConnection conn = new SqlConnection(m_connectionString))
            using (SqlCommand cmd = new SqlCommand(sql, conn))
            {
                cmd.Parameters.Add(m_database.CreateParameter("start", start));
                cmd.Parameters.Add(m_database.CreateParameter("stop", start + count - 1));
                conn.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        AssetMetadata metadata = new AssetMetadata();
                        metadata.FullID = DBGuid.FromDB(reader["id"]);
                        metadata.Name = (string)reader["name"];
                        metadata.Description = (string)reader["description"];
                        metadata.Type = Convert.ToSByte(reader["assetType"]);
                        metadata.Temporary = Convert.ToBoolean(reader["temporary"]);
                        metadata.CreatorID = (string)reader["creatorid"];
                        retList.Add(metadata);
                    }
                }
            }

            return retList;
        }
        public bool Store(AssetMetadata meta, string hash)
        {
            try
            {
                string oldhash;
                AssetMetadata existingAsset = Get(meta.ID, out oldhash);

                MySqlCommand cmd = m_Connection.CreateCommand();

                cmd.Parameters.AddWithValue("?id", meta.ID);
                cmd.Parameters.AddWithValue("?name", meta.Name);
                cmd.Parameters.AddWithValue("?description", meta.Description);
                cmd.Parameters.AddWithValue("?type", meta.Type.ToString());
                cmd.Parameters.AddWithValue("?hash", hash);
                cmd.Parameters.AddWithValue("?asset_flags", meta.Flags);

                if (existingAsset == null)
                {
                    cmd.CommandText = String.Format("insert into {0} (id, name, description, type, hash, asset_flags, create_time, access_time) values ( ?id, ?name, ?description, ?type, ?hash, ?asset_flags, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())", m_Table);

                    ExecuteNonQuery(cmd);

                    cmd.Dispose();

                    return true;
                }

                //cmd.CommandText = String.Format("update {0} set hash = ?hash, access_time = UNIX_TIMESTAMP() where id = ?id", m_Table);

                //ExecuteNonQuery(cmd);

                cmd.Dispose();
                return false;
            }
            catch(Exception e)
            {
                m_log.Error("[FSAssets] Failed to store asset with ID " + meta.ID);
            m_log.Error(e.ToString());
                return false;
            }
        }
Example #10
0
        private static AssetMetadata buildAssetMetadata(IDataReader row)
        {
            AssetMetadata metadata = new AssetMetadata();

            metadata.FullID = new UUID((string) row["UUID"]);
            metadata.Name = (string) row["Name"];
            metadata.Description = (string) row["Description"];
            metadata.Type = Convert.ToSByte(row["Type"]);
            metadata.Temporary = Convert.ToBoolean(row["Temporary"]); // Not sure if this is correct.
            metadata.Flags = (AssetFlags)Convert.ToInt32(row["asset_flags"]);
            metadata.CreatorID = row["CreatorID"].ToString();

            // Current SHA1s are not stored/computed.
            metadata.SHA1 = new byte[] {};

            return metadata;
        }
Example #11
0
        /// <summary>
        /// Returns a list of AssetMetadata objects. The list is a subset of
        /// the entire data set offset by <paramref name="start" /> containing
        /// <paramref name="count" /> elements.
        /// </summary>
        /// <param name="start">The number of results to discard from the total data set.</param>
        /// <param name="count">The number of rows the returned list should contain.</param>
        /// <returns>A list of AssetMetadata objects.</returns>
        public List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
        {
            List<AssetMetadata> retList = new List<AssetMetadata>(count);

            lock (m_dbLock)
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
                {
                    dbcon.Open();
                    NpgsqlCommand cmd = new NpgsqlCommand( @"SELECT ""Name"", ""Description"", ""AccessTime"", ""AssetType"", ""Temporary"", ""ID"", ""AssetFlags"", ""CreatorID""
                                            FROM XAssetsMeta 
                                            LIMIT :start, :count", dbcon);
                    cmd.Parameters.AddWithValue("start", start);
                    cmd.Parameters.AddWithValue("count", count);

                    try
                    {
                        using (NpgsqlDataReader dbReader = cmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                AssetMetadata metadata = new AssetMetadata();
                                metadata.Name = (string)dbReader["Name"];
                                metadata.Description = (string)dbReader["Description"];
                                metadata.Type = (sbyte)dbReader["AssetType"];
                                metadata.Temporary = Convert.ToBoolean(dbReader["Temporary"]); // Not sure if this is correct.
                                metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]);
                                metadata.FullID = DBGuid.FromDB(dbReader["ID"]);
                                metadata.CreatorID = dbReader["CreatorID"].ToString();

                                // We'll ignore this for now - it appears unused!
//                                metadata.SHA1 = dbReader["hash"]);

                                UpdateAccessTime(metadata, (int)dbReader["AccessTime"]);

                                retList.Add(metadata);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        m_log.Error("[XASSETS DB]: PGSql failure fetching asset set" + Environment.NewLine + e.ToString());
                    }
                }
            }

            return retList;
        }
Example #12
0
        /// <summary>
        /// Returns a list of AssetMetadata objects. The list is a subset of
        /// the entire data set offset by <paramref name="start" /> containing
        /// <paramref name="count" /> elements.
        /// </summary>
        /// <param name="start">The number of results to discard from the total data set.</param>
        /// <param name="count">The number of rows the returned list should contain.</param>
        /// <returns>A list of AssetMetadata objects.</returns>
        public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
        {
            List<AssetMetadata> retList = new List<AssetMetadata>(count);
            string sql = @" SELECT id, name, description, " + "\"assetType\"" + @", temporary, creatorid
                              FROM assets 
                             order by id
                             limit :stop
                            offset :start;";

            using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
            using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
            {
                cmd.Parameters.Add(m_database.CreateParameter("start", start));
                cmd.Parameters.Add(m_database.CreateParameter("stop", start + count - 1));
                conn.Open();
                using (NpgsqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        AssetMetadata metadata = new AssetMetadata();
                        metadata.FullID = DBGuid.FromDB(reader["id"]);
                        metadata.Name = (string)reader["name"];
                        metadata.Description = (string)reader["description"];
                        metadata.Type = Convert.ToSByte(reader["assetType"]);
                        metadata.Temporary = Convert.ToBoolean(reader["temporary"]);
                        metadata.CreatorID = (string)reader["creatorid"];
                        retList.Add(metadata);
                    }
                }
            }

            return retList;
        }
Example #13
0
 public AssetBase()
 {
     m_metadata = new AssetMetadata();
 }
Example #14
0
 public AssetBase()
 {
     m_metadata = new AssetMetadata();
 }
        protected void AdjustIdentifiers(AssetMetadata meta)
        {
            if (meta == null || m_Cache == null)
                return;

            UserAccount creator = m_Cache.GetUser(meta.CreatorID);
            if (creator != null)
                meta.CreatorID = meta.CreatorID + ";" + m_HomeURL + "/" + creator.FirstName + " " + creator.LastName;
        }
        public HttpStatusCode InventoryPutHandler(OSHttpRequest request, string path, string username, string[] if_headers)
        {
            // TODO: Figure out ETAG checks
            byte[] assetData = request.GetBody();
            if (assetData.Length == 0)
                return HttpStatusCode.BadRequest;
            string localPath = "";
            UUID agentID = AgentIDFromRequestPath("inventory", "/", path, ref localPath);

            string[] pathParts = localPath.Split('/');
            string assetName;
            if(localPath.EndsWith("/"))
            {
                assetName = pathParts[pathParts.Length - 2];
                localPath = localPath.Substring(0, localPath.Length - (assetName.Length + 1));
            }
            else
            {
                assetName = pathParts[pathParts.Length - 1];
                localPath = localPath.Substring(0, localPath.Length - assetName.Length);
            }
            InventoryNodeBase invObject = PathToInventory(agentID, localPath);

            if (invObject != null)
            {
                if (invObject is InventoryFolderBase)
                {
                    InventoryFolderBase parentFolder = (InventoryFolderBase)invObject;
                    OpenSim.Framework.AssetMetadata assetMetadata = new OpenSim.Framework.AssetMetadata();
                    assetMetadata.ContentType = request.Headers["Content-type"];
                    assetMetadata.CreationDate = DateTime.Now;
                    assetMetadata.Description = assetName;
                    assetMetadata.ID = UUID.Random().ToString();
                    assetMetadata.Name = assetName;
                    assetMetadata.Temporary = false;
                    //assetMetadata.SHA256 = OpenMetaverse.Utils.SHA256(assetData);
                    assetMetadata.SHA1 = OpenMetaverse.Utils.SHA1(assetData);
                    
                    sbyte type = CableBeachUtils.ContentTypeToSLAssetType(request.Headers["Content-type"]);

                    AssetBase asset = new AssetBase(UUID.Random(), assetName, type);

                    asset.Data = assetData;
                    asset.Metadata = assetMetadata;
                    string ret = m_AssetService.Store(asset);

                    // Check if asset was created
                    if (m_AssetService.GetMetadata(assetMetadata.ID) != null)
                    {
                        InventoryItemBase inventoryItem = new InventoryItemBase();
                        inventoryItem.AssetID = new UUID(assetMetadata.ID);
                        inventoryItem.AssetType = parentFolder.Type;
                        // TODO: conversion from long to int migth not be sufficient here
                        inventoryItem.CreationDate = (int) DateTime.Now.Ticks; 
                        inventoryItem.CreatorId = agentID.ToString();
                        inventoryItem.Owner = agentID;
                        inventoryItem.CurrentPermissions = 2147483647;
                        inventoryItem.NextPermissions = 2147483647;
                        inventoryItem.BasePermissions = 2147483647;
                        inventoryItem.EveryOnePermissions = 2147483647;
                        inventoryItem.GroupPermissions = 2147483647;
                        inventoryItem.InvType = (int)CableBeachMessages.InventoryType.Object;
                        inventoryItem.GroupOwned = false;
                        inventoryItem.Description = assetMetadata.Description;
                        inventoryItem.ID = UUID.Random();
                        inventoryItem.Name = assetMetadata.Name;
                        inventoryItem.Folder = parentFolder.ID;
                        inventoryItem.SalePrice = 0;
                        if (m_InventoryService.AddItem(inventoryItem))
                            return HttpStatusCode.Created;
                        //if (m_InventoryService.UpdateItem(
                    }
                    else 
                    { // failed asset creation, dont create inventory item either sender, send error back
                        //return HttpStatusCode.PreconditionFailed & HttpStatusCode.InternalServerError;
                        return HttpStatusCode.InternalServerError;
                    }
                }
            }
            return HttpStatusCode.InternalServerError;
        }
        public void AsssetBaseConstructorTest01()
        {
            AssetBase abase = new AssetBase();
            Assert.IsNotNull(abase.Metadata, "void constructor of AssetBase should have created a MetaData element but didn't.");
            UUID itemID = UUID.Random();
            UUID creatorID = UUID.Random();
            abase = new AssetBase(itemID.ToString(), "test item", (sbyte) AssetType.Texture, creatorID.ToString());

            Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase should have created a MetaData element but didn't.");
            Assert.That(abase.ID == itemID.ToString(), "string,string,sbyte,string constructor failed to set ID property");
            Assert.That(abase.Metadata.CreatorID == creatorID.ToString(), "string,string,sbyte,string constructor failed to set Creator ID");


            abase = new AssetBase(itemID.ToString(), "test item", -1, creatorID.ToString());
            Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase with unknown type should have created a MetaData element but didn't.");
            Assert.That(abase.Metadata.Type == -1, "Unknown Type passed to string,string,sbyte,string constructor and was a known type when it came out again");

            AssetMetadata metts = new AssetMetadata();
            metts.FullID = itemID;
            metts.ID = string.Empty;
            metts.Name = "test item";
            abase.Metadata = metts;

            Assert.That(abase.ToString() == itemID.ToString(), "ToString is overriden to be fullID.ToString()");
            Assert.That(abase.ID == itemID.ToString(),"ID should be MetaData.FullID.ToString() when string.empty or null is provided to the ID property");
        }
 public void AssetMetaDataNonNullContentTypeTest01()
 {
     AssetMetadata assetMetadata = new AssetMetadata();
     assetMetadata.ContentType = "image/jp2";
     Assert.That(assetMetadata.Type == (sbyte)AssetType.Texture, "Content type should be AssetType.Texture");
     Assert.That(assetMetadata.ContentType == "image/jp2", "Text of content type should be image/jp2");
     UUID rndID = UUID.Random();
     assetMetadata.ID = rndID.ToString();
     Assert.That(assetMetadata.ID.ToLower() == rndID.ToString().ToLower(), "assetMetadata.ID Setter/Getter not Consistent");
     DateTime fixedTime = DateTime.Now;
     assetMetadata.CreationDate = fixedTime;
 }
        /// <summary>
        /// Invokes the xGetAssetMetadata operation on the simian server to retrieve metadata for an asset
        /// This operation is generally used to determine if an asset exists in the database
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private AssetMetadata SimianGetMetadataOperation(string id)
        {
            try
            {
                NameValueCollection requestArgs = new NameValueCollection
                    {
                            { "RequestMethod", "xGetAssetMetadata" },
                            { "ID", id } 
                    };

                OSDMap response = SimianGrid.PostToService(m_serverUrl,requestArgs);
                if (! response["Success"].AsBoolean())
                {
                    // this is not really an error, this call is used to test existence
                    // m_log.DebugFormat("[SIMIAN ASSET CONNECTOR] Failed to get asset metadata; {0}",response["Message"].AsString());
                    return null;
                }
            
                AssetMetadata metadata = new AssetMetadata();
                metadata.ID = id;
                metadata.ContentType = response["ContentType"].AsString();
                metadata.CreatorID = response["CreatorID"].AsString();
                metadata.Local = false;
                metadata.Temporary = response["Temporary"];

                string lastModifiedStr = response["Last-Modified"].AsString();
                if (! String.IsNullOrEmpty(lastModifiedStr))
                {
                    DateTime lastModified;
                    if (DateTime.TryParse(lastModifiedStr, out lastModified))
                        metadata.CreationDate = lastModified;
                }

                return metadata;
            }
            catch (Exception ex)
            {
                m_log.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to get asset metadata; {0}", ex.Message);
            }

            return null;
        }
Example #20
0
 private void CreateMetaDataMap(AssetMetadata data, OSDMap map)
 {
     map["ContentType"] = OSD.FromString(data.ContentType);
     map["CreationDate"] = OSD.FromDate(data.CreationDate);
     map["CreatorID"] = OSD.FromString(data.CreatorID);
     map["Description"] = OSD.FromString(data.Description);
     map["ID"] = OSD.FromString(data.ID);
     map["Name"] = OSD.FromString(data.Name);
     map["Type"] = OSD.FromInteger(data.Type);
 }
Example #21
0
        private AssetBase LoadAssetBase(OSDMap map)
        {
            AssetBase asset = new AssetBase();
            asset.Data = map["AssetData"].AsBinary();

            AssetMetadata md = new AssetMetadata();
            md.ContentType = map["ContentType"].AsString();
            md.CreationDate = map["CreationDate"].AsDate();
            md.CreatorID = map["CreatorID"].AsString();
            md.Description = map["Description"].AsString();
            md.ID = map["ID"].AsString();
            md.Name = map["Name"].AsString();
            md.Type = (sbyte)map["Type"].AsInteger();

            asset.Metadata = md;
            asset.ID = md.ID;
            asset.FullID = UUID.Parse(md.ID);
            asset.Name = md.Name;
            asset.Type = md.Type;

            return asset;
        }
Example #22
0
 public AssetBase(UUID assetId, string name)
 {
     m_metadata        = new AssetMetadata();
     m_metadata.FullID = assetId;
     m_metadata.Name   = name;
 }
Example #23
0
 public AssetBase(UUID assetId, string name)
 {
     m_metadata = new AssetMetadata();
     m_metadata.FullID = assetId;
     m_metadata.Name = name;
 }
        public AssetMetadata Get(string id, out string hash)
        {
            hash = String.Empty;

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = String.Format("select id, name, description, type, hash, create_time, asset_flags from {0} where id = ?id", m_Table);
            cmd.Parameters.AddWithValue("?id", id);

            IDataReader reader = ExecuteReader(cmd);

            if (!reader.Read())
            {
                reader.Close();
                FreeCommand(cmd);
                return null;
            }

            AssetMetadata meta = new AssetMetadata();

            hash = reader["hash"].ToString();

            meta.ID = id;
            meta.FullID = new UUID(id);

            meta.Name = reader["name"].ToString();
            meta.Description = reader["description"].ToString();
            meta.Type = (sbyte)Convert.ToInt32(reader["type"]);
            meta.ContentType = SLUtil.SLAssetTypeToContentType(meta.Type);
            meta.CreationDate = Util.ToDateTime(Convert.ToInt32(reader["create_time"]));
            meta.Flags = (AssetFlags)Convert.ToInt32(reader["asset_flags"]);

            reader.Close();

            cmd.CommandText = String.Format("update {0} set access_time = UNIX_TIMESTAMP() where id = ?id", m_Table);

            cmd.ExecuteNonQuery();

            FreeCommand(cmd);

            return meta;
        }
Example #25
0
        /// <summary>
        /// Updates the access time of the asset if it was accessed above a given threshhold amount of time.
        /// </summary>
        /// <remarks>
        /// This gives us some insight into assets which haven't ben accessed for a long period.  This is only done
        /// over the threshold time to avoid excessive database writes as assets are fetched.
        /// </remarks>
        /// <param name='asset'></param>
        /// <param name='accessTime'></param>
        private void UpdateAccessTime(AssetMetadata assetMetadata, int accessTime)
        {
            DateTime now = DateTime.UtcNow;

            if ((now - Utils.UnixTimeToDateTime(accessTime)).TotalDays < DaysBetweenAccessTimeUpdates)
                return;

            lock (m_dbLock)
            {
                using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
                {
                    dbcon.Open();
                    NpgsqlCommand cmd =
                        new NpgsqlCommand(@"update XAssetsMeta set ""AccessTime""=:AccessTime where ID=:ID", dbcon);

                    try
                    {
                        using (cmd)
                        {
                            // create unix epoch time
                            cmd.Parameters.AddWithValue("ID", assetMetadata.ID);
                            cmd.Parameters.AddWithValue("AccessTime", (int)Utils.DateTimeToUnixTime(now));
                            cmd.ExecuteNonQuery();
                        }
                    }
                    catch (Exception e)
                    {
                        m_log.ErrorFormat(
                            "[XASSET PGSQL DB]: Failure updating access_time for asset {0} with name {1} : {2}", 
                            assetMetadata.ID, assetMetadata.Name, e.Message);
                    }
                }
            }
        }
        /// <summary>
        /// Returns a list of AssetMetadata objects. The list is a subset of
        /// the entire data set offset by <paramref name="start" /> containing
        /// <paramref name="count" /> elements.
        /// </summary>
        /// <param name="start">The number of results to discard from the total data set.</param>
        /// <param name="count">The number of rows the returned list should contain.</param>
        /// <returns>A list of AssetMetadata objects.</returns>
        public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
        {
            List<AssetMetadata> retList = new List<AssetMetadata>(count);

            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
            {
                dbcon.Open();

                using (MySqlCommand cmd
                    = new MySqlCommand(
                        "SELECT name,description,assetType,temporary,id,asset_flags,CreatorID FROM assets LIMIT ?start, ?count",
                        dbcon))
                {
                    cmd.Parameters.AddWithValue("?start", start);
                    cmd.Parameters.AddWithValue("?count", count);
    
                    try
                    {
                        using (MySqlDataReader dbReader = cmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                AssetMetadata metadata = new AssetMetadata();
                                metadata.Name = (string)dbReader["name"];
                                metadata.Description = (string)dbReader["description"];
                                metadata.Type = (sbyte)dbReader["assetType"];
                                metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct.
                                metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
                                metadata.FullID = DBGuid.FromDB(dbReader["id"]);
                                metadata.CreatorID = dbReader["CreatorID"].ToString();
    
                                // Current SHA1s are not stored/computed.
                                metadata.SHA1 = new byte[] { };
    
                                retList.Add(metadata);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        m_log.Error(
                            string.Format(
                                "[ASSETS DB]: MySql failure fetching asset set from {0}, count {1}.  Exception  ", 
                                start, count), 
                            e);
                    }
                }
            }

            return retList;
        }
Example #27
0
        /// <summary>
        /// Returns a list of AssetMetadata objects. The list is a subset of
        /// the entire data set offset by <paramref name="start" /> containing
        /// <paramref name="count" /> elements.
        /// </summary>
        /// <param name="start">The number of results to discard from the total data set.</param>
        /// <param name="count">The number of rows the returned list should contain.</param>
        /// <returns>A list of AssetMetadata objects.</returns>
        public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
        {
            List<AssetMetadata> retList = new List<AssetMetadata>(count);
            string sql = @"SELECT (name,description,assetType,temporary,id), Row = ROW_NUMBER() 
                            OVER (ORDER BY (some column to order by)) 
                            WHERE Row >= @Start AND Row < @Start + @Count";
            
            using (AutoClosingSqlCommand command = m_database.Query(sql))
            {
                command.Parameters.Add(m_database.CreateParameter("start", start));
                command.Parameters.Add(m_database.CreateParameter("count", count));

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        AssetMetadata metadata = new AssetMetadata();
                        metadata.FullID = new UUID((Guid)reader["id"]);
                        metadata.Name = (string)reader["name"];
                        metadata.Description = (string)reader["description"];
                        metadata.Type = Convert.ToSByte(reader["assetType"]);
                        metadata.Temporary = Convert.ToBoolean(reader["temporary"]);
                    }
                }
            }

            return retList;
        }
Example #28
0
 private void AdjustIdentifiers(AssetMetadata meta)
 {
     if (!string.IsNullOrEmpty(meta.CreatorID))
     {
         UUID uuid = UUID.Zero;
         UUID.TryParse(meta.CreatorID, out uuid);
         UserAccount creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid); 
         if (creator != null)
             meta.CreatorID = m_HomeURI + ";" + creator.FirstName + " " + creator.LastName;
     }
 }
        /// <summary>
        /// Get an asset's metadata
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AssetMetadata GetMetadata(string id)
        {
            if (String.IsNullOrEmpty(m_serverUrl))
            {
                m_log.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured");
                throw new InvalidOperationException();
            }

            AssetMetadata metadata = null;

            // Cache fetch
            if (m_cache != null)
            {
                AssetBase asset = m_cache.Get(id);
                if (asset != null)
                    return asset.Metadata;
            }

            Uri url;

            // Determine if id is an absolute URL or a grid-relative UUID
            if (!Uri.TryCreate(id, UriKind.Absolute, out url))
                url = new Uri(m_serverUrl + id);

            try
            {
                HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
                request.Method = "HEAD";

                using (WebResponse response = request.GetResponse())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        // Create the metadata object
                        metadata = new AssetMetadata();
                        metadata.ContentType = response.ContentType;
                        metadata.ID = id;

                        UUID uuid;
                        if (UUID.TryParse(id, out uuid))
                            metadata.FullID = uuid;

                        string lastModifiedStr = response.Headers.Get("Last-Modified");
                        if (!String.IsNullOrEmpty(lastModifiedStr))
                        {
                            DateTime lastModified;
                            if (DateTime.TryParse(lastModifiedStr, out lastModified))
                                metadata.CreationDate = lastModified;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset HEAD from " + url + " failed: " + ex.Message);
            }

            return metadata;
        }
        public void Import(string conn, string table, int start, int count, bool force, StoreDelegate store)
        {
            MySqlConnection importConn;

            try
            {
                importConn = new MySqlConnection(conn);

                importConn.Open();
            }
            catch (MySqlException e)
            {
                m_log.ErrorFormat("[FSASSETS]: Can't connect to database: {0}",
                        e.Message.ToString());

                return;
            }

            int imported = 0;

            MySqlCommand cmd = importConn.CreateCommand();

            string limit = String.Empty;
            if (count != -1)
            {
                limit = String.Format(" limit {0},{1}", start, count);
            }

            cmd.CommandText = String.Format("select * from {0}{1}", table, limit);

            MainConsole.Instance.Output("Querying database");
            IDataReader reader = cmd.ExecuteReader();

            MainConsole.Instance.Output("Reading data");

            while (reader.Read())
            {
                if ((imported % 100) == 0)
                {
                    MainConsole.Instance.Output(String.Format("{0} assets imported so far", imported));
                }

                AssetBase asset = new AssetBase();
                AssetMetadata meta = new AssetMetadata();

                meta.ID = reader["id"].ToString();
                meta.FullID = new UUID(meta.ID);

                meta.Name = reader["name"].ToString();
                meta.Description = reader["description"].ToString();
                meta.Type = (sbyte)Convert.ToInt32(reader["assetType"]);
                meta.ContentType = SLUtil.SLAssetTypeToContentType(meta.Type);
                meta.CreationDate = Util.ToDateTime(Convert.ToInt32(reader["create_time"]));

                asset.Metadata = meta;
                asset.Data = (byte[])reader["data"];

                store(asset, force);

                imported++;
            }

            reader.Close();
            cmd.Dispose();
            importConn.Close();

            MainConsole.Instance.Output(String.Format("Import done, {0} assets imported", imported));
        }
Example #31
0
        /// <summary>
        /// Returns a list of AssetMetadata objects. The list is a subset of
        /// the entire data set offset by <paramref name="start" /> containing
        /// <paramref name="count" /> elements.
        /// </summary>
        /// <param name="start">The number of results to discard from the total data set.</param>
        /// <param name="count">The number of rows the returned list should contain.</param>
        /// <returns>A list of AssetMetadata objects.</returns>
        public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
        {
            List<AssetMetadata> retList = new List<AssetMetadata>(count);

            lock (m_dbLock)
            {
                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
                {
                    dbcon.Open();
                    MySqlCommand cmd = new MySqlCommand("SELECT name,description,assetType,temporary,id FROM assets LIMIT ?start, ?count", dbcon);
                    cmd.Parameters.AddWithValue("?start", start);
                    cmd.Parameters.AddWithValue("?count", count);

                    try
                    {
                        using (MySqlDataReader dbReader = cmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                AssetMetadata metadata = new AssetMetadata();
                                metadata.Name = (string)dbReader["name"];
                                metadata.Description = (string)dbReader["description"];
                                metadata.Type = (sbyte)dbReader["assetType"];
                                metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct.
                                metadata.FullID = new UUID((string)dbReader["id"]);

                                // Current SHA1s are not stored/computed.
                                metadata.SHA1 = new byte[] { };

                                retList.Add(metadata);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        m_log.Error("[ASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString());
                    }
                }
            }

            return retList;
        }
 protected void AdjustIdentifiers(AssetMetadata meta)
 {
     UserAccount creator = m_UserAccountService.GetUserAccount (UUID.Zero, UUID.Parse(meta.CreatorID));
     if (creator != null)
         meta.CreatorID = m_ProfileServiceURL + "/" + meta.CreatorID + ";" + creator.FirstName + " " + creator.LastName;
 }