Example #1
3
        private static void AddUpdateDeleteInventories(ZipArchiveEntry inventoriesEntry)
        {
            Console.WriteLine("inventories.csv is {0} bytes", inventoriesEntry.Length);
            IEnumerable<Inventory> inventories = null;

            using (var entryStream = inventoriesEntry.Open())
            {
                Console.WriteLine("Starting inventories at {0:hh:mm:ss.fff}", DateTime.Now);
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var reader = new StreamReader(entryStream);
                var csv = new CsvReader(reader);
                csv.Configuration.RegisterClassMap(new InventoryMap());
                StringBuilder invForImport = new StringBuilder();
                inventories = csv.GetRecords<Inventory>().Where(i => !i.IsDead);

                var inventoryCollection = new InventoryCollection();
                inventoryCollection.SetItems(inventories);
                var importer = new NpgsqlBulkImporter(ConfigurationManager.ConnectionStrings["spurious"].ConnectionString, stopwatch);
                importer.BulkImport("inventories", inventoryCollection);

                stopwatch.Stop();
                Console.WriteLine("Finished inventories at {0:hh:mm:ss.fff}, taking {1}", DateTime.Now, stopwatch.Elapsed);
            }
        }
Example #2
0
 public InventoryItemControl(byte myslot,ref InventoryCollection inventoryCollection)
 {
     this.Slot = myslot;
     if (!inventoryCollection.ContainsKey(myslot))
     {
         Item = new InventoryItem();
         Item.Count = 0;
         Item.Damage = 0;
         Item.ID = 0;
         Item.Slot = myslot;
     } else
         Item = inventoryCollection[myslot];
     Block b = Blocks.Get(0x00);
     try
     {
         b = Blocks.Get(Item.ID);
     }
     catch (Exception) { }
     Img = b.Image;
     _Name = b.Name;
     Render();
     this.Inventory = inventoryCollection;
     this.Inventory.Changed += new InventoryCollection.InventoryChangedDelegate(inventoryCollection_Changed);
     this.AllowDrop = true;
     this.DragDrop += new System.Windows.Forms.DragEventHandler(this.InventoryItem_DragDrop);
     this.DragEnter += new System.Windows.Forms.DragEventHandler(this.InventoryItem_DragEnter);
     this.MouseDown += new MouseEventHandler(InventoryItem_MouseDown);
     this.KeyDown += new KeyEventHandler(InventoryItem_KeyDown);
     this.KeyUp += new KeyEventHandler(InventoryItem_KeyUp);
     Changed += Render;
 }
Example #3
0
 internal ProductVariant(Guid productKey, ProductAttributeCollection attributes, InventoryCollection inventory, bool template, string name, string sku, decimal price)
     : base(name, sku, price)
 {
     Mandate.ParameterNotNull(attributes, "attributes");
     Mandate.ParameterNotNull(inventory, "inventory");
     _productKey = productKey;
     _attibutes = attributes;
     _template = template;
 }
Example #4
0
 internal ProductBase(string name, string sku, decimal price, InventoryCollection inventory)
 {
     Mandate.ParameterNotNullOrEmpty(name, "name");
     Mandate.ParameterNotNullOrEmpty(sku, "sku");
     Mandate.ParameterNotNull(inventory, "inventory");
     _name = name;
     _sku = sku;
     _price = price;
     _inventory = inventory;
 }
        ///<summary>
        ///  Find an item given a PATH_DELIMITOR delimited path starting from this folder.
        ///
        ///  This method does not handle paths that contain multiple delimitors
        ///
        ///  FIXME: We do not yet handle situations where folders or items have the same name.  We could handle this by some
        ///  XPath like expression
        ///
        ///  FIXME: Delimitors which occur in names themselves are not currently escapable.
        ///</summary>
        ///<param name = "inventoryService">
        ///  Inventory service to query
        ///</param>
        ///<param name = "startFolder">
        ///  The folder from which the path starts
        ///</param>
        ///<param name = "path">
        ///  <param name = "path">
        ///    The path to the required item.
        ///  </param>
        ///  <returns>null if the item is not found</returns>
        public static InventoryItemBase FindItemByPath(
            IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
        {
            // If the path isn't just / then trim any starting extraneous slashes
            path = path.TrimStart(new[] { PATH_DELIMITER });

            string[] components = SplitEscapedPath(path);
            components[0] = UnescapePath(components[0]);

            //string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None);

            if (components.Length == 1)
            {
//                MainConsole.Instance.DebugFormat(
//                    "FOUND SINGLE COMPONENT [{0}].  Looking for this in [{1}] {2}",
//                    components[0], startFolder.Name, startFolder.ID);

                List <InventoryItemBase> items = inventoryService.GetFolderItems(startFolder.Owner, startFolder.ID);

//                MainConsole.Instance.DebugFormat("[INVENTORY ARCHIVE UTILS]: Found {0} items in FindItemByPath()", items.Count);

#if (!ISWIN)
                foreach (InventoryItemBase item in items)
                {
                    if (item.Name == components[0])
                    {
                        return(item);
                    }
                }
                return(null);
#else
                return(items.FirstOrDefault(item => item.Name == components[0]));
#endif
            }
            else
            {
//                MainConsole.Instance.DebugFormat("FOUND COMPONENTS [{0}] and [{1}]", components[0], components[1]);

                InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);

                return((from folder in contents.Folders
                        where folder.Name == components[0]
                        select FindItemByPath(inventoryService, folder, components[1])).FirstOrDefault());
            }
        }
