/// <summary>
        /// Not sure what sequence causes this function to be invoked. The only calling
        /// path is through the GET method 
        /// </summary>
        public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
        {
            // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: RetrieveAgent start");

            agent = null;

            // Eventually, we want to use a caps url instead of the agentID
            string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";

            try
            {
                OSDMap result = WebUtil.GetFromService(uri, 10000);
                if (result["Success"].AsBoolean())
                {
                    // OSDMap args = Util.GetOSDMap(result["_RawResult"].AsString());
                    OSDMap args = (OSDMap)result["_Result"];
                    if (args != null)
                    {
                        agent = new CompleteAgentData();
                        agent.Unpack(args, null);
                        return true;
                    }
                }
            }
            catch (Exception e)
            {
                m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
            }

            return false;
        }
Ejemplo n.º 2
0
 public bool CopyAgent(out IAgentData agent)
 {
     agent = new CompleteAgentData();
     CopyTo((AgentData)agent);
     return true;
 }
        public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
        {
            agent = null;
            // Eventually, we want to use a caps url instead of the agentID
            string uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
            //Console.WriteLine("   >>> DoRetrieveRootAgentCall <<< " + uri);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "GET";
            request.Timeout = 10000;
            //request.Headers.Add("authorization", ""); // coming soon

            HttpWebResponse webResponse = null;
            string reply = string.Empty;
            StreamReader sr = null;
            try
            {
                webResponse = (HttpWebResponse)request.GetResponse();
                if (webResponse == null)
                {
                    m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get ");
                }

                sr = new StreamReader(webResponse.GetResponseStream());
                reply = sr.ReadToEnd().Trim();

                //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was " + reply);

            }
            catch (WebException ex)
            {
                m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message);
                // ignore, really
                return false;
            }
            finally
            {
                if (sr != null)
                    sr.Close();
            }

            if (webResponse.StatusCode == HttpStatusCode.OK)
            {
                // we know it's jason
                OSDMap args = Util.GetOSDMap(reply);
                if (args == null)
                {
                    //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: Error getting OSDMap from reply");
                    return false;
                }

                agent = new CompleteAgentData();
                agent.Unpack(args);
                return true;
            }

            //Console.WriteLine("[REMOTE SIMULATION CONNECTOR]: DoRetrieveRootAgentCall returned status " + webResponse.StatusCode);
            return false;
        }