You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1008 lines
40 KiB

using Container.Common;
using System.Management;
using System.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Windows;
using Container.Model;
using Container.Control;
using System.Windows.Data;
using System.IO;
using Container.ChildWindows;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices;
using Newtonsoft.Json.Linq;
using Container.Viewmodel;
using Container.Business;
using AForge.Video.DirectShow;
using System.Collections;
namespace Container.Services
{
class CommandInfo
{
public string type { get; set; }
public string parameter { get; set; }
}
public class Building
{
public string buildingName;
public string code;
public List<Floor> floors;
}
public class DeviceType
{
public string id;
public string code;
public string dictValue;
}
public class AppModel
{
public string code;
public string filePath;
public string iconFilePath;
public string name;
public string spaceName;
public string screenInfoCode;
public string startup;
public string version;
public bool defaultFile;
}
public class AppListModel
{
public string AppID;
public string AppType;
public string Code;
public string Default;
public string File;
public string Logo;
public string PackageName;
public string PlatformType;
public string ShelfTime;
public string Startup;
public string Name;
public string Version;
}
public class AppTimeModel
{
public string AppCode;
public string BeginTimeSlot;
public string EndTimeSlot;
}
public class Floor
{
public string floorName;
public string code;
}
//public class Screensaver
//{
// public string Time;
// public string ScreenType;
// public string ScreenEffect;
// public string ScreenType;
// public string ScreenType;
//}
class HttpMessage
{
private HttpClient httpclient = new HttpClient();
private Class_Log log = new Class_Log();
private Class_Config config = new Class_Config();
App app;
public HttpMessage(string httpurl = "")
{
app = ((App)Application.Current);
}
/// <summary>
/// 心跳
/// </summary>
public string HeatBeat()
{
try
{
if (string.IsNullOrEmpty(app.LocalIP))
{
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
app.LocalIP = _IPAddress.ToString();
}
}
}
string sendmsg = "ip=" + app.LocalIP +
"&AppNameCH=" + app.AppPlayNameCH +
"&AppName=" + app.CurAppPlayName +
"&ContainerVersion=" + app.Containerversion +
"&AppVersion=" + app.Appversion; ////
httpclient.url = app.HttpUrl + "/Api/Dev/DeviceHeartbeat";
httpclient.message = sendmsg;
log.WriteLogFile(sendmsg, "DeviceHeartbeat");
log.WriteLogFile(httpclient.url, "DeviceHeartbeat");
string rev = httpclient.HttpPost();
//rev = "{\"code\":\"200\",\"msg\":\"\",\"data\":{\"isShutDown\":0,\"downTime\":\"12:00\",\"isReloaded\":0}}";
Dictionary<string, Object> dic = JsonConvert.DeserializeObject<Dictionary<string, Object>>(rev);
if (dic["data"] != null && dic["code"].ToString() == "200")
{
List<CommandInfo> Commands = JsonConvert.DeserializeObject<List<CommandInfo>>(dic["data"].ToString());
if (Commands.Count > 0)
{
if (Commands.FindIndex(p => (p.type.Equals("downTime"))) != -1)
{
app.shutdowntime = Commands.Find(p => (p.type.Equals("downTime"))).parameter;
}
//if (Commands.FindIndex(p => (p.type.Equals("AppName"))) != -1)
//{
// app.NowAppName = Commands.Find(p => (p.type.Equals("AppName"))).parameter;
//}
//else
//{
//}
}
return "ShutDownTime";
}
return "";
}
catch (Exception ex)
{
log.WriteLogFile("发送心跳包失败" + ex.ToString(), "HttpMessageErrorLog");
return "";
}
}
/// <summary>
/// 心跳
/// </summary>
public string HeatBeatForMqtt()
{
try
{
//if (string.IsNullOrEmpty(app.LocalIP))
//{
// foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
// {
// if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
// {
// app.LocalIP = _IPAddress.ToString();
// }
// }
//}
//string sendmsg = "ip=" + app.LocalIP +
// "&AppNameCH=" + app.AppPlayNameCH +
// "&AppName=" + app.AppPlayName +
// "&ContainerVersion=" + app.Containerversion +
// "&AppVersion=" + app.Appversion; ////
//string sendmsg = "{\"IP\":\"" + app.LocalIP + "\"}";
// Dictionary<string, object> data = new Dictionary<string, object> {
// { "Code",app.deviceid},
// { "AppName",app.AppPlayName},
// { "AppNameCH",app.AppPlayNameCH },
// { "CurTime",DateTime.Now.ToString("G")},
// { "AppVersion",app.Appversion},
// { "ContainerVersion",app.Containerversion}
//};
// KafkaProducer.Produce(Guid.NewGuid().ToString(), JsonConvert.SerializeObject(data));
Dictionary<string, object> data = new Dictionary<string, object> {
{ "AppName",app.AppPlayName},
{ "AppNameCH",app.AppPlayNameCH },
{ "AppVersion",app.Appversion},
{ "ContainerVersion",app.Containerversion},
{ "Code",app.deviceid}
};
MqServer.PublishMessage("deviceheatbeat", data, Array.Empty<string>(), false);
//mqttClient.PublishAsync(app.mqttCredentialsModel.ClientId, JsonConvert.SerializeObject(data));
return "";
}
catch (Exception ex)
{
log.WriteLogFile("发送心跳包失败" + ex.ToString(), "HttpMessageErrorLog");
return "";
}
}
/// <summary>
/// 获取楼栋楼层信息
/// </summary>
public bool GetBuildinginfo(ref string Errorlog)
{
try
{
string MethodStr = "/API/Dev/GetDeviceOptionsNew";
var data = new { MallCode = app.mallCode };
var ret = MyHttpClient.CryptPost(MethodStr, data);
if (!string.IsNullOrEmpty(ret))
{
var Jo = JObject.Parse(ret);
string code = Jo.Value<string>("code");
if (code == "200")
{
var Data = Jo.Value<JObject>("data");
List<Building> itemList = Data.Value<JArray>("buildings").ToObject<List<Building>>();
//解析漏洞信息应该是List
app.Buildinginfo.Clear();
app.Buildinginfo = itemList;
return true;
//List<ItemInfo> itemList = JsonConvert.DeserializeObject<List<ItemInfo>>(Data);
//string xmlstring = WriteToConfig(itemList, "1");
//if (!string.IsNullOrEmpty(xmlstring) && xmlstring != "")
//{
// ScreenSavers result = CommonMethod.DeserializeXML<ScreenSavers>(xmlstring);
// Mylog.WriteLogFile(result.ResList.ToString(), "HttpClient");
// return result;
//}
}
else {
return false;
}
}
else
return false;
//httpclient.message = "";
//string sendmsg = "";
//httpclient.url = app.HttpUrl + "/Dictionary/GetBuildings";
//httpclient.message = sendmsg;
//string rev = httpclient.HttpPost();
////rev = "{\"code\":\"200\",\"msg\":\"获取成功\",\"data\":[{\"id\":1,\"bName\":\"A栋\"},{\"id\":2,\"bName\":\"B栋\"}]}";http://192.168.0.142/api/account/Register?AccountName=af&Password=123456&ConfirmPassword=123456&NickName=阿福&AvatarSrc&Phone=18254698745&Email=123@123.com&RoleIDs=2,3,4,5&UserDefaultFile=true
//Dictionary<string, Object> dic = JsonConvert.DeserializeObject<Dictionary<string, Object>>(rev);
//if (dic["msg"] != null)
// Errorlog = dic["msg"].ToString();
//if (dic["data"] != null && dic["code"].ToString() == "200")
//{
// if (dic["data"].ToString().Trim().Equals(""))
// return false;
// string mes = dic["data"].ToString();
// //解析漏洞信息应该是List
// app.Buildinginfo.Clear();
// app.Buildinginfo = JsonConvert.DeserializeObject<List<Building>>(dic["data"].ToString());
// return true;
//}
//return false;
}
catch (Exception ex)
{
if (Errorlog.Trim().Equals(""))
Errorlog = "获取楼栋信息失败";
log.WriteLogFile("获取楼栋信息失败" + ex.ToString(), "HttpMessageErrorLog");
return false;
}
}
public bool CheckMallRegKey(string RegKey, ref string MallCode, ref string Errorlog)
{
try
{
string MethodStr = "/API/Dev/GetMallByRegKey";
var data = new { RegKey = RegKey };
var ret = MyHttpClient.CryptPost(MethodStr, data);
if (!string.IsNullOrEmpty(ret))
{
var Jo = JObject.Parse(ret);
string code = Jo.Value<string>("code");
Errorlog = Jo.Value<string>("msg");
if (code == "200")
{
MallCode = Jo.Value<string>("data");
return true;
}
else
{
return false;
}
}
else {
Errorlog = "获取商场信息信息失败";
return false;
}
}
catch (Exception ex)
{
if (Errorlog.Trim().Equals(""))
Errorlog = "获取商场信息信息失败";
log.WriteLogFile("获取商场信息信息失败" + ex.ToString(), "HttpMessageErrorLog");
return false;
}
}
public bool GetDeviceTypeList(ref string Errorlog)
{
try
{
string MethodStr = "/API/Dev/GetDictListByName";
var data = new { Name = "DeviceType" };
var ret = MyHttpClient.CryptPost(MethodStr, data);
if (!string.IsNullOrEmpty(ret))
{
var Jo = JObject.Parse(ret);
string code = Jo.Value<string>("code");
if (code == "200")
{
//var Data = JObject.Parse(Jo.Value<string>("data"));
List<DeviceType> itemList = Jo.Value<JArray>("data").ToObject<List<DeviceType>>();
//解析漏洞信息应该是List
app.DeviceTypeList.Clear();
app.DeviceTypeList = itemList;
return true;
}
else
return false;
}
else
return false;
}
catch (Exception ex)
{
if (Errorlog.Trim().Equals(""))
Errorlog = "获取设备类型失败";
log.WriteLogFile("获取设备类型失败" + ex.ToString(), "HttpMessageErrorLog");
return false;
}
}
[DllImport("user32")]
static extern int GetSystemMetrics(int n);
/// <summary>
/// 上传设备信息
/// </summary>
public bool UploadDeviceInfo(string build, string floor, string deviceType, ref string Errorlog, bool update = true)
{
try
{
//获取本机的IP地址和MAC地址....
string AddressIP = string.Empty;
if (update)
{
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
AddressIP = _IPAddress.ToString();
}
}
}
else {
AddressIP = app.LocalIP;
}
ManagementClass mc;
string mac = string.Empty;
mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (mo["IPEnabled"].ToString() == "True")
mac = mo["MacAddress"].ToString();
}
while (mac.IndexOf(":") >= 0)
mac = mac.Remove(mac.IndexOf(":"), 1);
//if (string.IsNullOrEmpty(app.deviceid))
//{
// log.WriteLogFile("设备信息上传失败:deviceid为空", "HttpMessageErrorLog");
// return false;
//}
if (string.IsNullOrEmpty(app.devicemark))
{
app.devicemark = System.Net.Dns.GetHostName();
//return false;
}
bool isSound = IsSound();
bool isVideo = IsVideo();
string MethodStr = "/API/Dev/AddDevice";
var data = new {
MallCode = app.mallCode,
IP = AddressIP,
MAC = mac,
ScreenInfo = app.ScreenWidth + "*" + app.ScreenHeight + " " + (app.ScreenWidth > app.ScreenHeight ? "横屏" : "竖屏"),
Building = build,
Floor = floor,
DevNum = app.devicemark,
SystemType = "Windows",
DeviceType = deviceType,
Code = app.deviceid,
Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
HardWare = (isSound ? "麦克风;" : "") + (isVideo ? "摄像头;" : "")
};
var ret = MyHttpClient.CryptPost(MethodStr, data);
log.WriteLogFile(ret, "dev");
if (!string.IsNullOrEmpty(ret))
{
var Jo = JObject.Parse(ret);
string code = Jo.Value<string>("code");
Errorlog = Jo.Value<string>("msg");
if (code == "200")
{
//var Data = JObject.Parse(Jo.Value<string>("data"));
app.Floor = floor.ToString();
app.BuildingID = build.ToString();
app.LocalIP = AddressIP;
app.DeviceType = deviceType;
var dicData = Jo.Value<JObject>("data");
var oldDevice = app.deviceid;
if (dicData != null)
{
app.deviceid = dicData["code"].ToString();
RabbitMQModel rabbit = new RabbitMQModel();
rabbit.UserName = dicData["userName"] == null ? "" : dicData["userName"].ToString();
rabbit.Password = dicData["password"] == null ? "" : dicData["password"].ToString();
rabbit.HostName = dicData["hostName"] == null ? "" : dicData["hostName"].ToString();
rabbit.Port = dicData["port"] == null ? 0 : Convert.ToInt32(dicData["port"]);
app.rabbitMQ = rabbit;
app.shutdowntime = dicData["shutdownTime"] == null ? "" : dicData["shutdownTime"].ToString();
app.BGFile = dicData["defaultPic"] == null ? "" : dicData["defaultPic"].ToString();
app.defaultCity= dicData["city"] == null ? "" : dicData["city"].ToString();
if (!string.IsNullOrEmpty(app.BGFile))
{
HttpClient httpClient = new HttpClient();
httpClient.DownLoadBGImage(app.BGFile, "pic");
}
}
if (update || oldDevice != app.deviceid)
config.WriteToConfig();
return true;
}
else
return false;
}
else
{
if (update)
{
return false;
}
else
{
return true;
}
}
}
catch (Exception ex)
{
if (Errorlog.Trim().Equals(""))
Errorlog = "设备信息上传失败";
log.WriteLogFile("设备信息上传失败" + ex.ToString(), "HttpMessageErrorLog");
if (update)
{
return false;
}
else {
return true;
}
}
}
private bool IsSound()
{
//// 获取默认音频捕捉设备
var devices = SharpDX.DirectSound.DirectSoundCapture.GetDevices(); // 枚举音频捕捉设备
if (devices.Count > 0)
{
return true;
}
else
{
return false;
}
}
private bool IsVideo()
{
//// 获取默认音频捕捉设备
var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count > 0)
{
return true;
}
else
{
return false;
}
}
public bool LoadAppConfig(ref string Errorlog)
{
try
{
string MethodStr = "/API/Dev/GetDevAppList";
var data = new { DevCode = app.deviceid, MallCode=app.mallCode, Paging=0 };
var ret = MyHttpClient.CryptPost(MethodStr, data);
if (!string.IsNullOrEmpty(ret))
{
log.WriteLogFile(ret,"devapp");
var Jo = JObject.Parse(ret);
string code = Jo.Value<string>("code");
Class_Config con = new Class_Config();
if (code == "200")
{
var resultData = Jo.Value<JObject>("data");
List<AppListModel> itemList = resultData.Value<JArray>("appList").ToObject<List<AppListModel>>();
List<AppTimeModel> appTimes = resultData.Value<JArray>("appTime").ToObject<List<AppTimeModel>>();
ArrayList list = new ArrayList();
foreach (var item in itemList)
{
bool flag = httpclient.DownLoadIcon(ref item.Logo);
log.WriteLogFile("item.Logo" + item.Logo, "Icon");
var appModel = app.AppList.Where(i => i.Code == item.Code).FirstOrDefault();
if ((appModel == null || appModel.Version != item.Version)&&!string.IsNullOrEmpty(item.File)) {
httpclient.DownLoadFiles(item.File,ref item.File);
}
if (!string.IsNullOrEmpty(item.Startup)&&(item.Startup.ToLower().StartsWith("https://") || item.Startup.ToLower().StartsWith("http://"))) {
item.Startup = log.WriteAppStart(item.Name, item.Startup);
}
con.WriteToExeConfig(item);
list.Add(item.Code);
}
var delApp = app.AppList.Where(i => !list.Contains(i.Code)).ToList();
foreach (var item in delApp)
{
con.RemoveExeConfig(item.Code, ref item.File, ref item.Logo, ref item.Startup);
if (!string.IsNullOrEmpty(item.File)&& Directory.Exists(item.File)) {
Directory.Delete(item.File);
}
if (!string.IsNullOrEmpty(item.Logo) && File.Exists(item.Logo))
{
File.Delete(item.Logo);
}
if (!string.IsNullOrEmpty(item.Logo) &&File.Exists(item.Startup))
{
File.Delete(item.Startup);
}
}
con.WriteToAppTimeConfig(appTimes);
//解析漏洞信息应该是List
app.AppList.Clear();
app.AppList = itemList;
app.AppTimeList.Clear();
app.AppTimeList = appTimes;
return true;
}
else
return false;
}
else
return false;
}
catch (Exception ex)
{
if (Errorlog.Trim().Equals(""))
Errorlog = "设备信息上传失败";
log.WriteLogFile("设备信息上传失败" + ex.ToString(), "HttpMessageErrorLog");
return false;
}
return false;
}
public bool LoadAppTimeConfig()
{
try
{
string MethodStr = "/API/Dev/GetDevAppTimeList";
var data = new { DevCode = app.deviceid, MallCode = app.mallCode, Paging = 0 };
var ret = MyHttpClient.CryptPost(MethodStr, data);
if (!string.IsNullOrEmpty(ret))
{
var Jo = JObject.Parse(ret);
string code = Jo.Value<string>("code");
Class_Config con = new Class_Config();
if (code == "200")
{
var resultData = Jo.Value<JObject>("data");
List<AppTimeModel> appTimes = resultData.Value<JArray>("appTime").ToObject<List<AppTimeModel>>();
con.WriteToAppTimeConfig(appTimes);
app.AppTimeList.Clear();
app.AppTimeList = appTimes;
return true;
}
else
return false;
}
else
return false;
}
catch (Exception ex)
{
log.WriteLogFile("设备信息上传失败" + ex.ToString(), "HttpMessageErrorLog");
return false;
}
return false;
}
public bool LoadScreenTime()
{
try
{
string MethodStr = "/API/Screensaver/GetScreensaver";
var data = new { MallCode = app.mallCode };
var ret = MyHttpClient.CryptPost(MethodStr, data);
log.WriteLogFile(ret,"screensaver");
if (!string.IsNullOrEmpty(ret))
{
var Jo = JObject.Parse(ret);
string code = Jo.Value<string>("code");
if (code == "200"||code=="201")
{
var dicData = Jo.Value<JObject>("data");
app.screensaver.ScreenTime = string.IsNullOrEmpty(dicData["time"].ToString()) ? 30 : Convert.ToInt32(dicData["time"]);
//Dictionary<string, Object> dicData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(Jo.Value<string>("data"));
//app.screenTime = string.IsNullOrEmpty(dicData["time"].ToString()) ? 30 : Convert.ToInt32(dicData["time"]);
string fileName = string.Empty;
if (!string.IsNullOrEmpty(dicData["screenFilePath"].ToString())) {
httpclient.DownLoadImage(dicData["screenFilePath"].ToString(), "exefile/PCScreen/config", ref fileName);
}
app.screensaver.ScreenType = string.IsNullOrEmpty(dicData["screenType"].ToString()) ? 0 : Convert.ToInt32(dicData["screenType"]);
app.screensaver.ScreenEffect = string.IsNullOrEmpty(dicData["screenEffect"].ToString()) ? 0 : Convert.ToInt32(dicData["screenEffect"]);
app.screensaver.ScreenFile = fileName;
app.screensaver.EffectType = string.IsNullOrEmpty(dicData["effectType"].ToString()) ? 0 : Convert.ToInt32(dicData["effectType"]);
// config.WriteToScreenConfig(dicData["screenType"].ToString(), dicData["screenEffect"].ToString(), fileName, dicData["effectType"].ToString());
return true;
}
}
return false;
}
catch (Exception ex)
{
log.WriteLogFile("屏保时间同步失败" + ex.ToString(), "HttpMessageErrorLog");
return false;
}
}
public bool LoadBG() {
return false;
//try
//{
// //获取本机的IP地址和MAC地址....
// string AddressIP = string.Empty;
// if (string.IsNullOrEmpty(app.LocalIP))
// {
// foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
// {
// if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
// {
// AddressIP = _IPAddress.ToString();
// }
// }
// }
// else {
// AddressIP = app.LocalIP;
// }
// httpclient.message = "";
// string sendmsg = "IP="+ AddressIP;
// httpclient.url = app.HttpUrl + "/Container/GetContainerBGByScreen";
// httpclient.message = sendmsg;
// string rev = httpclient.HttpPost();
// Dictionary<string, Object> dic = JsonConvert.DeserializeObject<Dictionary<string, Object>>(rev);
// if (dic["data"] != null && dic["code"].ToString() == "200")
// {
// app.bgPath = string.IsNullOrEmpty(dic["data"].ToString())?"": dic["data"].ToString();
// if (!string.IsNullOrEmpty(app.bgPath))
// {
// string filefolder = AppDomain.CurrentDomain.BaseDirectory + "/bgfile";
// try
// {
// if (!Directory.Exists(filefolder))
// {
// DirectoryInfo directoryInfo = new DirectoryInfo(filefolder);
// directoryInfo.Create();
// }
// }
// catch (Exception ex)
// {
// log.WriteLogFile(ex.ToString());
// }
// HttpClient httpClient = new HttpClient();
// string newname = Directory.GetCurrentDirectory() + "/exefile/PCScreen/pic/bg.png";
// if (File.Exists(newname)) {
// File.Delete(newname);
// }
// string fileName = "";
// httpClient.DownLoadImage(app.bgPath, "bgfile", ref fileName);
// var nf = Path.Combine(newname);//将新的文件名称路径字符串结合成路径。
// File.Copy(fileName, nf);//进行文件复制,第一个参数是需要复制的文件路径,第二个参数是目标文件夹中文件路径
// //string bgName = "bg.png";
// //httpClient.DownLoadImage(app.bgPath, "exefile/PCScreen/pic", ref bgName);
// if (app.pageBg == null)
// {
// app.pageBg = new BGPage();
// app.pageBg.LoadImage(fileName);
// app.pageBg.Show();
// }
// else
// {
// app.pageBg.LoadImage(fileName);
// }
// }
// else {
// if (app.pageBg == null)
// {
// app.pageBg = new BGPage();
// app.pageBg.LoadImage("");
// app.pageBg.Show();
// }
// else
// {
// app.pageBg.LoadImage("");
// }
// }
// return true;
// }
// return false;
//}
//catch (Exception ex)
//{
// log.WriteLogFile("设备信息上传失败" + ex.ToString(), "HttpMessageErrorLog");
// return false;
//}
}
/// <summary>
/// 下载应用程序
/// </summary>
//public string DownLoadexe(List<ExeModel> appList, ref string Errorlog)
//{
// try
// {
// string filename = "";
// app.appUrl = app.appUrl.Replace("\\", "/");
// if (app.appUrl.Contains("/"))
// filename = app.appUrl.Substring(app.appUrl.LastIndexOf("/"));
// else
// return "";
// //string localFile = AppDomain.CurrentDomain.BaseDirectory + "zipfile/" + filename;//本地地址
// //string Unzippath = AppDomain.CurrentDomain.BaseDirectory + "exefile/" + filename;//本地地址
// bool result = false;
// string iconpath = "";
// ExeModel appModel = appList.Where(i => i.AppID == app.Appdowninfo.AppID).FirstOrDefault();
// var appDownFlag = false;
// if (app.appUrl.LastIndexOf(".exe") >= 0) {
// appDownFlag = httpclient.DownLoadFilesExe(appModel, app.appUrl, ref filename);
// }
// else {
// appDownFlag = httpclient.DownLoadFiles(appModel, app.appUrl, ref filename);
// }
// if (appDownFlag && httpclient.DownLoadIcon(appModel,app.icourl, ref iconpath))
// {
// log.WriteLogFile("iconpath:"+iconpath);
// app.Appdowninfo.icopath = iconpath;
// Class_Config con = new Class_Config();
// //if (app.AppUpdate == false)
// //{
// result = con.WriteToExeConfig(app.Appdowninfo);
// if (app.Appdowninfo.exename.ToLower().Equals(app.defaultFile.ToLower())) {
// app.configstartexe =string.IsNullOrEmpty(app.Appdowninfo.exestartname)? app.Appdowninfo.exepath:(app.Appdowninfo.exepath + "/"+ app.Appdowninfo.exestartname);
// }
// var model = new ExeModel();
// model.AppID = app.Appdowninfo.AppID;
// model.exename = app.Appdowninfo.exename;
// model.exepath = app.Appdowninfo.exepath;
// model.exestartname = app.Appdowninfo.exestartname;
// model.icopath = app.Appdowninfo.icopath;
// model.Version = app.Appdowninfo.Version;
// app.NowAppList.Add(model);
// //}
// //else
// //{
// // result = con.WriteToExeConfig(app.Appdowninfo);
// //}
// if (result)
// return filename;//返回应用程序文件名
// else
// return "";
// }
// return "";
// }
// catch (Exception ex)
// {
// log.WriteLogFile("下载文件信息失败" + ex.ToString(), "HttpMessageErrorLog");
// return "";
// }
//}
/// <summary>
/// 上传下载状态
/// </summary>
public string UpLoadDownLoadState(ref string Errorlog,string state)
{
try
{
httpclient.message = "";
httpclient.url = app.HttpUrl + "/Device/DeviceFeedback";
string sendmsg = "State=" + state
+
"&Type=DownloadApp" //+ app.appName
+
"&Parameter=" + app.appName
+
"&IP=" + app.LocalIP;
httpclient.message = sendmsg;
string rev = httpclient.HttpPost();
Dictionary<string, Object> dic = JsonConvert.DeserializeObject<Dictionary<string, Object>>(rev);
if (dic["msg"] != null)
Errorlog = dic["msg"].ToString();
if (dic["code"].ToString() == "200")
{
//解析楼层信息应该是List
//app.Floors = JsonConvert.DeserializeObject<List<FloorModel>>(dic["data"].ToString());
return "";
}
return "上传失败";
}
catch (Exception ex)
{
log.WriteLogFile("下载文件信息失败" + ex.ToString(), "HttpMessageErrorLog");
return "";
}
}
/// <summary>
/// 上传图片
/// </summary>
public string UpLoadImg(ref string Errorlog, string img, string imgname,string userName,string type)
{
try
{
if (string.IsNullOrEmpty(app.LocalIP))
{
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
app.LocalIP = _IPAddress.ToString();
}
}
}
string sendmsg = string.Empty ;
if (type.Equals("local")) {
httpclient.url = app.HttpUrl + "/api/Dev/UploadScreenshot";//接口地址
sendmsg = "{\"Code\":\"" + app.deviceid + "\",\"FileName\":\"" + imgname + "\"}";
} else {
httpclient.url = app.HttpUrl + "/SaasLive/Manage/UploadScreenshot";//接口地址
sendmsg = "{\"Code\":\"" + app.deviceid + "\",\"FileName\":\"" + imgname + "\",\"UserName\":\""+ userName + "\"}";
}
httpclient.message = sendmsg;
log.WriteLogFile(httpclient.url, "HttpMessageErrorLog");
string rev = httpclient.HttpUploadFile(httpclient.url, img, httpclient.message);
Dictionary<string, Object> dic = JsonConvert.DeserializeObject<Dictionary<string, Object>>(rev);
Errorlog = dic["msg"].ToString();
if (dic["data"] != null && dic["code"].ToString() == "200")//成功并且返回下载地址不为空
{
return "true";//返回应用程序文件名
}
return "";
}
catch (Exception ex)
{
log.WriteLogFile("上传截屏信息失败" + ex.ToString(), "HttpMessageErrorLog");
return "";
}
}
/// <summary>
/// 设置触摸屏操作
/// </summary>
public bool ScreenOperSuccess(int status)
{
try
{
string MethodStr = "/API/Dev/SetOperable";
var data = new { Code = app.deviceid, Status = status };
var ret = MyHttpClient.CryptPost(MethodStr, data);
if (!string.IsNullOrEmpty(ret))
{
var Jo = JObject.Parse(ret);
string code = Jo.Value<string>("code");
if (code == "200")
{
return true;
}
else {
return false;
}
}
return false;
}
catch (Exception ex)
{
log.WriteLogFile("设置触摸屏操作失败" + ex.ToString(), "HttpMessageErrorLog");
return false;
}
}
public bool LoadCurrentLive()
{
try
{
httpclient.message = "";
string sendmsg = "{\"MallCode\":\"" + app.live.MallCode + "\"}";
log.WriteLogFile(app.live.SenderID, "CurrentLiv");
httpclient.url = app.live.SenderID + "/api/Order/GetCurrentLive";
httpclient.message = sendmsg;
string rev = httpclient.PostMoths(httpclient.message, httpclient.url);
log.WriteLogFile(rev, "CurrentLiv");
Dictionary<string, Object> dic = JsonConvert.DeserializeObject<Dictionary<string, Object>>(rev);
if (dic["data"] != null && dic["code"].ToString() == "200")
{
if (dic["data"].ToString().Trim().Equals(""))
return false;
string mes = dic["data"].ToString();
//解析漏洞信息应该是List
//app.Buildinginfo.Clear();
log.WriteLogFile(dic["data"].ToString());
CurrentLive live = JsonConvert.DeserializeObject<CurrentLive>(dic["data"].ToString());
app.curLive = live;
return true;
}
return false;
}
catch (Exception ex)
{
log.WriteLogFile("获取直播信息失败" + ex.ToString(), "CurrentLivErrorLog");
return false;
}
}
}
}