Example #6
0
        public virtual InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            // This method doesn't receive a valud principal id from the
            // connector. So we disregard the principal and look
            // by ID.
            //
            //m_log.DebugFormat("[XINVENTORY SERVICE]: Fetch contents for folder {0}", folderID.ToString());
            InventoryCollection inventory = new InventoryCollection();

            inventory.OwnerID = principalID;
            inventory.Folders = new List <InventoryFolderBase>();
            inventory.Items   = new List <InventoryItemBase>();

            XInventoryFolder[] folders = m_Database.GetFolders(
                new string[] { "parentFolderID" },
                new string[] { folderID.ToString() });

            foreach (XInventoryFolder x in folders)
            {
                //m_log.DebugFormat("[XINVENTORY]: Adding folder {0} to response", x.folderName);
                inventory.Folders.Add(ConvertToOpenSim(x));
            }

            XInventoryItem[] items = m_Database.GetItems(
                new string[] { "parentFolderID" },
                new string[] { folderID.ToString() });

            foreach (XInventoryItem i in items)
            {
                //m_log.DebugFormat("[XINVENTORY]: Adding item {0} to response", i.inventoryName);
                inventory.Items.Add(ConvertToOpenSim(i));
            }

            InventoryFolderBase f = new InventoryFolderBase(folderID, principalID);

            f = GetFolder(f);
            if (f != null)
            {
                inventory.Version = f.Version;
                inventory.OwnerID = f.Owner;
            }
            inventory.FolderID = folderID;

            return(inventory);
        }
Example #7
0
        /// <summary>
        /// Save an inventory folder
        /// </summary>
        /// <param name="inventoryFolder">The inventory folder to save</param>
        /// <param name="path">The path to which the folder should be saved</param>
        /// <param name="saveThisFolderItself">If true, save this folder itself.  If false, only saves contents</param>
        /// <param name="options"></param>
        /// <param name="userAccountService"></param>
        protected void SaveInvFolder(
            InventoryFolderBase inventoryFolder, string path, bool saveThisFolderItself,
            Dictionary <string, object> options, IUserAccountService userAccountService)
        {
            if (options.ContainsKey("excludefolders"))
            {
                if (((List <String>)options["excludefolders"]).Contains(inventoryFolder.Name) ||
                    ((List <String>)options["excludefolders"]).Contains(inventoryFolder.ID.ToString()))
                {
                    if (options.ContainsKey("verbose"))
                    {
                        m_log.InfoFormat(
                            "[INVENTORY ARCHIVER]: Skipping folder {0} at {1}",
                            inventoryFolder.Name, path);
                    }
                    return;
                }
            }

            if (options.ContainsKey("verbose"))
            {
                m_log.InfoFormat("[INVENTORY ARCHIVER]: Saving folder {0}", inventoryFolder.Name);
            }

            if (saveThisFolderItself)
            {
                path += CreateArchiveFolderName(inventoryFolder);

                // We need to make sure that we record empty folders
                m_archiveWriter.WriteDir(path);
            }

            InventoryCollection contents
                = m_scene.InventoryService.GetFolderContent(inventoryFolder.Owner, inventoryFolder.ID);

            foreach (InventoryFolderBase childFolder in contents.Folders)
            {
                SaveInvFolder(childFolder, path, true, options, userAccountService);
            }

            foreach (InventoryItemBase item in contents.Items)
            {
                SaveInvItem(item, path, options, userAccountService);
            }
        }
