示例#1
0
        /// <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);
        }
示例#3
0
        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);
            }
        }
        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]));
            }
        }
示例#6
0
        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 List <InventoryFolderBase> GetFoldersFromResponse(OSDArray items, UUID baseFolder, bool includeBaseFolder)
        {
            List <InventoryFolderBase> invFolders = new List <InventoryFolderBase>(items.Count);

            invFolders.AddRange(from t in items
                                select t as OSDMap
                                into item where item != null && item["Type"].AsString() == "Folder" let folderID = item["ID"].AsUUID() where folderID != baseFolder || includeBaseFolder select new InventoryFolderBase(folderID, item["Name"].AsString(), item["OwnerID"].AsUUID(), SLUtil.ContentTypeToSLAssetType(item["ContentType"].AsString()), item["ParentID"].AsUUID(), (ushort)item["Version"].AsInteger()));

            MainConsole.Instance.Debug("[SIMIAN INVENTORY CONNECTOR]: Parsed " + invFolders.Count + " folders from SimianGrid response");
            return(invFolders);
        }