DreamineVMS 1.0.0.0
Windows PC의 RTSP·USB 카메라 영상을 HLS로 변환해 원격 CCTV Viewer에 전달하는 데스크톱 에이전트입니다.
로딩중...
검색중...
일치하는것 없음
Program.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.Hybrid.Interfaces;
2using Dreamine.Hybrid.State;
3using Dreamine.Hybrid.Wpf.DependencyInjection;
4using Dreamine.Hybrid.Wpf.Hosting;
10using DreamineVMS.Services.Auth; // VmsDatabase
18using Microsoft.Extensions.Configuration;
19using Microsoft.Extensions.DependencyInjection;
20using Microsoft.Extensions.Hosting;
21using Microsoft.Extensions.Logging;
22
23namespace DreamineVMS;
24
33public static class Program
34{
43 [STAThread]
44 public static void Main()
45 {
46 HostApplicationBuilder builder = Host.CreateApplicationBuilder();
47
48 builder.Configuration
49 .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
50 .AddJsonFile("appsettings.local.json", optional: true, reloadOnChange: true);
51
52 RegisterOptions(builder);
53 RegisterAuthServices(builder);
54
55 // FFmpeg 경로 자동 확인 및 다운로드 (없으면 로컬 ffmpeg\ffmpeg.exe로 대체)
56 string configuredFfmpegPath = builder.Configuration["Ffmpeg:Path"] ?? @"C:\ffmpeg\bin\ffmpeg.exe";
57 var progress = new Progress<string>(msg => Console.WriteLine($"[FFmpeg] {msg}"));
58 string resolvedFfmpegPath = FfmpegBootstrapper.EnsureAsync(configuredFfmpegPath, progress)
59 .GetAwaiter().GetResult();
60 builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
61 {
62 ["Ffmpeg:Path"] = resolvedFfmpegPath
63 });
67 RegisterHybridState(builder);
71
72 using IHost host = builder.Build();
73
74 // 도메인 핵심 서비스를 미리 인스턴스화하고 Dashboard 상태 동기화를 시작합니다.
75 _ = host.Services.GetRequiredService<IVmsCameraRepository>();
76 _ = host.Services.GetRequiredService<ICameraRuntimeStateService>();
77 _ = host.Services.GetRequiredService<FfmpegHlsStreamService>();
78
79 IVmsDashboardStateService dashboardStateService =
80 host.Services.GetRequiredService<IVmsDashboardStateService>();
81 dashboardStateService.Start();
82
83 host.RunDreamineWpfApp<App>();
84 }
85
102 private static void RegisterOptions(HostApplicationBuilder builder)
103 {
104 builder.Services.Configure<HostOptions>(options =>
105 {
106 options.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
107 });
108
109 builder.Services.Configure<VmsServerOptions>(
110 builder.Configuration.GetSection("VmsServer"));
111
112 builder.Services.Configure<FfmpegOptions>(
113 builder.Configuration.GetSection("Ffmpeg"));
114 }
115
132 private static void RegisterDreamineHybrid(HostApplicationBuilder builder)
133 {
134 builder.Services.AddDreamineHybridWpf();
135 }
136
153 private static void RegisterAuthServices(HostApplicationBuilder builder)
154 {
155 builder.Services.AddSingleton<VmsDatabase>();
156
157 // 에이전트: 중앙 서버 통신 + HLS 세그먼트 업로더
158 builder.Services.AddSingleton<AgentApiClient>();
159 builder.Services.AddHostedService<HlsSegmentPusherService>();
160 }
161
178 private static void RegisterApplicationServices(HostApplicationBuilder builder)
179 {
180 builder.Services.AddSingleton<AgentSettingsWriter>();
181 builder.Services.AddSingleton<AgentSettingsViewModel>();
182 builder.Services.AddSingleton<MainWindow>();
183 builder.Services.AddSingleton<MainWindowViewModel>();
184 }
185
202 private static void RegisterBlazorViewModels(HostApplicationBuilder builder)
203 {
204 builder.Services.AddScoped<LivePageViewModel>();
205 builder.Services.AddScoped<DashboardPageViewModel>();
206 builder.Services.AddScoped<VmsLocalDashboardViewModel>();
207 }
208
225 private static void RegisterCameraServices(HostApplicationBuilder builder)
226 {
227 builder.Services.AddSingleton<IVmsCameraRepository, SqliteCameraRepository>();
228 builder.Services.AddSingleton<ICameraRuntimeStateService, CameraRuntimeStateService>();
229
230 builder.Services.AddSingleton<FfmpegHlsStreamService>();
231
232 builder.Services.AddSingleton<ICameraStreamService>(
233 serviceProvider => serviceProvider.GetRequiredService<FfmpegHlsStreamService>());
234 }
235
252 private static void RegisterHybridState(HostApplicationBuilder builder)
253 {
254 builder.Services.AddSingleton<IHybridStateStore<VmsDashboardState>>(
255 new HybridStateStore<VmsDashboardState>(VmsDashboardState.Empty));
256 }
257
274 private static void RegisterDashboardServices(HostApplicationBuilder builder)
275 {
276 builder.Services.AddSingleton<IVmsDashboardStateService, VmsDashboardStateService>();
277 }
278
295 private static void RegisterHostedServices(HostApplicationBuilder builder)
296 {
297 builder.Services.AddHostedService(
298 serviceProvider => serviceProvider.GetRequiredService<FfmpegHlsStreamService>());
299
300 builder.Services.AddHostedService<VmsBlazorServerHostedService<AppShell>>();
301 }
302}
static void RegisterBlazorViewModels(HostApplicationBuilder builder)
Definition Program.cs:202
static void RegisterDreamineHybrid(HostApplicationBuilder builder)
Definition Program.cs:132
static void RegisterOptions(HostApplicationBuilder builder)
Definition Program.cs:102
static void RegisterHostedServices(HostApplicationBuilder builder)
Definition Program.cs:295
static void RegisterHybridState(HostApplicationBuilder builder)
Definition Program.cs:252
static void RegisterApplicationServices(HostApplicationBuilder builder)
Definition Program.cs:178
static void Main()
Definition Program.cs:44
static void RegisterCameraServices(HostApplicationBuilder builder)
Definition Program.cs:225
static void RegisterAuthServices(HostApplicationBuilder builder)
Definition Program.cs:153
static void RegisterDashboardServices(HostApplicationBuilder builder)
Definition Program.cs:274
static async Task< string > EnsureAsync(string configuredPath, IProgress< string >? progress=null)