-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPage.xaml.cs
70 lines (64 loc) · 2.39 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using Alfred.Models.Index;
using Alfred.Storage;
using Alfred.ViewModels.Index;
namespace Alfred
{
/// <summary>
/// Interaction logic for MainPage.xaml
/// </summary>
public partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
InitializeOrUpdateIndex();
rfcIndexList.DocumentContainer = rfcDocuments;
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
if (!Storage.Storage.IndexPath.Exists) return;
RfcIndex index = RfcIndex.FromFile(Storage.Storage.IndexPath.FullName);
rfcIndexList.DataContext = new RfcIndexViewModel(index);
rfcIndexSearch.SearchCriteriaChanged += rfcIndexSearch_SearchCriteriaChanged;
}
private static void InitializeOrUpdateIndex()
{
if (!Storage.Storage.IndexPath.Exists)
{
if (MessageBox.Show("The rfc index was not downloaded yet, download it now?",
"Missing index!",
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
DownloadIndex();
}
else
{
if ((DateTime.Now - Storage.Storage.IndexPath.LastWriteTime).TotalDays > 30)
{
if (MessageBox.Show("The rfc index was not updated since more than 30 days, update it now?",
"Update index?",
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
DownloadIndex();
}
}
}
private static void DownloadIndex()
{
using (var client = new WebClient())
{
client.DownloadFile(Remote.IndexUri, Storage.Storage.IndexPath.FullName);
}
}
private void rfcIndexSearch_SearchCriteriaChanged(object sender, EventArgs e)
{
rfcIndexList.SearchText = rfcIndexSearch.SearchText;
}
private void rfcIndexList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
rfcIndexEntry.DataContext = rfcIndexList.SelectedEntry;
}
}
}