예제 #1
0
        public string ToXml()
        {
            string s = "<?xml version=\"1.0\"?><methodCall>";

            s += $"<methodName>{XmlRpcValue.EscapeString(MethodName)}</methodName>";
            s += Parameters.ToXml();
            s += "</methodCall>";
            return(s);
        }
예제 #2
0
    protected static string BuildPostData()
    {
        string data = "<llsd><array>";

        foreach (string capabilityName in CapabilityNames)
        {
            data += $"<string>{XmlRpcValue.EscapeString(capabilityName)}</string>"; // TODO: Not nice to depend on XmlRpc here
        }
        data += "</array></llsd>";
        return(data);
    }
예제 #3
0
        protected void ParseResponseAgents(XmlNode node)
        {
            if (node.Name != "array")
            {
                throw new Exception($"Expected <array> got <{node.Name}>");
            }

            foreach (object childObject in node.ChildNodes)
            {
                XmlNode child = (XmlNode)childObject;
                if (child.Name != "map")
                {
                    throw new Exception($"Expected <map> got <{child.Name}>");
                }

                Guid       agentId    = Guid.Empty;
                AvatarName avatarName = new AvatarName();

                child = child.FirstChild;
                while (child != null)
                {
                    string key = child.InnerText;
                    child = child.NextSibling; // Move to value
                    if (child == null)
                    {
                        throw new Exception("Expected a value.");
                    }

                    switch (key)
                    {
                    case "username":
                        // We don't care about this since UserNames are always constructed.
                        //
                        //if (child.Name != "string")
                        //{
                        //    Logger.LogWarning($"AvatarNameCache.ParseResponseAgents: Expected username type string, got \"{child.Name}\"");
                        //}
                        //else
                        //{
                        //    avatarName.UserName = XmlRpcValue.EscapeString(child.InnerText.Trim()); // TODO: Not nice to depend on XmlRpc here
                        //}
                        break;

                    case "display_name":
                        if (child.Name != "string")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $": Expected display_name type string, got \"{child.Name}\"");
                        }
                        else
                        {
                            avatarName.DisplayName = XmlRpcValue.EscapeString(child.InnerText.Trim());     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    case "display_name_next_update":
                        if (child.Name != "date")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected display_name_next_update type date, got \"{child.Name}\"");
                        }
                        else
                        {
                            DateTime time = DateTime.Parse(XmlRpcValue.EscapeString(child.InnerText.Trim()));     // TODO: Not nice to depend on XmlRpc here
                            // TODO: Get the seconds from UNIX epoch
                        }
                        break;

                    case "legacy_first_name":
                        if (child.Name != "string")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected legacy_first_name type string, got \"{child.Name}\"");
                        }
                        else
                        {
                            avatarName.FirstName = XmlRpcValue.EscapeString(child.InnerText.Trim());     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    case "legacy_last_name":
                        if (child.Name != "string")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected legacy_last_name type string, got \"{child.Name}\"");
                        }
                        else
                        {
                            avatarName.LastName = XmlRpcValue.EscapeString(child.InnerText.Trim());     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    case "id":
                        if (child.Name != "uuid")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected id type uuid, got \"{child.Name}\"");
                        }
                        else
                        {
                            agentId = Guid.Parse(XmlRpcValue.EscapeString(child.InnerText.Trim()));     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    case "is_display_name_default":
                        if (child.Name != "boolean")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected is_display_name_default type boolean, got \"{child.Name}\"");
                        }
                        else
                        {
                            bool x = bool.Parse(XmlRpcValue.EscapeString(child.InnerText.Trim()));     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    default:
                        Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Unexpected key \"{child.InnerText}\"");
                        break;
                    }

                    child = child.NextSibling; // Move to next key
                }
                Logger.LogDebug("AvatarNameCache.ParseResponseAgents", $"Parsed: First=\"{avatarName.FirstName}\", Last=\"{avatarName.LastName}\", DisplayName=\"{avatarName.DisplayName}\"");

                // TODO: What if agentId was never received?
                NameCache[agentId] = avatarName;

                if (PendingRequests.ContainsKey(agentId))
                {
                    Request request = PendingRequests[agentId];
                    lock (PendingRequests)
                    {
                        PendingRequests.Remove(agentId);
                    }

                    foreach (Action <Guid, AvatarName> callback in request.Callbacks)
                    {
                        ThreadManager.ExecuteOnMainThread(() => callback.Invoke(agentId, avatarName));
                    }
                }
            }
        }