Esempio n. 1
0
        public async Task CreateInventory(UUID parentUuid, OSD newInventory, bool createLink, InventoryManager.ItemCreatedCallback callback)
        {
            var cap = getInventoryCap();

            if (cap == null)
            {
                Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client);
                return;
            }

            var           success = false;
            InventoryItem item    = null;

            try
            {
                var tid = UUID.Random();

                var url = $"{cap}/category/{parentUuid}?tid={tid}";

                if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
                {
                    success = false;

                    return;
                }

                var payload = OSDParser.SerializeLLSDXmlString(newInventory);

                using (var content = new StringContent(payload, Encoding.UTF8, "application/llsd+xml"))
                {
                    using (var reply = await httpClient.PostAsync(uri, content))
                    {
                        success = reply.IsSuccessStatusCode;

                        if (!success)
                        {
                            Logger.Log("Could not create inventory: " + reply.ReasonPhrase, Helpers.LogLevel.Warning);

                            return;
                        }

                        var data = await reply.Content.ReadAsStringAsync();

                        if (OSDParser.Deserialize(data) is OSDMap map && map["_embedded"] is OSDMap embedded)
                        {
                            var items = !createLink?
                                        parseItemsFromResponse((OSDMap)embedded["items"]) :
                                            parseLinksFromResponse((OSDMap)embedded["links"]);

                            item = items.First();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, Helpers.LogLevel.Warning);
            }
            finally
            {
                callback(success, item);
            }
        }
Esempio n. 2
0
        private void AddNewNotecard(string notecardName, string notecardDescription, string notecardContent, TreeNode node)
        {
            if (node == null) return;

            InventoryFolder folder = null;
            TreeNode folderNode = null;

            if (node.Tag is InventoryFolder)
            {
                folder = (InventoryFolder)node.Tag;
                folderNode = node;
            }
            else if (node.Tag is InventoryItem)
            {
                folder = (InventoryFolder)node.Parent.Tag;
                folderNode = node.Parent;
            }

            InventoryManager.ItemCreatedCallback itemCreated =
                new InventoryManager.ItemCreatedCallback(delegate(bool success, InventoryItem item)
                {
                    if (!success) return;

                    treInventory.BeginUpdate();

                    AddTreeItem(item, folderNode);

                    treInventory.Sort();
                    treInventory.EndUpdate();
                });

            client.Inventory.RequestCreateItem(
                folder.UUID, notecardName, notecardDescription,
                AssetType.Notecard, InventoryType.Notecard, PermissionMask.All,
                itemCreated);
        }
Esempio n. 3
0
        public async Task CreateInventory(UUID parentUuid, OSD newInventory, bool createLink, InventoryManager.ItemCreatedCallback callback)
        {
            var cap = getInventoryCap();

            if (cap == null)
            {
                Logger.Log("No AIS3 Capability!", Helpers.LogLevel.Warning, Client);
                return;
            }
            try
            {
                UUID tid = UUID.Random();

                string url     = $"{cap}/category/{parentUuid}?tid={tid}";
                var    content = new ByteArrayContent(OSDParser.SerializeLLSDXmlBytes(newInventory));
                content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/llsd+xml");
                var req   = httpClient.PostAsync(url, content);
                var reply = await req;

                if (reply.IsSuccessStatusCode &&
                    OSDParser.Deserialize(reply.Content.ReadAsStringAsync().Result) is OSDMap map &&
                    map["_embedded"] is OSDMap embedded)
                {
                    List <InventoryItem> items = !createLink
                        ? parseItemsFromResponse((OSDMap)embedded["items"])
                        : parseLinksFromResponse((OSDMap)embedded["links"]);

                    callback(true, items.First());
                }
                else
                {
                    Logger.Log("Could not create inventory: " + reply.ReasonPhrase, Helpers.LogLevel.Warning);
                    callback(false, null);
                }
            }