Example #8
0
        public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            InventoryCollection coll = null;

            if (!IsWithinSuitcaseTree(principalID, folderID))
            {
                return(new InventoryCollection());
            }

            coll = base.GetFolderContent(principalID, folderID);

            if (coll == null)
            {
                m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
                coll = new InventoryCollection();
            }
            return(coll);
        }
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            // Uncomment me to simulate a slow responding inventory server
            //Thread.Sleep(16000);

            InventoryCollection invCollection = new InventoryCollection();

            List <InventoryItemBase>   items   = GetFolderItems(userID, folderID);
            List <InventoryFolderBase> folders = RequestSubFolders(folderID);

            invCollection.UserID  = userID;
            invCollection.Folders = folders;
            invCollection.Items   = items;

            m_log.DebugFormat("[INVENTORY SERVICE]: Found {0} items and {1} folders in folder {2}", items.Count, folders.Count, folderID);

            return(invCollection);
        }
    void Start()
    {
        CardDatabase.LoadAllCards();
        GearDatabase.LoadAllGear();

        if (GameplayContext.CurrentInventory is null || GameplayContext.RequestReset)
        {
            playerInventory = new InventoryCollection();
            //two legs
            playerInventory.AddItem(GearDatabase.GetGearDataByID(0));
            playerInventory.AddItem(GearDatabase.GetGearDataByID(0));
            //two melee arm
            playerInventory.AddItem(GearDatabase.GetGearDataByID(1), 2);
            //two rifle arm
            playerInventory.AddItem(GearDatabase.GetGearDataByID(3), 2);
            GameplayContext.CurrentInventory = playerInventory;
            Debug.Log("made new inventory");
        }
        /// <summary>
        ///     Find a folder given a PATH_DELIMITER delimited path starting from this folder
        /// </summary>
        /// This method does not handle paths that contain multiple delimiters
        ///
        /// FIXME: We have no way of distinguishing folders with the same path.
        ///
        /// FIXME: Delimiters which occur in names themselves are not currently escapable.
        /// <param name="inventoryService">
        ///     Inventory service to query
        /// </param>
        /// <param name="startFolder">
        ///     The folder from which the path starts
        /// </param>
        /// <param name="path">
        ///     The path to the required folder.
        ///     It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
        /// </param>
        /// <returns>An empty list if the folder is not found, otherwise a list of all folders that match the name</returns>
        public static List <InventoryFolderBase> FindFolderByPath(
            IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
        {
            List <InventoryFolderBase> foundFolders = new List <InventoryFolderBase>();

            if (path == string.Empty)
            {
                foundFolders.Add(startFolder);
                return(foundFolders);
            }

            path = path.Trim();

            if (path == PATH_DELIMITER.ToString())
            {
                foundFolders.Add(startFolder);
                return(foundFolders);
            }

            // If the path isn't just / then trim any starting extraneous slashes
            path = path.TrimStart(new[] { PATH_DELIMITER });

//            MainConsole.Instance.DebugFormat("[INVENTORY ARCHIVE UTILS]: Adjusted path in FindFolderByPath() is [{0}]", path);

            string[] components = SplitEscapedPath(path);
            components[0] = UnescapePath(components[0]);

            //string[] components = path.Split(new string[] { PATH_DELIMITER.ToString() }, 2, StringSplitOptions.None);

            InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);

            foreach (InventoryFolderBase folder in contents.Folders.Where(folder => folder.Name == components[0]))
            {
                if (components.Length > 1)
                {
                    foundFolders.AddRange(FindFolderByPath(inventoryService, folder, components[1]));
                }
                else
                {
                    foundFolders.Add(folder);
                }
            }
            return(foundFolders);
        }
        public BackendResponse TryFetchInventory(Uri owner, out InventoryCollection inventory)
        {
            inventory = null;
            BackendResponse ret;
            List <InventoryFolderWithChildren> folders;

            ret = TryFetchFolderList(owner, out folders);

            if (ret == BackendResponse.Success)
            {
                // Add the retrieved folders to the inventory collection
                inventory         = new InventoryCollection();
                inventory.Folders = new Dictionary <UUID, InventoryFolderWithChildren>(folders.Count);
                foreach (InventoryFolderWithChildren folder in folders)
                {
                    inventory.Folders[folder.ID] = folder;
                }

                // Fetch inventory items
                UUID ownerID;
                if (Utils.TryGetOpenSimUUID(owner, out ownerID))
                {
                    inventory.UserID = ownerID;
                    inventory.Items  = new Dictionary <UUID, InventoryItemBase>();

                    foreach (InventoryFolderWithChildren folder in folders)
                    {
                        foreach (InventoryItemBase item in m_inventoryService.RequestFolderItems(folder.ID))
                        {
                            inventory.Items.Add(item.ID, item);
                        }
                    }

                    ret = BackendResponse.Success;
                }
                else
                {
                    ret = BackendResponse.NotFound;
                }
            }

            m_server.MetricsProvider.LogInventoryFetchInventory(EXTENSION_NAME, ret, owner, DateTime.Now);
            return(ret);
        }
Example #13
0
        /// <summary>
        /// Find a folder given a PATH_DELIMITER delimited path starting from this folder
        /// </summary>
        ///
        /// This method does not handle paths that contain multiple delimitors
        ///
        /// FIXME: We have no way of distinguishing folders with the same path.
        ///
        /// FIXME: Delimitors which occur in names themselves are not currently escapable.
        ///
        /// <param name="inventoryService">
        /// Inventory service to query
        /// </param>
        /// <param name="startFolder">
        /// The folder from which the path starts
        /// </param>
        /// <param name="path">
        /// The path to the required folder.
        /// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned.
        /// </param>
        /// <returns>An empty list if the folder is not found, otherwise a list of all folders that match the name</returns>
        public static List <InventoryFolderBase> FindFolderByPath(
            IInventoryService inventoryService, InventoryFolderBase startFolder, string path)
        {
            List <InventoryFolderBase> foundFolders = new List <InventoryFolderBase>();

            if (path == string.Empty)
            {
                foundFolders.Add(startFolder);
                return(foundFolders);
            }

            path = path.Trim();

            if (path == PATH_DELIMITER.ToString())
            {
                foundFolders.Add(startFolder);
                return(foundFolders);
            }

            string[] components = SplitEscapedPath(path);
            components[0] = UnescapePath(components[0]);

            //string[] components = path.Split(new string[] { PATH_DELIMITER.ToString() }, 2, StringSplitOptions.None);

            InventoryCollection contents = inventoryService.GetFolderContent(startFolder.Owner, startFolder.ID);

            foreach (InventoryFolderBase folder in contents.Folders)
            {
                if (folder.Name == components[0])
                {
                    if (components.Length > 1)
                    {
                        foundFolders.AddRange(FindFolderByPath(inventoryService, folder, components[1]));
                    }
                    else
                    {
                        foundFolders.Add(folder);
                    }
                }
            }

            return(foundFolders);
        }
Example #14
0
        byte[] HandleGetFolderContent(Dictionary <string, object> request)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();
            UUID principal = UUID.Zero;

            UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
            UUID folderID = UUID.Zero;

            UUID.TryParse(request["FOLDER"].ToString(), out folderID);

            InventoryCollection icoll = m_InventoryService.GetFolderContent(principal, folderID);

            if (icoll != null)
            {
                Dictionary <string, object> folders = new Dictionary <string, object>();
                int i = 0;
                if (icoll.Folders != null)
                {
                    foreach (InventoryFolderBase f in icoll.Folders)
                    {
                        folders["folder_" + i.ToString()] = EncodeFolder(f);
                        i++;
                    }
                    result["FOLDERS"] = folders;
                }
                if (icoll.Items != null)
                {
                    i = 0;
                    Dictionary <string, object> items = new Dictionary <string, object>();
                    foreach (InventoryItemBase it in icoll.Items)
                    {
                        items["item_" + i.ToString()] = EncodeItem(it);
                        i++;
                    }
                    result["ITEMS"] = items;
                }
            }

            string xmlString = ServerUtils.BuildXmlResponse(result);

            //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
            return(Util.UTF8NoBomEncoding.GetBytes(xmlString));
        }
