예제 #1
0
        public void AppendXMLList()
        {
            ListSerializable <User> users = new UserList();

            users.Add(new User("Toto", "Titi"));
            users.Add(new User("Tata", "Roro"));

            IWriter <User> writer = new XmlWriter <User>();

            writer.Write <UserList>(users, XmlFile);

            ListSerializable <User> OtherUsers = new UserList();

            OtherUsers.Add(new User("lala", "lala"));
            OtherUsers.Add(new User("test", "test"));

            writer.Append <UserList>(OtherUsers, XmlFile, "users");

            IReader <User>    reader    = new XmlReader <User>("users", "user");
            Collection <User> usersList = reader.read <UserList>(XmlFile);

            Assert.AreEqual(4, usersList.Count);
            for (int i = 0; i < users.Count(); i++)
            {
                Assert.AreEqual(users[i].Name, usersList[i].Name);
                Assert.AreEqual(users[i].Firstname, usersList[i].Firstname);
            }

            for (int i = 0; i < OtherUsers.Count(); i++)
            {
                Assert.AreEqual(OtherUsers[i].Name, usersList[i + 2].Name);
                Assert.AreEqual(OtherUsers[i].Firstname, usersList[i + 2].Firstname);
            }
        }
예제 #2
0
        /// <summary>
        /// Mainメソッドです。
        /// </summary>
        /// <param name="args">コマンドライン引数</param>
        static void Main(string[] args)
        {
            // 設定の読み込み
            var builder = new ConfigurationBuilder();

            builder.SetBasePath(Directory.GetCurrentDirectory());
            builder.AddJsonFile("appsettings.json");

            var config = builder.Build();

            // NLogの設定
            LogManager.Configuration = new NLogLoggingConfiguration(config.GetSection("NLog"));

            // loggerの生成
            var logger = LogManager.GetCurrentClassLogger();

            // Twitterオブジェクトの生成
            var twitter = new Twitter(config["Twitter:ConsumerKey"], config["Twitter:ConsumerSecret"],
                                      config["Twitter:AccessToken"], config["Twitter:AccessSecret"]);

            // ルームIdの読み込み
            var roomIds = CsvReader.ReadRoomIds(@"Input\RoomIds.csv");

            // 出力ファイル名
            var fileName = Path.Combine("Output", "followers_" + DateTime.Now.ToString("yyyyMMdd-hhmmss") + ".xml");

            var rooms = new List <Room>();

            foreach (var id in roomIds)
            {
                // ルームの作成
                var room = Room.CreateRoom(id).Result;

                // ルームを追加
                rooms.Add(room);

                // ルームを出力ファイルに追加
                XmlWriter.Append(Path.Combine(fileName), room);

                logger.Info($"{room.Name} {room.FollowerNum}");

                // コンソールに出力
                Console.WriteLine($"{room.Name} {room.FollowerNum}");
            }

            // フォロワー数順に並べる
            rooms = rooms.OrderByDescending(r => r.FollowerNum).ToList();

            // ツイートする内容
            var text = DateTime.Now.ToString() + Environment.NewLine + Environment.NewLine;

            foreach (var r in rooms.Take(5))
            {
                text += $"{r.Name} {r.FollowerNum}" + Environment.NewLine;
            }

            // ツイートする
            twitter.Tweet($"{text}");
        }
예제 #3
0
        public void AppendListXmlFile()
        {
            ListSerializable <User> users = new UserList();

            users.Add(new User("Toto", "Titi"));
            users.Add(new User("Tata", "Roro"));

            IWriter <User> writer = new XmlWriter <User>();

            writer.Append <UserList>(users, "invalidFile.xml", "users");
        }
예제 #4
0
        public void AppendXmlFile()
        {
            User user = new User("Toto", "Titi");

            IWriter <User> writer = new XmlWriter <User>();

            writer.Write(user, XmlFile);

            User user2 = new User("tata", "tata");

            writer.Append <UserList>(user2, "invalidFile.xml");
        }
예제 #5
0
        public void AppendXmlFileWithInvalidElementName()
        {
            ListSerializable <User> users = new UserList();

            users.Add(new User("Toto", "Titi"));
            users.Add(new User("Tata", "Roro"));

            IWriter <User> writer = new XmlWriter <User>();

            writer.Write <UserList>(users, XmlFile);
            ListSerializable <User> users2 = new UserList();

            users2.Add(new User("tata", "tata"));

            writer.Append <UserList>(users2, XmlFile, "");
        }
예제 #6
0
        public void AppendXML()
        {
            User user = new User("Toto", "Titi");

            IWriter <User> writer = new XmlWriter <User>();

            writer.Write(user, XmlFile);

            User user2 = new User("tata", "tata");

            writer.Append <UserList>(user2, XmlFile);

            IReader <User>    reader    = new XmlReader <User>("users", "user");
            Collection <User> usersList = reader.read <UserList>(XmlFile);

            Assert.AreEqual(2, usersList.Count);

            Assert.AreEqual(user.Name, usersList[0].Name);
            Assert.AreEqual(user.Firstname, usersList[0].Firstname);

            Assert.AreEqual(user2.Name, usersList[1].Name);
            Assert.AreEqual(user2.Firstname, usersList[1].Firstname);
        }