Esempio n. 1
0
        public WearableCacheItem[] Get(UUID id)
        {
            if (m_URL == String.Empty)
                return null;

            int size = 0;

            using (RestClient rc = new RestClient(m_URL))
            {
                List<WearableCacheItem> ret = new List<WearableCacheItem>();
                rc.AddResourcePath("bakes");
                rc.AddResourcePath(id.ToString());

                rc.RequestMethod = "GET";

                try
                {
                    Stream s = rc.Request(m_Auth);

                    using (XmlTextReader sr = new XmlTextReader(s))
                    {
                        sr.ReadStartElement("BakedAppearance");
                        while (sr.LocalName == "BakedTexture")
                        {
                            string sTextureIndex = sr.GetAttribute("TextureIndex");
                            int lTextureIndex = Convert.ToInt32(sTextureIndex);
                            string sCacheId = sr.GetAttribute("CacheId");
                            UUID lCacheId = UUID.Zero;
                            if (!(UUID.TryParse(sCacheId, out lCacheId)))
                            {
                                // ??  Nothing here
                            }

                            ++size;

                            sr.ReadStartElement("BakedTexture");
                            AssetBase a = (AssetBase)m_serializer.Deserialize(sr);
                            ret.Add(new WearableCacheItem() { CacheId = lCacheId, TextureIndex = (uint)lTextureIndex, TextureAsset = a, TextureID = a.FullID });

                            sr.ReadEndElement();
                        }

                        m_log.DebugFormat("[XBakes]: read {0} textures for user {1}", ret.Count, id);
                    }

                    return ret.ToArray();
                }
                catch (XmlException)
                {
                    return null;
                }
            }
        }
Esempio n. 2
0
        public void Store(UUID agentId, WearableCacheItem[] data)
        {
            if (m_URL == String.Empty)
                return;

            MemoryStream reqStream;

            using (MemoryStream bakeStream = new MemoryStream())
            using (XmlTextWriter bakeWriter = new XmlTextWriter(bakeStream, null))
            {
                bakeWriter.WriteStartElement(String.Empty, "BakedAppearance", String.Empty);

                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] != null)
                    {
                        bakeWriter.WriteStartElement(String.Empty, "BakedTexture", String.Empty);
                        bakeWriter.WriteAttributeString(String.Empty, "TextureIndex", String.Empty, data[i].TextureIndex.ToString());
                        bakeWriter.WriteAttributeString(String.Empty, "CacheId", String.Empty, data[i].CacheId.ToString());
                        if (data[i].TextureAsset != null)
                            m_serializer.Serialize(bakeWriter, data[i].TextureAsset);

                        bakeWriter.WriteEndElement();
                    }
                }

                bakeWriter.WriteEndElement();
                bakeWriter.Flush();

                reqStream = new MemoryStream(bakeStream.ToArray());
            }

            RestClient rc = new RestClient(m_URL);
            rc.AddResourcePath("bakes");
            rc.AddResourcePath(agentId.ToString());

            rc.RequestMethod = "POST";

            Util.FireAndForget(
                delegate
                {
                    rc.Request(reqStream, m_Auth);
                    m_log.DebugFormat("[XBakes]: stored {0} textures for user {1}", data.Length, agentId);
                }, null, "XBakesModule.Store"
            );
        }
        public virtual byte[] GetData(string id)
        {
            if (m_Cache != null)
            {
                AssetBase fullAsset = m_Cache.Get(id);

                if (fullAsset != null)
                    return fullAsset.Data;
            }

            List<string> serverURIs = m_registry.RequestModuleInterface<IConfigurationService>().FindValueOf("AssetServerURI");
            if (m_serverURL != string.Empty)
                serverURIs = new List<string>(new string[1] { m_serverURL });
            foreach (string m_ServerURI in serverURIs)
            {
                RestClient rc = new RestClient(m_ServerURI);
                rc.AddResourcePath("assets");
                rc.AddResourcePath(id);
                rc.AddResourcePath("data");

                rc.RequestMethod = "GET";

                Stream s = rc.Request();

                if (s == null)
                    return null;

                if (s.Length > 0)
                {
                    byte[] ret = new byte[s.Length];
                    s.Read(ret, 0, (int)s.Length);

                    return ret;
                }
            }

            return null;
        }
        public byte[] GetData(string id)
        {
            if (m_Cache != null)
            {
                AssetBase fullAsset = m_Cache.Get(id);

                if (fullAsset != null)
                    return fullAsset.Data;
            }

            using (RestClient rc = new RestClient(MapServer(id)))
            {
                rc.AddResourcePath("assets");
                rc.AddResourcePath(id);
                rc.AddResourcePath("data");

                rc.RequestMethod = "GET";

                using (Stream s = rc.Request(m_Auth))
                {
                    if (s == null)
                        return null;

                    if (s.Length > 0)
                    {
                        byte[] ret = new byte[s.Length];
                        s.Read(ret, 0, (int)s.Length);

                        return ret;
                    }
                }
                return null;
            }
        }
