-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
91 lines (77 loc) · 3.42 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
using AIStoryBuilders.AI;
using AIStoryBuilders.Model;
using AIStoryBuilders.Models;
using AIStoryBuilders.Services;
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Radzen;
namespace AIStoryBuildersOnline
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// Add services to the container.
AppMetadata appMetadata = new AppMetadata() { Version = "01.02.50" };
builder.Services.AddSingleton(appMetadata);
builder.Services.AddScoped<LogService>();
builder.Services.AddScoped<SettingsService>();
builder.Services.AddScoped<DatabaseService>();
builder.Services.AddScoped<OrchestratorMethods>();
builder.Services.AddScoped<AIStoryBuildersService>();
builder.Services.AddScoped<AIStoryBuildersStoryService>();
builder.Services.AddScoped<AIStoryBuildersTempService>();
// Radzen
builder.Services.AddScoped<DialogService>();
builder.Services.AddScoped<NotificationService>();
builder.Services.AddScoped<TooltipService>();
builder.Services.AddScoped<ContextMenuService>();
// Local Storage
builder.Services.AddBlazoredLocalStorage();
// Load Default files
var folderPath = "";
var filePath = "";
// AIStoryBuilders Directory
folderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}/AIStoryBuilders";
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
// AIStoryBuildersLog.csv
filePath = Path.Combine(folderPath, "AIStoryBuildersLog.csv");
if (!File.Exists(filePath))
{
using (var streamWriter = new StreamWriter(filePath))
{
streamWriter.WriteLine("Application started at " + DateTime.Now + " [" + DateTime.Now.Ticks.ToString() + "]");
}
}
else
{
// File already exists
string[] AIStoryBuildersLog;
// Open the file to get existing content
using (var file = new System.IO.StreamReader(filePath))
{
AIStoryBuildersLog = file.ReadToEnd().Split('\n');
if (AIStoryBuildersLog[AIStoryBuildersLog.Length - 1].Trim() == "")
{
AIStoryBuildersLog = AIStoryBuildersLog.Take(AIStoryBuildersLog.Length - 1).ToArray();
}
}
// Append the text to csv file
using (var streamWriter = new StreamWriter(filePath))
{
streamWriter.WriteLine(string.Join("\n", "Application started at " + DateTime.Now));
streamWriter.WriteLine(string.Join("\n", AIStoryBuildersLog));
}
}
await builder.Build().RunAsync();
}
}
}