本文整理汇总了C#中AgentCircuitData.PackAgentCircuitData方法的典型用法代码示例。如果您正苦于以下问题:C# AgentCircuitData.PackAgentCircuitData方法的具体用法?C# AgentCircuitData.PackAgentCircuitData怎么用?C# AgentCircuitData.PackAgentCircuitData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AgentCircuitData
的用法示例。
在下文中一共展示了AgentCircuitData.PackAgentCircuitData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoCreateChildAgentCall
public bool DoCreateChildAgentCall(RegionInfo region, AgentCircuitData aCircuit, string authKey, out string reason)
{
// Eventually, we want to use a caps url instead of the agentID
string uri = "http://" + region.ExternalHostName + ":" + region.HttpPort + "/agent/" + aCircuit.AgentID + "/";
//Console.WriteLine(" >>> DoCreateChildAgentCall <<< " + uri);
HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
AgentCreateRequest.Method = "POST";
AgentCreateRequest.ContentType = "application/json";
AgentCreateRequest.Timeout = 10000;
//AgentCreateRequest.KeepAlive = false;
AgentCreateRequest.Headers["authorization"] = GenerateAuthorization();
reason = String.Empty;
// Fill it in
OSDMap args = null;
try
{
args = aCircuit.PackAgentCircuitData();
}
catch (Exception e)
{
m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
reason = "PackAgentCircuitData exception";
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.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
// ignore. buffer will be empty, caller should check.
}
Stream os = null;
try
{ // send the Post
AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
os = AgentCreateRequest.GetRequestStream();
os.Write(buffer, 0, strBuffer.Length); //Send it
os.Close();
//m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
}
//catch (WebException ex)
catch
{
//m_log.InfoFormat("[REST COMMS]: Bad send on ChildAgentUpdate {0}", ex.Message);
reason = "cannot contact remote region";
return false;
}
// Let's wait for the response
//m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
try
{
WebResponse webResponse = AgentCreateRequest.GetResponse();
if (webResponse == null)
{
m_log.Info("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
reason = "response is null";
return false;
}
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string response = sr.ReadToEnd().Trim();
sr.Close();
m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
if (String.IsNullOrEmpty(response))
{
reason = "response is empty";
return false;
}
try
{
// we assume we got an OSDMap back
OSDMap r = GetOSDMap(response);
bool success = r["success"].AsBoolean();
reason = r["reason"].AsString();
return success;
}
catch (NullReferenceException e)
{
m_log.InfoFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
// check for old style response
if (response.ToLower().StartsWith("true"))
//.........这里部分代码省略.........
示例2: TestAgentCircuitDataOSDConversion
public void TestAgentCircuitDataOSDConversion()
{
AgentCircuitData Agent1Data = new AgentCircuitData();
Agent1Data.AgentID = AgentId;
Agent1Data.Appearance = AvAppearance;
Agent1Data.BaseFolder = BaseFolder;
Agent1Data.CapsPath = CapsPath;
Agent1Data.child = false;
Agent1Data.ChildrenCapSeeds = ChildrenCapsPaths;
Agent1Data.circuitcode = circuitcode;
Agent1Data.firstname = firstname;
Agent1Data.InventoryFolder = BaseFolder;
Agent1Data.lastname = lastname;
Agent1Data.SecureSessionID = SecureSessionId;
Agent1Data.SessionID = SessionId;
Agent1Data.startpos = StartPos;
OSDMap map2;
OSDMap map = Agent1Data.PackAgentCircuitData();
try
{
string str = OSDParser.SerializeJsonString(map);
//System.Console.WriteLine(str);
map2 = (OSDMap) OSDParser.DeserializeJson(str);
}
catch (System.NullReferenceException)
{
//spurious litjson errors :P
map2 = map;
Assert.That(1==1);
return;
}
AgentCircuitData Agent2Data = new AgentCircuitData();
Agent2Data.UnpackAgentCircuitData(map2);
Assert.That((Agent1Data.AgentID == Agent2Data.AgentID));
Assert.That((Agent1Data.BaseFolder == Agent2Data.BaseFolder));
Assert.That((Agent1Data.CapsPath == Agent2Data.CapsPath));
Assert.That((Agent1Data.child == Agent2Data.child));
Assert.That((Agent1Data.ChildrenCapSeeds.Count == Agent2Data.ChildrenCapSeeds.Count));
Assert.That((Agent1Data.circuitcode == Agent2Data.circuitcode));
Assert.That((Agent1Data.firstname == Agent2Data.firstname));
Assert.That((Agent1Data.InventoryFolder == Agent2Data.InventoryFolder));
Assert.That((Agent1Data.lastname == Agent2Data.lastname));
Assert.That((Agent1Data.SecureSessionID == Agent2Data.SecureSessionID));
Assert.That((Agent1Data.SessionID == Agent2Data.SessionID));
Assert.That((Agent1Data.startpos == Agent2Data.startpos));
/*
Enable this once VisualParams go in the packing method
for (int i = 0; i < 208; i++)
Assert.That((Agent1Data.Appearance.VisualParams[i] == Agent2Data.Appearance.VisualParams[i]));
*/
}
示例3: DoCreateChildAgentCallAsync
public async Task<Tuple<bool, string>> DoCreateChildAgentCallAsync(SimpleRegionInfo regionInfo, AgentCircuitData aCircuit)
{
string uri = regionInfo.InsecurePublicHTTPServerURI + "/agent/" + aCircuit.AgentID + "/";
HttpWebRequest agentCreateRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
agentCreateRequest.Method = "POST";
agentCreateRequest.ContentType = "application/json";
agentCreateRequest.Timeout = AGENT_UPDATE_TIMEOUT;
agentCreateRequest.ReadWriteTimeout = AGENT_UPDATE_TIMEOUT;
agentCreateRequest.Headers["authorization"] = GenerateAuthorization();
OSDMap args = null;
try
{
args = aCircuit.PackAgentCircuitData();
}
catch (Exception e)
{
m_log.Debug("[REST COMMS]: PackAgentCircuitData failed with exception: " + e.Message);
return Tuple.Create(false, "PackAgentCircuitData exception");
}
// Add the regionhandle of the destination region
ulong regionHandle = GetRegionHandle(regionInfo.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.WarnFormat("[REST COMMS]: Exception thrown on serialization of ChildCreate: {0}", e.Message);
return Tuple.Create(false, "Exception thrown on serialization of ChildCreate");
}
try
{ // send the Post
agentCreateRequest.ContentLength = buffer.Length; //Count bytes to send
Stream os = await agentCreateRequest.GetRequestStreamAsync();
await os.WriteAsync(buffer, 0, strBuffer.Length); //Send it
await os.FlushAsync();
os.Close();
//m_log.InfoFormat("[REST COMMS]: Posted CreateChildAgent request to remote sim {0}", uri);
}
catch (Exception e)
{
m_log.WarnFormat("[REST COMMS]: Unable to contact remote region {0}: {1}", regionInfo.RegionHandle, e.Message);
return Tuple.Create(false, "cannot contact remote region");
}
// Let's wait for the response
//m_log.Info("[REST COMMS]: Waiting for a reply after DoCreateChildAgentCall");
try
{
WebResponse webResponse = await agentCreateRequest.GetResponseAsync(AGENT_UPDATE_TIMEOUT);
if (webResponse == null)
{
m_log.Warn("[REST COMMS]: Null reply on DoCreateChildAgentCall post");
return Tuple.Create(false, "response from remote region was null");
}
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string response = await sr.ReadToEndAsync();
response.Trim();
sr.Close();
//m_log.InfoFormat("[REST COMMS]: DoCreateChildAgentCall reply was {0} ", response);
if (String.IsNullOrEmpty(response))
{
m_log.Info("[REST COMMS]: Empty response on DoCreateChildAgentCall post");
return Tuple.Create(false, "response from remote region was empty");
}
try
{
// we assume we got an OSDMap back
OSDMap r = GetOSDMap(response);
bool success = r["success"].AsBoolean();
string reason = r["reason"].AsString();
return Tuple.Create(success, reason);
}
catch (NullReferenceException e)
{
m_log.WarnFormat("[REST COMMS]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
// check for old style response
if (response.ToLower().StartsWith("true"))
return Tuple.Create(true, "");
return Tuple.Create(false, "exception on reply of DoCreateChildAgentCall");
}
//.........这里部分代码省略.........
示例4: CreateAgent
public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
{
// m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: CreateAgent start");
myipaddress = String.Empty;
reason = String.Empty;
if (destination == null)
{
m_log.Debug ("[GATEKEEPER SERVICE CONNECTOR]: Given destination is null");
return false;
}
string uri = (destination.ServerURI.EndsWith ("/") ? destination.ServerURI : (destination.ServerURI + "/"))
+ AgentPath () + aCircuit.AgentID + "/";
try
{
OSDMap args = aCircuit.PackAgentCircuitData ();
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 ());
args["teleport_flags"] = OSD.FromString (flags.ToString ());
OSDMap result = WebUtils.PostToService (uri, args, true, true);
if (result["Success"].AsBoolean ())
{
OSDMap unpacked = (OSDMap)result["_Result"];
if (unpacked != null)
{
reason = unpacked["reason"].AsString ();
myipaddress = unpacked["your_ip"].AsString ();
return unpacked["success"].AsBoolean ();
}
}
reason = result["Message"] != null ? result["Message"].AsString () : "error";
return false;
}
catch (Exception e)
{
m_log.Warn ("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString ());
reason = e.Message;
}
return false;
}