Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwigdn committed Dec 29, 2023
1 parent e8056c7 commit a016905
Show file tree
Hide file tree
Showing 30 changed files with 53 additions and 398 deletions.
3 changes: 0 additions & 3 deletions SecretSanta/Interfaces/IMailSender.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using SecretSanta.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace SecretSanta.Interfaces
Expand Down
2 changes: 0 additions & 2 deletions SecretSanta/Interfaces/IRandomizer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using SecretSanta.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace SecretSanta.Interfaces
{
Expand Down
3 changes: 0 additions & 3 deletions SecretSanta/Models/Config.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Newtonsoft.Json;
using SecretSanta.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace SecretSanta
{
Expand Down
4 changes: 1 addition & 3 deletions SecretSanta/Models/Participant.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace SecretSanta.Models
{
Expand Down
8 changes: 0 additions & 8 deletions SecretSanta/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
using CommandLine;
using Newtonsoft.Json;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Bson;
using System;
using System.IO;
using System.Linq;
using SecretSanta.Services;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SecretSanta
Expand Down
3 changes: 0 additions & 3 deletions SecretSanta/Services/MailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SecretSanta.Services
Expand Down
78 changes: 38 additions & 40 deletions SecretSanta/Services/ManualConfigService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
using SecretSanta.Models;
using SecretSanta.Utils;

Expand Down Expand Up @@ -36,9 +34,9 @@ public Config GetConfig(LocaleService localeService)

DisplaySeparator(_step++);
config.Participants.AddRange(GetParticipants());

DisplaySeparator(_step++);
var mailProviderSettings = GetMailProviderSettings();
var mailProviderSettings = GetMailProviderSettings();
config.SmtpHost = mailProviderSettings.SMTP_HOST;
config.SmtpPort = mailProviderSettings.SMTP_PORT;

Expand All @@ -54,43 +52,43 @@ public Config GetConfig(LocaleService localeService)

private string GetLanguage()
{
Console.WriteLine();
Console.WriteLine();
WriteSlow("Langue du programme / Software language");
Console.WriteLine();
Console.WriteLine();

Console.WriteLine($" 1. Français");
Console.WriteLine($" 2. English");

Console.WriteLine();
Console.WriteLine();
WriteSlow("Entrez le n° correspondant / Enter the corresponding number:");
Console.Write(" > ");

var lang = GetInteger(ReadLine(), max: 2, errorMessage: "Saisie invalide, veuillez réessayer. Invalid input, please try again.");
return lang == 1
? "fr"
return lang == 1
? "fr"
: "en";
}

private List<Participant> GetParticipants()
{
Console.WriteLine();
WriteSlow(_localeService.Get(LocaleService.QUESTION_PARTICIPANTS));
Console.WriteLine();
Console.WriteLine();
WriteSlow(_localeService.Get(LocaleService.QUESTION_PARTICIPANTS));
Console.WriteLine();
int participantsCount = GetInteger(GetAnswerFrom(_localeService.Get(LocaleService.QUESTION_PARTICIPANTS_COUNT)));

var list = new List<Participant>();
for (int i = 1 ; i <= participantsCount ; i++)
{
{
var participant = new Participant();

participant.Name = CheckDistinctString(
GetAnswerFrom(string.Format(_localeService.Get(LocaleService.QUESTION_PARTICPANT_NAME), i)),
list.Select(o => o.Name),
GetAnswerFrom(string.Format(_localeService.Get(LocaleService.QUESTION_PARTICPANT_NAME), i)),
list.Select(o => o.Name),
_localeService.Get(LocaleService.WARNING_NAME_EXISTS));

participant.Email = CheckDistinctString(
GetAnswerFrom(string.Format(_localeService.Get(LocaleService.QUESTION_PARTICPANT_EMAIL), i)),
list.Select(o => o.Email),
GetAnswerFrom(string.Format(_localeService.Get(LocaleService.QUESTION_PARTICPANT_EMAIL), i)),
list.Select(o => o.Email),
_localeService.Get(LocaleService.WARNING_EMAIL_EXISTS));

list.Add(participant);
Expand All @@ -108,15 +106,15 @@ private MailProviderSettings GetMailProviderSettings()
var settings = MailProviderSettings.Get(AskMailProviderQuestion());
if (settings == null)
settings = AskCustomMailProviderSettings();

return settings;
}

private MailProvider AskMailProviderQuestion()
{
Console.WriteLine();
Console.WriteLine();
WriteSlow(_localeService.Get(LocaleService.QUESTION_USER_PROVIDER));
Console.WriteLine();
Console.WriteLine();

System.Threading.Thread.Sleep(500);

Expand All @@ -125,23 +123,23 @@ private MailProvider AskMailProviderQuestion()
foreach (var value in Enum.GetValues(typeof(MailProvider)))
{
dic.Add(idx, (MailProvider)value);

var displayedValue = (MailProvider)value == MailProvider.UNKOWN
? _localeService.Get(LocaleService.QUESTION_USER_PROVIDER_UNKNOWN)
: $"{value}";

Console.WriteLine($" {idx ++}. {displayedValue}");
}

System.Threading.Thread.Sleep(500);

var selectedProvider = GetAnswerFrom(_localeService.Get(LocaleService.QUESTION_USER_PROVIDER_INDEX));
return dic[GetInteger(selectedProvider, max: idx)];
}

private MailProviderSettings AskCustomMailProviderSettings()
{
Console.WriteLine();
Console.WriteLine();
WriteSlow(_localeService.Get(LocaleService.QUESTION_USER_PROVIDER_MANUAL));

var host = GetAnswerFrom(_localeService.Get(LocaleService.QUESTION_USER_PROVIDER_HOST));
Expand All @@ -152,11 +150,11 @@ private MailProviderSettings AskCustomMailProviderSettings()

private (string email, string password) GetUserCredentials()
{
Console.WriteLine();
WriteSlow(_localeService.Get(LocaleService.QUESTION_USER_EMAIL_SETUP));
var email = GetAnswerFrom(_localeService.Get(LocaleService.QUESTION_USER_EMAIL));
Console.WriteLine();
WriteSlow(_localeService.Get(LocaleService.QUESTION_USER_EMAIL_SETUP));
var email = GetAnswerFrom(_localeService.Get(LocaleService.QUESTION_USER_EMAIL));
var password = GetAnswerFrom(_localeService.Get(LocaleService.QUESTION_USER_PASSWORD));
Console.WriteLine();
Console.WriteLine();
return (email, password);
}

Expand All @@ -169,39 +167,39 @@ public void DisplayEndProcess()
WriteSlow(_localeService.Get(LocaleService.AUTO_THANKS_2), false);
ReadLine();
}

#endregion Questions

#region Utils

private int GetInteger(string answer, int min = 1, int max = Int16.MaxValue, string errorMessage = null)
{
int count;
int count;
while (!int.TryParse(answer, System.Globalization.NumberStyles.Integer, null, out count) || count < min || count > max)
{
Console.WriteLine();
WriteSlow(errorMessage ?? _localeService.Get(LocaleService.WARNING_INTEGER));
Console.Write(" > ");
Console.WriteLine();
WriteSlow(errorMessage ?? _localeService.Get(LocaleService.WARNING_INTEGER));
Console.Write(" > ");
answer = ReadLine();
}
return count;
}

private string CheckDistinctString(string answer, IEnumerable<string> existing, string errorMessage)
{
while (existing.Any(o => o.ToLowerInvariant() == answer.ToLowerInvariant()))
{
Console.WriteLine();
WriteSlow(errorMessage);
Console.Write(" > ");
Console.WriteLine();
WriteSlow(errorMessage);
Console.Write(" > ");
answer = ReadLine();
}
return answer;
}

private string GetAnswerFrom(string question)
{
Console.WriteLine();
Console.WriteLine();
WriteSlow(question);
Console.Write(" > ");
return ReadLine();
Expand Down Expand Up @@ -234,4 +232,4 @@ private string ReadLine()
#endregion Utils

}
}
}
2 changes: 0 additions & 2 deletions SecretSanta/Services/RandomizeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
using SecretSanta.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace SecretSanta.Services
{
Expand Down
7 changes: 0 additions & 7 deletions SecretSanta/Utils/MailMessageFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
using MailKit.Net.Smtp;
using MimeKit;
using MimeKit.Text;
using SecretSanta.Interfaces;
using SecretSanta.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SecretSanta.Services
{
Expand Down
39 changes: 14 additions & 25 deletions SecretSanta/Utils/MailProviderSettings.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
using MailKit.Net.Smtp;
using MimeKit;
using MimeKit.Text;
using SecretSanta.Interfaces;
using SecretSanta.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace SecretSanta.Utils
{
public class MailProviderSettings
Expand All @@ -19,13 +8,13 @@ public class MailProviderSettings
public MailProviderSettings(string host, string port)
{
SMTP_HOST = host;
SMTP_PORT = port;
SMTP_PORT = port;
}

private MailProviderSettings() { }

public static MailProviderSettings Get(MailProvider provider)
{
{
string host;
string port;

Expand All @@ -40,23 +29,23 @@ public static MailProviderSettings Get(MailProvider provider)
host = "smtp.aol.com";
port = "465";
break;

case MailProvider.BOUYGUES:
case MailProvider.BBOX:
host = "smtp.bbox.fr";
port = "587";
break;

case MailProvider.FREE:
host = "smtp.free.fr";
port = "465";
break;

case MailProvider.GMAIL:
host = "smtp.gmail.com";
port = "465";
break;
break;

case MailProvider.HOTMAIL:
host = "smtp.live.com";
port = "587";
Expand All @@ -71,28 +60,28 @@ public static MailProviderSettings Get(MailProvider provider)
host = "smtps.numericable.fr";
port = "587";
break;

case MailProvider.ORANGE:
host = "smtp.orange.fr";
port = "465";
break;

case MailProvider.OUTLOOK:
host = "SMTP.office365.com";
port = "587";
break;

case MailProvider.SFR:
case MailProvider.NEUF:
host = "smtp.sfr.fr";
port = "465";
break;

case MailProvider.YAHOO:
host = "smtp.mail.yahoo.com";
port = "465";
break;

case MailProvider.ZOHO:
host = "smtp.zoho.com";
port = "465";
Expand Down Expand Up @@ -130,4 +119,4 @@ public enum MailProvider
ZOHO,
UNKOWN
}
}
}

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file removed secret-santa-configs/comtat.json/net6.0/MailKit.dll
Binary file not shown.
Binary file removed secret-santa-configs/comtat.json/net6.0/MimeKit.dll
Binary file not shown.
Binary file not shown.
Binary file removed secret-santa-configs/comtat.json/net6.0/SecretSanta
Binary file not shown.
Loading

0 comments on commit a016905

Please sign in to comment.