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.
1747 lines
73 KiB
1747 lines
73 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Xml;
|
|
using System.Xaml;
|
|
using System.IO;
|
|
using System.Collections;
|
|
using System.Net;
|
|
//using System.Net.Http;
|
|
using System.Text.RegularExpressions;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using Container.Model;
|
|
using System.Xml.Serialization;
|
|
using Transitionals;
|
|
using System.Runtime.InteropServices;
|
|
using Container.Services;
|
|
|
|
namespace Container.Common
|
|
{
|
|
public static class CommonMethod
|
|
{
|
|
/// <summary>
|
|
/// 反序列化XML为类实例
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="xmlObj"></param>
|
|
/// <returns></returns>
|
|
public static T DeserializeXML<T>(string xmlObj)
|
|
{
|
|
try
|
|
{
|
|
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
|
using (StringReader reader = new StringReader(xmlObj))
|
|
{
|
|
return (T)serializer.Deserialize(reader);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//MessageBox.Show(ex.ToString());
|
|
return default(T);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 序列化类实例为XML
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public static string SerializeXML<T>(T obj)
|
|
{
|
|
try
|
|
{
|
|
using (StringWriter writer = new StringWriter())
|
|
{
|
|
new XmlSerializer(obj.GetType()).Serialize((TextWriter)writer, obj);
|
|
return writer.ToString();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换效果
|
|
/// </summary>
|
|
/// <param name="effect">百叶窗-0,遮帘 -1,淡化 - 2,渐变 -3,溶解 - 4,旋转 - 5</param>
|
|
/// <returns></returns>
|
|
public static Transition GetTransition(string effect)
|
|
{
|
|
//所有的变换
|
|
//Transitionals.Transitions.StarTransition //星
|
|
//Transitionals.Transitions.RotateTransition //3d旋转
|
|
//Transitionals.Transitions.VerticalWipeTransition//下拉
|
|
//Transitionals.Transitions.PageTransition //翻页
|
|
//Transitionals.Transitions.RollTransition //旋转出
|
|
//Transitionals.Transitions.DiamondsTransition //棋盒棱形
|
|
//Transitionals.Transitions.VerticalBlindsTransition //垂直百叶窗
|
|
//Transitionals.Transitions.HorizontalWipeTransition //左拉
|
|
//Transitionals.Transitions.FadeAndBlurTransition //淡入
|
|
//Transitionals.Transitions.ExplosionTransition //球形散开
|
|
//Transitionals.Transitions.CheckerboardTransition //棋盒方形
|
|
//Transitionals.Transitions.TranslateTransition //飞入
|
|
//Transitionals.Transitions.RotateWipeTransition //旋转擦除
|
|
//Transitionals.Transitions.MeltTransition //柱状
|
|
//Transitionals.Transitions.DiagonalWipeTransition //斜擦除
|
|
//Transitionals.Transitions.FlipTransition //单面翻书
|
|
//Transitionals.Transitions.DotsTransition //球状棋盒
|
|
//Transitionals.Transitions.FadeAndGrowTransition //淡入
|
|
//Transitionals.Transitions.DoubleRotateWipeTransition //双线擦除
|
|
//Transitionals.Transitions.DoorTransition //门状
|
|
//Transitionals.Transitions.HorizontalBlindsTransition //水平百叶窗
|
|
//Transitionals.Transitions.FadeTransition //溶解
|
|
|
|
switch (effect)
|
|
{
|
|
case "马赛克":
|
|
return new Transitionals.Transitions.CheckerboardTransition();
|
|
case "上下滑动":
|
|
return new Transitionals.Transitions.VerticalWipeTransition();
|
|
case "左右滑动":
|
|
return new Transitionals.Transitions.HorizontalWipeTransition();
|
|
case "渐入":
|
|
return new Transitionals.Transitions.FadeTransition();
|
|
case "4":
|
|
return new Transitionals.Transitions.FadeTransition();
|
|
case "5":
|
|
return new Transitionals.Transitions.RollTransition();
|
|
default:
|
|
return new Transitionals.Transitions.FadeTransition();
|
|
}
|
|
}
|
|
|
|
///// <summary>
|
|
///// 以逆时针为方向对图像进行旋转
|
|
///// </summary>
|
|
///// <param name="b">位图流</param>
|
|
///// <param name="angle">旋转角度[0,360](前台给的)</param>
|
|
///// <returns></returns>
|
|
//public Bitmap RotateImg(System.Drawing.Image b, int angle)
|
|
//{
|
|
// angle = angle % 360;
|
|
|
|
// //弧度转换
|
|
// double radian = angle * Math.PI / 180.0;
|
|
// double cos = Math.Cos(radian);
|
|
// double sin = Math.Sin(radian);
|
|
|
|
// //原图的宽和高
|
|
// int w = (int)b.Width;
|
|
// int h = (int)b.Height;
|
|
// int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));
|
|
// int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));
|
|
|
|
// //目标位图
|
|
// Bitmap dsImage = new Bitmap(W, H);
|
|
// System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
|
|
// g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
|
|
// g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
|
|
|
// //计算偏移量
|
|
// System.Drawing.Point Offset = new System.Drawing.Point((int)(W - w) / 2, (int)(H - h) / 2);
|
|
|
|
// //构造图像显示区域:让图像的中心与窗口的中心点一致
|
|
// System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Offset.X, Offset.Y, w, h);
|
|
// System.Drawing.Point center = new System.Drawing.Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
|
|
// g.TranslateTransform(center.X, center.Y);
|
|
// g.RotateTransform(360 - angle);
|
|
|
|
// //恢复图像在水平和垂直方向的平移
|
|
// g.TranslateTransform(-center.X, -center.Y);
|
|
// g.DrawImage(b, rect);
|
|
|
|
// //重至绘图的所有变换
|
|
// g.ResetTransform();
|
|
// g.Save();
|
|
// g.Dispose();
|
|
|
|
// //保存旋转后的图片
|
|
// b.Dispose();
|
|
// //dsImage.Save("FocusPoint.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
|
|
// return dsImage;
|
|
|
|
//}
|
|
|
|
// 映射 DEVMODE 结构
|
|
// 可以参照 DEVMODE结构的指针定义:
|
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/dd183565(v=vs.85).aspx
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
public struct DEVMODE
|
|
{
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
public string dmDeviceName;
|
|
|
|
public short dmSpecVersion;
|
|
public short dmDriverVersion;
|
|
public short dmSize;
|
|
public short dmDriverExtra;
|
|
public int dmFields;
|
|
public int dmPositionX;
|
|
public int dmPositionY;
|
|
public int dmDisplayOrientation;
|
|
public int dmDisplayFixedOutput;
|
|
public short dmColor;
|
|
public short dmDuplex;
|
|
public short dmYResolution;
|
|
public short dmTTOption;
|
|
public short dmCollate;
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
public string dmFormName;
|
|
|
|
public short dmLogPixels;
|
|
public short dmBitsPerPel;
|
|
public int dmPelsWidth;
|
|
public int dmPelsHeight;
|
|
public int dmDisplayFlags;
|
|
public int dmDisplayFrequency;
|
|
public int dmICMMethod;
|
|
public int dmICMIntent;
|
|
public int dmMediaType;
|
|
public int dmDitherType;
|
|
public int dmReserved1;
|
|
public int dmReserved2;
|
|
public int dmPanningWidth;
|
|
public int dmPanningHeight;
|
|
};
|
|
|
|
// Win32 函数在托管环境下的声明
|
|
public class NativeMethods
|
|
{
|
|
// 平台调用的申明
|
|
[DllImport("user32.dll")]
|
|
public static extern int EnumDisplaySettings(
|
|
string deviceName, int modeNum, ref DEVMODE devMode);
|
|
[DllImport("user32.dll")]
|
|
public static extern int ChangeDisplaySettings(
|
|
ref DEVMODE devMode, int flags);
|
|
|
|
// 控制改变屏幕分辨率的常量
|
|
public const int ENUM_CURRENT_SETTINGS = -1;
|
|
public const int CDS_UPDATEREGISTRY = 0x01;
|
|
public const int CDS_TEST = 0x02;
|
|
public const int DISP_CHANGE_SUCCESSFUL = 0;
|
|
public const int DISP_CHANGE_RESTART = 1;
|
|
public const int DISP_CHANGE_FAILED = -1;
|
|
|
|
// 控制改变方向的常量定义
|
|
public const int DMDO_DEFAULT = 0;
|
|
public const int DMDO_90 = 1;
|
|
public const int DMDO_180 = 2;
|
|
public const int DMDO_270 = 3;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 改变分辨率
|
|
/// </summary>
|
|
/// <param name="displayOrientation">0:切换横屏,1:切换竖屏</param>
|
|
public static int ChangeResolution(int displayOrientation)
|
|
{
|
|
// 初始化 DEVMODE结构
|
|
DEVMODE devmode = new DEVMODE();
|
|
devmode.dmDeviceName = new String(new char[32]);
|
|
devmode.dmFormName = new String(new char[32]);
|
|
devmode.dmSize = (short)Marshal.SizeOf(devmode);
|
|
|
|
if (0 != NativeMethods.EnumDisplaySettings(null, NativeMethods.ENUM_CURRENT_SETTINGS, ref devmode))
|
|
{
|
|
//// 改变屏幕分辨率
|
|
//int iRet = NativeMethods.ChangeDisplaySettings(ref devmode, NativeMethods.CDS_TEST);
|
|
|
|
//if (iRet == NativeMethods.DISP_CHANGE_FAILED)
|
|
//{
|
|
// //MessageBox.Show("不能执行你的请求", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
//}
|
|
//else
|
|
//{
|
|
// int temp = devmode.dmPelsWidth;
|
|
// devmode.dmPelsWidth = devmode.dmPelsHeight;
|
|
// devmode.dmPelsHeight = temp;
|
|
// if (displayOrientation == 0)
|
|
// devmode.dmDisplayOrientation = NativeMethods.DMDO_90;
|
|
// else
|
|
// devmode.dmDisplayOrientation = NativeMethods.DMDO_DEFAULT;
|
|
|
|
// iRet = NativeMethods.ChangeDisplaySettings(ref devmode, NativeMethods.CDS_UPDATEREGISTRY);
|
|
|
|
// switch (iRet)
|
|
// {
|
|
// // 成功改变
|
|
// case NativeMethods.DISP_CHANGE_SUCCESSFUL:
|
|
// {
|
|
// break;
|
|
// }
|
|
// case NativeMethods.DISP_CHANGE_RESTART:
|
|
// {
|
|
// // MessageBox.Show("你需要重新启动电脑设置才能生效", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
// break;
|
|
// }
|
|
// default:
|
|
// {
|
|
// // MessageBox.Show("改变屏幕分辨率失败", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
// break;
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
|
|
if (devmode.dmDisplayOrientation == 0)
|
|
return 0;
|
|
else if (devmode.dmDisplayOrientation == 1)
|
|
return 90;
|
|
else if (devmode.dmDisplayOrientation == 2)
|
|
return 180;
|
|
else
|
|
return -90;
|
|
}
|
|
|
|
[DllImport("user32.dll")]
|
|
static extern void keybd_event
|
|
(
|
|
byte bVk,// 虚拟键值
|
|
byte bScan,// 硬件扫描码
|
|
uint dwFlags,// 动作标识
|
|
IntPtr dwExtraInfo// 与键盘动作关联的辅加信息
|
|
);
|
|
|
|
}
|
|
class Class_Config
|
|
{
|
|
private Class_Log log = new Class_Log();
|
|
private App app = ((App)System.Windows.Application.Current);
|
|
|
|
|
|
/// <summary>
|
|
/// 获取当前版本号
|
|
/// </summary>
|
|
public string GetVersion()
|
|
{
|
|
string currentVersion = "v1.2.5";
|
|
try
|
|
{
|
|
string localPath = Directory.GetCurrentDirectory() + "\\ScreenVersion.txt";
|
|
|
|
FileStream fs = new FileStream(localPath, FileMode.Open);
|
|
using (StreamReader sr = new StreamReader(fs))
|
|
{
|
|
string temp = sr.ReadLine();
|
|
currentVersion = temp.Substring(temp.LastIndexOf("V"));
|
|
}
|
|
fs.Close();
|
|
}
|
|
catch
|
|
{
|
|
currentVersion = "v1.2.5";
|
|
}
|
|
return currentVersion;
|
|
}
|
|
/// <summary>
|
|
/// 截屏
|
|
/// </summary>
|
|
public static string PrintScreen(string imgname)
|
|
{
|
|
string path = Environment.CurrentDirectory + @"\Screen\" + imgname;
|
|
Bitmap bit = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
|
|
Graphics g = Graphics.FromImage(bit);
|
|
g.CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), bit.Size);
|
|
|
|
try
|
|
{
|
|
if (File.Exists(path))
|
|
File.Delete(path);
|
|
bit.Save(path);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
// System.Windows.MessageBox.Show(ex.ToString());
|
|
}
|
|
finally
|
|
{
|
|
g.Dispose();
|
|
bit.Dispose();
|
|
}
|
|
|
|
return path;
|
|
}
|
|
/// <summary>
|
|
/// /加载配置
|
|
/// </summary>
|
|
public void LoadConfig()
|
|
{
|
|
try
|
|
{
|
|
string AddressIP = string.Empty;
|
|
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
|
|
{
|
|
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
|
|
{
|
|
AddressIP = _IPAddress.ToString();
|
|
}
|
|
}
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//Config.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Config");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("DeviceInfo");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现DeviceInfo标签");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
app.BuildingID = xnSecond.SelectSingleNode("BuildingID").InnerText;
|
|
app.Floor = xnSecond.SelectSingleNode("Floor").InnerText;
|
|
app.deviceid = xnSecond.SelectSingleNode("deviceid").InnerText;
|
|
app.devicemark = xnSecond.SelectSingleNode("devicemark").InnerText;
|
|
app.DeviceType = xnSecond.SelectSingleNode("devicetype").InnerText;
|
|
app.FileServerPath= xnSecond.SelectSingleNode("fileserverpath").InnerText;
|
|
}
|
|
log.WriteLogFile(app.deviceid,"config");
|
|
xnSecond = xnFirst.SelectSingleNode("Http");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现Http标签");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (xnSecond.SelectSingleNode("Url").InnerText != "")
|
|
app.HttpUrl = xnSecond.SelectSingleNode("Url").InnerText;
|
|
log.WriteLogFile(xnSecond.SelectSingleNode("LocalIP").InnerText, "config");
|
|
log.WriteLogFile(AddressIP, "config");
|
|
if (xnSecond.SelectSingleNode("LocalIP").InnerText != "")
|
|
{
|
|
if (AddressIP != xnSecond.SelectSingleNode("LocalIP").InnerText&& AddressIP!="127.0.0.1")
|
|
{
|
|
app.LocalIP = "";
|
|
app.BuildingID = "";
|
|
app.Floor = "";
|
|
app.devicemark = "";
|
|
app.deviceid = "";
|
|
app.HttpUrl = "";
|
|
app.DeviceType = "";
|
|
app.FileServerPath = "";
|
|
}
|
|
else
|
|
{
|
|
app.LocalIP = xnSecond.SelectSingleNode("LocalIP").InnerText;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
xnSecond = xnFirst.SelectSingleNode("MQTT");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现MQTT标签");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (xnSecond.SelectSingleNode("UserName").InnerText != "")
|
|
app.rabbitMQ.UserName = xnSecond.SelectSingleNode("UserName").InnerText;
|
|
if (xnSecond.SelectSingleNode("Password").InnerText != "")
|
|
app.rabbitMQ.Password = xnSecond.SelectSingleNode("Password").InnerText;
|
|
if (xnSecond.SelectSingleNode("HostName").InnerText != "")
|
|
app.rabbitMQ.HostName = xnSecond.SelectSingleNode("HostName").InnerText;
|
|
if (xnSecond.SelectSingleNode("Port").InnerText != "")
|
|
app.rabbitMQ.Port =Convert.ToInt32( xnSecond.SelectSingleNode("Port").InnerText);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
XmlDocument doc = new XmlDocument(); // 创建dom对象
|
|
XmlDeclaration xmldecl;
|
|
xmldecl = doc.CreateXmlDeclaration("1.0", "gb2312", null);
|
|
doc.AppendChild(xmldecl);
|
|
XmlElement root = doc.CreateElement("Config"); // 创建根节点
|
|
|
|
doc.AppendChild(root); // 加入到xml document
|
|
XmlElement FillItem; // 创建FillItem元素
|
|
|
|
FillItem = doc.CreateElement("DeviceInfo");
|
|
root.AppendChild(FillItem); // 添加到xml document
|
|
|
|
XmlElement Node = doc.CreateElement("BuildingID");
|
|
Node.InnerText = app.BuildingID;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Floor");
|
|
Node.InnerText = app.Floor;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("deviceid");
|
|
Node.InnerText = app.deviceid;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("devicemark");
|
|
Node.InnerText = app.deviceid;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("devicetype");
|
|
Node.InnerText = app.DeviceType;
|
|
FillItem.AppendChild(Node);
|
|
|
|
FillItem = doc.CreateElement("Http");
|
|
root.AppendChild(FillItem); // 添加到xml document
|
|
|
|
Node = doc.CreateElement("LocalIP");
|
|
Node.InnerText = app.LocalIP;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Url");
|
|
Node.InnerText = app.HttpUrl;
|
|
FillItem.AppendChild(Node);
|
|
|
|
|
|
FillItem = doc.CreateElement("MQTT");
|
|
root.AppendChild(FillItem); // 添加到xml document
|
|
|
|
Node = doc.CreateElement("UserName");
|
|
Node.InnerText = app.rabbitMQ.UserName;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Password");
|
|
Node.InnerText = app.rabbitMQ.Password;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("HostName");
|
|
Node.InnerText = app.rabbitMQ.HostName;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Port");
|
|
Node.InnerText = app.rabbitMQ.Port.ToString();
|
|
FillItem.AppendChild(Node);
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
XmlTextWriter writer = new XmlTextWriter(stream, null);
|
|
writer.Formatting = System.Xml.Formatting.Indented;
|
|
doc.Save(writer);
|
|
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
|
|
|
|
stream.Position = 0;
|
|
|
|
string XMLString = sr.ReadToEnd();
|
|
doc.Save(@"config\\config.xml"); // 保存文件
|
|
sr.Close();
|
|
stream.Close();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("LoadConfig:[" + e.ToString() + "]");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// /加载配置
|
|
/// </summary>
|
|
public void LoadInitialConfig()
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//InitialConfig.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Config");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("Http");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现Http标签");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (xnSecond.SelectSingleNode("HttpUrl").InnerText != "")
|
|
app.configurl = xnSecond.SelectSingleNode("HttpUrl").InnerText;
|
|
if (xnSecond.SelectSingleNode("WebSocketAddress").InnerText != "")
|
|
app.configwebsocket = xnSecond.SelectSingleNode("WebSocketAddress").InnerText;
|
|
if (xnSecond.SelectSingleNode("RegKey").InnerText != "")
|
|
app.mallRegKey = xnSecond.SelectSingleNode("RegKey").InnerText;
|
|
if (xnSecond.SelectSingleNode("Startexe").InnerText != "")
|
|
app.configstartexe = xnSecond.SelectSingleNode("Startexe").InnerText;
|
|
if (xnSecond.SelectSingleNode("Port").InnerText != "")
|
|
app.configport = xnSecond.SelectSingleNode("Port").InnerText;
|
|
if (xnSecond.SelectSingleNode("MallCode").InnerText != "")
|
|
app.mallCode = xnSecond.SelectSingleNode("MallCode").InnerText;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("LoadInitialConfig:[" + e.ToString() + "]");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// /修改配置
|
|
/// </summary>
|
|
public void WriteToInitialConfig()
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//InitialConfig.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Config");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("Http");
|
|
if (xnSecond == null)
|
|
{
|
|
XmlElement HttpNode = doc.CreateElement("Http");
|
|
HttpNode.InnerText = app.deviceid;
|
|
xnFirst.AppendChild(HttpNode);
|
|
|
|
XmlElement Node = doc.CreateElement("HttpUrl");
|
|
Node.InnerText = app.configurl;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("WebSocketAddress");
|
|
Node.InnerText = app.configwebsocket;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("RegKey");
|
|
Node.InnerText = app.mallRegKey;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Startexe");
|
|
Node.InnerText = app.configstartexe;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Port");
|
|
Node.InnerText = app.configport;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("MallCode");
|
|
Node.InnerText = app.mallCode;
|
|
HttpNode.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
XmlNode xnnode = xnSecond.SelectSingleNode("HttpUrl");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("HttpUrl");
|
|
Node.InnerText = app.configurl;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("HttpUrl").InnerText = app.configurl;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("RegKey");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("RegKey");
|
|
Node.InnerText = app.mallRegKey;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("RegKey").InnerText = app.mallRegKey;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("WebSocketAddress");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("WebSocketAddress");
|
|
Node.InnerText = app.configwebsocket;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("WebSocketAddress").InnerText = app.configwebsocket;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("Startexe");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("Startexe");
|
|
Node.InnerText = app.configstartexe;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("Startexe").InnerText = app.configstartexe;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("Port");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("Port");
|
|
Node.InnerText = app.configport;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("Port").InnerText = app.configport;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("MallCode");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("MallCode");
|
|
Node.InnerText = app.mallCode;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("MallCode").InnerText = app.mallCode;
|
|
}
|
|
}
|
|
|
|
doc.Save(strConfigxml);
|
|
}
|
|
else
|
|
{
|
|
XmlDocument doc = new XmlDocument(); // 创建dom对象
|
|
XmlDeclaration xmldecl;
|
|
xmldecl = doc.CreateXmlDeclaration("1.0", "gb2312", null);
|
|
doc.AppendChild(xmldecl);
|
|
XmlElement root = doc.CreateElement("Config"); // 创建根节点
|
|
|
|
doc.AppendChild(root); // 加入到xml document
|
|
XmlElement HttpNode = doc.CreateElement("Http");
|
|
HttpNode.InnerText = app.deviceid;
|
|
root.AppendChild(HttpNode);
|
|
|
|
XmlElement Node = doc.CreateElement("HttpUrl");
|
|
Node.InnerText = app.configurl;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("RegKey");
|
|
Node.InnerText = app.mallRegKey;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("WebSocketAddress");
|
|
Node.InnerText = app.configwebsocket;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
|
|
Node = doc.CreateElement("Startexe");
|
|
Node.InnerText = app.configstartexe;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Port");
|
|
Node.InnerText = app.configport;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("MallCode");
|
|
Node.InnerText = app.mallCode;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
XmlTextWriter writer = new XmlTextWriter(stream, null);
|
|
writer.Formatting = System.Xml.Formatting.Indented;
|
|
doc.Save(writer);
|
|
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
|
|
|
|
stream.Position = 0;
|
|
|
|
string XMLString = sr.ReadToEnd();
|
|
doc.Save(@"config\\InitialConfig.xml"); // 保存文件
|
|
sr.Close();
|
|
stream.Close();
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("WriteConfig:[" + e.ToString() + "]");
|
|
}
|
|
}
|
|
public void WriteToConfig()
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//Config.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Config");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("DeviceInfo");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现DeviceInfo标签");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
XmlNode xnnode = xnSecond.SelectSingleNode("BuildingID");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("BuildingID");
|
|
Node.InnerText = app.BuildingID;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("BuildingID").InnerText = app.BuildingID;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("Floor");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("Floor");
|
|
Node.InnerText = app.Floor;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("Floor").InnerText = app.Floor;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("deviceid");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("deviceid");
|
|
Node.InnerText = app.deviceid;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("deviceid").InnerText = app.deviceid;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("devicemark");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("devicemark");
|
|
Node.InnerText = app.devicemark;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("devicemark").InnerText = app.devicemark;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("devicetype");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("devicetype");
|
|
Node.InnerText = app.DeviceType;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("devicetype").InnerText = app.DeviceType;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("fileserverpath");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("fileserverpath");
|
|
Node.InnerText = app.FileServerPath;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("fileserverpath").InnerText = app.FileServerPath;
|
|
}
|
|
|
|
}
|
|
xnSecond = xnFirst.SelectSingleNode("Http");
|
|
if (xnSecond == null)
|
|
{
|
|
XmlElement HttpNode = doc.CreateElement("Http");
|
|
HttpNode.InnerText = app.deviceid;
|
|
xnFirst.AppendChild(HttpNode);
|
|
|
|
XmlElement Node = doc.CreateElement("LocalIP");
|
|
Node.InnerText = app.LocalIP;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Url");
|
|
Node.InnerText = app.HttpUrl;
|
|
HttpNode.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("LocalIP").InnerText = app.LocalIP;
|
|
xnSecond.SelectSingleNode("Url").InnerText = app.HttpUrl;
|
|
}
|
|
|
|
xnSecond = xnFirst.SelectSingleNode("MQTT");
|
|
if (xnSecond == null)
|
|
{
|
|
XmlElement HttpNode = doc.CreateElement("MQTT");
|
|
HttpNode.InnerText = app.deviceid;
|
|
xnFirst.AppendChild(HttpNode);
|
|
|
|
XmlElement Node = doc.CreateElement("UserName");
|
|
Node.InnerText = app.rabbitMQ.UserName;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Password");
|
|
Node.InnerText = app.rabbitMQ.Password;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("HostName");
|
|
Node.InnerText = app.rabbitMQ.HostName;
|
|
HttpNode.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Port");
|
|
Node.InnerText = app.rabbitMQ.Port.ToString();
|
|
HttpNode.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("UserName").InnerText = app.rabbitMQ.UserName;
|
|
xnSecond.SelectSingleNode("Password").InnerText = app.rabbitMQ.Password;
|
|
xnSecond.SelectSingleNode("HostName").InnerText = app.rabbitMQ.HostName;
|
|
xnSecond.SelectSingleNode("Port").InnerText = app.rabbitMQ.Port.ToString();
|
|
}
|
|
doc.Save(strConfigxml);
|
|
}
|
|
else
|
|
{
|
|
XmlDocument doc = new XmlDocument(); // 创建dom对象
|
|
XmlDeclaration xmldecl;
|
|
xmldecl = doc.CreateXmlDeclaration("1.0", "gb2312", null);
|
|
doc.AppendChild(xmldecl);
|
|
XmlElement root = doc.CreateElement("Config"); // 创建根节点
|
|
|
|
doc.AppendChild(root); // 加入到xml document
|
|
XmlElement FillItem; // 创建FillItem元素
|
|
XmlElement FillMQTTItem; // 创建FillItem元素
|
|
|
|
FillItem = doc.CreateElement("DeviceInfo");
|
|
root.AppendChild(FillItem); // 添加到xml document
|
|
FillMQTTItem = doc.CreateElement("MQTT");
|
|
root.AppendChild(FillMQTTItem); // 添加到xml document
|
|
|
|
XmlElement Node = doc.CreateElement("BuildingID");
|
|
Node.InnerText = app.BuildingID;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Floor");
|
|
Node.InnerText = app.Floor;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("deviceid");
|
|
Node.InnerText = app.deviceid;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("devicemark");
|
|
Node.InnerText = app.devicemark;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("devicetype");
|
|
Node.InnerText = app.DeviceType;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("fileserverpath");
|
|
Node.InnerText = app.FileServerPath;
|
|
FillItem.AppendChild(Node);
|
|
|
|
FillItem = doc.CreateElement("Http");
|
|
root.AppendChild(FillItem); // 添加到xml document
|
|
|
|
Node = doc.CreateElement("LocalIP");
|
|
Node.InnerText = app.LocalIP;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Url");
|
|
Node.InnerText = app.HttpUrl;
|
|
FillItem.AppendChild(Node);
|
|
|
|
XmlElement NodeMQTT = doc.CreateElement("UserName");
|
|
NodeMQTT.InnerText = app.rabbitMQ == null ? "" : app.rabbitMQ.UserName;
|
|
FillMQTTItem.AppendChild(NodeMQTT);
|
|
|
|
NodeMQTT = doc.CreateElement("Password");
|
|
NodeMQTT.InnerText = app.rabbitMQ == null ? "" : app.rabbitMQ.Password;
|
|
FillMQTTItem.AppendChild(NodeMQTT);
|
|
|
|
NodeMQTT = doc.CreateElement("HostName");
|
|
NodeMQTT.InnerText = app.rabbitMQ == null ? "" : app.rabbitMQ.HostName;
|
|
FillMQTTItem.AppendChild(NodeMQTT);
|
|
|
|
NodeMQTT = doc.CreateElement("Port");
|
|
NodeMQTT.InnerText = app.rabbitMQ == null ? "" : app.rabbitMQ.Port.ToString();
|
|
FillMQTTItem.AppendChild(NodeMQTT);
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
XmlTextWriter writer = new XmlTextWriter(stream, null);
|
|
writer.Formatting = System.Xml.Formatting.Indented;
|
|
doc.Save(writer);
|
|
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
|
|
|
|
stream.Position = 0;
|
|
|
|
string XMLString = sr.ReadToEnd();
|
|
doc.Save(@"config\\config.xml"); // 保存文件
|
|
sr.Close();
|
|
stream.Close();
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("WriteConfig:[" + e.ToString() + "]");
|
|
}
|
|
}
|
|
|
|
|
|
public bool WriteToExeConfig(AppListModel exeinfo)
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//ExeConfig.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
if (!UpdateExeConfig(exeinfo))
|
|
{
|
|
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Root");
|
|
XmlElement FillItem; // 创建FillItem元素
|
|
|
|
FillItem = doc.CreateElement("ExeInfo");
|
|
// 添加到xml document
|
|
|
|
XmlElement Node = doc.CreateElement("AppID");
|
|
Node.InnerText = exeinfo.AppID;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("AppType");
|
|
Node.InnerText = exeinfo.AppType;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Code");
|
|
Node.InnerText = exeinfo.Code;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Default");
|
|
Node.InnerText = exeinfo.Default;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("File");
|
|
Node.InnerText = exeinfo.File;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Logo");
|
|
Node.InnerText = exeinfo.Logo;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Name");
|
|
Node.InnerText = exeinfo.Name;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("PackageName");
|
|
Node.InnerText = exeinfo.PackageName;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("PlatformType");
|
|
Node.InnerText = exeinfo.PlatformType;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("ShelfTime");
|
|
Node.InnerText = exeinfo.ShelfTime;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Startup");
|
|
Node.InnerText = exeinfo.Startup;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Version");
|
|
Node.InnerText = exeinfo.Version;
|
|
FillItem.AppendChild(Node);
|
|
|
|
xnFirst.AppendChild(FillItem);
|
|
doc.Save(strConfigxml);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
XmlDocument doc = new XmlDocument(); // 创建dom对象
|
|
XmlDeclaration xmldecl;
|
|
xmldecl = doc.CreateXmlDeclaration("1.0", "gb2312", null);
|
|
doc.AppendChild(xmldecl);
|
|
XmlElement root = doc.CreateElement("Root"); // 创建根节点
|
|
|
|
doc.AppendChild(root); // 加入到xml document
|
|
XmlElement FillItem; // 创建FillItem元素
|
|
|
|
FillItem = doc.CreateElement("ExeInfo");
|
|
// 添加到xml document
|
|
|
|
XmlElement Node = doc.CreateElement("AppID");
|
|
Node.InnerText = exeinfo.AppID;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("AppType");
|
|
Node.InnerText = exeinfo.AppType;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Code");
|
|
Node.InnerText = exeinfo.Code;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Default");
|
|
Node.InnerText = exeinfo.Default;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("File");
|
|
Node.InnerText = exeinfo.File;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Logo");
|
|
Node.InnerText = exeinfo.Logo;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Name");
|
|
Node.InnerText = exeinfo.Name;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("PackageName");
|
|
Node.InnerText = exeinfo.PackageName;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("PlatformType");
|
|
Node.InnerText = exeinfo.PlatformType;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("ShelfTime");
|
|
Node.InnerText = exeinfo.ShelfTime;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Startup");
|
|
Node.InnerText = exeinfo.Startup;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("Version");
|
|
Node.InnerText = exeinfo.Version;
|
|
FillItem.AppendChild(Node);
|
|
|
|
root.AppendChild(FillItem);
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
XmlTextWriter writer = new XmlTextWriter(stream, null);
|
|
writer.Formatting = System.Xml.Formatting.Indented;
|
|
doc.Save(writer);
|
|
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
|
|
|
|
stream.Position = 0;
|
|
|
|
string XMLString = sr.ReadToEnd();
|
|
doc.Save(@"config\\ExeConfig.xml"); // 保存配置文件
|
|
sr.Close();
|
|
stream.Close();
|
|
}
|
|
return true;
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("WriteExeConfig:[" + e.ToString() + "]", "ExeConfigLog");
|
|
return false;
|
|
}
|
|
}
|
|
public bool UpdateExeConfig(AppListModel exeinfo)
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\ExeConfig.xml";
|
|
if (!File.Exists(fpath))
|
|
{
|
|
return WriteToExeConfig(exeinfo);
|
|
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//ExeConfig.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Root");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("ExeInfo");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现ExeInfo标签");
|
|
return false;
|
|
}
|
|
XmlNodeList xnChildList = xnFirst.ChildNodes;
|
|
|
|
|
|
for (int i = 0; i < xnChildList.Count; i++)
|
|
{
|
|
XmlNode xnChild = xnChildList.Item(i);
|
|
XmlNodeList xnn = xnChild.ChildNodes;
|
|
|
|
for (int j = 0; j < xnn.Count; j++)
|
|
{
|
|
XmlNode xnChildItem = xnn.Item(j);
|
|
if (xnChildItem.LocalName.Equals("Code"))
|
|
{
|
|
if (xnChildItem.InnerText.ToString().Trim().Equals(exeinfo.Code))
|
|
{
|
|
xnChild.SelectSingleNode("AppID").InnerText = exeinfo.AppID;
|
|
xnChild.SelectSingleNode("AppType").InnerText = exeinfo.AppType;
|
|
xnChild.SelectSingleNode("Default").InnerText = exeinfo.Default;
|
|
xnChild.SelectSingleNode("File").InnerText = exeinfo.File;
|
|
xnChild.SelectSingleNode("Logo").InnerText = exeinfo.Logo;
|
|
xnChild.SelectSingleNode("Name").InnerText = exeinfo.Name;
|
|
xnChild.SelectSingleNode("PackageName").InnerText = exeinfo.PackageName;
|
|
xnChild.SelectSingleNode("PlatformType").InnerText = exeinfo.PlatformType;
|
|
xnChild.SelectSingleNode("ShelfTime").InnerText = exeinfo.ShelfTime;
|
|
xnChild.SelectSingleNode("Startup").InnerText = exeinfo.Startup;
|
|
xnChild.SelectSingleNode("Version").InnerText = exeinfo.Version;
|
|
doc.Save(strConfigxml);
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("UpdateExeConfig:[" + e.ToString() + "]", "ExeConfigLog");
|
|
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool RemoveExeConfig(string code,ref string filePath,ref string logo,ref string startup)
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\ExeConfig.xml";
|
|
if (!File.Exists(fpath))
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现ExeConfig.xml文件");
|
|
return false;
|
|
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//ExeConfig.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Root");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("ExeInfo");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现ExeInfo标签");
|
|
return false;
|
|
}
|
|
XmlNodeList xnChildList = xnFirst.ChildNodes;
|
|
|
|
|
|
for (int i = 0; i < xnChildList.Count; i++)
|
|
{
|
|
XmlNode xnChild = (XmlElement)xnChildList.Item(i);
|
|
XmlNodeList xnn = xnChild.ChildNodes;
|
|
|
|
for (int j = 0; j < xnn.Count; j++)
|
|
{
|
|
XmlNode xnChildItem = xnn.Item(j);
|
|
if (xnChildItem.LocalName.Equals("Code"))
|
|
{
|
|
if (xnChildItem.InnerText.ToString().Trim().Equals(code))
|
|
{
|
|
|
|
xnFirst.RemoveChild(xnChild);
|
|
filePath= xnChild.SelectSingleNode("File").InnerText;
|
|
logo = xnChild.SelectSingleNode("Logo").InnerText;
|
|
startup= xnChild.SelectSingleNode("Startup").InnerText;
|
|
doc.Save(strConfigxml);
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("UpdateExeConfig:[" + e.ToString() + "]", "ExeConfigLog");
|
|
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
public bool WriteToAppTimeConfig(List<AppTimeModel> timeList)
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//AppTimeConfig.xml";
|
|
if (File.Exists(strConfigxml))
|
|
{
|
|
File.Delete(strConfigxml);
|
|
}
|
|
if (timeList.Count > 0)
|
|
{
|
|
XmlDocument doc = new XmlDocument(); // 创建dom对象
|
|
XmlDeclaration xmldecl;
|
|
xmldecl = doc.CreateXmlDeclaration("1.0", "gb2312", null);
|
|
doc.AppendChild(xmldecl);
|
|
XmlElement root = doc.CreateElement("Root"); // 创建根节点
|
|
|
|
doc.AppendChild(root); // 加入到xml document
|
|
|
|
foreach (var item in timeList)
|
|
{
|
|
XmlElement FillItem; // 创建FillItem元素
|
|
|
|
FillItem = doc.CreateElement("AppTimeInfo");
|
|
// 添加到xml document
|
|
|
|
XmlElement Node = doc.CreateElement("AppCode");
|
|
Node.InnerText = item.AppCode;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("BeginTimeSlot");
|
|
Node.InnerText = item.BeginTimeSlot;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("EndTimeSlot");
|
|
Node.InnerText = item.EndTimeSlot;
|
|
FillItem.AppendChild(Node);
|
|
root.AppendChild(FillItem);
|
|
}
|
|
MemoryStream stream = new MemoryStream();
|
|
XmlTextWriter writer = new XmlTextWriter(stream, null);
|
|
writer.Formatting = System.Xml.Formatting.Indented;
|
|
doc.Save(writer);
|
|
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
|
|
|
|
stream.Position = 0;
|
|
|
|
string XMLString = sr.ReadToEnd();
|
|
doc.Save(@"config\\AppTimeConfig.xml"); // 保存配置文件
|
|
sr.Close();
|
|
stream.Close();
|
|
}
|
|
return true;
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("WriteToaAppTimeConfig:[" + e.ToString() + "]", "ExeConfigLog");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取ExeConfig配置文件中的应用信息
|
|
/// </summary>
|
|
public void ReadAppInfo(ref List<AppListModel> AppList)
|
|
{
|
|
try
|
|
{
|
|
AppList.Clear();
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\ExeConfig.xml";
|
|
if (!File.Exists(fpath))
|
|
{
|
|
return;
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//ExeConfig.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Root");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("ExeInfo");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现ExeInfo标签");
|
|
return;
|
|
}
|
|
XmlNodeList xnChildList = xnFirst.ChildNodes;
|
|
|
|
|
|
for (int i = 0; i < xnChildList.Count; i++)
|
|
{
|
|
XmlNode xnChild = xnChildList.Item(i);
|
|
XmlNodeList xnn = xnChild.ChildNodes;
|
|
AppListModel appinfo = new AppListModel();
|
|
if (xnn.Count > 0)
|
|
{
|
|
for (int j = 0; j < xnn.Count; j++)
|
|
{
|
|
XmlNode xnChildItem = xnn.Item(j);
|
|
if (xnChildItem.LocalName.Equals("AppID"))
|
|
{
|
|
appinfo.AppID = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("AppType"))
|
|
{
|
|
appinfo.AppType = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("Code"))
|
|
{
|
|
appinfo.Code = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("Default"))
|
|
{
|
|
appinfo.Default = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("File"))
|
|
{
|
|
appinfo.File = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("Logo"))
|
|
{
|
|
appinfo.Logo = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("Name"))
|
|
{
|
|
appinfo.Name = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("PackageName"))
|
|
{
|
|
appinfo.PackageName = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("PlatformType"))
|
|
{
|
|
appinfo.PlatformType = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("ShelfTime"))
|
|
{
|
|
appinfo.ShelfTime = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("Startup"))
|
|
{
|
|
appinfo.Startup = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("Version"))
|
|
{
|
|
appinfo.Version = xnChildItem.InnerText.ToString();
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(appinfo.ShelfTime) || Convert.ToDateTime(appinfo.ShelfTime) > DateTime.Now.AddDays(-1))
|
|
{
|
|
AppList.Add(appinfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile("读取ExeConfig配置文件失败"+ex.ToString(),"ExeConfigLog");
|
|
}
|
|
}
|
|
|
|
public void ReadAppTimeInfo(ref List<AppTimeModel> AppTimeList)
|
|
{
|
|
try
|
|
{
|
|
AppTimeList.Clear();
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\AppTimeConfig.xml";
|
|
if (!File.Exists(fpath))
|
|
{
|
|
return;
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//AppTimeConfig.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Root");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("AppTimeInfo");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现AppTimeInfo标签");
|
|
return;
|
|
}
|
|
XmlNodeList xnChildList = xnFirst.ChildNodes;
|
|
|
|
|
|
for (int i = 0; i < xnChildList.Count; i++)
|
|
{
|
|
XmlNode xnChild = xnChildList.Item(i);
|
|
XmlNodeList xnn = xnChild.ChildNodes;
|
|
AppTimeModel appTime = new AppTimeModel();
|
|
if (xnn.Count > 0)
|
|
{
|
|
for (int j = 0; j < xnn.Count; j++)
|
|
{
|
|
XmlNode xnChildItem = xnn.Item(j);
|
|
if (xnChildItem.LocalName.Equals("AppCode"))
|
|
{
|
|
appTime.AppCode = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("BeginTimeSlot"))
|
|
{
|
|
appTime.BeginTimeSlot = xnChildItem.InnerText.ToString();
|
|
}
|
|
else if (xnChildItem.LocalName.Equals("EndTimeSlot"))
|
|
{
|
|
appTime.EndTimeSlot = xnChildItem.InnerText.ToString();
|
|
}
|
|
|
|
}
|
|
AppTimeList.Add(appTime);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile("读取AppTimeInfo配置文件失败" + ex.ToString(), "AppTimeInfoLog");
|
|
}
|
|
}
|
|
|
|
public bool UpdateConfig(string devNum)
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\config\\config.xml";
|
|
if (!File.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "config//config.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Config");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("DeviceInfo");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现DeviceInfo标签");
|
|
return false;
|
|
}
|
|
else {
|
|
XmlNode xnnode = xnSecond.SelectSingleNode("devicemark");
|
|
if (xnnode != null)
|
|
{
|
|
xnSecond.SelectSingleNode("devicemark").InnerText = app.devicemark;
|
|
}
|
|
}
|
|
doc.Save(strConfigxml);
|
|
return true;
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("UpdateConfig:[" + e.ToString() + "]", "ExeConfigLog");
|
|
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void WriteToScreenConfig(string touchType, string screenEffect,string screenFilePath, string effectType)
|
|
{
|
|
try
|
|
{
|
|
string fpath = Directory.GetCurrentDirectory() + "\\exefile\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
fpath = Directory.GetCurrentDirectory() + "\\exefile\\PCScreen\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
fpath = Directory.GetCurrentDirectory() + "\\exefile\\PCScreen\\config\\";
|
|
if (!Directory.Exists(fpath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath);
|
|
directoryInfo.Create();
|
|
}
|
|
string strConfigxml = AppDomain.CurrentDomain.BaseDirectory + "exefile//PCScreen//config//Screensaver.xml";
|
|
if (File.Exists(strConfigxml) == true)
|
|
{
|
|
XmlDocument doc = new XmlDocument();
|
|
doc.Load(strConfigxml);
|
|
XmlNode xnFirst = doc.SelectSingleNode("Config");
|
|
XmlNode xnSecond = xnFirst.SelectSingleNode("Parameter");
|
|
if (xnSecond == null)
|
|
{
|
|
log.WriteLogFile("配置文件错误-未发现Parameter标签");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
XmlNode xnnode = xnSecond.SelectSingleNode("TouchType");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("TouchType");
|
|
Node.InnerText = touchType;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("TouchType").InnerText = touchType;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("ScreenEffect");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("ScreenEffect");
|
|
Node.InnerText = screenEffect;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("ScreenEffect").InnerText = screenEffect;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("ScreenFilePath");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("ScreenFilePath");
|
|
Node.InnerText = screenFilePath;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("ScreenFilePath").InnerText = screenFilePath;
|
|
}
|
|
|
|
xnnode = xnSecond.SelectSingleNode("EffectType");
|
|
if (xnnode == null)
|
|
{
|
|
XmlElement Node = doc.CreateElement("EffectType");
|
|
Node.InnerText = effectType;
|
|
xnSecond.AppendChild(Node);
|
|
}
|
|
else
|
|
{
|
|
xnSecond.SelectSingleNode("EffectType").InnerText = effectType;
|
|
}
|
|
}
|
|
|
|
doc.Save(strConfigxml);
|
|
}
|
|
else
|
|
{
|
|
XmlDocument doc = new XmlDocument(); // 创建dom对象
|
|
XmlDeclaration xmldecl;
|
|
xmldecl = doc.CreateXmlDeclaration("1.0", "gb2312", null);
|
|
doc.AppendChild(xmldecl);
|
|
XmlElement root = doc.CreateElement("Config"); // 创建根节点
|
|
|
|
doc.AppendChild(root); // 加入到xml document
|
|
XmlElement FillItem; // 创建FillItem元素
|
|
|
|
FillItem = doc.CreateElement("Parameter");
|
|
root.AppendChild(FillItem); // 添加到xml document
|
|
|
|
XmlElement Node = doc.CreateElement("TouchType");
|
|
Node.InnerText = touchType;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("ScreenEffect");
|
|
Node.InnerText = screenEffect;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("ScreenFilePath");
|
|
Node.InnerText = screenFilePath;
|
|
FillItem.AppendChild(Node);
|
|
|
|
Node = doc.CreateElement("EffectType");
|
|
Node.InnerText = effectType;
|
|
FillItem.AppendChild(Node);
|
|
|
|
MemoryStream stream = new MemoryStream();
|
|
XmlTextWriter writer = new XmlTextWriter(stream, null);
|
|
writer.Formatting = System.Xml.Formatting.Indented;
|
|
doc.Save(writer);
|
|
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
|
|
|
|
stream.Position = 0;
|
|
|
|
string XMLString = sr.ReadToEnd();
|
|
doc.Save(@"exefile//PCScreen//config//Screensaver.xml"); // 保存文件
|
|
sr.Close();
|
|
stream.Close();
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.WriteLogFile("WriteToScreenConfig:[" + e.ToString() + "]");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|