当前位置: 首页>>代码示例>>C#>>正文


C# IAgentData.Pack方法代码示例

本文整理汇总了C#中IAgentData.Pack方法的典型用法代码示例。如果您正苦于以下问题:C# IAgentData.Pack方法的具体用法?C# IAgentData.Pack怎么用?C# IAgentData.Pack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAgentData的用法示例。


在下文中一共展示了IAgentData.Pack方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoChildAgentUpdateCall

        public bool DoChildAgentUpdateCall(RegionInfo region, IAgentData cAgentData)
        {
            // Eventually, we want to use a caps url instead of the agentID
            string uri = "http://" + region.ExternalHostName + ":" + region.HttpPort + "/agent/" + cAgentData.AgentID + "/";
            //Console.WriteLine("   >>> DoChildAgentUpdateCall <<< " + uri);

            HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
            ChildUpdateRequest.Method = "PUT";
            ChildUpdateRequest.ContentType = "application/json";
            ChildUpdateRequest.Timeout = AGENT_UPDATE_TIMEOUT;
            //ChildUpdateRequest.KeepAlive = false;
            ChildUpdateRequest.Headers["authorization"] = GenerateAuthorization();

            // Fill it in
            OSDMap args = null;
            try
            {
                args = cAgentData.Pack();
            }
            catch (Exception e)
            {
                m_log.Error("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message);
                return false;
            }

            // Add the regionhandle of the destination region
            ulong regionHandle = GetRegionHandle(region.RegionHandle);
            args["destination_handle"] = OSD.FromString(regionHandle.ToString());

            string strBuffer = "";
            byte[] buffer = new byte[1];
            try
            {
                strBuffer = OSDParser.SerializeJsonString(args);
                UTF8Encoding str = new UTF8Encoding();
                buffer = str.GetBytes(strBuffer);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
                // ignore. buffer will be empty, caller should check.
            }

            Stream os = null;
            try
            { // send the Post
                ChildUpdateRequest.ContentLength = buffer.Length;   //Count bytes to send
                os = ChildUpdateRequest.GetRequestStream();
                os.Write(buffer, 0, strBuffer.Length);         //Send it
                os.Close();
                //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
            }
            catch (WebException)
            {
                // Normal case of network error connecting to a region (e.g. a down one)
                return false;
            }
            catch (Exception ex)
            {
                m_log.ErrorFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
                return false;
            }

            // Let's wait for the response
//            m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate");
            try
            {
                WebResponse webResponse = ChildUpdateRequest.GetResponse();
                if (webResponse != null)
                {
                    StreamReader sr = new StreamReader(webResponse.GetResponseStream());
                    string reply = sr.ReadToEnd().Trim();
                    sr.Close();
                    //m_log.InfoFormat("[REST COMMS]: ChildAgentUpdate reply was {0} ", reply);
                    bool rc = false;
                    if (!bool.TryParse(reply, out rc))
                        rc = false;
                    return rc;
                }
                m_log.Info("[REST COMMS]: Null reply on ChildAgentUpdate post");
            }
            catch (Exception ex)
            {
                m_log.InfoFormat("[REST COMMS]: exception on reply of ChildAgentUpdate {0}", ex.Message);
            }
            return false;
        }
开发者ID:digitalmystic,项目名称:halcyon,代码行数:87,代码来源:RegionClient.cs

示例2: UpdateAgent

        /// <summary>
        /// This is the worker function to send AgentData to a neighbor region
        /// </summary>
        private bool UpdateAgent(GridRegion destination, IAgentData cAgentData, int timeout)
        {
            // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: UpdateAgent start");

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

            try
            {
                OSDMap args = cAgentData.Pack();

                args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
                args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
                args["destination_name"] = OSD.FromString(destination.RegionName);
                args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());

                OSDMap result = WebUtil.PutToServiceCompressed(uri, args, timeout);
                if (result["Success"].AsBoolean())
                    return true;

                result = WebUtil.PutToService(uri, args, timeout);

                return result["Success"].AsBoolean();
            }
            catch (Exception e)
            {
                m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
            }

            return false;
        }
开发者ID:JAllard,项目名称:osmodified,代码行数:34,代码来源:SimulationServiceConnector.cs

