/// <summary>
        ///   Execute the inventory write request
        /// </summary>
        public void Execute()
        {
            try
            {
                InventoryFolderBase inventoryFolder = null;
                InventoryItemBase inventoryItem = null;
                InventoryFolderBase rootFolder =
                    m_registry.RequestModuleInterface<IInventoryService>().GetRootFolder(m_userInfo.PrincipalID);

                if (m_defaultFolderToSave != null)
                    rootFolder = m_defaultFolderToSave;

                bool saveFolderContentsOnly = false;

                // Eliminate double slashes and any leading / on the path.
                string[] components
                    = m_invPath.Split(
                        new[] {InventoryFolderImpl.PATH_DELIMITER}, StringSplitOptions.RemoveEmptyEntries);

                int maxComponentIndex = components.Length - 1;

                // If the path terminates with a STAR then later on we want to archive all nodes in the folder but not the
                // folder itself.  This may get more sophisicated later on
                if (maxComponentIndex >= 0 && components[maxComponentIndex] == STAR_WILDCARD)
                {
                    saveFolderContentsOnly = true;
                    maxComponentIndex--;
                }

                m_invPath = String.Empty;
                for (int i = 0; i <= maxComponentIndex; i++)
                {
                    m_invPath += components[i] + InventoryFolderImpl.PATH_DELIMITER;
                }

                // Annoyingly Split actually returns the original string if the input string consists only of delimiters
                // Therefore if we still start with a / after the split, then we need the root folder
                if (m_invPath.Length == 0)
                {
                    inventoryFolder = rootFolder;
                }
                else
                {
                    m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
                    List<InventoryFolderBase> candidateFolders
                        = InventoryArchiveUtils.FindFolderByPath(
                            m_registry.RequestModuleInterface<IInventoryService>(), rootFolder, m_invPath);
                    if (candidateFolders.Count > 0)
                        inventoryFolder = candidateFolders[0];
                }

                // The path may point to an item instead
                if (inventoryFolder == null)
                {
                    inventoryItem =
                        InventoryArchiveUtils.FindItemByPath(m_registry.RequestModuleInterface<IInventoryService>(),
                                                             rootFolder, m_invPath);
                    //inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
                }

                if (null == inventoryFolder && null == inventoryItem)
                {
                    // We couldn't find the path indicated 
                    string errorMessage = string.Format("Aborted save.  Could not find inventory path {0}", m_invPath);
                    Exception e = new InventoryArchiverException(errorMessage);
                    if (m_module != null)
                        m_module.TriggerInventoryArchiveSaved(m_id, false, m_userInfo, m_invPath, m_saveStream, e);
                    throw e;
                }

                m_archiveWriter = new TarArchiveWriter(m_saveStream);

                if (inventoryFolder != null)
                {
                    MainConsole.Instance.DebugFormat(
                        "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
                        inventoryFolder.Name,
                        inventoryFolder.ID,
                        m_invPath == String.Empty ? InventoryFolderImpl.PATH_DELIMITER : m_invPath);

                    //recurse through all dirs getting dirs and files
                    SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !saveFolderContentsOnly);
                }
                else if (inventoryItem != null)
                {
                    MainConsole.Instance.DebugFormat(
                        "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
                        inventoryItem.Name, inventoryItem.ID, m_invPath);

                    SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH);
                }

                // Don't put all this profile information into the archive right now.
                //SaveUsers();
            }
            catch (Exception)
            {
                m_saveStream.Close();
                throw;
            }
            if (m_saveAssets)
            {
                foreach (AssetBase asset in m_assetsToAdd)
                {
                    m_assetUuids[asset.ID] = (AssetType) asset.Type;
                }
                new AssetsRequest(
                    new AssetsArchiver(m_archiveWriter), m_assetUuids,
                    m_registry.RequestModuleInterface<IAssetService>(), ReceivedAllAssets).Execute();
            }
            else
            {
                MainConsole.Instance.Debug("[INVENTORY ARCHIVER]: Save Complete");
                m_archiveWriter.Close();
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Execute the inventory write request
        /// </summary>
        public void Execute()
        {
            try
            {
                InventoryFolderBase inventoryFolder = null;
                InventoryItemBase   inventoryItem   = null;
                InventoryFolderBase rootFolder      =
                    m_registry.RequestModuleInterface <IInventoryService>().GetRootFolder(m_userInfo.PrincipalID);

                if (m_defaultFolderToSave != null)
                {
                    rootFolder = m_defaultFolderToSave;
                }

                bool saveFolderContentsOnly = false;

                // Eliminate double slashes and any leading / on the path.
                string[] components
                    = m_invPath.Split(
                          new[] { InventoryFolderImpl.PATH_DELIMITER }, StringSplitOptions.RemoveEmptyEntries);

                int maxComponentIndex = components.Length - 1;

                // If the path terminates with a STAR then later on we want to archive all nodes in the folder but not the
                // folder itself.  This may get more sophisicated later on
                if (maxComponentIndex >= 0 && components[maxComponentIndex] == STAR_WILDCARD)
                {
                    saveFolderContentsOnly = true;
                    maxComponentIndex--;
                }

                m_invPath = String.Empty;
                for (int i = 0; i <= maxComponentIndex; i++)
                {
                    m_invPath += components[i] + InventoryFolderImpl.PATH_DELIMITER;
                }

                // Annoyingly Split actually returns the original string if the input string consists only of delimiters
                // Therefore if we still start with a / after the split, then we need the root folder
                if (m_invPath.Length == 0)
                {
                    inventoryFolder = rootFolder;
                }
                else
                {
                    m_invPath = m_invPath.Remove(m_invPath.LastIndexOf(InventoryFolderImpl.PATH_DELIMITER));
                    List <InventoryFolderBase> candidateFolders
                        = InventoryArchiveUtils.FindFolderByPath(
                              m_registry.RequestModuleInterface <IInventoryService>(), rootFolder, m_invPath);
                    if (candidateFolders.Count > 0)
                    {
                        inventoryFolder = candidateFolders[0];
                    }
                }

                // The path may point to an item instead
                if (inventoryFolder == null)
                {
                    inventoryItem =
                        InventoryArchiveUtils.FindItemByPath(m_registry.RequestModuleInterface <IInventoryService>(),
                                                             rootFolder, m_invPath);
                    //inventoryItem = m_userInfo.RootFolder.FindItemByPath(m_invPath);
                }

                if (null == inventoryFolder && null == inventoryItem)
                {
                    // We couldn't find the path indicated
                    string    errorMessage = string.Format("Aborted save.  Could not find inventory path {0}", m_invPath);
                    Exception e            = new InventoryArchiverException(errorMessage);
                    if (m_module != null)
                    {
                        m_module.TriggerInventoryArchiveSaved(m_id, false, m_userInfo, m_invPath, m_saveStream, e);
                    }
                    throw e;
                }

                m_archiveWriter = new TarArchiveWriter(m_saveStream);

                if (inventoryFolder != null)
                {
                    MainConsole.Instance.DebugFormat(
                        "[INVENTORY ARCHIVER]: Found folder {0} {1} at {2}",
                        inventoryFolder.Name,
                        inventoryFolder.ID,
                        m_invPath == String.Empty ? InventoryFolderImpl.PATH_DELIMITER : m_invPath);

                    //recurse through all dirs getting dirs and files
                    SaveInvFolder(inventoryFolder, ArchiveConstants.INVENTORY_PATH, !saveFolderContentsOnly);
                }
                else if (inventoryItem != null)
                {
                    MainConsole.Instance.DebugFormat(
                        "[INVENTORY ARCHIVER]: Found item {0} {1} at {2}",
                        inventoryItem.Name, inventoryItem.ID, m_invPath);

                    SaveInvItem(inventoryItem, ArchiveConstants.INVENTORY_PATH);
                }

                // Don't put all this profile information into the archive right now.
                //SaveUsers();
            }
            catch (Exception)
            {
                m_saveStream.Close();
                throw;
            }
            if (m_saveAssets)
            {
                foreach (AssetBase asset in m_assetsToAdd)
                {
                    m_assetUuids[asset.ID] = (AssetType)asset.Type;
                }
                new AssetsRequest(
                    new AssetsArchiver(m_archiveWriter), m_assetUuids,
                    m_registry.RequestModuleInterface <IAssetService>(), ReceivedAllAssets).Execute();
            }
            else
            {
                MainConsole.Instance.Debug("[INVENTORY ARCHIVER]: Save Complete");
                m_archiveWriter.Close();
            }
        }