Skip to content

Commit

Permalink
rem - doc - Moved Textify.Online to Nettify
Browse files Browse the repository at this point in the history
---

We've moved Textify.Offline to Nettify as it was released.

---

Type: rem
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Dec 20, 2023
1 parent ebc592d commit 47fb5e0
Show file tree
Hide file tree
Showing 20 changed files with 1,186 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Nettify.Demo/Fixtures/Cases/Addresstigation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Nettify Copyright (C) 2023-2024 Aptivi
//
// This file is part of Nettify
//
// Nettify is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nettify is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using System;
using Nettify.MailAddress;

namespace Nettify.Demo.Fixtures.Cases
{
internal class Addresstigation : IFixture
{
public string FixtureID => "Addresstigation";
public void RunFixture()
{
// Prompt for an e-mail address
Console.Write("Enter an e-mail address: ");
string address = Console.ReadLine();

// Query it
var ispInstance = IspTools.GetIspConfig(address);
var ispMail = ispInstance.EmailProvider;
Console.WriteLine($"ISP Name: {ispMail.DisplayName} [{ispMail.DisplayShortName}]");
Console.WriteLine($"Main domain: {ispMail.DominatingDomain}");
foreach (string domain in ispMail.Domain)
Console.WriteLine($" Domain: {domain}");
foreach (var server in ispMail.IncomingServer)
{
Console.WriteLine($" Incoming server hostname: {server.Hostname}:{server.Port}");
Console.WriteLine($" Socket type: {server.SocketType}");
Console.WriteLine($" Server type: {server.Type}");
Console.WriteLine($" Username: {server.Username}");
Console.WriteLine($" Leave messages on server? {server.Pop3.LeaveMessagesOnServer}");
Console.WriteLine($" Auth methods: {string.Join(", ", server.Authentication)}");
}
Console.WriteLine($"Outgoing server hostname: {ispMail.OutgoingServer.Hostname}:{ispMail.OutgoingServer.Port}");
Console.WriteLine($"Socket type: {ispMail.OutgoingServer.SocketType}");
Console.WriteLine($"Server type: {ispMail.OutgoingServer.Type}");
Console.WriteLine($"Username: {ispMail.OutgoingServer.Username}");
Console.WriteLine($"Auth methods: {string.Join(", ", ispMail.OutgoingServer.AuthenticationMethods)}");
}
}
}
75 changes: 75 additions & 0 deletions Nettify.Demo/Fixtures/Cases/Dictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// Nettify Copyright (C) 2023-2024 Aptivi
//
// This file is part of Nettify
//
// Nettify is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nettify is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using System;
using Nettify.EnglishDictionary;

namespace Nettify.Demo.Fixtures.Cases
{
internal class Dictionary : IFixture
{
public string FixtureID => "Dictionary";
public void RunFixture()
{
// Prompt for a word
Console.Write("Enter a word: ");
string input = Console.ReadLine();

// Analyze them
var result = DictionaryManager.GetWordInfo(input);
foreach (var word in result)
{
// General info
Console.WriteLine($" Word: {word.Word}");
Console.WriteLine($" Phonetic: {word.PhoneticWord}");

// Meanings
foreach (var meaning in word.Meanings)
{
// Part of Speech
Console.WriteLine($" Part of Speech: {meaning.PartOfSpeech}");

// Definitions
foreach (var definition in meaning.Definitions)
{
// A definition and an example
Console.WriteLine($" Definition: {definition.Definition}");
Console.WriteLine($" Example in Sentence: {definition.Example}");

// Synonyms and Antonyms
Console.WriteLine($" Def. Synonyms: {string.Join(", ", definition.Synonyms)}");
Console.WriteLine($" Def. Antonyms: {string.Join(", ", definition.Antonyms)}");
}

// Synonyms and Antonyms
Console.WriteLine($" Base Synonyms: {string.Join(", ", meaning.Synonyms)}");
Console.WriteLine($" Base Antonyms: {string.Join(", ", meaning.Antonyms)}");
}

// Sources
foreach (var source in word.SourceUrls)
Console.WriteLine($" Source: {source}");

// License
var license = word.LicenseInfo;
Console.WriteLine($" License: {license.Name} [{license.Url}]");
}
}
}
}
6 changes: 6 additions & 0 deletions Nettify.Demo/Fixtures/FixtureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ internal static class FixtureManager
{
internal static IFixture[] fixtures =
[
// Addresses
new Addresstigation(),

// Dictionary
new Dictionary(),

// Forecast
new Forecast(),

Expand Down
91 changes: 91 additions & 0 deletions Nettify/EnglishDictionary/DictionaryManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// Nettify Copyright (C) 2023-2024 Aptivi
//
// This file is part of Nettify
//
// Nettify is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nettify is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace Nettify.EnglishDictionary
{
/// <summary>
/// Dictionary management module
/// </summary>
public static partial class DictionaryManager
{
private static readonly List<DictionaryWord> CachedWords = [];
private static readonly HttpClient DictClient = new HttpClient();

/// <summary>
/// Gets the word information and puts it into an array of dictionary words
/// </summary>
public static DictionaryWord[] GetWordInfo(string Word)
{
if (CachedWords.Any((word) => word.Word == Word))
{
// We already have a word, so there is no reason to download it again
return CachedWords.Where((word) => word.Word == Word).ToArray();
}
else
{
// Download the word information
HttpResponseMessage Response = DictClient.GetAsync($"https://api.dictionaryapi.dev/api/v2/entries/en/{Word}").Result;
Response.EnsureSuccessStatusCode();
Stream WordInfoStream = Response.Content.ReadAsStreamAsync().Result;
string WordInfoString = new StreamReader(WordInfoStream).ReadToEnd();

// Serialize it to DictionaryWord to cache it so that we don't have to download it again
DictionaryWord[] Words = (DictionaryWord[])JsonConvert.DeserializeObject(WordInfoString, typeof(DictionaryWord[]));
CachedWords.AddRange(Words);

// Return the word
return [.. CachedWords];
}
}

/// <summary>
/// Gets the word information and puts it into an array of dictionary words
/// </summary>
public static async Task<DictionaryWord[]> GetWordInfoAsync(string Word)
{
if (CachedWords.Any((word) => word.Word == Word))
{
// We already have a word, so there is no reason to download it again
return CachedWords.Where((word) => word.Word == Word).ToArray();
}
else
{
// Download the word information
HttpResponseMessage Response = await DictClient.GetAsync($"https://api.dictionaryapi.dev/api/v2/entries/en/{Word}");
Response.EnsureSuccessStatusCode();
Stream WordInfoStream = await Response.Content.ReadAsStreamAsync();
string WordInfoString = new StreamReader(WordInfoStream).ReadToEnd();

// Serialize it to DictionaryWord to cache it so that we don't have to download it again
DictionaryWord[] Words = (DictionaryWord[])JsonConvert.DeserializeObject(WordInfoString, typeof(DictionaryWord[]));
CachedWords.AddRange(Words);

// Return the word
return [.. CachedWords];
}
}
}
}
Loading

0 comments on commit 47fb5e0

Please sign in to comment.