Example #15
0
        /// <summary>
        ///     Construct an LLSD reply packet to a CAPS inventory request
        /// </summary>
        /// <param name="invFetch"></param>
        /// <returns></returns>
        private LLSDInventoryDescendents FetchInventoryReply(LLSDFetchInventoryDescendents invFetch)
        {
            LLSDInventoryDescendents    reply    = new LLSDInventoryDescendents();
            LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents();

            contents.agent_id  = m_agentID;
            contents.owner_id  = invFetch.owner_id;
            contents.folder_id = invFetch.folder_id;

            reply.folders.Array.Add(contents);
            InventoryCollection inv = new InventoryCollection();

            inv.Folders = new List <InventoryFolderBase>();
            inv.Items   = new List <InventoryItemBase>();
            int version = 0;

            if (CAPSFetchInventoryDescendents != null)
            {
                inv = CAPSFetchInventoryDescendents(m_agentID, invFetch.folder_id, invFetch.owner_id, invFetch.fetch_folders, invFetch.fetch_items, invFetch.sort_order, out version);
            }

            if (inv.Folders != null)
            {
                foreach (InventoryFolderBase invFolder in inv.Folders)
                {
                    contents.categories.Array.Add(ConvertInventoryFolder(invFolder));
                }
            }

            if (inv.Items != null)
            {
                foreach (InventoryItemBase invItem in inv.Items)
                {
                    contents.items.Array.Add(ConvertInventoryItem(invItem));
                }
            }

            contents.descendents = contents.items.Array.Count + contents.categories.Array.Count;
            contents.version     = version;

            return(reply);
        }
        public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            InventoryCollection inventory = new InventoryCollection();

            inventory.Folders = new List <InventoryFolderBase>();
            inventory.Items   = new List <InventoryItemBase>();
            inventory.UserID  = principalID;

            try
            {
                Dictionary <string, object> ret = MakeRequest("GETFOLDERCONTENT",
                                                              new Dictionary <string, object> {
                    { "PRINCIPAL", principalID.ToString() },
                    { "FOLDER", folderID.ToString() }
                });

                if (!CheckReturn(ret))
                {
                    return(null);
                }

                Dictionary <string, object> folders =
                    (Dictionary <string, object>)ret["FOLDERS"];
                Dictionary <string, object> items =
                    (Dictionary <string, object>)ret["ITEMS"];

                foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
                {
                    inventory.Folders.Add(BuildFolder((Dictionary <string, object>)o));
                }
                foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
                {
                    inventory.Items.Add(BuildItem((Dictionary <string, object>)o));
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetFolderContent: {0}", e.Message);
            }

            return(inventory);
        }
Example #17
0
        public InventoryCollection[] GetMultipleFoldersContent(UUID userID, UUID[] folderIDs)
        {
            string invURL = GetInventoryServiceURL(userID);

            if (invURL == null) // not there, forward to local inventory connector to resolve
            {
                return(m_LocalGridInventoryService.GetMultipleFoldersContent(userID, folderIDs));
            }
            else
            {
                InventoryCollection[] coll = new InventoryCollection[folderIDs.Length];
                int i = 0;
                foreach (UUID fid in folderIDs)
                {
                    coll[i++] = GetFolderContent(userID, fid);
                }

                return(coll);
            }
        }
Example #18
0
        public override InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            UUID sessionID = GetSessionID(userID);

            try
            {
                return(m_RemoteConnector.GetFolderContent(userID.ToString(), folderID, sessionID));
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetFolderContent operation failed, {0} {1}",
                                  e.Source, e.Message);
            }
            InventoryCollection nullCollection = new InventoryCollection();

            nullCollection.Folders = new List <InventoryFolderBase>();
            nullCollection.Items   = new List <InventoryItemBase>();
            nullCollection.UserID  = userID;
            return(nullCollection);
        }
        public override InventoryCollection GetRecursiveFolderContents(UUID userId, UUID folderId)
        {
            m_log.InfoFormat("[LOCAL INVENTORY SERVICE]: Processing request for folder {0} recursive contents", folderId);

            InventoryCollection invCollection = new InventoryCollection();

            List <InventoryFolderBase> folders = GetRecursiveFolderList(folderId);
            List <InventoryItemBase>   items   = RequestItemsInMultipleFolders(folders);

            invCollection.UserID  = UUID.Zero;
            invCollection.Folders = folders;
            invCollection.Items   = items;


            m_log.InfoFormat(
                "[LOCAL INVENTORY SERVICE]: Sending back recursive folder contents containing {0} folders and {1} items",
                invCollection.Folders.Count, invCollection.Items.Count);

            return(invCollection);
        }
