This repository has been archived by the owner on Jul 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddPage.xaml.cs
55 lines (45 loc) · 1.63 KB
/
AddPage.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
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Tizen.Wearable.CircularUI.Forms;
using Xamarin.Forms.Xaml;
namespace WakeOnLan
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class AddPage : CirclePage
{
private static Regex _macRegex = new Regex("^[0-9A-Fa-f]{12}$", RegexOptions.Compiled);
public static Regex MacSeparators = new Regex("[-: ]", RegexOptions.Compiled);
public event Action ItemAdded;
/*public static string GetRandomMacAddress()
{
var random = new Random();
var buffer = new byte[6];
random.NextBytes(buffer);
var result = String.Concat(buffer.Select(x => string.Format("{0}:", x.ToString("X2"))).ToArray());
return result.TrimEnd(':');
}*/
public AddPage()
{
InitializeComponent();
// MacField.Text = GetRandomMacAddress();
}
async private void AddClicked(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(NameField.Text) || string.IsNullOrWhiteSpace(MacField.Text))
{
Toast.DisplayText(Resx.AppResources.AllFieldsRequired);
return;
}
var mac = MacSeparators.Replace(MacField.Text, "");
if (!_macRegex.IsMatch(mac))
{
Toast.DisplayText(Resx.AppResources.MacFormat);
return;
}
LanPc.List.Add(new LanPc(NameField.Text, MacField.Text));
ItemAdded?.Invoke();
await Navigation.PopModalAsync();
}
}
}