Example #1
0
        ///////////////////////////////////////////////////////////////////////////
        //    Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3    //
        ///////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     Resolves an agent name to an agent UUID by searching the directory
        ///     services.
        /// </summary>
        /// <param name="Client">the OpenMetaverse grid client</param>
        /// <param name="FirstName">the first name of the agent</param>
        /// <param name="LastName">the last name of the agent</param>
        /// <param name="millisecondsTimeout">timeout for the search in milliseconds</param>
        /// <param name="dataTimeout">timeout for receiving answers from services</param>
        /// <param name="alarm">a decaying alarm for retrieving data</param>
        /// <param name="AgentUUID">an object to store the agent UUID</param>
        /// <returns>true if the agent name could be resolved to an UUID</returns>
        private static bool directAgentNameToUUID(GridClient Client, string FirstName, string LastName,
                                                  uint millisecondsTimeout,
                                                  uint dataTimeout,
                                                  DecayingAlarm alarm,
                                                  ref UUID AgentUUID)
        {
            if (string.IsNullOrEmpty(FirstName) || string.IsNullOrEmpty(LastName))
            {
                return(false);
            }
            var agentUUID   = UUID.Zero;
            var requestUUID = UUID.Zero;
            EventHandler <DirPeopleReplyEventArgs> DirPeopleReplyDelegate = (sender, args) =>
            {
                if (!args.QueryID.Equals(requestUUID))
                {
                    return;
                }

                alarm.Alarm(dataTimeout);
                var agentSearchData =
                    args.MatchedPeople.AsParallel().FirstOrDefault(
                        o =>
                        o.FirstName.Equals(FirstName, StringComparison.OrdinalIgnoreCase) &&
                        o.LastName.Equals(LastName, StringComparison.OrdinalIgnoreCase));
                if (!agentSearchData.Equals(default(DirectoryManager.AgentSearchData)))
                {
                    agentUUID = agentSearchData.AgentID;
                    alarm.Signal.Set();
                }
            };

            Client.Directory.DirPeopleReply += DirPeopleReplyDelegate;
            requestUUID = Client.Directory.StartPeopleSearch(
                string.Format(Utils.EnUsCulture, "{0} {1}", FirstName, LastName), 0);
            if (!alarm.Signal.WaitOne((int)millisecondsTimeout, true))
            {
                Client.Directory.DirPeopleReply -= DirPeopleReplyDelegate;
                return(false);
            }
            Client.Directory.DirPeopleReply -= DirPeopleReplyDelegate;
            if (!agentUUID.Equals(UUID.Zero))
            {
                AgentUUID = agentUUID;
                return(true);
            }
            return(false);
        }
Example #2
0
        ///////////////////////////////////////////////////////////////////////////
        //    Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3    //
        ///////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     Resolves a group name to an UUID by using the directory search.
        /// </summary>
        /// <param name="Client">the OpenMetaverse grid client</param>
        /// <param name="GroupName">the name of the group to resolve</param>
        /// <param name="millisecondsTimeout">timeout for the search in milliseconds</param>
        /// <param name="dataTimeout">timeout for receiving answers from services</param>
        /// <param name="alarm">a decaying alarm for retrieving data</param>
        /// <param name="GroupUUID">an object in which to store the UUID of the group</param>
        /// <returns>true if the group name could be resolved to an UUID</returns>
        private static bool directGroupNameToUUID(GridClient Client, string GroupName,
                                                  uint millisecondsTimeout, uint dataTimeout, DecayingAlarm alarm,
                                                  ref UUID GroupUUID)
        {
            if (string.IsNullOrEmpty(GroupName))
            {
                return(false);
            }
            var groupUUID   = UUID.Zero;
            var requestUUID = UUID.Zero;
            EventHandler <DirGroupsReplyEventArgs> DirGroupsReplyDelegate = (sender, args) =>
            {
                if (!args.QueryID.Equals(requestUUID))
                {
                    return;
                }

                alarm.Alarm(dataTimeout);
                var groupSearchData =
                    args.MatchedGroups.AsParallel()
                    .FirstOrDefault(o => o.GroupName.Equals(GroupName, StringComparison.OrdinalIgnoreCase));
                if (!groupSearchData.Equals(default(DirectoryManager.GroupSearchData)))
                {
                    groupUUID = groupSearchData.GroupID;
                    alarm.Signal.Set();
                }
            };

            Client.Directory.DirGroupsReply += DirGroupsReplyDelegate;
            requestUUID = Client.Directory.StartGroupSearch(GroupName, 0, DirectoryManager.DirFindFlags.Groups);
            if (!alarm.Signal.WaitOne((int)millisecondsTimeout, true))
            {
                Client.Directory.DirGroupsReply -= DirGroupsReplyDelegate;
                return(false);
            }
            Client.Directory.DirGroupsReply -= DirGroupsReplyDelegate;
            if (!groupUUID.Equals(UUID.Zero))
            {
                GroupUUID = groupUUID;
                return(true);
            }
            return(false);
        }