// TODO: unused
        // private void Dump(Dictionary<UUID, bool> lst)
        // {
        //     m_log.Debug("XXX -------- UUID DUMP ------- XXX");
        //     foreach (KeyValuePair<UUID, bool> kvp in lst)
        //         m_log.Debug(" >> " + kvp.Key + " (texture? " + kvp.Value + ")");
        //     m_log.Debug("XXX -------- UUID DUMP ------- XXX");
        // }

        #endregion


        #region Public interface

        public void Get(UUID assetID, UUID ownerID, string userAssetURL)
        {
            // The act of gathering UUIDs downloads some assets from the remote server
            // but not all...
            HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, userAssetURL);

            uuidGatherer.AddForInspection(assetID);
            uuidGatherer.GatherAll();

            m_log.DebugFormat("[HG ASSET MAPPER]: Preparing to get {0} assets", uuidGatherer.GatheredUuids.Count);
            bool success = true;

            foreach (UUID uuid in uuidGatherer.GatheredUuids.Keys)
            {
                if (FetchAsset(userAssetURL, uuid) == null)
                {
                    success = false;
                }
            }
            if (uuidGatherer.FailedUUIDs.Count > 0)
            {
                success = false;
            }

            // maybe all pieces got here...
            if (!success)
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Problems getting item {0} from asset server {1}", assetID, userAssetURL);
            }
            else
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Successfully got item {0} from asset server {1}", assetID, userAssetURL);
            }
        }
Пример #2
0
        // TODO: unused
        // private void Dump(Dictionary<UUID, bool> lst)
        // {
        //     m_log.Debug("XXX -------- UUID DUMP ------- XXX");
        //     foreach (KeyValuePair<UUID, bool> kvp in lst)
        //         m_log.Debug(" >> " + kvp.Key + " (texture? " + kvp.Value + ")");
        //     m_log.Debug("XXX -------- UUID DUMP ------- XXX");
        // }

        #endregion


        #region Public interface

        public void Get(UUID assetID, UUID ownerID, string userAssetURL)
        {
            // Get the item from the remote asset server onto the local AssetService

            AssetMetadata meta = FetchMetadata(userAssetURL, assetID);

            if (meta == null)
            {
                return;
            }

            Dictionary <UUID, sbyte> ids          = new Dictionary <UUID, sbyte>();
            HGUuidGatherer           uuidGatherer = new HGUuidGatherer(m_scene.AssetService, userAssetURL);

            uuidGatherer.AddForInspection(assetID);
            uuidGatherer.GatherAll();
            m_log.DebugFormat("[HG ASSET MAPPER]: Preparing to get {0} assets", ids.Count);
            bool success = true;

            foreach (UUID uuid in uuidGatherer.GatheredUuids.Keys)
            {
                if (FetchAsset(userAssetURL, uuid) == null)
                {
                    success = false;
                }
            }

            // maybe all pieces got here...
            if (!success)
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Problems getting item {0} from asset server {1}", assetID, userAssetURL);
            }
            else
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Successfully got item {0} from asset server {1}", assetID, userAssetURL);
            }
        }
