Exemplo n.º 1
0
        public void CheckFriend(object id)
        {
            var friendlist = VkWebRequest.GetFriends((Int32)id);

            foreach (var newFriend in friendlist)
            {
                Add(newFriend, (Int32)id);
            }
            locker.WaitOne();
            //threads += 1;
            locker.ReleaseMutex();
        }
Exemplo n.º 2
0
        public void CheckFriend(object id)
        {
            var friendlist = VkWebRequest.GetFriends((Int32)id);

            foreach (var newFriend in friendlist)
            {
                Add(newFriend, (Int32)id);
                if (SetControl.SetControler.Intersect(newFriend, ThreadId))
                {
                    mutex.WaitOne();
                    if (!Intersection)
                    {
                        Intersection = true;
                        intersect    = newFriend;
                    }
                    mutex.ReleaseMutex();
                    return;
                }
            }
        }
Exemplo n.º 3
0
        public async void CheckFriendAsync(object id)
        {
            var friendlist = await TaskManager <List <ItemInfo> > .RunTask(() => VkWebRequest.GetFriends((Int32)id));

            TaskManager <List <ItemInfo> > .ReleaseTask();

            foreach (var newFriend in friendlist)
            {
                Add(newFriend, (Int32)id);
                if (SetControl.SetControler.Intersect(newFriend, ThreadId) || Intersection)
                {
                    mutex.WaitOne();
                    if (!Intersection)
                    {
                        Intersection = true;
                        intersect    = newFriend;
                    }
                    mutex.ReleaseMutex();
                    await Task.Yield();
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "main";
            Console.WriteLine("Write ur vk id:");
            ItemInfo In = VkWebRequest.HttpVkUserRequest(Console.ReadLine(), "");

            Console.WriteLine("Write id to find:");
            ItemInfo Out = VkWebRequest.HttpVkUserRequest(Console.ReadLine(), "");

            if (In.is_closed || Out.is_closed || !String.IsNullOrEmpty(In.deactivated) || !String.IsNullOrEmpty(Out.deactivated))
            {
                Console.WriteLine("one of this is closed");
                return;
            }
            var timer = System.Diagnostics.Stopwatch.StartNew();

            ThreadPool.QueueUserWorkItem(first.Runtime, In);
            try
            {
                second.Runtime(Out);
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message + " " + Thread.CurrentThread.Name);
                return;
            }
            timer.Stop();
            Console.WriteLine("Time to Seach " + timer.Elapsed);
            if (second.QueueIsEmpty && first.QueueIsEmpty)
            {
                Console.WriteLine("no friends to connect");
            }
            else
            {
                Console.WriteLine("End of seach!");
                PrintResultFromTwoSets(In, Out);
            }
        }
Exemplo n.º 5
0
        public static List <ItemInfo> GetFriends(Int32 id)
        {
            var res = VkWebRequest.HttpVkFriendRequest(id);

            using (var stream = res.GetResponseStream())
            {
                using (var reader = new StreamReader(stream))
                {
                    var json             = reader.ReadToEnd();
                    var jObject          = JObject.Parse(json);
                    var friendlistJToken = jObject["response"]["items"].Children().ToList();
                    if (friendlistJToken != null)
                    {
                        var friendlist = new List <ItemInfo>(friendlistJToken.Select(x => JsonConvert.DeserializeObject <ItemInfo>(x.ToString())));
                        return(friendlist);
                    }
                    else
                    {
                        throw new Exception("List is null");
                    }
                }
            }
        }