Exemple #1
0
        public static void VkDumpMessageHistory(string folder)
        {
            var config = ConfigLazy.Value;
            var api    = new Api(config.VkAccessToken, config.VkApiVersion, config.VkUri);

            var dialogs = VkUtils.GetDialogs(api);
            var userIds = dialogs.Select(a => a.Message.UserId).ToList();

            var messages = new List <Message>();

            foreach (var userId in userIds)
            {
                var messageHistory = VkUtils.GetMessageHistory(api, userId);
                messages.AddRange(messageHistory);
            }

            var dateTimeStr = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture)
                              .Replace(":", "_")
                              .Replace("-", "_")
                              .Replace(" ", "_")
                              .Replace("/", "_");

            var serialized = JsonConvert.SerializeObject(messages, Formatting.Indented);
            var fileName   = $@"all_messages_{dateTimeStr}.txt";
            var path       = Path.Combine(folder, fileName);

            File.WriteAllText(path, serialized);
        }
Exemple #2
0
        public static void VkDumpMessages(string folder, int[] userIds)
        {
            var config = ConfigLazy.Value;
            var api    = new Api(config.VkAccessToken, config.VkApiVersion, config.VkUri);

            var dateTimeStr = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture)
                              .Replace(":", "_")
                              .Replace("-", "_")
                              .Replace(" ", "_")
                              .Replace("/", "_");

            foreach (var userId in userIds)
            {
                var messageHistory = VkUtils.GetMessageHistory(api, userId);
                var serialized     = JsonConvert.SerializeObject(messageHistory, Formatting.Indented);
                var fileName       = $@"{userId}_{dateTimeStr}.txt";
                var path           = Path.Combine(folder, fileName);
                File.WriteAllText(path, serialized);
            }
        }