예제 #1
0
        static void Main(string[] args)
        {
            Setting setting = YamlObject.GetFromFile <Setting>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "setting.yml"));
            var     slack   = new Slack(setting.Token);
            Dictionary <string, List <string> > message = setting.GetMessages();

            var directroy = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "images"));

            Parallel.ForEach(directroy.EnumerateFiles("*", SearchOption.TopDirectoryOnly), new ParallelOptions()
            {
                MaxDegreeOfParallelism = 5
            }, file =>
            {
                var user = file.Name.Replace(file.Extension, "");
                if (!message.ContainsKey(user))
                {
                    Console.WriteLine($"message is not found user: {file.Name}");
                    return;
                }

                var binary = ReadImageFile(file);

                var channel = slack.FileUpload(user, binary).Result;

                message[user].ForEach(x => slack.MessageSend(user, x, channel).Wait());
            });
        }