97 lines
3.7 KiB
C#
97 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Reflection.Emit;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Media;
|
|
using IniParser;
|
|
using Newtonsoft.Json;
|
|
using Prism.Ioc;
|
|
using SWS.Commons;
|
|
using SWS.Model;
|
|
using SWS.Service;
|
|
using Unity;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
|
|
|
|
namespace SWS.Electrical
|
|
{
|
|
public class GlobalObj
|
|
{
|
|
public static List<TreeModel> treeDrawings=new List<TreeModel>();
|
|
//public static IUnityContainer container;
|
|
//public static IContainerExtension _prismContainer;
|
|
public static FileIniDataParser configIni = new FileIniDataParser();
|
|
public enum dialogPar
|
|
{
|
|
info,
|
|
para1,
|
|
para2
|
|
}
|
|
public static string LocalWorkDir = string.Empty;//本地文件路径
|
|
/// <summary>
|
|
/// 检查是否登录
|
|
/// </summary>
|
|
public static async Task<bool> CheckLogin()
|
|
{
|
|
try
|
|
{
|
|
var data = configIni.ReadFile(GlobalObject.configPath);
|
|
string token = data["LoginInfo"]["LoginToken"];
|
|
string loginkey = data["LoginInfo"]["LoginMark"];
|
|
string curProjId = data["LoginInfo"]["CurProjId"];
|
|
LocalWorkDir= data["Profile"]["strLocalWorkDir"];
|
|
string address = data["Profile"]["strIPAddress"];
|
|
string port = data["Profile"]["nPort"];
|
|
string dbType = data["Profile"]["nConType"];
|
|
if (dbType == "1")
|
|
{
|
|
string strDomain = data["Profile"]["strDomainName"];
|
|
GlobalObject.client = new HttpClient()
|
|
{
|
|
BaseAddress = new Uri($"{strDomain}/api/"),
|
|
Timeout = TimeSpan.FromSeconds(120)
|
|
};
|
|
}
|
|
else if (dbType == "0")
|
|
{
|
|
GlobalObject.client = new HttpClient()
|
|
{
|
|
BaseAddress = new Uri($"http://{address}:{port}/api/"),
|
|
Timeout = TimeSpan.FromSeconds(120)
|
|
};
|
|
}
|
|
GlobalObject.client.DefaultRequestHeaders.Add("logintoken",token);
|
|
GlobalObject.client.DefaultRequestHeaders.Add("loginkey", loginkey);
|
|
var loginService = GlobalObject.container.Resolve<LoginService>();
|
|
var flag = await loginService.ValidateLogin(token, loginkey);
|
|
if (flag && GlobalObject.curProject == null)
|
|
{
|
|
//第一次要在后台初始化一些数据
|
|
Task.Factory.StartNew(async () => {
|
|
var projectService = GlobalObject.container.Resolve<ProjectService>();
|
|
var listProjects = (await projectService.GetProjects(1, 1000)).Rows;
|
|
var p= listProjects.FirstOrDefault(a=>a.ProjectId== curProjId);
|
|
GlobalObject.curProject = p;
|
|
var obj = await projectService.InitProjInfo(curProjId, "");
|
|
var treeData = obj.First(x => (string)x["Name"] == "图纸树(按目录)")["data"];
|
|
treeDrawings = JsonConvert.DeserializeObject<List<TreeModel>>(treeData.ToString());
|
|
|
|
});
|
|
}
|
|
return flag;
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|