Esempio n. 5
0
        object TextureFetchJob(object arg)
        {
            IrrManager.IrrWorkItem irrWorkItem = (IrrManager.IrrWorkItem)arg;
            TextureDownloadRequest req = (TextureDownloadRequest)irrWorkItem.arg;

            m_log.Debug("[TextureFetchJob]: handling req " + req.uuid);
            try
            {
                RestClient rest = new RestClient(VUtil.assetServerUri);
                rest.RequestMethod = "GET";
                rest.AddResourcePath("assets");
                rest.AddResourcePath(req.uuid.ToString());
                rest.AddHeader("Authorization", "OpenGrid " + VUtil.authToken.ToString());

                System.IO.Stream stream = rest.Request(timeout);
                m_log.Debug("[TextureFetchJob]: downloaded JP2 for " + req.uuid);

                XmlSerializer xs = new XmlSerializer(typeof(AssetBase));

                //System.IO.StreamReader x = new StreamReader(stream);
                //string test = x.ReadToEnd();

                //stream.Seek(0, SeekOrigin.Begin);
                AssetBase ab = (AssetBase)xs.Deserialize(stream);
                OpenViewer.Primitives.ExtendedAssetTexture texAsset = new OpenViewer.Primitives.ExtendedAssetTexture(req.uuid, ab.Data,ab.Type);
                imageReceivedCallback(texAsset);
                return null;
            }
            catch (Exception e)
            {
                m_log.Warn("[TextureFetchJob]: could not fetch texture " + req.uuid + ": " + e.Message);
                if (e is System.Net.WebException && ((System.Net.WebException)e).Status == System.Net.WebExceptionStatus.ProtocolError)
                {
                    // no retry
                    return null;
                }
                else
                {
                    return irrWorkItem;
                }
            }
        }
Esempio n. 6
0
        public string IrrFileCreateCache(string _filename, string _directory)
        {
            if (string.IsNullOrEmpty(_filename))
                return "Filename is null or empty.";

            if (System.IO.File.Exists(_directory + "/" + _filename))
                return _filename + " is Already exist";

            string err = string.Empty;
            string uuid = System.IO.Path.GetFileNameWithoutExtension(_filename);
            string filenameWithoutPath = System.IO.Path.GetFileName(_filename);
            int timeout = Reference.Viewer.Config.Source.Configs["Startup"].GetInt("asset_timeout", 60000);

            try
            {
                RestClient rest = new RestClient(VUtil.assetServerUri);
                rest.RequestMethod = "GET";
                rest.AddResourcePath("assets");
                rest.AddResourcePath(uuid);
                rest.AddHeader("Authorization", "OpenGrid " + VUtil.authToken.ToString());

                System.IO.Stream stream = rest.Request(timeout);

                XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
                AssetBase ab = (AssetBase)xs.Deserialize(stream);

                bool tryToDecompress = true;
                if (tryToDecompress
                    && ab.Data.Length >= 2
                    && ab.Data[0] == 0x1f // gzip header == 0x1f8b
                    && ab.Data[1] == 0x8b)
                {
                    try
                    {
                        // try to uncompress
                        string compressedFilename = _directory + "/" + filenameWithoutPath + ".gz";
                        System.IO.File.WriteAllBytes(compressedFilename, ab.Data);
                        string dstFile = _directory + "/" + filenameWithoutPath;

                        Lib3Di.Compress.AddDecompressionRequest(new DecompressionRequest(compressedFilename, dstFile));
                        Lib3Di.Compress.DecompressWaitingRequests(); // Handle all waiting decompression requests here - one at a time (to prevent file collisions and simultaneous decompression in separate IrrMeshThreads). We could also make a separate thread to handle all decompression requests in sequence, but that thread would need to live forever and would only be active at the start of the program when assets are being downloaded, so it makes more sense to handle decompression requests here (invoked from an IrrMeshThread), where DecompressWaitingRequests() locks the queue and processes everything serially.
                    }
                    catch (Exception e)
                    {
                        Reference.Log.Warn("[IRR MANAGER]: " + e.Message);
                        Reference.Log.Debug("[IRR MANAGER]: " + e.StackTrace);
                        File.WriteAllBytes(_directory + "/" + filenameWithoutPath, ab.Data);
                    }
                    finally
                    {
                        File.Delete(_directory + "/" + filenameWithoutPath + ".gz");
                    }
                }
                else
                {
                    System.IO.File.WriteAllBytes(_directory + "/" + filenameWithoutPath, ab.Data);
                }
            }
            catch (Exception e)
            {
                err = e.Message;
            }

            return err;
        }
        public virtual byte[] GetData(string id)
        {
            if (m_Cache != null)
            {
                AssetBase fullAsset = m_Cache.Get(id);

                if (fullAsset != null)
                    return fullAsset.Data;
            }

            foreach (string m_ServerURI in m_ServerURIs)
            {
                RestClient rc = new RestClient(m_ServerURI);
                rc.AddResourcePath("assets");
                rc.AddResourcePath(id);
                rc.AddResourcePath("data");

                rc.RequestMethod = "GET";

                Stream s = rc.Request();

                if (s == null)
                    return null;

                if (s.Length > 0)
                {
                    byte[] ret = new byte[s.Length];
                    s.Read(ret, 0, (int)s.Length);

                    return ret;
                }
            }

            return null;
        }