public void UnmarkSetDataUsedForUpdates(QueryMatchID queryMatchId)
        {
            if (SetDataUsedByQueryMatches.TryGetValue(queryMatchId, out var dataUsedByQueryMatch))
            {
                foreach (var id in dataUsedByQueryMatch)
                {
                    UnreserveDataForQueryMatch(id, queryMatchId);
                }

                dataUsedByQueryMatch.Clear();
                SetDataUsedByQueryMatches.Remove(queryMatchId);
            }

            var queryId = queryMatchId.queryID;

            if (SetDataUsedByQueries.TryGetValue(queryId, out var dataUsedByQuery))
            {
                dataUsedByQuery.Remove(dataUsedByQueryMatch);
                if (dataUsedByQuery.Count == 0)
                {
                    SetDataUsedByQueries.Remove(queryId);
                }
            }
        }
        public void Register(QueryArgs args)
        {
            var queryMatchId = QueryMatchID.Generate();

            var countBefore = m_Data.Count;

            m_Data.Register(queryMatchId, args);

            // make sure we increment the global counter
            Assert.AreEqual(countBefore + 1, m_Data.Count);

            int index;

            Assert.True(m_Data.MatchIdToIndex.TryGetValue(queryMatchId, out index));
            Assert.True(m_Data.ValidIndices.Contains(index));

            Assert.AreEqual(m_Data.QueryArgs[index], args);
            Assert.AreEqual(m_Data.Exclusivities[index], args.exclusivity);
            Assert.AreEqual(m_Data.UpdateMatchInterval[index], args.commonQueryData.updateMatchInterval);
            Assert.AreEqual(m_Data.TimeOuts[index], args.commonQueryData.timeOut);
            Assert.AreEqual(m_Data.ReAcquireOnLoss[index], args.commonQueryData.reacquireOnLoss);
            Assert.AreEqual(m_Data.Conditions[index], args.conditions);
            Assert.AreEqual(m_Data.TraitRequirements[index], args.traitRequirements);
            Assert.AreEqual(m_Data.AcquireHandlers[index], args.onAcquire);
            Assert.AreEqual(m_Data.UpdateHandlers[index], args.onMatchUpdate);
            Assert.AreEqual(m_Data.LossHandlers[index], args.onLoss);
            Assert.AreEqual(m_Data.TimeoutHandlers[index], args.onTimeout);
            // make sure we got all necessary intermediate / result containers from the pools when we registered
            Assert.NotNull(m_Data.CachedTraits[index]);
            Assert.NotNull(m_Data.ConditionRatings[index]);
            Assert.NotNull(m_Data.ConditionMatchSets[index]);
            Assert.NotNull(m_Data.ReducedConditionRatings[index]);
            Assert.NotNull(m_Data.QueryResults[index]);
            // make sure we initialize the best match id to an invalid id
            Assert.AreEqual(m_Data.BestMatchDataIds[index], (int)ReservedDataIDs.Invalid);
        }
Example #3
0
 /// <summary>
 /// Notifies the MARS backend that a particular query is no longer needed.
 /// This function is not required if the Registration was oneShot - the query will be unregistered automatically
 /// </summary>
 /// <param name="caller">The object that had made a query</param>
 /// <param name="queryMatchID">The identifier of the query</param>
 /// <param name="allMatches">Whether to unregister all matches referring to the same query as <paramref name="queryMatchID"/></param>
 /// <returns>True if the query was stopped, false if the query was not currently running</returns>
 public static bool UnregisterQuery(this IUsesQueryResults caller, QueryMatchID queryMatchID, bool allMatches = false)
 {
     return(IUsesQueryResultsMethods.UnregisterQuery(queryMatchID, allMatches));
 }