Example #20
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="gear">the gear to equip</param>
    /// <param name="inventory">the inventory to return unequipped items into</param>
    public void SetEquippedGear(GearData gear, InventoryCollection inventory)
    {
        if (equippedGear != null && inventory != null)
        {
            inventory.AddItem(equippedGear);
        }

        equippedGear = gear;
        if (gear != null)
        {
            icon.enabled = true;
            icon.sprite  = gear.art;
            UpdateDependants(true, inventory);
        }
        else
        {
            icon.enabled = false;
            UpdateDependants(false, inventory);
        }
    }
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            InventoryCollection invCol = m_InventoryService.GetFolderContent(userID, folderID);

            if (UserManager != null)
            {
                // Protect ourselves against the caller subsequently modifying the items list
                List <InventoryItemBase> items = new List <InventoryItemBase>(invCol.Items);

                Util.FireAndForget(delegate
                {
                    foreach (InventoryItemBase item in items)
                    {
                        UserManager.AddUser(item.CreatorIdAsUuid, item.CreatorData);
                    }
                });
            }

            return(invCol);
        }
        public InventoryCollection FetchDescendants(InventoryFolderBase fb)
        {
            m_log.Info("[HGStandaloneInvService]: Processing request for folder " + fb.ID);

            // Uncomment me to simulate a slow responding inventory server
            //Thread.Sleep(16000);

            InventoryCollection invCollection = new InventoryCollection();

            List <InventoryItemBase>   items   = m_inventoryService.RequestFolderItems(fb.ID);
            List <InventoryFolderBase> folders = m_inventoryService.RequestSubFolders(fb.ID);

            invCollection.UserID  = fb.Owner;
            invCollection.Folders = folders;
            invCollection.Items   = items;

            m_log.DebugFormat("[HGStandaloneInvService]: Found {0} items and {1} folders", items.Count, folders.Count);

            return(invCollection);
        }
Example #23
0
        public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs)
        {
            InventoryItemBase[] itemArr = new InventoryItemBase[itemIDs.Length];
            try
            {
                Dictionary <string, object> resultSet = MakeRequest("GETMULTIPLEITEMS",
                                                                    new Dictionary <string, object> {
                    { "PRINCIPAL", principalID.ToString() },
                    { "ITEMS", String.Join(",", itemIDs) },
                    { "COUNT", itemIDs.Length.ToString() }
                });

                if (!CheckReturn(resultSet))
                {
                    return(null);
                }

                int i = 0;
                foreach (KeyValuePair <string, object> kvp in resultSet)
                {
                    InventoryCollection inventory = new InventoryCollection();
                    if (kvp.Key.StartsWith("item_"))
                    {
                        if (kvp.Value is Dictionary <string, object> )
                        {
                            itemArr[i++] = BuildItem((Dictionary <string, object>)kvp.Value);
                        }
                        else
                        {
                            itemArr[i++] = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[XINVENTORY SERVICES CONNECTOR]: Exception in GetMultipleItems: {0}", e.Message);
            }

            return(itemArr);
        }
Example #24
0
        private void LoadPreviouslyLoadedArchives(IRegistryCore registry)
        {
            IUserAccountService UserAccountService = registry.RequestModuleInterface <IUserAccountService>();
            UserAccount         uinfo            = UserAccountService.GetUserAccount(UUID.Zero, LibraryOwner);
            IInventoryService   InventoryService = registry.RequestModuleInterface <IInventoryService>();

            //Make the user account for the default IAR
            if (uinfo == null)
            {
                uinfo             = new UserAccount(LibraryOwner);
                uinfo.Name        = LibraryOwnerName;
                uinfo.Email       = "";
                uinfo.ServiceURLs = new Dictionary <string, object>();
                uinfo.UserLevel   = 0;
                uinfo.UserFlags   = 0;
                uinfo.ScopeID     = UUID.Zero;
                uinfo.UserTitle   = "";
                UserAccountService.StoreUserAccount(uinfo);
                InventoryService.CreateUserInventory(uinfo.PrincipalID);
                uinfo = UserAccountService.GetUserAccount(UUID.Zero, LibraryOwner);
                if (uinfo == null)
                {
                    //Grid mode, can't create the user... leave
                    return;
                }
            }
            InventoryCollection col = InventoryService.GetFolderContent(LibraryOwner, UUID.Zero);

            foreach (InventoryFolderBase folder in col.Folders)
            {
                if (folder.Name == "My Inventory")
                {
                    continue;                                //Pass My Inventory by
                }
                InventoryFolderImpl f = new InventoryFolderImpl(folder);

                TraverseFolders(f, folder.ID, InventoryService);
                //This is our loaded folder
                AddToDefaultInventory(f);
            }
        }
Example #25
0
        //
        // These 2 are for local and foreign users coming back, respectively
        //

        private void ProcessInventoryForComingHome(IClientAPI client)
        {
            if (!client.IsActive)
            {
                return;
            }
            m_log.DebugFormat("[HG INVENTORY ACCESS MODULE]: Restoring root folder for local user {0}", client.Name);
            InventoryFolderBase root    = m_Scene.InventoryService.GetRootFolder(client.AgentId);
            InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID);

            List <InventoryFolderBase> keep = new List <InventoryFolderBase>();

            foreach (InventoryFolderBase f in content.Folders)
            {
                if (f.Name != "My Suitcase" && f.Name != "Current Outfit")
                {
                    keep.Add(f);
                }
            }
            client.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray());
        }
Example #26
0
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            InventoryCollection c;

            if (m_Inventories.TryGetValue(userID, out InventoryCollection inv))
            {
                c         = new InventoryCollection();
                c.OwnerID = userID;

                c.Folders = inv.Folders.FindAll(delegate(InventoryFolderBase f)
                {
                    return(f.ParentID == folderID);
                });
                c.Items = inv.Items.FindAll(delegate(InventoryItemBase i)
                {
                    return(i.Folder == folderID);
                });
                return(c);
            }
            return(null);
        }
        private int FindAssetPerms(InventoryFolderBase folder, UUID assetID)
        {
            InventoryCollection contents = GetFolderContent(folder.Owner, folder.ID);

            int perms = 0;

            foreach (InventoryItemBase item in contents.Items)
            {
                if (item.AssetID == assetID)
                {
                    perms = (int)item.CurrentPermissions | perms;
                }
            }

            foreach (InventoryFolderBase subfolder in contents.Folders)
            {
                perms = perms | FindAssetPerms(subfolder, assetID);
            }

            return(perms);
        }
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            InventoryCollection invCol = m_RemoteConnector.GetFolderContent(userID, folderID);

            // Commenting this for now, because it's causing more grief than good
            //if (invCol != null && UserManager != null)
            //{
            //    // Protect ourselves against the caller subsequently modifying the items list
            //    List<InventoryItemBase> items = new List<InventoryItemBase>(invCol.Items);

            //    if (items != null && items.Count > 0)
            //        //Util.FireAndForget(delegate
            //        //{
            //            foreach (InventoryItemBase item in items)
            //                if (!string.IsNullOrEmpty(item.CreatorData))
            //                    UserManager.AddUser(item.CreatorIdAsUuid, item.CreatorData);
            //        //});
            //}

            return(invCol);
        }