示例3: UpdateAgent

        private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
        {
            // Eventually, we want to use a caps url instead of the agentID
            string uri = string.Empty;
            try
            {
                uri = "http://" + destination.ExternalEndPoint.Address + ":" + destination.HttpPort + AgentPath() + cAgentData.AgentID + "/";
            }
            catch (Exception e)
            {
                m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Unable to resolve external endpoint on agent update. Reason: " + e.Message);
                return false;
            }

            if (FailedSends.ContainsKey(uri))
            {
                if (FailedSends[uri] > DateTime.Now)
                    return true; //It completed successfully kinda, lets just let it go
            }
            //Console.WriteLine("   >>> DoAgentUpdateCall <<< " + uri);

            HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
            ChildUpdateRequest.Method = "PUT";
            ChildUpdateRequest.ContentType = "application/json";
            ChildUpdateRequest.Timeout = 30000;
            //ChildUpdateRequest.KeepAlive = false;

            // Fill it in
            OSDMap args = null;
            try
            {
                args = cAgentData.Pack();
            }
            catch (Exception e)
            {
                m_log.Debug("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message);
            }
            // Add the input arguments
            args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
            args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
            args["destination_name"] = OSD.FromString(destination.RegionName);
            args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());

            string strBuffer = "";
            byte[] buffer = new byte[1];
            try
            {
                strBuffer = OSDParser.SerializeJsonString(args);
                Encoding str = Util.UTF8;
                buffer = str.GetBytes(strBuffer);

            }
            catch (Exception e)
            {
                m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
                // ignore. buffer will be empty, caller should check.
            }

            Stream os = null;
            try
            { // send the Post
                ChildUpdateRequest.ContentLength = buffer.Length;   //Count bytes to send
                os = ChildUpdateRequest.GetRequestStream();
                os.Write(buffer, 0, strBuffer.Length);         //Send it
                //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Posted AgentUpdate request to remote sim {0}", uri);
            }
            catch (WebException ex)
            //catch
            {
                m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on AgentUpdate {0}", ex.Message);
                FailedSends.Add(uri, DateTime.Now.AddMinutes(TimeBeforeNextCheck));
                
                return false;
            }
            finally
            {
                if (os != null)
                    os.Close();
            }

            // Let's wait for the response
            //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate");

            WebResponse webResponse = null;
            StreamReader sr = null;
            try
            {
                webResponse = ChildUpdateRequest.GetResponse();
                if (webResponse == null)
                {
                    m_log.Info("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post");
                }

                sr = new StreamReader(webResponse.GetResponseStream());
                //reply = sr.ReadToEnd().Trim();
                sr.ReadToEnd().Trim();
                sr.Close();
                //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);

            }
//.........这里部分代码省略.........
开发者ID:NickyPerian,项目名称:Aurora,代码行数:101,代码来源:SimulationServiceConnector.cs

示例4: UpdateAgent

        private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
        {
            // Try local first
            if (cAgentData is AgentData)
            {
                if (m_localBackend.UpdateAgent(destination, (AgentData) cAgentData))
                    return true;
            }
            else if (cAgentData is AgentPosition)
            {
                if (m_localBackend.UpdateAgent(destination, (AgentPosition) cAgentData))
                    return true;
            }

            // else do the remote thing
            if (!m_localBackend.IsLocalRegion(destination.RegionHandle))
            {
                // Eventually, we want to use a caps url instead of the agentID
                string uri = MakeUri(destination, true) + cAgentData.AgentID + "/";

                if (m_blackListedRegions.ContainsKey(uri))
                {
                    //Check against time
                    if (m_blackListedRegions[uri] > 3 &&
                        Util.EnvironmentTickCountSubtract(m_blackListedRegions[uri]) > 0)
                    {
                        MainConsole.Instance.Warn("[SimServiceConnector]: Blacklisted region " + destination.RegionName + " requested");
                        //Still blacklisted
                        return false;
                    }
                }
                try
                {
                    OSDMap args = cAgentData.Pack();

                    args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
                    args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
                    args["destination_name"] = OSD.FromString(destination.RegionName);
                    args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());

                    OSDMap result = WebUtils.PutToService(uri, args, true, true, false);
                    if (!result["Success"].AsBoolean())
                    {
                        if (m_blackListedRegions.ContainsKey(uri))
                        {
                            if (m_blackListedRegions[uri] == 3)
                            {
                                //add it to the blacklist as the request completely failed 3 times
                                m_blackListedRegions[uri] = Util.EnvironmentTickCount() + 60*1000; //60 seconds
                            }
                            else if (m_blackListedRegions[uri] == 0)
                                m_blackListedRegions[uri]++;
                        }
                        else
                            m_blackListedRegions[uri] = 0;
                        return result["Success"].AsBoolean();
                    }
                    //Clear out the blacklist if it went through
                    m_blackListedRegions.Remove(uri);

                    OSDMap innerResult = (OSDMap) result["_Result"];
                    return innerResult["Updated"].AsBoolean();
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e);
                }

                return false;
            }

            return false;
        }
