Пример #1
0
        private void RemoveKeys(PhraseAppClient client, IEnumerable <string> removedKeys)
        {
            Console.WriteLine("Removig keys");

            foreach (var removedKey in removedKeys)
            {
                Console.WriteLine($"Removig {removedKey}");
                client.RemoveKey(removedKey);
            }

            NotifyAboutRemovedKeys(client, removedKeys);
        }
Пример #2
0
        private void NotifyAboutRemovedKeys(PhraseAppClient client, IEnumerable <string> removedKeys)
        {
            Console.WriteLine("Sending notification about removed keys");

            var removedKeysCollection = removedKeys.ToList();

            if (!removedKeysCollection.Any())
            {
                return;
            }

            var notificationMessageBuilder = new StringBuilder();

            notificationMessageBuilder.AppendLine("*Из системы перевода удалены следующие ключи:*");

            notificationMessageBuilder.AppendLine(
                string.Join(
                    "\n",
                    removedKeysCollection
                    .Select(key =>
            {
                var keyLink = client.GetKeyLink(key);

                return($"<{keyLink}|{key}>");
            })
                    .Take(MaxRemovedKeysCountToNotify)));

            if (removedKeysCollection.Count > MaxRemovedKeysCountToNotify)
            {
                notificationMessageBuilder.AppendLine(
                    $"И ещё {removedKeysCollection.Count - MaxRemovedKeysCountToNotify} ключей");
            }

            var slackClient = new SlackClient(Config.SlackWebhookUrl);

            new SlackMessageBuilder(slackClient)
            .AsUser("некачественныйперевод.рф")
            .WithIcon(":flag-gb:")
            .ToChannel("#new-translations")
            .WithText(notificationMessageBuilder.ToString())
            .Send();
        }