Example #4
0
 /// <summary>
 /// Notifies the MARS backend that a particular query's arguments have been modified.
 /// </summary>
 /// <param name="caller">The object making the query</param>
 /// <param name="queryMatchID">The identifier of the query</param>
 /// <param name="queryArgs">The different specified data requirements we are querying for</param>
 public static void ModifyQuery(this IUsesQueryResults caller, QueryMatchID queryMatchID, QueryArgs queryArgs)
 {
     IUsesQueryResultsMethods.ModifyQuery(queryMatchID, queryArgs);
 }
 /// <summary>
 /// Registers to get event(s) from the MARS backend
 /// Allows a user to specify a custom query ID to use - make sure it is unique!
 /// </summary>
 /// <param name="caller">The object making the query</param>
 /// <param name="queryMatchID">The identifier to use for this query</param>
 /// <param name="queryArgs">The different specified data requirements we are querying for</param>
 public static void RegisterQuery(this IUsesQueryResults caller, QueryMatchID queryMatchID, QueryArgs queryArgs)
 {
     IUsesDevQueryResultsMethods.RegisterOverrideQuery(queryMatchID, queryArgs);
 }
 /// <summary>
 /// Checks whether data used by a query match has changed
 /// </summary>
 /// <param name="queryMatchID">ID of the query match using data</param>
 /// <returns>True if the data has changed, false otherwise</returns>
 public static bool QueryDataDirty(this IUsesDatabaseQuerying obj, QueryMatchID queryMatchID)
 {
     return(IUsesDatabaseQueryingMethods.QueryDataDirty(queryMatchID));
 }
 /// <summary>
 /// Tells the database that data is no longer used by a query match
 /// </summary>
 /// <param name="queryMatchID">ID of the query match no longer using its data</param>
 public static void UnmarkDataUsedForUpdates(this IUsesDatabaseQuerying obj, QueryMatchID queryMatchID)
 {
     IUsesDatabaseQueryingMethods.UnmarkDataUsedForUpdates(queryMatchID);
 }
 /// <summary>
 /// Tells the database that data will be used to update a query match
 /// </summary>
 /// <param name="dataID">ID for the data used by a query match</param>
 /// <param name="queryMatchID">ID of the query match using this data</param>
 /// <param name="exclusivity">Specification of how the data should be reserved</param>
 public static void MarkDataUsedForUpdates(this IUsesDatabaseQuerying obj, int dataID, QueryMatchID queryMatchID, Exclusivity exclusivity)
 {
     IUsesDatabaseQueryingMethods.MarkDataUsedForUpdates(dataID, queryMatchID, exclusivity);
 }
 /// <summary>
 /// Called to get set event(s) from the MARS backend
 /// Allows a user to specify a custom query ID to use - make sure it is unique!
 /// </summary>
 /// <param name="caller">The object making the query</param>
 /// <param name="queryMatchID">The identifier to use for this query</param>
 /// <param name="queryArgs">The different specified data requirements we are querying for</param>
 public static void RegisterSetQuery(this IUsesSetQueryResults caller, QueryMatchID queryMatchID, SetQueryArgs queryArgs)
 {
     ISetQueryResultsMethods.RegisterSetOverrideQuery(queryMatchID, queryArgs);
 }
 /// <summary>
 /// Tells the database that data will be used to update a set query match
 /// </summary>
 /// <param name="queryMatchID">ID of the query match using this data</param>
 /// <param name="data">Specification of which data is used for each set child</param>
 public static void MarkSetDataUsedForUpdates(this IUsesDatabaseQuerying obj, QueryMatchID queryMatchID, HashSet <int> data)
 {
     IUsesDatabaseQueryingMethods.MarkSetDataUsedForUpdates(queryMatchID, data);
 }