Пример #3
0
        public void Post(UUID assetID, UUID ownerID, string userAssetURL)
        {
            m_log.DebugFormat("[HG ASSET MAPPER]: Starting to send asset {0} with children to asset server {1}", assetID, userAssetURL);

            // Find all the embedded assets

            AssetBase asset = m_scene.AssetService.Get(assetID.ToString());

            if (asset == null)
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Something wrong with asset {0}, it could not be found", assetID);
                return;
            }

            HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, string.Empty);

            uuidGatherer.AddForInspection(asset.FullID);
            uuidGatherer.GatherAll();

            // Check which assets already exist in the destination server

            string url = userAssetURL;

            if (!url.EndsWith("/") && !url.EndsWith("="))
            {
                url = url + "/";
            }

            string[] remoteAssetIDs = new string[uuidGatherer.GatheredUuids.Count];
            int      i = 0;

            foreach (UUID id in uuidGatherer.GatheredUuids.Keys)
            {
                remoteAssetIDs[i++] = url + id.ToString();
            }

            bool[] exist = m_scene.AssetService.AssetsExist(remoteAssetIDs);

            var existSet = new HashSet <string>();

            i = 0;
            foreach (UUID id in uuidGatherer.GatheredUuids.Keys)
            {
                if (exist[i])
                {
                    existSet.Add(id.ToString());
                }
                ++i;
            }

            // Send only those assets which don't already exist in the destination server

            bool success = true;

            foreach (UUID uuid in uuidGatherer.GatheredUuids.Keys)
            {
                if (!existSet.Contains(uuid.ToString()))
                {
                    asset = m_scene.AssetService.Get(uuid.ToString());
                    if (asset == null)
                    {
                        m_log.DebugFormat("[HG ASSET MAPPER]: Could not find asset {0}", uuid);
                    }
                    else
                    {
                        try
                        {
                            success &= PostAsset(userAssetURL, asset);
                        }
                        catch (Exception e)
                        {
                            m_log.Error(
                                string.Format(
                                    "[HG ASSET MAPPER]: Failed to post asset {0} (type {1}, length {2}) referenced from {3} to {4} with exception  ",
                                    asset.ID, asset.Type, asset.Data.Length, assetID, userAssetURL),
                                e);

                            // For debugging purposes for now we will continue to throw the exception up the stack as was already happening.  However, after
                            // debugging we may want to simply report the failure if we can tell this is due to a failure
                            // with a particular asset and not a destination network failure where all asset posts will fail (and
                            // generate large amounts of log spam).
                            throw e;
                        }
                    }
                }
                else
                {
                    m_log.DebugFormat(
                        "[HG ASSET MAPPER]: Didn't post asset {0} referenced from {1} because it already exists in asset server {2}",
                        uuid, assetID, userAssetURL);
                }
            }

            if (!success)
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Problems sending asset {0} with children to asset server {1}", assetID, userAssetURL);
            }
            else
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Successfully sent asset {0} with children to asset server {1}", assetID, userAssetURL);
            }
        }
Пример #4
0
        public void Post(UUID assetID, UUID ownerID, string userAssetURL)
        {
            AssetBase asset = m_scene.AssetService.Get(assetID.ToString());

            if (asset == null)
            {
                m_log.DebugFormat("[HG ASSET MAPPER POST]: Something wrong with asset {0}, it could not be found", assetID);
                return;
            }
            m_log.DebugFormat("[HG ASSET MAPPER  POST]: Starting to send asset {0} to asset server {1}", assetID, userAssetURL);

            // Find all the embedded assets
            HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, string.Empty);

            uuidGatherer.AddForInspection(asset.FullID);
            uuidGatherer.GatherAll(true);

            // Check which assets already exist in the destination server

            string url = userAssetURL;

            if (!url.EndsWith("/") && !url.EndsWith("="))
            {
                url = url + "/";
            }

            string[] remoteAssetIDs = new string[uuidGatherer.GatheredUuids.Count];
            int      i = 0;

            foreach (UUID id in uuidGatherer.GatheredUuids.Keys)
            {
                remoteAssetIDs[i++] = url + id.ToString();
            }

            bool[] exist;
            try
            {
                exist = m_scene.AssetService.AssetsExist(remoteAssetIDs);
            }
            catch
            {
                m_log.DebugFormat("[HG ASSET MAPPER POST]: Problems sending asset {0} to asset server {1}", assetID, userAssetURL);
                return;
            }

            var existSet = new HashSet <string>();

            i = 0;
            foreach (UUID id in uuidGatherer.GatheredUuids.Keys)
            {
                if (exist[i])
                {
                    existSet.Add(id.ToString());
                }
                ++i;
            }

            // Send only those assets which don't already exist in the destination server

            bool success  = true;
            var  notFound = new List <string>();
            var  posted   = new List <string>();

            foreach (UUID uuid in uuidGatherer.GatheredUuids.Keys)
            {
                string idstr = uuid.ToString();
                if (existSet.Contains(idstr))
                {
                    continue;
                }

                asset = m_scene.AssetService.Get(idstr);
                if (asset == null)
                {
                    notFound.Add(idstr);
                    continue;
                }

                try
                {
                    bool b = PostAsset(userAssetURL, asset, false);
                    if (b)
                    {
                        posted.Add(idstr);
                    }
                    success &= b;
                }
                catch (Exception e)
                {
                    m_log.Error(
                        string.Format(
                            "[HG ASSET MAPPER POST]: Failed to post asset {0} (type {1}, length {2}) referenced from {3} to {4} with exception  ",
                            asset.ID, asset.Type, asset.Data.Length, assetID, userAssetURL),
                        e);

                    // For debugging purposes for now we will continue to throw the exception up the stack as was already happening.  However, after
                    // debugging we may want to simply report the failure if we can tell this is due to a failure
                    // with a particular asset and not a destination network failure where all asset posts will fail (and
                    // generate large amounts of log spam).
                    throw;
                }
            }
            StringBuilder sb = null;

            if (notFound.Count > 0)
            {
                if (sb == null)
                {
                    sb = new StringBuilder(512);
                }
                i = notFound.Count;
                sb.Append("[HG ASSET MAPPER POST]: Missing assets:\n\t");
                for (int j = 0; j < notFound.Count; ++j)
                {
                    sb.Append(notFound[j]);
                    if (i < j)
                    {
                        sb.Append(',');
                    }
                }
                m_log.Debug(sb.ToString());
                sb.Clear();
            }
            if (existSet.Count > 0)
            {
                if (sb == null)
                {
                    sb = new StringBuilder(512);
                }
                i = existSet.Count;
                sb.Append("[HG ASSET MAPPER POST]: Already at destination server:\n\t");
                foreach (UUID id in existSet)
                {
                    sb.Append(id);
                    if (--i > 0)
                    {
                        sb.Append(',');
                    }
                }
                m_log.Debug(sb.ToString());
                sb.Clear();
            }
            if (posted.Count > 0)
            {
                if (sb == null)
                {
                    sb = new StringBuilder(512);
                }
                i = posted.Count;
                sb.Append("[HG ASSET MAPPER POST]: Posted assets:\n\t");
                for (int j = 0; j < posted.Count; ++j)
                {
                    sb.Append(posted[j]);
                    if (i < j)
                    {
                        sb.Append(',');
                    }
                }
                m_log.Debug(sb.ToString());
            }

            if (!success)
            {
                m_log.DebugFormat("[HG ASSET MAPPER POST]: Problems sending asset {0} to asset server {1}", assetID, userAssetURL);
            }
            else
            {
                m_log.DebugFormat("[HG ASSET MAPPER POST]: Successfully sent asset {0} to asset server {1}", assetID, userAssetURL);
            }
        }
