From 3a9ab04ae50f7e0cf66dc2f0de332f8aeae092d8 Mon Sep 17 00:00:00 2001 From: MyAngelKamikaze Date: Tue, 1 Oct 2024 11:40:22 +0900 Subject: [PATCH] remove telegram --- ElectronicObserver/App.xaml.cs | 2 - ElectronicObserver/FormMainWpf.xaml | 1 - .../ViewModels/FormMainViewModel.cs | 7 - .../FormMainTranslationViewModel.cs | 1 - .../Window/Tools/Telegram/Channel.cs | 35 ---- .../Window/Tools/Telegram/Guid.cs | 13 -- .../Window/Tools/Telegram/Image.cs | 16 -- .../Window/Tools/Telegram/Item.cs | 25 --- .../Window/Tools/Telegram/Link.cs | 16 -- .../Window/Tools/Telegram/Rss.cs | 19 -- .../Tools/Telegram/TelegramResources.en.resx | 123 ------------- .../Tools/Telegram/TelegramResources.resx | 103 ----------- .../Telegram/TelegramTranslationViewModel.cs | 10 -- .../Tools/Telegram/TelegramViewModel.cs | 164 ------------------ .../Window/Tools/Telegram/TelegramWindow.xaml | 78 --------- .../Tools/Telegram/TelegramWindow.xaml.cs | 13 -- .../Window/Tools/Telegram/TweetViewModel.cs | 24 --- 17 files changed, 650 deletions(-) delete mode 100644 ElectronicObserver/Window/Tools/Telegram/Channel.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/Guid.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/Image.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/Item.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/Link.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/Rss.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/TelegramResources.en.resx delete mode 100644 ElectronicObserver/Window/Tools/Telegram/TelegramResources.resx delete mode 100644 ElectronicObserver/Window/Tools/Telegram/TelegramTranslationViewModel.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/TelegramViewModel.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/TelegramWindow.xaml delete mode 100644 ElectronicObserver/Window/Tools/Telegram/TelegramWindow.xaml.cs delete mode 100644 ElectronicObserver/Window/Tools/Telegram/TweetViewModel.cs diff --git a/ElectronicObserver/App.xaml.cs b/ElectronicObserver/App.xaml.cs index e7124cd49..1ba4d1198 100644 --- a/ElectronicObserver/App.xaml.cs +++ b/ElectronicObserver/App.xaml.cs @@ -68,7 +68,6 @@ using ElectronicObserver.Window.Tools.SortieRecordViewer.Sortie.Battle.Phase; using ElectronicObserver.Window.Tools.SortieRecordViewer.SortieCostViewer; using ElectronicObserver.Window.Tools.SortieRecordViewer.SortieDetail; -using ElectronicObserver.Window.Tools.Telegram; using ElectronicObserver.Window.Wpf; using ElectronicObserver.Window.Wpf.EquipmentUpgradePlanViewer; using ElectronicObserver.Window.Wpf.ExpeditionCheck; @@ -306,7 +305,6 @@ private void ConfigureServices() .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() .AddSingleton() // tools .AddSingleton() diff --git a/ElectronicObserver/FormMainWpf.xaml b/ElectronicObserver/FormMainWpf.xaml index 39e83cda4..94f1ace38 100644 --- a/ElectronicObserver/FormMainWpf.xaml +++ b/ElectronicObserver/FormMainWpf.xaml @@ -716,7 +716,6 @@ - EquipmentUpgradePlannerResources.Title; public string AutoRefreshTitle => AutoRefreshResources.Title; public string ExpeditionCalculatorTitle => ExpeditionCalculatorResources.Title; - public string Telegram => TelegramResources.Title; public string StripMenu_Debug => MainResources.Debug.Replace("_", "__").Replace("&", "_"); public string StripMenu_Debug_LoadAPIFromFile => MainResources.Debug_LoadAPIFromFile.Replace("_", "__").Replace("&", "_"); diff --git a/ElectronicObserver/Window/Tools/Telegram/Channel.cs b/ElectronicObserver/Window/Tools/Telegram/Channel.cs deleted file mode 100644 index 92a670b74..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/Channel.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Collections.Generic; -using System.Xml.Serialization; - -namespace ElectronicObserver.Window.Tools.Telegram; - -[XmlRoot(ElementName = "channel")] -public class Channel -{ - [XmlElement(ElementName = "title")] - public string Title { get; set; } = ""; - - [XmlElement(ElementName = "link")] - public List Link { get; set; } = new(); - - [XmlElement(ElementName = "description")] - public string Description { get; set; } = ""; - - [XmlElement(ElementName = "generator")] - public string Generator { get; set; } = ""; - - [XmlElement(ElementName = "webMaster")] - public string WebMaster { get; set; } = ""; - - [XmlElement(ElementName = "language")] - public string Language { get; set; } = ""; - - [XmlElement(ElementName = "image")] - public Image Image { get; set; } = new(); - - [XmlElement(ElementName = "ttl")] - public int Ttl { get; set; } - - [XmlElement(ElementName = "item")] - public List Item { get; set; } = new(); -} diff --git a/ElectronicObserver/Window/Tools/Telegram/Guid.cs b/ElectronicObserver/Window/Tools/Telegram/Guid.cs deleted file mode 100644 index 0e34c7211..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/Guid.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Xml.Serialization; - -namespace ElectronicObserver.Window.Tools.Telegram; - -[XmlRoot(ElementName = "guid")] -public class Guid -{ - [XmlAttribute(AttributeName = "isPermaLink")] - public bool IsPermaLink { get; set; } - - [XmlText] - public string Text { get; set; } = ""; -} diff --git a/ElectronicObserver/Window/Tools/Telegram/Image.cs b/ElectronicObserver/Window/Tools/Telegram/Image.cs deleted file mode 100644 index 48e5588d5..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/Image.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Xml.Serialization; - -namespace ElectronicObserver.Window.Tools.Telegram; - -[XmlRoot(ElementName = "image")] -public class Image -{ - [XmlElement(ElementName = "url")] - public string Url { get; set; } = ""; - - [XmlElement(ElementName = "title")] - public string Title { get; set; } = ""; - - [XmlElement(ElementName = "link")] - public string Link { get; set; } = ""; -} diff --git a/ElectronicObserver/Window/Tools/Telegram/Item.cs b/ElectronicObserver/Window/Tools/Telegram/Item.cs deleted file mode 100644 index e27ef5344..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/Item.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Xml.Serialization; - -namespace ElectronicObserver.Window.Tools.Telegram; - -[XmlRoot(ElementName = "item")] -public class Item -{ - [XmlElement(ElementName = "title")] - public string Title { get; set; } = ""; - - [XmlElement(ElementName = "description")] - public string Description { get; set; } = ""; - - [XmlElement(ElementName = "pubDate")] - public string PubDate { get; set; } = ""; - - [XmlElement(ElementName = "guid")] - public Guid Guid { get; set; } = new(); - - [XmlElement(ElementName = "link")] - public string Link { get; set; } = ""; - - [XmlElement(ElementName = "author")] - public string Author { get; set; } = ""; -} diff --git a/ElectronicObserver/Window/Tools/Telegram/Link.cs b/ElectronicObserver/Window/Tools/Telegram/Link.cs deleted file mode 100644 index e1cb99873..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/Link.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Xml.Serialization; - -namespace ElectronicObserver.Window.Tools.Telegram; - -[XmlRoot(ElementName = "link")] -public class Link -{ - [XmlAttribute(AttributeName = "href")] - public string Href { get; set; } = ""; - - [XmlAttribute(AttributeName = "rel")] - public string Rel { get; set; } = ""; - - [XmlAttribute(AttributeName = "type")] - public string Type { get; set; } = ""; -} diff --git a/ElectronicObserver/Window/Tools/Telegram/Rss.cs b/ElectronicObserver/Window/Tools/Telegram/Rss.cs deleted file mode 100644 index 10668b904..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/Rss.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Xml.Serialization; - -namespace ElectronicObserver.Window.Tools.Telegram; - -[XmlRoot(ElementName = "rss")] -public class Rss -{ - [XmlElement(ElementName = "channel")] - public Channel Channel { get; set; } = new(); - - [XmlAttribute(AttributeName = "atom")] - public string Atom { get; set; } = ""; - - [XmlAttribute(AttributeName = "version")] - public double Version { get; set; } - - [XmlText] - public string Text { get; set; } = ""; -} diff --git a/ElectronicObserver/Window/Tools/Telegram/TelegramResources.en.resx b/ElectronicObserver/Window/Tools/Telegram/TelegramResources.en.resx deleted file mode 100644 index 38f8d0af2..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/TelegramResources.en.resx +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Telegram - - \ No newline at end of file diff --git a/ElectronicObserver/Window/Tools/Telegram/TelegramResources.resx b/ElectronicObserver/Window/Tools/Telegram/TelegramResources.resx deleted file mode 100644 index 6b6ce84a9..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/TelegramResources.resx +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 運営電文 - - \ No newline at end of file diff --git a/ElectronicObserver/Window/Tools/Telegram/TelegramTranslationViewModel.cs b/ElectronicObserver/Window/Tools/Telegram/TelegramTranslationViewModel.cs deleted file mode 100644 index cfe71328d..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/TelegramTranslationViewModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using ElectronicObserver.ViewModels.Translations; - -namespace ElectronicObserver.Window.Tools.Telegram; - -public class TelegramTranslationViewModel : TranslationBaseViewModel -{ - public string Title => TelegramResources.Title; - - public string Search => SortieRecordViewerResources.Search; -} diff --git a/ElectronicObserver/Window/Tools/Telegram/TelegramViewModel.cs b/ElectronicObserver/Window/Tools/Telegram/TelegramViewModel.cs deleted file mode 100644 index c09693782..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/TelegramViewModel.cs +++ /dev/null @@ -1,164 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using System.Timers; -using System.Windows.Media.Imaging; -using System.Xml.Serialization; -using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.DependencyInjection; -using CommunityToolkit.Mvvm.Input; -using ElectronicObserver.Common; - -namespace ElectronicObserver.Window.Tools.Telegram; - -public partial class TelegramViewModel : WindowViewModelBase -{ - private HttpClient Client { get; } = new(); - public TelegramTranslationViewModel TelegramTranslation { get; } - - [ObservableProperty] - private List _tweets = new(); - - [ObservableProperty] - private string? _errorMessage; - - private List TweetSources { get; } = new() - { - "https://rsshub.app/twitter/user/c2_staff/excludeReplies=1", - "https://rsshub.app/twitter/user/KanColle_STAFF/excludeReplies=1", - }; - - private Timer Timer { get; } = new() - { - Interval = 1000, - AutoReset = true, - Enabled = true, - }; - private static int Timeout => 10; - - [ObservableProperty] - [NotifyCanExecuteChangedFor(nameof(GetTweetsCommand))] - private int _secondsTillNextFetch; - - [ObservableProperty] - private string _searchButtonText = ""; - - private bool CanSearch => SecondsTillNextFetch <= 0; - - public TelegramViewModel() - { - TelegramTranslation = Ioc.Default.GetRequiredService(); - - SearchButtonText = TelegramTranslation.Search; - - Timer.Elapsed += (_, _) => - { - if (SecondsTillNextFetch is 0) return; - - System.Windows.Application.Current.Dispatcher.BeginInvoke(() => - { - SecondsTillNextFetch -= 1; - - SearchButtonText = SecondsTillNextFetch switch - { - > 0 => SecondsTillNextFetch.ToString(), - _ => TelegramTranslation.Search, - }; - }); - }; - - Timer.Start(); - } - - [RelayCommand(CanExecute = nameof(CanSearch))] - private async Task GetTweets() - { - if (SecondsTillNextFetch > 0) return; - - ErrorMessage = null; - - try - { - IEnumerable tweets = Enumerable.Empty(); - - foreach (Task> item in TweetSources.Select(GetTweets)) - { - tweets = tweets.Concat(await item); - } - - Tweets = tweets - .OrderByDescending(t => t.PubDate) - .ToList(); - - SecondsTillNextFetch = Timeout; - } - catch (Exception ex) - { - Tweets = new(); - ErrorMessage = $"Failed to load tweets: {ex.Message} {ex.StackTrace}"; - } - } - - private async Task> GetTweets(string url) - { - XmlSerializer serializer = new(typeof(Rss)); - HttpResponseMessage response = await Client.GetAsync(url); - Stream xmlStream = await response.Content.ReadAsStreamAsync(); - Rss data = (Rss)serializer.Deserialize(xmlStream)!; - - Stream imageStream = await GetImageStream(data.Channel.Image.Url); - - BitmapImage profileImage = MakeBitmap(imageStream); - - return data.Channel.Item.Select(i => ToTweetViewModel(i, profileImage)).ToList(); - } - - private BitmapImage MakeBitmap(Stream imageStream) - { - BitmapImage bitmap = new(); - - bitmap.BeginInit(); - bitmap.StreamSource = imageStream; - bitmap.CacheOption = BitmapCacheOption.OnLoad; - bitmap.EndInit(); - bitmap.Freeze(); - - return bitmap; - } - - private async Task GetImageStream(string url) - { - url = url.Replace("_normal", "_400x400"); - - HttpResponseMessage imageResponse = await Client.GetAsync(url); - return await imageResponse.Content.ReadAsStreamAsync(); - } - - private static TweetViewModel ToTweetViewModel(Item item, BitmapImage image) => new() - { - Image = image, - Author = item.Author, - Description = ParseDescription(item.Description), - PubDate = DateTime.Parse(item.PubDate).ToLocalTime(), - Link = item.Link - }; - - private static string ParseDescription(string description) - { - int start = description.IndexOf("
", StringComparison.InvariantCulture); - int end = description.IndexOf("
", StringComparison.InvariantCulture); - - if (start > 0 && end > 0 && start < end) - { - description = description[..start]; - } - - description = description.Replace("
", "\n"); - - return WebUtility.HtmlDecode(description); - } -} diff --git a/ElectronicObserver/Window/Tools/Telegram/TelegramWindow.xaml b/ElectronicObserver/Window/Tools/Telegram/TelegramWindow.xaml deleted file mode 100644 index 653078499..000000000 --- a/ElectronicObserver/Window/Tools/Telegram/TelegramWindow.xaml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -