Example #1
0
        static void AddInfo()
        {
            string name, num;

            Console.Write("이름: ");
            name = Console.ReadLine();

            Console.Write("전화번호: ");
            num = Console.ReadLine();

            Console.Clear();
            Addresser.Add(new Info(name, num));
            Console.WriteLine($"{Addresser[Addresser.Count - 1].Name} {Addresser[Addresser.Count - 1].Number}가 정상적으로 등록되었습니다.");
            Console.WriteLine("계속 하려면 아무 키나 눌러주세요.");
            Console.ReadLine();
            Console.Clear();
        }
Example #2
0
        /// <summary>
        /// Loads all mutual friends of all friends and saves them into a graph
        /// </summary>
        public void LoadConnections(FriendList fl, BackgroundWorker worker = null)
        {
            data    = new FriendGraph();
            friends = new Dictionary <string, Friend>();

            // creates id->friend addresser
            foreach (Friend f in fl)
            {
                friends.Add(f.id, f);
                data.Add(f, new List <Friend>());
            }

            // downloades mutual friends of every friend in the list
            int i = 0;

            foreach (KeyValuePair <string, Friend> pair in friends)
            {
                if (worker != null && worker.CancellationPending)
                {
                    throw new InterruptedException();
                }

                FriendList mutualFriends = GraphAPI.GetData <FriendList>(pair.Key + "/mutualfriends");

                foreach (Friend f in mutualFriends)
                {
                    if (!data[pair.Value].Contains(f))
                    {
                        data[pair.Value].Add(f);
                    }
                }

                // reporting progress
                if (worker != null)
                {
                    worker.ReportProgress((++i * 100) / friends.Count, i);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Loads saved connection out of a file
        /// </summary>
        public void LoadConnections(string filename, BackgroundWorker worker = null)
        {
            Dictionary <string, List <Friend> > parsedData;

            data    = new FriendGraph();
            friends = new Addresser();

            // loading raw data about friends to an object in an undesired format
            using (FileStream fs = File.Open(filename, FileMode.Open))
                using (StreamReader sr = new StreamReader(fs))
                    using (JsonTextReader jr = new JsonTextReader(sr)) {
                        JsonSerializer serializer = new JsonSerializer();
                        parsedData = serializer.Deserialize <Dictionary <string, List <Friend> > >(jr);
                    }

            // reporting progress
            if (worker != null)
            {
                worker.ReportProgress(15);
            }

            int i = 0;

            // find all distinct friends and create id->friend addresser
            // friends with no mutual friends with us will get lost (but what would they do inside the graph anyway)
            foreach (KeyValuePair <string, List <Friend> > pair in parsedData)
            {
                if (worker != null && worker.CancellationPending)
                {
                    throw new InterruptedException();
                }

                foreach (Friend f in pair.Value)
                {
                    if (!friends.ContainsKey(f.id))
                    {
                        friends.Add(f.id, f);
                        data.Add(f, new List <Friend>());
                    }
                }

                // reporting progress
                if (worker != null)
                {
                    worker.ReportProgress(15 + (++i * 70) / parsedData.Count);
                }
            }

            i = 0;
            // create the real graph out of the list of connections (connect our addresser)
            foreach (KeyValuePair <string, List <Friend> > pair in parsedData)
            {
                foreach (Friend f in pair.Value)
                {
                    data[friends[pair.Key]].Add(friends[f.id]);                     // we add inside friends[f.id] not f so we unify the pointers
                }                                                                   // (and actually toss away a lot of redundant data)

                // reporting progress
                if (worker != null)
                {
                    worker.ReportProgress(85 + (++i * 15) / parsedData.Count);
                }
            }
        }