99 lines
3.0 KiB
C#
99 lines
3.0 KiB
C#
using Bricscad.ApplicationServices;
|
|
using SWS.CAD.ViewModels.myViewModelBase;
|
|
using SWS.Commons;
|
|
using SWS.Service;
|
|
|
|
namespace SWS.CAD.ViewModels
|
|
{
|
|
public class ConfigViewModel : DialogBase
|
|
{
|
|
private string address;
|
|
public string Address
|
|
{
|
|
get { return this.address; }
|
|
set
|
|
{
|
|
if (value != this.address)
|
|
{
|
|
this.address = value;
|
|
RaisePropertyChanged(nameof(Address));
|
|
}
|
|
}
|
|
}
|
|
private int port;
|
|
public int Port
|
|
{
|
|
get { return this.port; }
|
|
set
|
|
{
|
|
if (value != this.port)
|
|
{
|
|
this.port = value;
|
|
RaisePropertyChanged(nameof(Port));
|
|
}
|
|
}
|
|
}
|
|
private string _directory;
|
|
public string Directory
|
|
{
|
|
get { return this._directory; }
|
|
set
|
|
{
|
|
if (value != this._directory)
|
|
{
|
|
this._directory = value;
|
|
RaisePropertyChanged(nameof(Directory));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ConfigService _configService;
|
|
LoginService _LoginService;
|
|
public ConfigViewModel(ConfigService configService, LoginService loginService) : base()
|
|
{
|
|
title = "设置";
|
|
_configService = configService;
|
|
_LoginService = loginService;
|
|
_configService.Read(out address, out port, out _directory);
|
|
}
|
|
public override async void ExecuteOKCommandAsync(object obj)
|
|
{
|
|
if (string.IsNullOrEmpty(Directory))
|
|
{
|
|
Application.ShowAlertDialog("本地文件目录不能为空。");
|
|
return;
|
|
}
|
|
if (!System.IO.Directory.Exists(Directory))
|
|
{
|
|
Application.ShowAlertDialog("本地文件目录不存在。");
|
|
return;
|
|
}
|
|
var data = _configService.parser.ReadFile(_configService.path);
|
|
|
|
_configService._httpService.Init(address, port);
|
|
IsBusy = true;
|
|
var testRes = await _LoginService.Login("1", "11");
|
|
IsBusy = false;
|
|
if (testRes.StartsWith("http错误。"))
|
|
{
|
|
Application.ShowAlertDialog("无法连接上服务器。请检查服务器 和 端口。");
|
|
return;
|
|
}
|
|
if (address.StartsWith("http"))
|
|
{
|
|
address = address.Replace("https://", "").Replace("http://", "");
|
|
}
|
|
data["Profile"]["Address"] = address;
|
|
data["Profile"]["Port"] = port.ToString();
|
|
data["Profile"]["Directory"] = _directory;
|
|
_configService.parser.WriteFile(_configService.path, data);
|
|
GlobalObject.isConfigIniCreateBySys = false;
|
|
GlobalObject.SetLocalFileDirectory(_directory);
|
|
|
|
CloseWindowAction?.Invoke();//关闭
|
|
}
|
|
}
|
|
}
|