Example #29
0
        public virtual InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            // This method doesn't receive a valud principal id from the
            // connector. So we disregard the principal and look
            // by ID.
            //
            m_log.DebugFormat("[XINVENTORY SERVICE]: Fetch contents for folder {0}", folderID.ToString());
            InventoryCollection inventory = new InventoryCollection();

            inventory.UserID = principalID;

            inventory.Folders = m_Database.GetFolders(
                new string[] { "parentFolderID" },
                new string[] { folderID.ToString() });

            inventory.Items = m_Database.GetItems(
                new string[] { "parentFolderID" },
                new string[] { folderID.ToString() });

            return(inventory);
        }
        //
        // These 2 are for local and foreign users going away respectively
        //

        private void ProcessInventoryForHypergriding(IClientAPI client)
        {
            if (client is IClientCore)
            {
                IClientCore      core = (IClientCore)client;
                IClientInventory inv;

                if (core.TryGet <IClientInventory>(out inv))
                {
                    InventoryFolderBase root = m_Scene.InventoryService.GetRootFolder(client.AgentId);
                    if (root != null)
                    {
                        m_log.DebugFormat("[HG INVENTORY ACCESS MODULE]: Changing root inventory for user {0}", client.Name);
                        InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID);

                        List <InventoryFolderBase> keep = new List <InventoryFolderBase>();

                        foreach (InventoryFolderBase f in content.Folders)
                        {
                            if (f.Name != "My Suitcase")
                            {
                                f.Name = f.Name + " (Unavailable)";
                                keep.Add(f);
                            }
                        }

                        // items directly under the root folder
                        foreach (InventoryItemBase it in content.Items)
                        {
                            it.Name = it.Name + " (Unavailable)";
                        }
                        ;

                        // Send the new names
                        inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray());
                    }
                }
            }
        }
        public BackendResponse TryFetchFolderContents(Uri owner, UUID folderID, out InventoryCollection contents)
        {
            contents = null;
            BackendResponse ret;

            InventoryCollection         collection;
            InventoryFolderWithChildren folder;

            if (inventories.TryGetValue(owner, out collection) && collection.Folders.TryGetValue(folderID, out folder))
            {
                contents         = new InventoryCollection();
                contents.UserID  = collection.UserID;
                contents.Folders = new Dictionary <UUID, InventoryFolderWithChildren>();
                contents.Items   = new Dictionary <UUID, InventoryItemBase>();

                foreach (InventoryNodeBase invBase in folder.Children.Values)
                {
                    if (invBase is InventoryItemBase)
                    {
                        InventoryItemBase invItem = invBase as InventoryItemBase;
                        contents.Items.Add(invItem.ID, invItem);
                    }
                    else
                    {
                        InventoryFolderWithChildren invFolder = invBase as InventoryFolderWithChildren;
                        contents.Folders.Add(invFolder.ID, invFolder);
                    }
                }

                ret = BackendResponse.Success;
            }
            else
            {
                ret = BackendResponse.NotFound;
            }

            server.MetricsProvider.LogInventoryFetchFolderContents(EXTENSION_NAME, ret, owner, folderID, DateTime.Now);
            return(ret);
        }
        /// <summary>
        /// Save an inventory folder
        /// </summary>
        /// <param name="inventoryFolder">The inventory folder to save</param>
        /// <param name="path">The path to which the folder should be saved</param>
        /// <param name="saveThisFolderItself">If true, save this folder itself.  If false, only saves contents</param>
        protected void SaveInvFolder(InventoryFolderBase inventoryFolder, string path, bool saveThisFolderItself)
        {
            if (saveThisFolderItself)
            {
                path += CreateArchiveFolderName(inventoryFolder);

                // We need to make sure that we record empty folders
                m_archiveWriter.WriteDir(path);
            }

            InventoryCollection contents = FindInventoryCollection(inventoryFolder.Owner, inventoryFolder.ID);

            foreach (InventoryFolderBase childFolder in contents.Folders)
            {
                SaveInvFolder(childFolder, path, true);
            }

            foreach (InventoryItemBase item in contents.Items)
            {
                SaveInvItem(item, path);
            }
        }
        private void TraverseFolders(InventoryFolderImpl folderimp, UUID ID, Scene m_MockScene)
        {
            InventoryCollection col = m_MockScene.InventoryService.GetFolderContent(m_service.LibraryOwner, ID);

            foreach (InventoryItemBase item in col.Items)
            {
                folderimp.Items[item.ID] = item;
            }
            foreach (InventoryFolderBase folder in col.Folders)
            {
                InventoryFolderImpl childFolder = new InventoryFolderImpl(folder);
                foreach (KeyValuePair <String, AssetType> type in m_assetTypes)
                {
                    if (childFolder.Name.ToLower().StartsWith(type.Key.ToLower()))
                    {
                        childFolder.Type = (short)type.Value;
                    }
                }
                TraverseFolders(childFolder, folder.ID, m_MockScene);
                folderimp.AddChildFolder(childFolder);
            }
        }
