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});
#if (!ISWIN)
            foreach (string mServerUri in serverURIs)
            {
                RestClient rc = new RestClient(mServerUri);
                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;
                }
            }
#else
            foreach (RestClient rc in serverURIs.Select(m_ServerURI => 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;
                }
            }
#endif

            return null;
        }
Пример #2
0
        public byte[] GetData(string id)
        {
            if (m_Cache != null)
            {
                Aurora.Framework.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";

                System.IO.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;
        }
        private void NotifyDataServices(string servicesStr, string serviceName)
        {
            Stream reply = null;
            string delimStr = ";";
            char [] delimiter = delimStr.ToCharArray();

            string[] services = servicesStr.Split(delimiter);

            for (int i = 0; i < services.Length; i++)
            {
                string url = services[i].Trim();
                RestClient cli = new RestClient(url);
                cli.AddQueryParameter("service", serviceName);
                cli.AddQueryParameter("host", m_hostname);
                cli.AddQueryParameter("port", m_listener_port);
                cli.RequestMethod = "GET";
                try
                {
                    reply = cli.Request();
                }
                catch (WebException)
                {
                    m_log.Warn("[DATASNAPSHOT]: Unable to notify " + url);
                }
                catch (Exception e)
                {
                    m_log.Warn("[DATASNAPSHOT]: Ignoring unknown exception " + e.ToString());
                }
                byte[] response = new byte[1024];
                // int n = 0;
                try
                {
                    // n = reply.Read(response, 0, 1024);
                    reply.Read(response, 0, 1024);
                }
                catch (Exception e)
                {
                    m_log.WarnFormat("[DATASNAPSHOT]: Unable to decode reply from data service. Ignoring. {0}", e.StackTrace);
                }
                // This is not quite working, so...
                // string responseStr = Util.UTF8.GetString(response);
                //m_log.Info("[DATASNAPSHOT]: data service notified: " + url);
            }
        }