开发者ID:savino1976,项目名称:Aurora-Sim,代码行数:73,代码来源:SimulationServiceConnector.cs

示例5: DoChildAgentUpdateCall

        public bool DoChildAgentUpdateCall(GridRegion region, IAgentData cAgentData)
        {
            // Eventually, we want to use a caps url instead of the agentID
            string uri = string.Empty;
            try
            {
                uri = "http://" + region.ExternalEndPoint.Address + ":" + region.HttpPort + "/agent/" + cAgentData.AgentID + "/";
            }
            catch (Exception e)
            {
                m_log.Debug("[REST COMMS]: Unable to resolve external endpoint on agent update. Reason: " + e.Message);
                return false;
            }
            //Console.WriteLine("   >>> DoChildAgentUpdateCall <<< " + uri);

            HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
            ChildUpdateRequest.Method = "PUT";
            ChildUpdateRequest.ContentType = "application/json";
            ChildUpdateRequest.Timeout = 10000;
            //ChildUpdateRequest.KeepAlive = false;

            // Fill it in
            OSDMap args = null;
            try
            {
                args = cAgentData.Pack();
            }
            catch (Exception e)
            {
                m_log.Debug("[REST COMMS]: PackUpdateMessage failed with exception: " + e.Message);
            }
            // Add the regionhandle of the destination region
            ulong regionHandle = GetRegionHandle(region.RegionHandle);
            args["destination_handle"] = OSD.FromString(regionHandle.ToString());

            string strBuffer = "";
            byte[] buffer = new byte[1];
            try
            {
                strBuffer = OSDParser.SerializeJsonString(args);
                Encoding str = Util.UTF8;
                buffer = str.GetBytes(strBuffer);

            }
            catch (Exception e)
            {
                m_log.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
                // ignore. buffer will be empty, caller should check.
            }

            Stream os = null;
            try
            { // send the Post
                ChildUpdateRequest.ContentLength = buffer.Length;   //Count bytes to send
                os = ChildUpdateRequest.GetRequestStream();
                os.Write(buffer, 0, strBuffer.Length);         //Send it
                //m_log.InfoFormat("[REST COMMS]: Posted ChildAgentUpdate request to remote sim {0}", uri);
            }
            //catch (WebException ex)
            catch
            {
                //m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);

                return false;
            }
            finally
            {
                if (os != null)
                    os.Close();
            }

            // Let's wait for the response
            //m_log.Info("[REST COMMS]: Waiting for a reply after ChildAgentUpdate");

            WebResponse webResponse = null;
            StreamReader sr = null;
            try
            {
                webResponse = ChildUpdateRequest.GetResponse();
                if (webResponse == null)
                {
                    m_log.Info("[REST COMMS]: Null reply on ChilAgentUpdate post");
                }

                sr = new StreamReader(webResponse.GetResponseStream());
                //reply = sr.ReadToEnd().Trim();
                sr.ReadToEnd().Trim();
                sr.Close();
                //m_log.InfoFormat("[REST COMMS]: ChilAgentUpdate reply was {0} ", reply);

            }
            catch (WebException ex)
            {
                m_log.InfoFormat("[REST COMMS]: exception on reply of ChilAgentUpdate {0}", ex.Message);
                // ignore, really
            }
            finally
            {
                if (sr != null)
                    sr.Close();
//.........这里部分代码省略.........
开发者ID:AlphaStaxLLC,项目名称:taiga,代码行数:101,代码来源:RegionClient.cs


注:本文中的IAgentData.Pack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。