Пример #5
0
        public void Post(UUID assetID, UUID ownerID, string userAssetURL)
        {
            m_log.DebugFormat("[HG ASSET MAPPER]: Starting to send asset {0} with children to asset server {1}", assetID, userAssetURL);

            // Find all the embedded assets

            AssetBase asset = m_scene.AssetService.Get(assetID.ToString());

            if (asset == null)
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Something wrong with asset {0}, it could not be found", assetID);
                return;
            }

            HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, string.Empty);

            uuidGatherer.AddForInspection(assetID);
            uuidGatherer.GatherAll();

            // Check which assets already exist in the destination server

            string url = userAssetURL;

            if (!url.EndsWith("/") && !url.EndsWith("="))
            {
                url += "/";
            }

            IDictionary <UUID, sbyte> ids = uuidGatherer.GatheredUuids;

            string[] remoteAssetIDs = new string[ids.Count];
            int      i = 0;

            foreach (UUID id in ids.Keys)
            {
                remoteAssetIDs[i++] = url + id.ToString();
            }

            bool[] exist = m_scene.AssetService.AssetsExist(remoteAssetIDs);

            var existSet = new HashSet <string>();

            i = 0;
            foreach (UUID id in ids.Keys)
            {
                if (exist[i])
                {
                    existSet.Add(id.ToString());
                }
                ++i;
            }

            // Send only those assets which don't already exist in the destination server

            bool success = true;

            foreach (UUID uuid in ids.Keys)
            {
                if (!existSet.Contains(uuid.ToString()))
                {
                    asset = m_scene.AssetService.Get(uuid.ToString());
                    if (asset == null)
                    {
                        m_log.DebugFormat("[HG ASSET MAPPER]: Could not find asset {0}", uuid);
                    }
                    else
                    {
                        success &= PostAsset(userAssetURL, asset);
                    }
                }
                else
                {
                    m_log.DebugFormat("[HG ASSET MAPPER]: Didn't post asset {0} because it already exists in asset server {1}", uuid, userAssetURL);
                }
            }

            if (!success)
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Problems sending asset {0} with children to asset server {1}", assetID, userAssetURL);
            }
            else
            {
                m_log.DebugFormat("[HG ASSET MAPPER]: Successfully sent asset {0} with children to asset server {1}", assetID, userAssetURL);
            }
        }