/// <summary> /// 如果不符合报警条件,则自动返回 /// </summary> /// <param name="pointId"></param> /// <param name="value"></param> public static void AutoBackAlarm(int pointId, double value) { Task.Run(() => { try { using (SysDB db = new SysDB()) { var arr = db.Alarm.Where(m => m.IsConfirm == false && m.IsBack == false && m.PointId == pointId && m.Expression != null).ToArray(); foreach (var alarm in arr) { var expression = string.Format(alarm.Expression, value); var result = Convert.ToBoolean(db.Database.ExecSqlString($"select ({expression})")); if (result == false) { //不符合报警条件,可以返回 alarm.IsBack = true; db.Update(alarm); } } } } catch (Exception ex) { using (Way.Lib.CLog log = new Way.Lib.CLog("AutoBackAlarm error")) { log.Log(ex.ToString()); } } }); }
/// <summary> /// 添加报警 /// </summary> public static void AddAlarm(Alarm alarm) { alarm.AlarmTime = DateTime.Now; Task.Run(() => { try { using (SysDB db = new SysDB()) { if (db.Alarm.Any(m => m.IsConfirm == false && m.IsReset == false && m.IsBack == false && m.Address == alarm.Address && m.Content == alarm.Content)) { //有同样的报警,而且没有确认 return; } db.Insert(alarm); } } catch (Exception ex) { using (Way.Lib.CLog log = new Way.Lib.CLog("AddAlarm error")) { log.Log(ex.ToString()); } } }); }
static SysDB() { using (var db = new SysDB()) { if (db.UserInfo.Count() == 0) { db.Insert(new UserInfo() { Name = "sa", Password = "******", Role = UserInfo_RoleEnum.Admin }); } } }
public static void Init() { try { using (SysDB db = new SysDB()) { var sysSetting = db.SystemSetting.FirstOrDefault(); if (string.IsNullOrEmpty(sysSetting.LogPath)) { return; } try { //目录不存在,创建目录 if (System.IO.Directory.Exists(sysSetting.LogPath) == false) { System.IO.Directory.CreateDirectory(sysSetting.LogPath); } LogDataPath = $"data source=\"{sysSetting.LogPath.Replace("\\", "/")}/log_data.db\""; using (logDB = new DB.SunRiz(LogDataPath, Way.EntityDB.DatabaseType.Sqlite)) { } } catch { return; } } } catch (Exception ex) { using (Way.Lib.CLog log = new Way.Lib.CLog("SystemLog error ")) { log.Log(ex.ToString()); } } }
public static void Main(string[] args) { try { //System.Diagnostics.Debugger.Launch(); Console.OutputEncoding = System.Text.Encoding.UTF8; int port = 8988; if (args != null && args.Length > 0) { port = Convert.ToInt32(args[0]); } Console.WriteLine($"server starting at port:{port}..."); var webroot = $"{Way.Lib.PlatformHelper.GetAppDirectory()}web"; #if DEBUG if (System.IO.Directory.Exists(@"D:\注释\2016\EasyJobCore\Way.Lib.ScriptRemoting.Test.Web\组态")) { webroot = @"D:\注释\2016\EasyJobCore\Way.Lib.ScriptRemoting.Test.Web\组态"; } else if (System.IO.Directory.Exists(@"D:\projects\c#\EasyJob\Way.Lib.ScriptRemoting.Test.Web\组态")) { webroot = @"D:\projects\c#\EasyJob\Way.Lib.ScriptRemoting.Test.Web\组态"; } #endif if (!System.IO.Directory.Exists(webroot)) { System.IO.Directory.CreateDirectory(webroot); } if (!System.IO.Directory.Exists(Way.Lib.PlatformHelper.GetAppDirectory() + "windows/")) { System.IO.Directory.CreateDirectory(Way.Lib.PlatformHelper.GetAppDirectory() + "windows/"); } Console.WriteLine($"path:{webroot}"); ScriptRemotingServer.Start(port, webroot, 1); Console.WriteLine($"web server started"); //注册数据库触发器 SysDB.RegisterActionCapture(new DBTriggers.ImageFilesTrigger()); SysDB.RegisterActionCapture(new DBTriggers.DevicePointFolderTrigger()); SysDB.RegisterActionCapture(new DBTriggers.ControlWindowTrigger()); SysDB.RegisterActionCapture(new DBTriggers.ControlWindowFolderTrigger()); using (var db = new SysDB()) { db.ImageFiles.FirstOrDefault(); } Console.WriteLine($"database ready"); SystemLog.Init(); //记录历史 HistoryRecord.HistoryAutoRec.ReStart(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } while (true) { Console.Write("Web>"); var line = Console.ReadLine(); if (line == null) { //是在后台运行的 while (true) { System.Threading.Thread.Sleep(10000000); } } else if (line == "exit") { break; } } ScriptRemotingServer.Stop(); System.Diagnostics.Process.GetCurrentProcess().Kill(); }