/// <summary> /// Gets the user folder for the given folder-type /// </summary> /// <param name="userID"></param> /// <param name="type"></param> /// <returns></returns> public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) { string contentType = SLUtil.SLAssetTypeToContentType((int)type); NameValueCollection requestArgs = new NameValueCollection { { "RequestMethod", "GetFolderForType" }, { "ContentType", contentType }, { "OwnerID", userID.ToString() } }; OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs); if (response["Success"].AsBoolean() && response["Folder"] is OSDMap) { OSDMap folder = (OSDMap)response["Folder"]; return(new InventoryFolderBase( folder["ID"].AsUUID(), folder["Name"].AsString(), folder["OwnerID"].AsUUID(), (short)SLUtil.ContentTypeToSLAssetType(folder["ContentType"].AsString()), folder["ParentID"].AsUUID(), (ushort)folder["Version"].AsInteger() )); } else { m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Default folder not found for content type " + contentType + ": " + response["Message"].AsString()); return(GetRootFolder(userID)); } }
private List <InventoryFolderBase> GetFoldersFromResponse(OSDArray items, UUID baseFolder, bool includeBaseFolder) { List <InventoryFolderBase> invFolders = new List <InventoryFolderBase>(items.Count); for (int i = 0; i < items.Count; i++) { OSDMap item = items[i] as OSDMap; if (item != null && item["Type"].AsString() == "Folder") { UUID folderID = item["ID"].AsUUID(); if (folderID == baseFolder && !includeBaseFolder) { continue; } invFolders.Add(new InventoryFolderBase( folderID, item["Name"].AsString(), item["OwnerID"].AsUUID(), (short)SLUtil.ContentTypeToSLAssetType(item["ContentType"].AsString()), item["ParentID"].AsUUID(), (ushort)item["Version"].AsInteger() )); } } // m_log.Debug("[SIMIAN INVENTORY CONNECTOR]: Parsed " + invFolders.Count + " folders from SimianGrid response"); return(invFolders); }
// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- private void DoJsonReadNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) { AssetBase a = m_scene.AssetService.Get(assetID.ToString()); if (a == null) { GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID)); } if (a.Type != (sbyte)AssetType.Notecard) { GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID)); } m_log.DebugFormat("[JsonStoreScripts] read notecard in context {0}", storeID); try { string jsondata = SLUtil.ParseNotecardToString(Encoding.UTF8.GetString(a.Data)); int result = m_store.SetValue(storeID, path, jsondata, true) ? 1 : 0; m_comms.DispatchReply(scriptID, result, "", reqID.ToString()); return; } catch (Exception e) { m_log.WarnFormat("[JsonStoreScripts] Json parsing failed; {0}", e.Message); } GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID.ToString())); m_comms.DispatchReply(scriptID, 0, "", reqID.ToString()); }
public AssetMetadata Get(string id, out string hash) { hash = String.Empty; AssetMetadata meta = null; UUID uuid = new UUID(id); string query = String.Format("select \"id\", \"type\", \"hash\", \"create_time\", \"access_time\", \"asset_flags\" from {0} where \"id\" = :id", m_Table); using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) { dbcon.Open(); cmd.Parameters.Add(m_database.CreateParameter("id", uuid)); using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default)) { if (reader.Read()) { meta = new AssetMetadata(); hash = reader["hash"].ToString(); meta.ID = id; meta.FullID = uuid; meta.Name = String.Empty; meta.Description = String.Empty; 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"]); int atime = Convert.ToInt32(reader["access_time"]); UpdateAccessTime(atime, uuid); } } } return(meta); }
public void Import(string conn, string table, int start, int count, bool force, FSStoreDelegate store) { int imported = 0; string limit = String.Empty; if (count != -1) { limit = String.Format(" limit {0} offset {1}", start, count); } string query = String.Format("select * from {0}{1}", table, limit); try { using (NpgsqlConnection remote = new NpgsqlConnection(conn)) using (NpgsqlCommand cmd = new NpgsqlCommand(query, remote)) { remote.Open(); MainConsole.Instance.Output("Querying database"); MainConsole.Instance.Output("Reading data"); using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default)) { 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 = String.Empty; meta.Description = String.Empty; 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++; } } } } catch (Exception e) { m_log.ErrorFormat("[PGSQL FSASSETS]: Error importing assets: {0}", e.Message.ToString()); return; } MainConsole.Instance.Output(String.Format("Import done, {0} assets imported", imported)); }
//rejected: not thread-safe. Other .NET wrappers ignore it too. //void _Err(string func) //{ // var r = SLApi.sqlite3_errcode(_db); // if(r != 0 && r != SLError.Row) throw new SLException(r, _db, func); //} /// <summary> /// Called by GetX functions when sqlite3_column_x returns null/0. /// Shows warning if sqlite3_errcode is not 0 or Row. /// Does not throw exception because it is not thread-safe. /// </summary> /// <param name="func"></param> void _WarnGet([CallerMemberName] string func = null) { var r = SLApi.sqlite3_errcode(_db); if (r != 0 && r != SLError.Row) { SLUtil.Warn(r, func, "Note: it may be a false positive if this database connection is used by multiple threads simultaneously without locking."); } }
/// protected virtual void Dispose(bool disposing) { if (_db != default) { var r = SLApi.sqlite3_close_v2(_db); Debug.Assert(r == 0); SLUtil.Warn(r, "sqlite3_close"); _db = default; } }
// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- private void DoJsonReadNotecard( UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) { UUID assetID; if (!UUID.TryParse(notecardIdentifier, out assetID)) { SceneObjectPart part = m_scene.GetSceneObjectPart(hostID); assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard); } AssetBase a = m_scene.AssetService.Get(assetID.ToString()); if (a == null) { GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID)); } if (a.Type != (sbyte)AssetType.Notecard) { GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID)); } m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}", storeID); try { int result; string[] data = SLUtil.ParseNotecardToArray(a.Data); if (data.Length == 0) { result = m_store.SetValue(storeID, path, string.Empty, true) ? 1 : 0; } else { StringBuilder sb = new StringBuilder(256); for (int i = 0; i < data.Length; ++i) { sb.AppendLine(data[i]); } result = m_store.SetValue(storeID, path, sb.ToString(), true) ? 1 : 0; } m_comms.DispatchReply(scriptID, result, "", reqID.ToString()); return; } catch (Exception e) { m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message); } GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID)); m_comms.DispatchReply(scriptID, 0, "", reqID.ToString()); }
private AssetBase GetRemote(string id) { AssetBase asset = null; 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); using (WebResponse response = request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { string creatorID = response.Headers.GetOne("X-Asset-Creator-Id") ?? String.Empty; // Create the asset object asset = new AssetBase(id, String.Empty, SLUtil.ContentTypeToSLAssetType(response.ContentType), creatorID); UUID assetID; if (UUID.TryParse(id, out assetID)) { asset.FullID = assetID; } // Grab the asset data from the response stream using (MemoryStream stream = new MemoryStream()) { responseStream.CopyTo(stream, Int32.MaxValue); asset.Data = stream.ToArray(); } } } // Cache store if (m_cache != null && asset != null) { m_cache.Cache(asset); } return(asset); } catch (Exception ex) { m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message); return(null); } }
public AssetMetadata Get(string id, out string hash) { hash = String.Empty; AssetMetadata meta = new AssetMetadata(); using (MySqlConnection conn = new MySqlConnection(m_ConnectionString)) { try { conn.Open(); } catch (MySqlException e) { m_log.ErrorFormat("[FSASSETS]: Database open failed with {0}", e.ToString()); return(null); } using (MySqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = String.Format("select id, name, description, type, hash, create_time, asset_flags, access_time from {0} where id = ?id", m_Table); cmd.Parameters.AddWithValue("?id", id); using (IDataReader reader = cmd.ExecuteReader()) { if (!reader.Read()) { return(null); } 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"]); int AccessTime = Convert.ToInt32(reader["access_time"]); UpdateAccessTime(id, AccessTime); } } conn.Close(); } return(meta); }
public static void Cache(UUID assetID, string text) { CacheCheck(); lock (m_Notecards) { if (m_Notecards.ContainsKey(assetID)) { return; } Notecard nc = new Notecard { lastRef = DateTime.Now, text = SLUtil.ParseNotecardToList(text).ToArray() }; m_Notecards[assetID] = nc; } }
// protected void OnObjectAddedToScene(SceneObjectGroup sog) // { // m_log.InfoFormat( // "[WATER WARS]: Got notice of {0} {1} at {2} added to scene", // sog.Name, sog.LocalId, sog.AbsolutePosition); // //// if (sog.Name == GameManager.IN_WORLD_NAME) //// new GameManager(this, sog); // } /// <summary> /// Get our configuration object from a given prim /// </summary> /// <param name="so"></param> /// <returns>The config found, null if none could be found</returns> protected IConfig GetPrimConfig(SceneObjectGroup so) { IConfig config = null; IList <TaskInventoryItem> gmConfigItems = so.RootPart.Inventory.GetInventoryItems(WaterWarsConstants.REGISTRATION_INI_NAME); if (gmConfigItems.Count > 0) { AssetBase asset = Scenes[0].AssetService.Get(gmConfigItems[0].AssetID.ToString()); IConfigSource gmConfigSource = GameModelConfigurationParser.Parse( SLUtil.ParseNotecardToString(Encoding.UTF8.GetString(asset.Data))); config = gmConfigSource.Configs[GameModelConfigurationParser.GENERAL_SECTION_NAME]; } return(config); }
// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- private void DoJsonReadNotecard( UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) { UUID assetID; if (!UUID.TryParse(notecardIdentifier, out assetID)) { SceneObjectPart part = m_scene.GetSceneObjectPart(hostID); assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard); } AssetBase a = m_scene.AssetService.Get(assetID.ToString()); if (a == null) { GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID)); } if (a.Type != (sbyte)AssetType.Notecard) { GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID)); } m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}", storeID); try { string jsondata = SLUtil.ParseNotecardToString(a.Data); int result = m_store.SetValue(storeID, path, jsondata, true) ? 1 : 0; m_comms.DispatchReply(scriptID, result, "", reqID.ToString()); return; } catch (SLUtil.NotANotecardFormatException e) { m_log.WarnFormat("[JsonStoreScripts]: Notecard parsing failed; assetId {0} at line number {1}", assetID.ToString(), e.lineNumber); } catch (Exception e) { m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message); } GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID)); m_comms.DispatchReply(scriptID, 0, "", reqID.ToString()); }
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, access_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"]); int AccessTime = Convert.ToInt32(reader["access_time"]); reader.Close(); UpdateAccessTime(AccessTime, cmd); FreeCommand(cmd); return(meta); }
private void RecordNoteCardEmbeddedAssetUuids(AssetBase textAsset) { List <UUID> ids = SLUtil.GetEmbeddedAssetIDs(textAsset.Data); if (ids == null || ids.Count == 0) { return; } for (int i = 0; i < ids.Count; ++i) { if (ids[i] == UUID.Zero) { continue; } if (!UncertainAssetsUUIDs.Contains(ids[i])) { UncertainAssetsUUIDs.Add(ids[i]); } AddForInspection(ids[i]); } }
/// <summary> /// Fetch configuration. /// </summary> /// <exception cref="ConfigurationException">Thrown if there is a problem with the configuration.</exception> /// <param name="configNotecardName"></param> /// <returns></returns> public virtual string FetchConfiguration(string configNotecardName) { IList <TaskInventoryItem> items = m_part.Inventory.GetInventoryItems(configNotecardName); if (items.Count == 0) { string message = string.Format( "Could not find configuration notecard with name {0}. Please create one.", configNotecardName); throw new ConfigurationException(message); } else if (items.Count > 1) { m_log.ErrorFormat( "[WATER WARS]: Unexpectedly found {0} {1} items in {2}", items.Count, configNotecardName, m_part.Name); } AssetBase asset = m_scene.AssetService.Get(items[0].AssetID.ToString()); return(SLUtil.ParseNotecardToString(Encoding.UTF8.GetString(asset.Data))); }
/// <summary> /// Add a new folder to the user's inventory /// </summary> /// <param name="folder"></param> /// <returns>true if the folder was successfully added</returns> public bool AddFolder(InventoryFolderBase folder) { NameValueCollection requestArgs = new NameValueCollection { { "RequestMethod", "AddInventoryFolder" }, { "FolderID", folder.ID.ToString() }, { "ParentID", folder.ParentID.ToString() }, { "OwnerID", folder.Owner.ToString() }, { "Name", folder.Name }, { "ContentType", SLUtil.SLAssetTypeToContentType(folder.Type) } }; OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs); bool success = response["Success"].AsBoolean(); if (!success) { m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Error creating folder " + folder.Name + " for " + folder.Owner + ": " + response["Message"].AsString()); } return(success); }
/// <summary> /// Add a new item to the user's inventory /// </summary> /// <param name="item"></param> /// <returns>true if the item was successfully added</returns> public bool AddItem(InventoryItemBase item) { // A folder of UUID.Zero means we need to find the most appropriate home for this item if (item.Folder == UUID.Zero) { InventoryFolderBase folder = GetFolderForType(item.Owner, (AssetType)item.AssetType); if (folder != null && folder.ID != UUID.Zero) { item.Folder = folder.ID; } else { item.Folder = item.Owner; // Root folder } } if ((AssetType)item.AssetType == AssetType.Gesture) { UpdateGesture(item.Owner, item.ID, item.Flags == 1); } if (item.BasePermissions == 0) { m_log.WarnFormat("[SIMIAN INVENTORY CONNECTOR]: Adding inventory item {0} ({1}) with no base permissions", item.Name, item.ID); } OSDMap permissions = new OSDMap { { "BaseMask", OSD.FromInteger(item.BasePermissions) }, { "EveryoneMask", OSD.FromInteger(item.EveryOnePermissions) }, { "GroupMask", OSD.FromInteger(item.GroupPermissions) }, { "NextOwnerMask", OSD.FromInteger(item.NextPermissions) }, { "OwnerMask", OSD.FromInteger(item.CurrentPermissions) } }; OSDMap extraData = new OSDMap() { { "Flags", OSD.FromInteger(item.Flags) }, { "GroupID", OSD.FromUUID(item.GroupID) }, { "GroupOwned", OSD.FromBoolean(item.GroupOwned) }, { "SalePrice", OSD.FromInteger(item.SalePrice) }, { "SaleType", OSD.FromInteger(item.SaleType) }, { "Permissions", permissions } }; // Add different asset type only if it differs from inventory type // (needed for links) string invContentType = SLUtil.SLInvTypeToContentType(item.InvType); string assetContentType = SLUtil.SLAssetTypeToContentType(item.AssetType); if (invContentType != assetContentType) { extraData["LinkedItemType"] = OSD.FromString(assetContentType); } NameValueCollection requestArgs = new NameValueCollection { { "RequestMethod", "AddInventoryItem" }, { "ItemID", item.ID.ToString() }, { "AssetID", item.AssetID.ToString() }, { "ParentID", item.Folder.ToString() }, { "OwnerID", item.Owner.ToString() }, { "Name", item.Name }, { "Description", item.Description }, { "CreatorID", item.CreatorId }, { "CreatorData", item.CreatorData }, { "ContentType", invContentType }, { "ExtraData", OSDParser.SerializeJsonString(extraData) } }; OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs); bool success = response["Success"].AsBoolean(); if (!success) { m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Error creating item " + item.Name + " for " + item.Owner + ": " + response["Message"].AsString()); } return(success); }
public void Import(string conn, string table, int start, int count, bool force, FSStoreDelegate store) { int imported = 0; using (MySqlConnection importConn = new MySqlConnection(conn)) { try { importConn.Open(); } catch (MySqlException e) { m_log.ErrorFormat("[FSASSETS]: Can't connect to database: {0}", e.Message.ToString()); return; } using (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"); using (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++; } } } importConn.Close(); } MainConsole.Instance.Output(String.Format("Import done, {0} assets imported", imported)); }
protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { byte[] result = new byte[0]; string[] p = SplitParams(path); if (p.Length == 0) { return(result); } if (p.Length > 1) { string id = p[0]; string cmd = p[1]; if (cmd == "data") { result = m_AssetService.GetData(id); if (result == null) { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } else { httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = "application/octet-stream"; } } else if (cmd == "metadata") { AssetMetadata metadata = m_AssetService.GetMetadata(id); if (metadata != null) { XmlSerializer xs = new XmlSerializer(typeof(AssetMetadata)); result = ServerUtils.SerializeResult(xs, metadata); httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(metadata.Type); } else { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } else { // Unknown request httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } else if (p.Length == 1) { // Get the entire asset (metadata + data) string id = p[0]; AssetBase asset = m_AssetService.Get(id); if (asset != null) { XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); result = ServerUtils.SerializeResult(xs, asset); httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type); } else { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } else { // Unknown request httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.ContentType = "text/plain"; result = new byte[0]; } return(result); }
public void SLUtilTypeConvertTests() { int[] assettypes = new int[] { -1, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 , 23, 24, 25, 46, 47, 48 }; string[] contenttypes = new string[] { "application/octet-stream", "image/x-j2c", "audio/ogg", "application/vnd.ll.callingcard", "application/vnd.ll.landmark", "application/vnd.ll.clothing", "application/vnd.ll.primitive", "application/vnd.ll.notecard", "application/vnd.ll.folder", "application/vnd.ll.rootfolder", "application/vnd.ll.lsltext", "application/vnd.ll.lslbyte", "image/tga", "application/vnd.ll.bodypart", "application/vnd.ll.trashfolder", "application/vnd.ll.snapshotfolder", "application/vnd.ll.lostandfoundfolder", "audio/x-wav", "image/tga", "image/jpeg", "application/vnd.ll.animation", "application/vnd.ll.gesture", "application/x-metaverse-simstate", "application/vnd.ll.favoritefolder", "application/vnd.ll.link", "application/vnd.ll.linkfolder", "application/vnd.ll.currentoutfitfolder", "application/vnd.ll.outfitfolder", "application/vnd.ll.myoutfitsfolder" }; for (int i = 0; i < assettypes.Length; i++) { Assert.That(SLUtil.SLAssetTypeToContentType(assettypes[i]) == contenttypes[i], "Expecting {0} but got {1}", contenttypes[i], SLUtil.SLAssetTypeToContentType(assettypes[i])); } for (int i = 0; i < contenttypes.Length; i++) { if (SLUtil.ContentTypeToSLAssetType(contenttypes[i]) == 18) { Assert.That(contenttypes[i] == "image/tga"); } else { Assert.That(SLUtil.ContentTypeToSLAssetType(contenttypes[i]) == assettypes[i], "Expecting {0} but got {1}", assettypes[i], SLUtil.ContentTypeToSLAssetType(contenttypes[i])); } } int[] inventorytypes = new int[] { -1, 0, 1, 2, 3, 6, 7, 8, 9, 10, 15, 17, 18, 20 }; string[] invcontenttypes = new string[] { "application/octet-stream", "image/x-j2c", "audio/ogg", "application/vnd.ll.callingcard", "application/vnd.ll.landmark", "application/vnd.ll.primitive", "application/vnd.ll.notecard", "application/vnd.ll.folder", "application/octet-stream", "application/vnd.ll.lsltext", "image/x-j2c", "application/vnd.ll.primitive", "application/vnd.ll.clothing", "application/vnd.ll.gesture" }; for (int i = 0; i < inventorytypes.Length; i++) { Assert.That(SLUtil.SLInvTypeToContentType(inventorytypes[i]) == invcontenttypes[i], "Expected {0}, Got {1}", invcontenttypes[i], SLUtil.SLInvTypeToContentType(inventorytypes[i])); } invcontenttypes = new string[] { "image/x-j2c", "image/jp2", "image/tga", "image/jpeg", "application/ogg", "audio/ogg", "audio/x-wav", "application/vnd.ll.callingcard", "application/x-metaverse-callingcard", "application/vnd.ll.landmark", "application/x-metaverse-landmark", "application/vnd.ll.clothing", "application/x-metaverse-clothing", "application/vnd.ll.bodypart", "application/x-metaverse-bodypart", "application/vnd.ll.primitive", "application/x-metaverse-primitive", "application/vnd.ll.notecard", "application/x-metaverse-notecard", "application/vnd.ll.folder", "application/vnd.ll.rootfolder", "application/vnd.ll.lsltext", "application/x-metaverse-lsl", "application/vnd.ll.lslbyte", "application/x-metaverse-lso", "application/vnd.ll.trashfolder", "application/vnd.ll.snapshotfolder", "application/vnd.ll.lostandfoundfolder", "application/vnd.ll.animation", "application/x-metaverse-animation", "application/vnd.ll.gesture", "application/x-metaverse-gesture", "application/x-metaverse-simstate", "application/octet-stream" }; sbyte[] invtypes = new sbyte[] { 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 18, 18, 18, 18, 6, 6, 7, 7, 8, 9, 10, 10, 10, 10 , 8, 8, 8, 19, 19, 20, 20, 15, -1 }; for (int i = 0; i < invtypes.Length; i++) { Assert.That(SLUtil.ContentTypeToSLInvType(invcontenttypes[i]) == invtypes[i], "Expected {0}, Got {1}", invtypes[i], SLUtil.ContentTypeToSLInvType(invcontenttypes[i])); } }
private AssetBase Get(string id, out string sha) { string hash = string.Empty; int startTime = System.Environment.TickCount; AssetMetadata metadata; lock (m_readLock) { metadata = m_DataConnector.Get(id, out hash); } sha = hash; if (metadata == null) { AssetBase asset = null; if (m_FallbackService != null) { asset = m_FallbackService.Get(id); if (asset != null) { asset.Metadata.ContentType = SLUtil.SLAssetTypeToContentType((int)asset.Type); sha = GetSHA256Hash(asset.Data); m_log.InfoFormat("[FSASSETS]: Added asset {0} from fallback to local store", id); Store(asset); } } if (asset == null) { // m_log.InfoFormat("[FSASSETS]: Asset {0} not found", id); m_missingAssets++; } return(asset); } AssetBase newAsset = new AssetBase(); newAsset.Metadata = metadata; try { newAsset.Data = GetFsData(hash); if (newAsset.Data.Length == 0) { AssetBase asset = null; if (m_FallbackService != null) { asset = m_FallbackService.Get(id); if (asset != null) { asset.Metadata.ContentType = SLUtil.SLAssetTypeToContentType((int)asset.Type); sha = GetSHA256Hash(asset.Data); m_log.InfoFormat("[FSASSETS]: Added asset {0} from fallback to local store", id); Store(asset); } } if (asset == null) { m_missingAssetsFS++; } // m_log.InfoFormat("[FSASSETS]: Asset {0}, hash {1} not found in FS", id, hash); else { // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8) // Fix bad assets before sending them elsewhere if (asset.Type == (int)AssetType.Object && asset.Data != null) { string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data)); asset.Data = Utils.StringToBytes(xml); } return(asset); } } lock (m_statsLock) { m_readTicks += Environment.TickCount - startTime; m_readCount++; } // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8) // Fix bad assets before sending them elsewhere if (newAsset.Type == (int)AssetType.Object && newAsset.Data != null) { string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(newAsset.Data)); newAsset.Data = Utils.StringToBytes(xml); } return(newAsset); } catch (Exception exception) { m_log.Error(exception.ToString()); Thread.Sleep(5000); Environment.Exit(1); return(null); } }
protected void PreAssetRequestCallback(string fetchedAssetID, object assetType, AssetBase fetchedAsset) { // Check for broken asset types and fix them with the AssetType gleaned by UuidGatherer if (fetchedAsset != null && fetchedAsset.Type == (sbyte)AssetType.Unknown) { m_log.InfoFormat("[ARCHIVER]: Rewriting broken asset type for {0} to {1}", fetchedAsset.ID, SLUtil.AssetTypeFromCode((sbyte)assetType)); fetchedAsset.Type = (sbyte)assetType; } AssetRequestCallback(fetchedAssetID, this, fetchedAsset); }
protected internal void Execute() { Culture.SetCurrentCulture(); // We can stop here if there are no assets to fetch if (m_repliesRequired == 0) { PerformAssetsRequestCallback(false); return; } m_timeOutTimer = new System.Timers.Timer(60000); m_timeOutTimer.AutoReset = false; m_timeOutTimer.Elapsed += OnTimeout; m_timeout = false; int gccontrol = 0; foreach (KeyValuePair <UUID, sbyte> kvp in m_uuids) { string thiskey = kvp.Key.ToString(); try { m_timeOutTimer.Enabled = true; AssetBase asset = m_assetService.Get(thiskey); if (m_timeout) { break; } m_timeOutTimer.Enabled = false; if (asset == null) { m_notFoundAssetUuids.Add(new UUID(thiskey)); continue; } sbyte assetType = kvp.Value; if (asset != null && assetType == (sbyte)AssetType.Unknown) { m_log.InfoFormat("[ARCHIVER]: Rewriting broken asset type for {0} to {1}", thiskey, SLUtil.AssetTypeFromCode(assetType)); asset.Type = assetType; } m_foundAssetUuids.Add(asset.FullID); m_assetsArchiver.WriteAsset(PostProcess(asset)); if (++gccontrol > 10000) { gccontrol = 0; GC.Collect(); } } catch (Exception e) { m_log.ErrorFormat("[ARCHIVER]: Execute failed with {0}", e); } } m_timeOutTimer.Dispose(); int totalerrors = m_notFoundAssetUuids.Count + m_previousErrorsCount; if (m_timeout) { m_log.DebugFormat("[ARCHIVER]: Aborted because AssetService request timeout. Successfully added {0} assets", m_foundAssetUuids.Count); } else if (totalerrors == 0) { m_log.DebugFormat("[ARCHIVER]: Successfully added all {0} assets", m_foundAssetUuids.Count); } else { m_log.DebugFormat("[ARCHIVER]: Successfully added {0} assets ({1} of total possible assets requested were not found, were damaged or were not assets)", m_foundAssetUuids.Count, totalerrors); } GC.Collect(); PerformAssetsRequestCallback(m_timeout); }
protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { byte[] result = new byte[0]; string[] p = SplitParams(path); if (p.Length == 0) { return(result); } string id = string.Empty; if (p.Length > 1) { id = p[0]; string cmd = p[1]; if (cmd == "data") { result = m_AssetService.GetData(id); if (result == null) { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } else { httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = "application/octet-stream"; } } else if (cmd == "metadata") { AssetMetadata metadata = m_AssetService.GetMetadata(id); if (metadata != null) { XmlSerializer xs = new XmlSerializer(typeof(AssetMetadata)); result = ServerUtils.SerializeResult(xs, metadata); httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(metadata.Type); } else { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } else { // Unknown request httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } else if (p.Length == 1) { // Get the entire asset (metadata + data) id = p[0]; AssetBase asset = m_AssetService.Get(id); if (asset != null) { XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); result = ServerUtils.SerializeResult(xs, asset); httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type); } else { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } else { // Unknown request httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; httpResponse.ContentType = "text/plain"; result = new byte[0]; } if (httpResponse.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !string.IsNullOrEmpty(id)) { httpResponse.StatusCode = (int)HttpStatusCode.Redirect; string rurl = m_RedirectURL; if (!path.StartsWith("/")) { rurl += "/"; } rurl += path; httpResponse.AddHeader("Location", rurl); m_log.DebugFormat("[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode); } return(result); }
public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { byte[] result = new byte[0]; string[] p = SplitParams(path); if (p.Length == 0) { return(result); } IGridRegistrationService urlModule = m_registry.RequestModuleInterface <IGridRegistrationService>(); if (m_SessionID != "" && urlModule != null) { if (!urlModule.CheckThreatLevel(m_SessionID, "Asset_Get", ThreatLevel.Low)) { return(new byte[0]); } } if (p.Length > 1 && p[1] == "data") { result = m_AssetService.GetData(p[0]); if (result == null) { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } else { httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = "application/octet-stream"; } } else if (p.Length > 1 && p[1] == "exists") { try { bool RetVal = m_AssetService.GetExists(p[0]); XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); result = ServerUtils.SerializeResult(xs, RetVal); if (result == null) { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } else { httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = "application/octet-stream"; } } catch (Exception ex) { result = new byte[0]; MainConsole.Instance.Warn("[AssetServerGetHandler]: Error serializing the result for /exists for asset " + p[0] + ", " + ex); } } else { AssetBase asset = m_AssetService.Get(p[0]); if (asset != null) { XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); result = Util.CompressBytes(ServerUtils.SerializeResult(xs, asset)); httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type) + "/gzip"; } else { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } return(result); }
private List <InventoryItemBase> GetItemsFromResponse(OSDArray items) { List <InventoryItemBase> invItems = new List <InventoryItemBase>(items.Count); for (int i = 0; i < items.Count; i++) { OSDMap item = items[i] as OSDMap; if (item != null && item["Type"].AsString() == "Item") { InventoryItemBase invItem = new InventoryItemBase(); invItem.AssetID = item["AssetID"].AsUUID(); invItem.AssetType = SLUtil.ContentTypeToSLAssetType(item["ContentType"].AsString()); invItem.CreationDate = item["CreationDate"].AsInteger(); invItem.CreatorId = item["CreatorID"].AsString(); invItem.CreatorData = item["CreatorData"].AsString(); invItem.CreatorIdAsUuid = item["CreatorID"].AsUUID(); invItem.Description = item["Description"].AsString(); invItem.Folder = item["ParentID"].AsUUID(); invItem.ID = item["ID"].AsUUID(); invItem.InvType = SLUtil.ContentTypeToSLInvType(item["ContentType"].AsString()); invItem.Name = item["Name"].AsString(); invItem.Owner = item["OwnerID"].AsUUID(); OSDMap extraData = item["ExtraData"] as OSDMap; if (extraData != null && extraData.Count > 0) { invItem.Flags = extraData["Flags"].AsUInteger(); invItem.GroupID = extraData["GroupID"].AsUUID(); invItem.GroupOwned = extraData["GroupOwned"].AsBoolean(); invItem.SalePrice = extraData["SalePrice"].AsInteger(); invItem.SaleType = (byte)extraData["SaleType"].AsInteger(); OSDMap perms = extraData["Permissions"] as OSDMap; if (perms != null) { invItem.BasePermissions = perms["BaseMask"].AsUInteger(); invItem.CurrentPermissions = perms["OwnerMask"].AsUInteger(); invItem.EveryOnePermissions = perms["EveryoneMask"].AsUInteger(); invItem.GroupPermissions = perms["GroupMask"].AsUInteger(); invItem.NextPermissions = perms["NextOwnerMask"].AsUInteger(); } if (extraData.ContainsKey("LinkedItemType")) { invItem.AssetType = SLUtil.ContentTypeToSLAssetType(extraData["LinkedItemType"].AsString()); } } if (invItem.BasePermissions == 0) { m_log.InfoFormat("[SIMIAN INVENTORY CONNECTOR]: Forcing item permissions to full for item {0} ({1})", invItem.Name, invItem.ID); invItem.BasePermissions = (uint)PermissionMask.All; invItem.CurrentPermissions = (uint)PermissionMask.All; invItem.EveryOnePermissions = (uint)PermissionMask.All; invItem.GroupPermissions = (uint)PermissionMask.All; invItem.NextPermissions = (uint)PermissionMask.All; } invItems.Add(invItem); } } // m_log.Debug("[SIMIAN INVENTORY CONNECTOR]: Parsed " + invItems.Count + " items from SimianGrid response"); return(invItems); }
public void SLUtilTypeConvertTests() { int[] assettypes = new int[] { -1, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 , 23, 24, 25, 46, 47, 48 }; string[] contenttypes = new string[] { "application/octet-stream", "image/x-j2c", "audio/ogg", "application/vnd.ll.callingcard", "application/vnd.ll.landmark", "application/vnd.ll.clothing", "application/vnd.ll.primitive", "application/vnd.ll.notecard", "application/vnd.ll.folder", "application/vnd.ll.rootfolder", "application/vnd.ll.lsltext", "application/vnd.ll.lslbyte", "image/tga", "application/vnd.ll.bodypart", "application/vnd.ll.trashfolder", "application/vnd.ll.snapshotfolder", "application/vnd.ll.lostandfoundfolder", "audio/x-wav", "image/tga", "image/jpeg", "application/vnd.ll.animation", "application/vnd.ll.gesture", "application/x-metaverse-simstate", "application/vnd.ll.favoritefolder", "application/vnd.ll.link", "application/vnd.ll.linkfolder", "application/vnd.ll.currentoutfitfolder", "application/vnd.ll.outfitfolder", "application/vnd.ll.myoutfitsfolder" }; for (int i = 0; i < assettypes.Length; i++) { Assert.That(SLUtil.SLAssetTypeToContentType(assettypes[i]) == contenttypes[i], "Expecting {0} but got {1}", contenttypes[i], SLUtil.SLAssetTypeToContentType(assettypes[i])); } for (int i = 0; i < contenttypes.Length; i++) { int expected; if (contenttypes[i] == "image/tga") { expected = 12; // if we know only the content-type "image/tga", then we assume the asset type is TextureTGA; not ImageTGA } else { expected = assettypes[i]; } Assert.AreEqual(expected, SLUtil.ContentTypeToSLAssetType(contenttypes[i]), String.Format("Incorrect AssetType mapped from Content-Type {0}", contenttypes[i])); } int[] inventorytypes = new int[] { -1, 0, 1, 2, 3, 6, 7, 8, 9, 10, 15, 17, 18, 20 }; string[] invcontenttypes = new string[] { "application/octet-stream", "image/x-j2c", "audio/ogg", "application/vnd.ll.callingcard", "application/vnd.ll.landmark", "application/vnd.ll.primitive", "application/vnd.ll.notecard", "application/vnd.ll.folder", "application/vnd.ll.rootfolder", "application/vnd.ll.lsltext", "image/x-j2c", "application/vnd.ll.primitive", "application/vnd.ll.clothing", "application/vnd.ll.gesture" }; for (int i = 0; i < inventorytypes.Length; i++) { Assert.AreEqual(invcontenttypes[i], SLUtil.SLInvTypeToContentType(inventorytypes[i]), String.Format("Incorrect Content-Type mapped from InventoryType {0}", inventorytypes[i])); } invcontenttypes = new string[] { "image/x-j2c", "image/jp2", "image/tga", "image/jpeg", "application/ogg", "audio/ogg", "audio/x-wav", "application/vnd.ll.callingcard", "application/x-metaverse-callingcard", "application/vnd.ll.landmark", "application/x-metaverse-landmark", "application/vnd.ll.clothing", "application/x-metaverse-clothing", "application/vnd.ll.bodypart", "application/x-metaverse-bodypart", "application/vnd.ll.primitive", "application/x-metaverse-primitive", "application/vnd.ll.notecard", "application/x-metaverse-notecard", "application/vnd.ll.folder", "application/vnd.ll.rootfolder", "application/vnd.ll.lsltext", "application/x-metaverse-lsl", "application/vnd.ll.lslbyte", "application/x-metaverse-lso", "application/vnd.ll.trashfolder", "application/vnd.ll.snapshotfolder", "application/vnd.ll.lostandfoundfolder", "application/vnd.ll.animation", "application/x-metaverse-animation", "application/vnd.ll.gesture", "application/x-metaverse-gesture", "application/x-metaverse-simstate", "application/octet-stream" }; sbyte[] invtypes = new sbyte[] { 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 18, 18, 18, 18, 6, 6, 7, 7, 8, 9, 10, 10, 10, 10 , 8, 8, 8, 19, 19, 20, 20, 15, -1 }; for (int i = 0; i < invtypes.Length; i++) { Assert.AreEqual(invtypes[i], SLUtil.ContentTypeToSLInvType(invcontenttypes[i]), String.Format("Incorrect InventoryType mapped from Content-Type {0}", invcontenttypes[i])); } }
public override byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) { byte[] result = new byte[0]; string[] p = SplitParams(path); if (p.Length == 0) { return(result); } if (p.Length > 1 && p[1] == "data") { result = m_AssetService.GetData(p[0]); if (result == null) { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } else { httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = "application/octet-stream"; } } else if (p.Length > 1 && p[1] == "metadata") { AssetMetadata metadata = m_AssetService.GetMetadata(p[0]); if (metadata != null) { XmlSerializer xs = new XmlSerializer(typeof(AssetMetadata)); result = ServerUtils.SerializeResult(xs, metadata); httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(metadata.Type); } else { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } else { AssetBase asset = m_AssetService.Get(p[0]); if (asset != null) { XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); result = ServerUtils.SerializeResult(xs, asset); httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type); } else { httpResponse.StatusCode = (int)HttpStatusCode.NotFound; httpResponse.ContentType = "text/plain"; result = new byte[0]; } } return(result); }
/// <summary> /// Creates a new asset /// </summary> /// Returns a random ID if none is passed into it /// <param name = "asset"></param> /// <returns></returns> public UUID Store(AssetBase asset) { if (String.IsNullOrEmpty(m_serverUrl)) { MainConsole.Instance.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured"); throw new InvalidOperationException(); } bool storedInCache = false; string errorMessage = null; // AssetID handling if (asset.ID == UUID.Zero) { asset.ID = UUID.Random(); } // Cache handling if (m_cache != null) { m_cache.Cache(asset); storedInCache = true; } // Local asset handling if ((asset.Flags & AssetFlags.Local) == AssetFlags.Local) { if (!storedInCache) { MainConsole.Instance.Error("Cannot store local " + asset.TypeString + " asset without an asset cache"); asset.ID = UUID.Zero; } return(asset.ID); } // Distinguish public and private assets bool isPublic = true; switch ((AssetType)asset.Type) { case AssetType.CallingCard: case AssetType.Gesture: case AssetType.LSLBytecode: case AssetType.LSLText: isPublic = false; break; } // Make sure ContentType is set if (String.IsNullOrEmpty(asset.TypeString)) { asset.TypeString = SLUtil.SLAssetTypeToContentType(asset.Type); } // Build the remote storage request List <MultipartForm.Element> postParameters = new List <MultipartForm.Element> { new MultipartForm.Parameter("AssetID", asset.ID.ToString()), new MultipartForm.Parameter("CreatorID", asset.CreatorID.ToString()), new MultipartForm.Parameter("Temporary", ((asset.Flags & AssetFlags.Temperary) == AssetFlags.Temperary) ? "1" : "0"), new MultipartForm.Parameter("Public", isPublic ? "1" : "0"), new MultipartForm.File("Asset", asset.Name, asset.TypeString, asset.Data) }; // Make the remote storage request try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_serverUrl); HttpWebResponse response = MultipartForm.Post(request, postParameters); using (Stream responseStream = response.GetResponseStream()) { string responseStr = null; try { responseStr = responseStream.GetStreamString(); OSD responseOSD = OSDParser.Deserialize(responseStr); if (responseOSD.Type == OSDType.Map) { OSDMap responseMap = (OSDMap)responseOSD; if (responseMap["Success"].AsBoolean()) { return(asset.ID); } else { errorMessage = "Upload failed: " + responseMap["Message"].AsString(); } } else { errorMessage = "Response format was invalid:\n" + responseStr; } } catch (Exception ex) { if (!String.IsNullOrEmpty(responseStr)) { errorMessage = "Failed to parse the response:\n" + responseStr; } else { errorMessage = "Failed to retrieve the response: " + ex.Message; } } } } catch (WebException ex) { errorMessage = ex.Message; } MainConsole.Instance.WarnFormat("[SIMIAN ASSET CONNECTOR]: Failed to store asset \"{0}\" ({1}, {2}): {3}", asset.Name, asset.ID, asset.TypeString, errorMessage); return(UUID.Zero); }