Esempio n. 1
0
 public object SearchHistory(string[] pointNames, DateTime startTime, DateTime endTime)
 {
     using (var hisDB = new DB.SunRiz(HistoryRecord.HistoryAutoRec.HistoryDataPath, Way.EntityDB.DatabaseType.Sqlite))
     {
         List <object> result = new List <object>();
         foreach (string pointName in pointNames)
         {
             var data = (from m in hisDB.History
                         where m.Time >= startTime && m.Time <= endTime && m.Address == pointName
                         orderby m.Time
                         select m).ToArray();
             var resultData = new object[data.Length];
             for (int i = 0; i < resultData.Length; i++)
             {
                 resultData[i] = new
                 {
                     seconds = Helper.ConvertDateTimeInt(data[i].Time.GetValueOrDefault()),
                     value   = data[i].Value.GetValueOrDefault()
                 };
             }
             result.Add(resultData);
         }
         return(result);
     }
 }
Esempio n. 2
0
        public int UpdateSystemSetting(SystemSetting data)
        {
            var needRestartHistory = false;

            if (data.ChangedProperties.Any(m => m.Key == "HistoryPath"))
            {
                //历史保存路径修改了
                needRestartHistory = true;

                //这里确保能创建数据库
                if (!string.IsNullOrEmpty(data.HistoryPath))
                {
                    var HistoryDataPath = $"data source=\"{data.HistoryPath.Replace("\\", "/")}/history_data.db\"";
                    using (var hisDB = new DB.SunRiz(HistoryDataPath, Way.EntityDB.DatabaseType.Sqlite))
                    {
                    }
                }
            }

            if (data.ChangedProperties.Any(m => m.Key == "LogPath"))
            {
                SystemLog.Init();
            }
            SystemHelper.AddSysLog(this.User.id.Value, "更新系统设置:" + Newtonsoft.Json.JsonConvert.SerializeObject(data.ChangedProperties));

            this.db.Update(data);
            if (needRestartHistory)
            {
                HistoryRecord.HistoryAutoRec.ReStart();
            }
            return(data.id.Value);
        }
Esempio n. 3
0
 protected override void OnUnLoad()
 {
     if (_hisDB != null)
     {
         _hisDB.Dispose();
         _hisDB = null;
     }
     base.OnUnLoad();
 }
Esempio n. 4
0
        /// <summary>
        /// 添加系统日志
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="content"></param>
        public static void AddSysLog(int userid, string content)
        {
            if (string.IsNullOrEmpty(SystemLog.LogDataPath))
            {
                return;
            }

            using (var db = new DB.SunRiz(SystemLog.LogDataPath, Way.EntityDB.DatabaseType.Sqlite))
            {
                db.Insert(new SysLog {
                    UserId  = userid,
                    Content = content,
                    Time    = DateTime.Now
                });
            }
        }