Example #34
0
    private void UpdateDependants(bool enabled, InventoryCollection inventory)
    {
        foreach (EquipmentSlot slot in dependants)
        {
            bool setgear = false;
            if (enabled)
            {
                slot.gameObject.SetActive(true);
                if (equippedGear != null)
                {
                    //check if the slot is of a type that the equipped gear doesn't provide
                    if (Array.IndexOf(equippedGear.DoesntProvide, GearLoadout.GetSlotType(slot.SlotID)) > -1)
                    {
                        slot.SetEquippedGear(null, inventory);
                        setgear = true;
                        slot.gameObject.SetActive(false);
                    }
                }
                else
                {
                    slot.SetEquippedGear(null, inventory);
                    slot.gameObject.SetActive(false);
                    setgear = true;
                }
            }
            else
            {
                slot.SetEquippedGear(null, inventory);
                slot.gameObject.SetActive(false);
                setgear = true;
            }

            if (!setgear)
            {
                slot.UpdateDependants(enabled, inventory);
            }
        }
    }
Example #35
0
        public virtual InventoryCollection GetFolderContent(UUID UserID, UUID folderID)
        {
            object remoteValue = DoRemoteByURL("InventoryServerURI", UserID, folderID);
            if (remoteValue != null || m_doRemoteOnly)
                return (InventoryCollection) remoteValue;

            // This method doesn't receive a valud principal id from the
            // connector. So we disregard the principal and look
            // by ID.
            //
            MainConsole.Instance.DebugFormat("[XINVENTORY SERVICE]: Fetch contents for folder {0}", folderID.ToString());
            InventoryCollection inventory = new InventoryCollection
                                                {
                                                    UserID = UserID,
                                                    FolderID = folderID,
                                                    Folders = m_Database.GetFolders(
                                                        new[] {"parentFolderID"},
                                                        new[] {folderID.ToString()}),
                                                    Items = m_Database.GetItems(UserID,
                                                                                new[] {"parentFolderID"},
                                                                                new[] {folderID.ToString()})
                                                };

            return inventory;
        }
Example #36
0
 public ProductVariant(Guid productKey, ProductAttributeCollection attributes, InventoryCollection inventory, string name, string sku, decimal price)
     : this(productKey, attributes, inventory, false, name, sku, price)
 {
 }
 private InventoryCollection FindInventoryCollection(UUID userID, UUID folderID)
 {
     InventoryCollection collection = new InventoryCollection();
     collection.UserID = userID;
     collection.Items = new List<InventoryItemBase> ();
     if (m_items.ContainsKey (folderID))
         collection.Items = m_items[folderID];
     collection.Folders = new List<InventoryFolderBase> ();
     if (m_childFolders.ContainsKey (folderID))
         collection.Folders = m_childFolders[folderID];
     return collection;
 }
Example #38
0
        public virtual InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
        {
            // This method doesn't receive a valud principal id from the
            // connector. So we disregard the principal and look
            // by ID.
            //
            m_log.DebugFormat("[XINVENTORY SERVICE]: Fetch contents for folder {0}", folderID.ToString());
            InventoryCollection inventory = new InventoryCollection();
            inventory.UserID = principalID;

            inventory.Folders = m_Database.GetFolders (
                    new string[] { "parentFolderID"},
                    new string[] { folderID.ToString() });

            inventory.Items = m_Database.GetItems (
                    new string[] { "parentFolderID"},
                    new string[] { folderID.ToString() });

            return inventory;
        }
