-
Notifications
You must be signed in to change notification settings - Fork 8
/
Program.cs
111 lines (97 loc) · 3.37 KB
/
Program.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Toolbelt.Blazor.Extensions.DependencyInjection;
using Blazored.LocalStorage;
using atomex_frontend.Storages;
using System.Net.Http;
using Plk.Blazor.DragDrop;
using Atomex.Common;
using atomex_frontend.Common;
namespace atomex_frontend
{
public class Program
{
public static async Task Main(string[] args)
{
FileSystem.UseFileSystem(new WebFileSystem());
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddI18nText();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddBlazorDragDrop();
builder.Services.AddScoped<AccountStorage, AccountStorage>();
builder.Services.AddScoped<UserStorage, UserStorage>();
builder.Services.AddScoped<RegisterStorage, RegisterStorage>();
builder.Services.AddScoped<WalletStorage, WalletStorage>();
builder.Services.AddScoped<SwapStorage, SwapStorage>();
builder.Services.AddScoped<BakerStorage, BakerStorage>();
builder.Services.AddScoped<TezosTokenStorage, TezosTokenStorage>();
await builder
.Build()
.UseLocalTimeZone()
.RunAsync();
}
}
public static class EnumExtensions
{
public static T GetAttribute<T>(this Enum value) where T : Attribute
{
var type = value.GetType();
var memberInfo = type.GetMember(value.ToString());
if (memberInfo.Length == 0)
{
return null;
}
var attributes = memberInfo[0].GetCustomAttributes(typeof(T), false);
return attributes.Length > 0
? (T)attributes[0]
: null;
}
public static string ToName(this Enum value)
{
var attribute = value.GetAttribute<DescriptionAttribute>();
return attribute == null ? value.ToString() : attribute.Description;
}
public static T Next<T>(this T src) where T : struct
{
if (!typeof(T).IsEnum) throw new ArgumentException(String.Format("Argument {0} is not an Enum", typeof(T).FullName));
T[] Arr = (T[])Enum.GetValues(src.GetType());
int j = Array.IndexOf<T>(Arr, src) + 1;
return (Arr.Length == j) ? Arr[0] : Arr[j];
}
public static T Previous<T>(this T src) where T : struct
{
if (!typeof(T).IsEnum) throw new ArgumentException(String.Format("Argument {0} is not an Enum", typeof(T).FullName));
T[] Arr = (T[])Enum.GetValues(src.GetType());
int j = Array.IndexOf<T>(Arr, src) - 1;
return (Arr.Length == j) ? Arr[0] : Arr[j];
}
private static Random rng = new Random();
public static void Shuffle<T>(this IList<T> list)
{
int n = list.Count;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
}
public static class DecimalExtension
{
public static decimal TruncateByFormat(this decimal d, string format)
{
var s = d.ToString(format, CultureInfo.InvariantCulture);
return decimal.Parse(s, CultureInfo.InvariantCulture);
}
}
}