public string GetEvents(int year, int month, int day, string cnlNums, string viewIDs, int viewID, int lastCount, int startEvNum, long dataAge) { try { UserRights userRights; AppData.CheckLoggedOn(out userRights); // создание фильтра событий HashSet <int> cnlSet = GetCnlSet(cnlNums, viewIDs, viewID, userRights); EventTableLight.EventFilter eventFilter = cnlSet == null ? new EventTableLight.EventFilter(EventTableLight.EventFilters.None) : new EventTableLight.EventFilter(EventTableLight.EventFilters.Cnls); eventFilter.CnlNums = cnlSet; // получение событий DataAccess dataAccess = AppData.DataAccess; DateTime date = new DateTime(year, month, day); EventTableLight tblEvent = dataAccess.DataCache.GetEventTable(date); long newDataAge = WebUtils.DateTimeToJs(tblEvent.FileModTime); DispEvent[] eventsToSend; if (tblEvent.FileModTime > DateTime.MinValue && dataAge < newDataAge) { // применение фильтра событий bool reversed; List <EventTableLight.Event> events = tblEvent.GetFilteredEvents(eventFilter, lastCount, startEvNum, out reversed); // преобразование событий для передачи int evCnt = events.Count; eventsToSend = new DispEvent[evCnt]; if (reversed) { for (int i = 0, j = evCnt - 1; i < evCnt; i++, j--) { eventsToSend[i] = dataAccess.GetDispEvent(events[j], DataFormatter); } } else { for (int i = 0; i < evCnt; i++) { eventsToSend[i] = dataAccess.GetDispEvent(events[i], DataFormatter); } } } else { eventsToSend = new DispEvent[0]; } return(JsSerializer.Serialize(new ArcDTO(eventsToSend, newDataAge))); } catch (Exception ex) { AppData.Log.WriteException(ex, Localization.UseRussian ? "Ошибка при получении событий по фильтру, где каналы={0}, ид. представления={1}" : "Error getting events by the filter where channels={0}, view id={1}", cnlNums, viewID); return(GetErrorDtoJs(ex)); } }
protected void Page_Load(object sender, EventArgs e) { string errDetails = ""; try { // настройка выходного потока Response.ClearContent(); Response.TrySkipIisCustomErrors = true; // перевод веб-страницы Translator.TranslatePage(this, "Scada.Web.WFrmError"); lblProductName.Text = CommonPhrases.ProductName; // определение сообщения об ошибке Exception ex = Server.GetLastError(); if (ex != null) { if (ex.InnerException != null) { ex = ex.InnerException; } if (ex is HttpException) { Response.StatusCode = ((HttpException)ex).GetHttpCode(); } errDetails = ex.Message; } // вывод информации об ошибке в журнал приложения StringBuilder sbLogMsg = new StringBuilder(); sbLogMsg .Append(Localization.UseRussian ? "Ошибка приложения: " : "Application error: "); if (ex != null) { sbLogMsg .AppendLine() .Append(ex.ToString()); } sbLogMsg .AppendLine() .Append(Localization.UseRussian ? "Страница: " : "Page: ") .Append(Request.Url.AbsoluteUri); if (Context.Session != null) { UserData userData = UserData.GetUserData(); if (userData != null) { sbLogMsg .AppendLine() .Append(Localization.UseRussian ? "Пользователь: " : "User: "******"вход не выполнен" : "not logged on")); } } AppData.GetAppData().Log.WriteAction(sbLogMsg.ToString(), Log.ActTypes.Exception); } finally { // вывод сообщения об ошибке на форму if (errDetails != "") { lblErrDetails.Text = WebUtils.HtmlEncodeWithBreak(errDetails); } else { lblErrDetailsCaption.Visible = lblErrDetails.Visible = false; } Server.ClearError(); } }
/// <summary> /// Получить часовые данные входных каналов /// </summary> private HourCnlData[] GetHourCnlDataArr(int year, int month, int day, int startHour, int endHour, IList <int> cnlList, bool existing, ref long[] dataAgeArr) { if (startHour > endHour) { throw new ArgumentException("Start hour must be less or equal than end hour."); } DataAccess dataAccess = AppData.DataAccess; DataCache dataCache = dataAccess.DataCache; DateTime date = new DateTime(year, month, day); DateTime startDT = date.AddHours(startHour); DateTime startDate = startDT.Date; DateTime endDT = date.AddHours(endHour); DateTime endDate = endDT.Date; int hourCnt = endHour - startHour + 1; int dayCnt = (int)(endDate - startDate).TotalDays + 1; List <HourCnlData> hourCnlDataList = new List <HourCnlData>(hourCnt); long[] newDataAgeArr = new long[dayCnt]; DateTime nowDT = DateTime.Now; DateTime curDate = startDate; for (int dayInd = 0; dayInd < dayCnt; dayInd++) { SrezTableLight tblHour = dataCache.GetHourTable(curDate); long newDataAge = WebUtils.DateTimeToJs(tblHour.FileModTime); long prevDataAge = dayInd < dataAgeArr.Length ? dataAgeArr[dayInd] : 0; bool modified = prevDataAge <= 0 || prevDataAge < newDataAge; newDataAgeArr[dayInd] = newDataAge; DateTime nextDate = curDate.AddDays(1.0); if (existing) { // получение всех существующих часовых срезов DateTime dayStartDT = curDate > startDate ? curDate : startDT; DateTime dayEndDT = curDate < endDate ? nextDate : endDT; foreach (SrezTableLight.Srez snapshot in tblHour.SrezList.Values) { DateTime snapshotDT = snapshot.DateTime; if (dayStartDT <= snapshotDT && snapshotDT <= dayEndDT) { double hour = (snapshotDT - date).TotalHours; if (modified) { AppendHourCnlData(hourCnlDataList, hour, cnlList, snapshot, snapshotDT, nowDT); } else { AppendEmptyHourCnlData(hourCnlDataList, hour); } } } } else { // заполнение данных по целым часам int dayStartHour = curDate > startDate ? 0 : startDT.Hour; int dayEndHour = curDate < endDate ? 23 : endDT.Hour; for (int dayHour = dayStartHour; dayHour <= dayEndHour; dayHour++) { DateTime snapshotDT = curDate.AddHours(dayHour); SrezTableLight.Srez snapshot; tblHour.SrezList.TryGetValue(snapshotDT, out snapshot); double hour = (snapshotDT - date).TotalHours; if (modified) { AppendHourCnlData(hourCnlDataList, hour, cnlList, snapshot, snapshotDT, nowDT); } else { AppendEmptyHourCnlData(hourCnlDataList, hour); } } } curDate = nextDate; } dataAgeArr = newDataAgeArr; return(hourCnlDataList.ToArray()); }