private List <VkCommands.Data.IData> searchPeople(ISearchProfile sProfile,
                                                          int currentDepth, ISearchSubscriber subscriber)
        {
            List <IData> tergetUsers = new List <IData>();
            Friends      friends     = FriendsHelper.getFriends(CoreId);
            User         user        = null;
            bool         isTarget    = true;

            if (OnFirstStep)
            {
                for (int i = 0; i < friends.Users.Count; i++)
                {
                    if (isStopped)
                    {
                        return(tergetUsers);
                    }

                    user     = friends.Users[i];
                    isTarget = detectTargetUser(sProfile, user);
                    if (isTarget)
                    {
                        if (sProfile.CheckFriends)
                        {
                            if (!FriendsHelper.areFriends(user.Id,
                                                          AuthFactory.getCurrentAuth().InitialUser).GetAreFriends)
                            {
                                tergetUsers.Add(user);
                                subscriber.onItemFoundEvent(new ItemUpdatedEvent(user.Id));
                            }
                        }
                        else
                        {
                            tergetUsers.Add(user);
                            subscriber.onItemFoundEvent(new ItemUpdatedEvent(user.Id));
                        }
                    }
                    if (currentDepth < Depth)
                    {
                        //if (sProfile.Criteria[NextIterationCriteria].Equals(user.NextIterationCriteria))
                        //{
                        CoreId = user.Id;
                        tergetUsers.AddRange(searchPeople(sProfile, currentDepth + 1, subscriber));
                        //}
                    }
                }
            }
            return(tergetUsers);
        }
示例#2
0
        public static List <User> performeTreesSearchForPeople(string coreId, int depth,
                                                               Dictionary <string, string> criteria, ISearchSubscriber subscriber, bool checkFriends)
        {
            ISearchProfile sProfile = SearchProfileFactory.createSearchProfile(SearchType.People);

            strategy =
                SearchStrategyFactory.createTreeSearchStrategy(SearchStrategyType.BalancedTrees);

            strategy.CoreId       = coreId;
            strategy.OnFirstStep  = true;
            strategy.Depth        = depth;
            sProfile.Criteria     = criteria;
            sProfile.CheckFriends = checkFriends;
            List <IData> targets = strategy.search(sProfile, subscriber);

            return(targets.Cast <User>().ToList());
        }
 public override List <VkCommands.Data.IData> search(ISearchProfile sProfile, ISearchSubscriber subscriber)
 {
     isStopped = false;
     subscriber.onSearchStarted();
     if (sProfile.GetType() == typeof(PeopleSearchProfile))
     {
         List <IData> data = searchPeople(sProfile, 0, subscriber);
         subscriber.onSearchFinished();
         return(data);
     }
     else if (sProfile.GetType() == typeof(GroupSearchProfile))
     {
         return(searchGroup(sProfile, 0));
     }
     else
     {
         return(null);
     }
 }
示例#4
0
 public abstract List <IData> search(ISearchProfile sProfile, ISearchSubscriber subscriber);
        private bool detectTargetUser(ISearchProfile sProfile, User user)
        {
            object temp     = null;
            string criteria = string.Empty;
            bool   isTarget = true;

            foreach (KeyValuePair <string, string> entry in sProfile.Criteria)
            {
                PropertyInfo[] propertyInfos = typeof(User).GetProperties();
                for (int j = 0; j < propertyInfos.Length; j++)
                {
                    if (propertyInfos[j].Name.Equals(entry.Key))
                    {
                        temp = propertyInfos[j].GetValue(user, null);
                        if (temp == null)
                        {
                            isTarget = false;
                            break;
                        }
                        criteria = temp.ToString();
                        if (entry.Key.Equals("BDate"))
                        {
                            if (!isInInterval(criteria, entry.Value))
                            {
                                isTarget = false;
                                break;
                            }
                        }
                        else if (entry.Key.Equals("Status"))
                        {
                            string   keywordsStr = Regex.Replace(entry.Value, @"\s+", "");
                            string[] keywords    = null;
                            if (keywordsStr.Contains(","))
                            {
                                keywords = keywordsStr.Split(',');
                            }
                            else
                            {
                                keywords = new string[] { keywordsStr }
                            };
                            foreach (string keyword in keywords)
                            {
                                if (!criteria.Contains(keyword))
                                {
                                    isTarget = false;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (!criteria.Equals(entry.Value))
                            {
                                isTarget = false;
                                break;
                            }
                        }
                    }
                }
            }

            return(isTarget);
        }
 private List <VkCommands.Data.IData> searchGroup(ISearchProfile sProfile, int currentDepth)
 {
     return(null);
 }