Example #11
0
        // Test that when we insert a group's arguments, we insert one entry into the group data,
        // one entry per member into the member data, and generate an index mapping between them.
        // Since we have the lower-level query data tests, this mostly tests the mapping between groups & members
        public void RegisterGroupData()
        {
            var relations    = TestUtils.GetRelations(m_GroupQueryTestObject);
            var args         = TestUtils.DefaultSetArgs(relations);
            var queryMatchId = QueryMatchID.Generate();

            m_Pipeline.Register(queryMatchId, args);

            Assert.True(m_Pipeline.Data.MatchIdToIndex.TryGetValue(queryMatchId, out var groupIndex));

            // was the group order weight calculated upon registration?
            Assert.Greater(m_Pipeline.Data.OrderWeights[groupIndex], 0f);

            // one entry in the member indices for every member ?
            var memberIndices = m_Pipeline.Data.MemberIndices[groupIndex];

            Assert.AreEqual(relations.children.Count, memberIndices.Length);

            foreach (var memberIndex in memberIndices)
            {
                // did all member objects get correctly inserted to the member data ?
                var memberObject = m_Pipeline.MemberData.ObjectReferences[memberIndex];
                Assert.Contains(memberObject, relations.children.Keys);
                // is the member index within the bounds of the member data?
                Assert.Less(memberIndex, m_Pipeline.MemberData.Count);

                var memberships = m_Pipeline.MemberData.RelationMemberships[memberIndex];
                // it's OK for the memberships entry to be null - that means this group member is not in any Relations
                if (memberships == null)
                {
                    continue;
                }

                foreach (var membership in memberships)
                {
                    Assert.LessOrEqual(membership.RelationIndex, relations.Count);
                }
            }

            // one entry in the relation index pairs indices for each relation ?
            var relationIndexPairs = m_Pipeline.Data.RelationIndexPairs[groupIndex];

            Assert.AreEqual(relations.Count, relationIndexPairs.Length);

            foreach (var pair in relationIndexPairs)
            {
                Assert.AreNotEqual(pair.Child1, pair.Child2);
                // every member of these pairs should belong to our member indices
                Assert.Contains(pair.Child1, memberIndices);
                Assert.Contains(pair.Child2, memberIndices);
            }

            var localRelationIndexPairs = m_Pipeline.Data.LocalRelationIndexPairs[groupIndex];

            Assert.AreEqual(relations.Count, localRelationIndexPairs.Length);
            foreach (var pair in localRelationIndexPairs)
            {
                Assert.AreNotEqual(pair.Child1, pair.Child2);
                // every member of these pairs should be an index less than the count of members this group has
                Assert.Less(pair.Child1, memberIndices.Length);
                Assert.Less(pair.Child2, memberIndices.Length);
            }

            // check that SearchData got initialized
            var searchData = m_Pipeline.Data.SearchData[groupIndex];

            Assert.NotNull(searchData);
            Assert.AreEqual(searchData.MatchBuffer.SetSize, memberIndices.Length);
            Assert.AreEqual(searchData.MemberRatings.Length, memberIndices.Length);
        }
 /// <summary>
 /// Notifies the MARS backend that a particular set query's arguments have been modified.
 /// </summary>
 /// <param name="caller">The object making the set query.</param>
 /// <param name="queryMatchID">The identifier of the query</param>
 /// <param name="queryArgs">The different specified data requirements we are querying for</param>
 internal static void ModifySetQuery(this IUsesSetQueryResults caller, QueryMatchID queryMatchID,
                                     SetQueryArgs queryArgs)
 {
     ISetQueryResultsMethods.ModifySetQuery(queryMatchID, queryArgs);
 }
 /// <summary>
 /// Revoke the match for a single Proxy in a group, which must not be marked as required.
 /// </summary>
 /// <param name="caller">The object that had made a query</param>
 /// <param name="queryMatchId">The identifier of the query match instance</param>
 /// <param name="memberProxy">The proxy to unmatch.</param>
 /// <returns>True if the proxy had a match that it has now given up, false otherwise</returns>
 internal static bool UnmatchNonRequiredMember(this IUsesSetQueryResults caller, QueryMatchID queryMatchId, IMRObject memberProxy)
 {
     return(ISetQueryResultsMethods.UnmatchNonRequiredMember(queryMatchId, memberProxy));
 }
 /// <summary>
 /// Revoke the matches found for a given ProxyGroup instance
 /// </summary>
 /// <param name="caller">The object that had made a query</param>
 /// <param name="queryMatchId">The identifier of the query match instance</param>
 /// <param name="searchForNewMatch">
 /// If true, the system will try to match the query again without prompting.
 /// If false, a new match will not be found automatically, but must be specified.
 /// </param>
 /// <returns>True if the query had a match which was unset, false if the query had not been matched yet</returns>
 internal static bool UnmatchGroup(this IUsesSetQueryResults caller, QueryMatchID queryMatchId, bool searchForNewMatch = true)
 {
     return(ISetQueryResultsMethods.UnmatchGroupQuery(queryMatchId, searchForNewMatch));
 }
 /// <summary>
 /// Notifies the MARS backend that a particular set query is no longer needed.
 /// This function is not required if the Registration was oneShot - the query will be unregistered automatically
 /// </summary>
 /// <param name="caller">The object that had made a query</param>
 /// <param name="eventMatchId">The identifier of the query</param>
 /// <param name="allMatches">Whether to unregister all matches referring to the same query as <paramref name="eventMatchId"/></param>
 /// <returns>True if the query was stopped, false if the query was not currently running</returns>
 public static bool UnregisterSetQuery(this IUsesSetQueryResults caller, QueryMatchID eventMatchId, bool allMatches = false)
 {
     return(ISetQueryResultsMethods.UnregisterSetQuery(eventMatchId, allMatches));
 }
