53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using Nancy;
|
|
using Nancy.Hosting.Self;
|
|
using Nancy.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Media;
|
|
using 电子展板.Base;
|
|
|
|
namespace 电子展板.ViewModels
|
|
{
|
|
public class MainWindowViewModel : ViewModelBase
|
|
{
|
|
private Window window;
|
|
public DelegateCommand<Window> LoadedCommand { get; set; }
|
|
public DelegateCommand<CancelEventArgs> WindowClosingCommand { get; set; }
|
|
public MainWindowViewModel()
|
|
{
|
|
LoadedCommand = new DelegateCommand<Window>(Loaded);
|
|
WindowClosingCommand = new DelegateCommand<CancelEventArgs>(WindowClosing);
|
|
}
|
|
|
|
private void Loaded(Window window)
|
|
{
|
|
this.window = window;
|
|
int screenIndex = 0;
|
|
this.window.Left = (int)(Screen.AllScreens[screenIndex].Bounds.Left / GetDpiScaleX());
|
|
this.window.Top = (int)(Screen.AllScreens[screenIndex].Bounds.Top / GetDpiScaleX());
|
|
this.window.Width = (int)(Screen.AllScreens[screenIndex].Bounds.Width / GetDpiScaleX());
|
|
this.window.Height = (int)(Screen.AllScreens[screenIndex].Bounds.Height / GetDpiScaleX());
|
|
GlobalVariable.WebServer = new NancyHost(new Uri("http://localhost:80"));
|
|
GlobalVariable.WebServer.Start();
|
|
}
|
|
|
|
private void WindowClosing(CancelEventArgs args)
|
|
{
|
|
GlobalVariable.WebServer?.Stop();
|
|
GlobalVariable.WebServer?.Dispose();
|
|
GlobalVariable.WebServer = null;
|
|
Environment.Exit(0);
|
|
}
|
|
public double GetDpiScaleX()
|
|
{
|
|
return VisualTreeHelper.GetDpi(this.window).DpiScaleX;
|
|
}
|
|
}
|
|
}
|