Execute() public method

Execute the inventory write request
public Execute ( ) : void
return void
示例#1
0
        public bool ArchiveInventory(
            Guid id, string firstName, string lastName, string invPath, Stream saveStream,
            Dictionary <string, object> options)
        {
            UserAccount userInfo = m_registry.RequestModuleInterface <IUserAccountService>()
                                   .GetUserAccount(null, firstName, lastName);

            if (userInfo != null)
            {
                try
                {
                    bool UseAssets = true;
                    if (options.ContainsKey("assets"))
                    {
                        object Assets;
                        options.TryGetValue("assets", out Assets);
                        bool.TryParse(Assets.ToString(), out UseAssets);
                    }

                    string checkPermissions = "";
                    if (options.ContainsKey("checkPermissions"))
                    {
                        Object temp;
                        if (options.TryGetValue("checkPermissions", out temp))
                        {
                            checkPermissions = temp.ToString().ToUpper();
                        }
                    }

                    var saveArchive = new InventoryArchiveWriteRequest(
                        id,
                        this,
                        m_registry,
                        userInfo,
                        invPath,
                        saveStream,
                        UseAssets,
                        null,
                        new List <AssetBase>(),
                        checkPermissions);

                    saveArchive.Execute();
                }
                catch (EntryPointNotFoundException e)
                {
                    MainConsole.Instance.ErrorFormat(
                        "[Archiver]: Mismatch between Mono and zlib1g library version when trying to create compression stream."
                        + "If you've manually installed Mono, have you appropriately updated zlib1g as well?");
                    MainConsole.Instance.Error(e);

                    return(false);
                }

                return(true);
            }

            return(false);
        }
        public bool ArchiveInventory(
            Guid id, string firstName, string lastName, string invPath, Stream saveStream,
            Dictionary<string, object> options)
        {
            UserAccount userInfo = m_registry.RequestModuleInterface<IUserAccountService>()
                                             .GetUserAccount(null, firstName, lastName);

            if (userInfo != null)
            {
                try
                {
                    bool UseAssets = true;
                    if (options.ContainsKey("assets"))
                    {
                        object Assets;
                        options.TryGetValue("assets", out Assets);
                        bool.TryParse(Assets.ToString(), out UseAssets);
                    }

                    string checkPermissions = "";
                    if (options.ContainsKey("checkPermissions"))
                    {
                        Object temp;
                        if (options.TryGetValue("checkPermissions", out temp))
                            checkPermissions = temp.ToString().ToUpper();
                    }

                    var saveArchive = new InventoryArchiveWriteRequest(
                        id,
                        this,
                        m_registry,
                        userInfo,
                        invPath,
                        saveStream,
                        UseAssets,
                        null,
                        new List<AssetBase>(),
                        checkPermissions);

                    saveArchive.Execute();
                }
                catch (EntryPointNotFoundException e)
                {
                    MainConsole.Instance.ErrorFormat(
                        "[Archiver]: Mismatch between Mono and zlib1g library version when trying to create compression stream."
                        + "If you've manually installed Mono, have you appropriately updated zlib1g as well?");
                    MainConsole.Instance.Error(e);

                    return false;
                }

                return true;
            }

            return false;
        }
        /// <summary>
        /// Handles the default inventory save.
        /// </summary>
        /// <param name="scene">Scene.</param>
        /// <param name="cmd">Cmd.</param>
        private void HandleDefInvSave( IScene scene, string[] cmd )
        {
            if (!m_enabled)
                return;

            if (m_busy)
                return;

            string fileName = IARName;

            // optional filename
            int el = cmd.Length;
            if (el >= 4)
            {
                fileName = cmd[3];

                // some file sanity checks
                string extension = Path.GetExtension (fileName);

                if (extension == string.Empty)
                {
                    fileName = fileName + ".iar";
                }

            }

            string fileDir = Path.GetDirectoryName (fileName);
            if (fileDir == "")
            {
                fileDir = "./DefaultInventory";
                fileName = fileDir + '/' + fileName;
            }
            if (!Directory.Exists (fileDir))
            {
                MainConsole.Instance.Info ("[LIBDEF]: The folder specified, '" + fileDir + "' does not exist!");
                return;
            }

            // don't try and write to an existing file
            if (File.Exists (fileName))
            {
                if (MainConsole.Instance.Prompt ("[LIBDEF]: The inventory file '" + fileName + "' exists. Overwrite?", "yes") != "yes")
                    return;

                File.Delete (fileName);
            }

            // good to go... do it...
            m_busy = true;
            m_service = m_registry.RequestModuleInterface<ILibraryService>();

            RegionInfo regInfo = new RegionInfo();
            IScene m_MockScene = null;

            //Make the scene for the IAR loader
            if (m_registry is IScene)
                m_MockScene = (IScene)m_registry;
            else
            {
                m_MockScene = new Scene();
                m_MockScene.Initialize(regInfo);
                m_MockScene.AddModuleInterfaces(m_registry.GetInterfaces());
            }

            UserAccount uinfo = m_MockScene.UserAccountService.GetUserAccount(null, m_service.LibraryOwner);
            //Make the user account for the default IAR
            if (uinfo == null)
            {
                uinfo = new UserAccount(m_service.LibraryOwner);
                uinfo.Name = m_service.LibraryOwnerName;
                m_MockScene.InventoryService.CreateUserInventory(m_service.LibraryOwner, false);
            }

            List<AssetBase> assets = new List<AssetBase> ();
            if (m_MockScene.InventoryService != null)
            {
                //Add the folders to the user's inventory
                InventoryCollection i = m_MockScene.InventoryService.GetFolderContent (m_service.LibraryOwner, UUID.Zero);
                if (i != null)
                {
                    foreach (InventoryItemBase item in i.Items)
                    {
                        AssetBase asset = m_MockScene.RequestModuleInterface<IAssetService> ().Get (item.AssetID.ToString ());
                        if (asset != null)
                            assets.Add (asset);
                    }
                }
            }
            InventoryFolderBase rootFolder = null;
            List<InventoryFolderBase> rootFolders = m_MockScene.InventoryService.GetRootFolders (m_service.LibraryOwner);
            foreach (InventoryFolderBase folder in rootFolders)
            {
                if (folder.Name == "My Inventory")
                    continue;

                rootFolder = folder;
                break;
            }
            if (rootFolder != null)
            {
                //Save the IAR of the default assets
                MainConsole.Instance.Info ("[LIBDEF]: Saving default inventory to " + fileName);
                InventoryArchiveWriteRequest write = new InventoryArchiveWriteRequest (Guid.NewGuid (), null, m_MockScene,
                    uinfo, "/", new GZipStream (new FileStream (fileName, FileMode.Create), CompressionMode.Compress), true, rootFolder, assets);
                write.Execute ();
            }

            m_busy = false;
        }