Dreamine.Web
1.0.0.0
WPF와 Blazor를 한 코드 흐름으로 연결하고 반복적인 MVVM 코드를 줄이는 오픈소스 FullKit 공식 웹 애플리케이션입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
MainWindow.xaml.cs
이 파일의 문서화 페이지로 가기
1
using
Dreamine.Hybrid.Wpf.Controls;
2
using
Dreamine.Hybrid.Wpf.Hosting;
3
using
Microsoft.Web.WebView2.Wpf;
4
using
System.ComponentModel;
5
using
System.Net.Http;
6
using
System.Windows;
7
8
namespace
DreamineWeb.Views
;
9
18
public
partial class
MainWindow
: Window
19
{
28
private
readonly DreamineBlazorServerHostOptions
_serverOptions
;
29
54
public
MainWindow
(DreamineBlazorServerHostOptions serverOptions)
55
{
56
_serverOptions
= serverOptions ??
throw
new
ArgumentNullException(nameof(serverOptions));
57
InitializeComponent();
58
59
if
(DesignerProperties.GetIsInDesignMode(
this
))
return
;
60
61
Loaded +=
OnLoaded
;
62
}
63
88
private
async
void
OnLoaded
(
object
sender, RoutedEventArgs e)
89
{
90
var webView = HybridWebViewHost.CreateWebView();
91
WebViewHost.Child = webView;
92
93
await
NavigateAsync
(webView, $
"http://localhost:{_serverOptions.Port}"
,
94
_serverOptions
.InstanceId,
"/admin"
);
95
}
96
161
private
static
async Task
NavigateAsync
(WebView2 webView,
string
baseUrl,
string
expectedInstanceId,
162
string
path =
"/admin"
,
int
timeoutMs = 15000,
int
intervalMs = 500)
163
{
164
var targetUrl = $
"{baseUrl}{path}"
;
165
var instanceUrl = $
"{baseUrl}/_dreamine/instance"
;
166
try
167
{
168
await Task.Delay(1200);
169
170
using
var cts =
new
CancellationTokenSource(timeoutMs);
171
using
var http =
new
HttpClient();
172
var alive =
false
;
173
174
while
(!cts.IsCancellationRequested)
175
{
176
try
177
{
178
var
id
= await http.GetStringAsync(instanceUrl, cts.Token);
179
if
(
string
.Equals(
id
.Trim(), expectedInstanceId, StringComparison.Ordinal))
180
{ alive =
true
;
break
; }
181
}
182
catch
(HttpRequestException) { }
183
catch
(TaskCanceledException) { }
184
185
await Task.Delay(intervalMs, cts.Token);
186
}
187
188
if
(!alive)
189
{
190
await HybridWebViewHost.ShowOfflineMessageAsync(webView, targetUrl);
191
return
;
192
}
193
194
webView.Source =
new
Uri(targetUrl);
195
}
196
catch
(TaskCanceledException) { }
197
}
198
}
DreamineWeb.Views
Definition
MainWindow.xaml.cs:8
DreamineWeb.Views.MainWindow.MainWindow
MainWindow(DreamineBlazorServerHostOptions serverOptions)
Definition
MainWindow.xaml.cs:54
DreamineWeb.Views.MainWindow.NavigateAsync
static async Task NavigateAsync(WebView2 webView, string baseUrl, string expectedInstanceId, string path="/admin", int timeoutMs=15000, int intervalMs=500)
Definition
MainWindow.xaml.cs:161
DreamineWeb.Views.MainWindow._serverOptions
readonly DreamineBlazorServerHostOptions _serverOptions
Definition
MainWindow.xaml.cs:28
DreamineWeb.Views.MainWindow.OnLoaded
async void OnLoaded(object sender, RoutedEventArgs e)
Definition
MainWindow.xaml.cs:88
Views
MainWindow.xaml.cs
다음에 의해 생성됨 :
1.17.0