Example #16
0
 /// <summary>
 /// Try to assign a new data match to a Proxy, instead of the match being picked automatically.
 /// </summary>
 /// <param name="caller">The object that had made a query</param>
 /// <param name="queryMatchId">The query identifier to assign the match for</param>
 /// <param name="newMatchId">The identifier of the data to assign as the match</param>
 /// <param name="matchConditions">
 /// If true, all Conditions on the Proxy must be met by the new data.
 /// If false, the data only has to have all the traits required by the Proxy.
 /// </param>
 /// <returns>A description of the result of the call</returns>
 public static bool AssignQueryMatch(this IUsesQueryResults caller,
                                     QueryMatchID queryMatchId, int newMatchId, bool matchConditions = true)
 {
     return(IUsesQueryResultsMethods.AssignQueryMatch(queryMatchId, newMatchId, matchConditions));
 }
Example #17
0
 // This method is internal so that users call the methods on Proxy / ProxyGroup, which wrap this.
 /// <summary>
 /// Revoke the match found for a given Proxy instance, without removing it from the system.
 /// </summary>
 /// <param name="caller">The object that had made a query</param>
 /// <param name="queryMatchId">The identifier of the query match instance</param>
 /// <param name="searchForNewMatch">
 /// If true, the system will try to match the query again without prompting.
 /// If false, a new match will not be found automatically, but must be specified.
 /// </param>
 /// <returns>True if the query had a match which was unset, false if the query had not been matched yet</returns>
 internal static bool UnmatchProxy(this IUsesQueryResults caller, QueryMatchID queryMatchId, bool searchForNewMatch = true)
 {
     return(IUsesQueryResultsMethods.UnmatchStandaloneProxy(queryMatchId, searchForNewMatch));
 }
 /// <summary>
 /// Tells the database that a certain set of child data is no longer used by a set query match.
 /// This should be used when a set's non-required children are lost, in order to free up their data.
 /// </summary>
 /// <param name="queryMatchID">ID of the query match no longer using some of its data</param>
 /// <param name="childrenToUnmark">Collection of child MR objects whose data should be unmarked</param>
 public static void UnmarkPartialSetDataUsedForUpdates(this IUsesDatabaseQuerying obj, QueryMatchID queryMatchID,
                                                       ICollection <IMRObject> childrenToUnmark)
 {
     IUsesDatabaseQueryingMethods.UnmarkPartialSetDataUsedForUpdates(queryMatchID, childrenToUnmark);
 }