Example #39
0
        /// <summary>
        /// Construct an LLSD reply packet to a CAPS inventory request
        /// </summary>
        /// <param name="invFetch"></param>
        /// <returns></returns>
        private LLSDInventoryDescendents FetchInventoryReply(LLSDFetchInventoryDescendents invFetch)
        {
            LLSDInventoryDescendents reply = new LLSDInventoryDescendents();
            LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents();
            contents.agent_id = m_agentID;
            contents.owner_id =  invFetch.owner_id;
            contents.folder_id = invFetch.folder_id;

            reply.folders.Array.Add(contents);
            InventoryCollection inv = new InventoryCollection();
            inv.Folders = new List<InventoryFolderBase>();
            inv.Items = new List<InventoryItemBase>();
            int version = 0;
            if (CAPSFetchInventoryDescendents != null)
            {
                inv = CAPSFetchInventoryDescendents(m_agentID, invFetch.folder_id, invFetch.owner_id, invFetch.fetch_folders, invFetch.fetch_items, invFetch.sort_order, out version);
            }

            if (inv.Folders != null)
            {
                foreach (InventoryFolderBase invFolder in inv.Folders)
                {
                    contents.categories.Array.Add(ConvertInventoryFolder(invFolder));
                }
            }

            if (inv.Items != null)
            {
                foreach (InventoryItemBase invItem in inv.Items)
                {
                    contents.items.Array.Add(ConvertInventoryItem(invItem));
                }
            }

            contents.descendents = contents.items.Array.Count + contents.categories.Array.Count;
            contents.version = version;

            return reply;
        }
Example #40
0
        /// <summary>
        /// Construct an LLSD reply packet to a CAPS inventory request
        /// </summary>
        /// <param name="invFetch"></param>
        /// <returns></returns>
        private string FetchInventoryReply(OSDArray fetchRequest, UUID AgentID, bool Library)
        {
            OSDMap contents = new OSDMap();
            OSDArray folders = new OSDArray();

            foreach (OSD m in fetchRequest)
            {
                OSDMap invFetch = (OSDMap)m;
                OSDMap internalContents = new OSDMap();

                UUID agent_id = invFetch["agent_id"].AsUUID();
                UUID owner_id = invFetch["owner_id"].AsUUID();
                UUID folder_id = invFetch["folder_id"].AsUUID();
                bool fetch_folders = invFetch["fetch_folders"].AsBoolean();
                bool fetch_items = invFetch["fetch_items"].AsBoolean();
                int sort_order = invFetch["sort_order"].AsInteger();

                //Set the normal stuff
                internalContents["agent_id"] = AgentID;
                internalContents["owner_id"] = owner_id;
                internalContents["folder_id"] = folder_id;


                InventoryCollection inv = new InventoryCollection();
                inv.Folders = new List<InventoryFolderBase>();
                inv.Items = new List<InventoryItemBase>();
                int version = 0;
                inv = HandleFetchInventoryDescendentsCAPS(AgentID, folder_id, owner_id, fetch_folders, fetch_items, sort_order, Library, out version);

                OSDArray categories = new OSDArray();
                if (inv.Folders != null)
                {
                    foreach (InventoryFolderBase invFolder in inv.Folders)
                    {
                        categories.Add(ConvertInventoryFolder(invFolder));
                    }
                }
                internalContents["categories"] = categories;

                OSDArray items = new OSDArray();
                if (inv.Items != null)
                {
                    foreach (InventoryItemBase invItem in inv.Items)
                    {
                        items.Add(ConvertInventoryItem(invItem, AgentID));
                    }
                }
                internalContents["items"] = items;

                internalContents["descendents"] = items.Count + categories.Count;
                internalContents["version"] = version;

                //Now add it to the folder array
                folders.Add(internalContents);
            }

            contents["folders"] = folders;
            return OSDParser.SerializeLLSDXmlString(contents);
        }
Example #41
0
        public InventoryCollection HandleFetchInventoryDescendentsCAPS(UUID agentID, UUID folderID, UUID ownerID,
                                                   bool fetchFolders, bool fetchItems, int sortOrder, bool Library, out int version)
        {
            // FIXME MAYBE: We're not handling sortOrder!

            InventoryFolderImpl fold;

            InventoryCollection contents = new InventoryCollection();
            //if (Library)
            // {
            //version = 0;
            if (m_libraryService != null && m_libraryService.LibraryRootFolder != null)
            {
                if ((fold = m_libraryService.LibraryRootFolder.FindFolder(folderID)) != null)
                {
                    version = 0;
                    InventoryCollection ret = new InventoryCollection();
                    ret.Folders = new List<InventoryFolderBase>();
                    ret.Items = fold.RequestListOfItems();

                    return ret;
                }
            }
            //return contents;
            //}

            //if (folderID != UUID.Zero)
            //{
            if (fetchFolders)
            {
                contents = m_inventoryService.GetFolderContent(agentID, folderID);
            }
            if (fetchItems)
            {
                contents.Items = m_inventoryService.GetFolderItems(agentID, folderID);
            }
            InventoryFolderBase containingFolder = new InventoryFolderBase();
            containingFolder.ID = folderID;
            containingFolder.Owner = agentID;
            containingFolder = m_inventoryService.GetFolder(containingFolder);
            if (containingFolder != null)
                version = containingFolder.Version;
            else
                version = 1;
            //}
            //else
            //{
            //    // Lost itemsm don't really need a version
            //    version = 1;
            //}

            return contents;

        }