107 lines
4.5 KiB
C#
107 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
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 IniParser.Model;
|
|
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
|
|
{
|
|
string token = IniHelper.ReadValueFromIniFile("LoginInfo", "LoginToken");
|
|
string loginkey = IniHelper.ReadValueFromIniFile("LoginInfo", "LoginMark");
|
|
string curProjId = IniHelper.ReadValueFromIniFile("LoginInfo", "CurProjId");
|
|
LocalWorkDir = IniHelper.ReadValueFromIniFile("Profile", "strLocalWorkDir");
|
|
string address = IniHelper.ReadValueFromIniFile("Profile", "strIPAddress");
|
|
string port = IniHelper.ReadValueFromIniFile("Profile", "nPort");
|
|
string dbType = IniHelper.ReadValueFromIniFile("Profile", "nConType");
|
|
string domain = IniHelper.ReadValueFromIniFile("Profile", "strDomainName");
|
|
if (dbType == "1")
|
|
{
|
|
string strDomain = domain;
|
|
GlobalObject.client = new HttpClient()
|
|
{
|
|
BaseAddress = new Uri($"{strDomain}/api/"),
|
|
Timeout = TimeSpan.FromSeconds(600)
|
|
};
|
|
}
|
|
else if (dbType == "0")
|
|
{
|
|
GlobalObject.client = new HttpClient()
|
|
{
|
|
BaseAddress = new Uri($"http://{address}:{port}/api/"),
|
|
Timeout = TimeSpan.FromSeconds(600)
|
|
};
|
|
}
|
|
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 && !string.IsNullOrEmpty(curProjId))
|
|
{
|
|
//第一次要在后台初始化一些数据
|
|
var projectService = GlobalObject.container.Resolve<ProjectService>();
|
|
GlobalObject.curProject = await projectService.GetEntity(curProjId);
|
|
if (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());
|
|
|
|
});
|
|
}
|
|
}
|
|
if (GlobalObject.curProject == null)
|
|
{ GlobalObject.curProject = new ec_project() { ProjectId = curProjId }; }
|
|
return flag;
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|