/// <summary> /// Calls the ReadData method of the current archives. /// </summary> public void ReadCurrentData(ICurrentData curData) { foreach (CurrentArchiveLogic archiveLogic in currentArchives) { if (archiveLogic.IsReady) { try { archiveLogic.Lock(); archiveLogic.ReadData(curData, out bool completed); if (completed) { return; } } catch (Exception ex) { log.WriteException(ex, ServerPhrases.ErrorInArchive, nameof(ReadCurrentData), archiveLogic.Code); } finally { Unlock(archiveLogic); } } } log.WriteError(Locale.IsRussian ? "Не удалось считать текущие данные" : "Unable to read current data"); }
/// <summary> /// Reads the current data. /// </summary> public override void ReadData(ICurrentData curData, out bool completed) { if (File.Exists(adapter.FileName)) { stopwatch.Restart(); Slice slice = adapter.ReadSingleSlice(); for (int i = 0, cnlCnt = slice.CnlNums.Length; i < cnlCnt; i++) { int cnlNum = slice.CnlNums[i]; int cnlIndex = curData.GetCnlIndex(cnlNum); if (cnlIndex >= 0) { curData.Timestamps[cnlIndex] = slice.Timestamp; curData.CnlData[cnlIndex] = slice.CnlData[i]; } } completed = true; stopwatch.Stop(); arcLog?.WriteAction(ServerPhrases.ReadingSliceCompleted, slice.CnlNums.Length, stopwatch.ElapsedMilliseconds); } else { completed = false; } }
public ProfileConfigureViewModel(INavigationService navigationService, ICurrentData currentData, IServerConnection serverConnection) : base(navigationService) { this.navigationService = navigationService; this.currentData = currentData; this.serverConnection = serverConnection; }
public ProfileConfigurePage(ICurrentData currentData, IColorsRepository colorsRepository, IServerConnection serverConnection) { InitializeComponent(); this.currentData = currentData; this.colorsRepository = colorsRepository; this.serverConnection = serverConnection; InitializeControls(); }
/// <summary> /// Writes the current data. /// </summary> public override void WriteData(ICurrentData curData) { stopwatch.Restart(); InitCnlIndexes(curData, ref cnlIndexes); CopyCnlData(curData, slice, cnlIndexes); adapter.WriteSingleSlice(slice); stopwatch.Stop(); arcLog?.WriteAction(ServerPhrases.WritingSliceCompleted, slice.CnlNums.Length, stopwatch.ElapsedMilliseconds); }
/// <summary> /// Initializes the indexes that map the archive input channels to all channels. /// </summary> protected void InitCnlIndexes(ICurrentData curData, ref int[] cnlIndexes) { if (cnlIndexes == null) { int cnlCnt = CnlNums.Length; cnlIndexes = new int[cnlCnt]; for (int i = 0; i < cnlCnt; i++) { cnlIndexes[i] = curData.GetCnlIndex(CnlNums[i]); } } }
/// <summary> /// Processes new data. /// </summary> public override bool ProcessData(ICurrentData curData) { if (nextWriteTime <= curData.Timestamp) { nextWriteTime = GetNextWriteTime(curData.Timestamp, archiveOptions.WritingPeriod); WriteData(curData); return(true); } else { return(false); } }
/// <summary> /// Calls the ProcessData method of the current and historical archives. /// </summary> public void ProcessData(ICurrentData curData) { foreach (CurrentArchiveLogic archiveLogic in currentArchives) { if (archiveLogic.IsReady) { try { archiveLogic.Lock(); if (archiveLogic.ProcessData(curData)) { archiveLogic.LastWriteTime = curData.Timestamp; } } catch (Exception ex) { log.WriteException(ex, ServerPhrases.ErrorInArchive, nameof(ProcessData), archiveLogic.Code); } finally { Unlock(archiveLogic); } } } foreach (HistoricalArchiveLogic archiveLogic in historicalArchives) { if (archiveLogic.IsReady) { try { archiveLogic.Lock(); if (archiveLogic.ProcessData(curData)) { archiveLogic.LastWriteTime = curData.Timestamp; } } catch (Exception ex) { log.WriteException(ex, ServerPhrases.ErrorInArchive, nameof(ProcessData), archiveLogic.Code); } finally { Unlock(archiveLogic); } } } }
/// <summary> /// Copies the current data to the slice that contains the archive input channels. /// </summary> protected void CopyCnlData(ICurrentData curData, Slice slice, int[] cnlIndexes) { if (slice.CnlNums == CnlNums) { slice.Timestamp = curData.Timestamp; for (int i = 0, cnlCnt = CnlNums.Length; i < cnlCnt; i++) { slice.CnlData[i] = curData.CnlData[cnlIndexes[i]]; } } else { throw new ScadaException("Inappropriate slice."); } }
public ClockPage(IServerConnection serverConnection, ICurrentData currentData, IColorsRepository colorsRepository) { this.serverConnection = serverConnection; this.currentData = currentData; this.colorsRepository = colorsRepository; InitializeComponent(); currentData.OnUpdate += UpdateProfilesPicker; currentData.OnUpdate += UpdateDeletingProfilesPicker; profilePicker.SelectedIndexChanged += SelectProfile; deletePicker.SelectedIndexChanged += SelectedDeletingIndexPicker; Device.StartTimer(TimeSpan.FromMilliseconds(500), () => { clockCanvas.InvalidateSurface(); return(true); }); }
/// <summary> /// Writes the current data. /// </summary> public override void WriteData(ICurrentData curData) { stopwatch.Restart(); InitCnlIndexes(curData, ref cnlIndexes); lock (pointQueue.SyncRoot) { for (int i = 0, cnlCnt = CnlNums.Length; i < cnlCnt; i++) { int cnlIndex = cnlIndexes[i]; pointQueue.EnqueueWithoutLock(CnlNums[i], curData.Timestamps[cnlIndex], curData.CnlData[cnlIndex]); } } pointQueue.RemoveExcessPoints(); stopwatch.Stop(); arcLog?.WriteAction(ServerPhrases.QueueingPointsCompleted, CnlNums.Length, stopwatch.ElapsedMilliseconds); }
public ClockViewModel(INavigationService navigationService, ICanvasDrawing canvasDrawing, IGetTime getTime, IServerConnection serverConnection, ICurrentData currentData) : base(navigationService) { this.canvasDrawing = canvasDrawing; this.getTime = getTime; this.serverConnection = serverConnection; this.currentData = currentData; HubConnection connection = serverConnection.Connection; connection.On <string>("GetAllProfiles", async(messege) => { await GetAllProfiles(messege); }); connection.Closed += async(error) => { await Task.Delay(2000); await connection.StartAsync(); }; }
/// <summary> /// Calls the WriteData method of the current archives. /// </summary> public void WriteCurrentData(ICurrentData curData) { foreach (CurrentArchiveLogic archiveLogic in currentArchives) { if (archiveLogic.IsReady) { try { archiveLogic.Lock(); archiveLogic.WriteData(curData); archiveLogic.LastWriteTime = curData.Timestamp; } catch (Exception ex) { log.WriteError(ex, ServerPhrases.ErrorInArchive, nameof(WriteCurrentData), archiveLogic.Code); } finally { Unlock(archiveLogic); } } } }
/// <summary> /// Processes new data. /// </summary> public override bool ProcessData(ICurrentData curData) { if (options.WritingMode == WritingMode.AutoWithPeriod && nextWriteTime <= curData.Timestamp) { DateTime writeTime = GetClosestWriteTime(curData.Timestamp, writingPeriod); nextWriteTime = writeTime.AddSeconds(writingPeriod); stopwatch.Restart(); TrendTable trendTable = GetCurrentTrendTable(writeTime); InitCnlIndexes(curData, ref cnlIndexes); CopyCnlData(curData, slice, cnlIndexes); slice.Timestamp = writeTime; adapter.WriteSlice(trendTable, slice); stopwatch.Stop(); arcLog?.WriteAction(ServerPhrases.WritingSliceCompleted, slice.CnlNums.Length, stopwatch.ElapsedMilliseconds); return(true); } else { return(false); } }
/// <summary> /// Processes new data. /// </summary> /// <remarks>Returns true if the data has been written to the archive.</remarks> public override bool ProcessData(ICurrentData curData) { if (archiveOptions.WritingMode == WritingMode.AutoWithPeriod) { if (nextWriteTime <= curData.Timestamp) { DateTime writeTime = GetClosestWriteTime(curData.Timestamp, writingPeriod); nextWriteTime = writeTime.AddSeconds(writingPeriod); stopwatch.Restart(); InitCnlIndexes(curData, ref cnlIndexes); int cnlCnt = CnlNums.Length; lock (pointQueue.SyncRoot) { for (int i = 0; i < cnlCnt; i++) { pointQueue.EnqueueWithoutLock(CnlNums[i], writeTime, curData.CnlData[cnlIndexes[i]]); } } pointQueue.RemoveExcessPoints(); stopwatch.Stop(); arcLog?.WriteAction(ServerPhrases.QueueingPointsCompleted, cnlCnt, stopwatch.ElapsedMilliseconds); return(true); } } else if (archiveOptions.WritingMode == WritingMode.AutoOnChange) { stopwatch.Restart(); int changesCnt = 0; bool firstTime = cnlIndexes == null; InitCnlIndexes(curData, ref cnlIndexes); if (firstTime) { // do not write data for the first time for (int i = 0, cnlCnt = CnlNums.Length; i < cnlCnt; i++) { prevCnlData[i] = curData.CnlData[cnlIndexes[i]]; } } else { for (int i = 0, cnlCnt = CnlNums.Length; i < cnlCnt; i++) { CnlData curCnlData = curData.CnlData[cnlIndexes[i]]; if (prevCnlData[i] != curCnlData) { pointQueue.EnqueuePoint(CnlNums[i], curData.Timestamp, curCnlData); prevCnlData[i] = curCnlData; changesCnt++; } } } if (changesCnt > 0) { pointQueue.RemoveExcessPoints(); stopwatch.Stop(); arcLog?.WriteAction(ServerPhrases.QueueingPointsCompleted, changesCnt, stopwatch.ElapsedMilliseconds); return(true); } else { stopwatch.Stop(); } } return(false); }
/// <summary> /// Reads the current data. /// </summary> public override void ReadData(ICurrentData curData, out bool completed) { NpgsqlTransaction trans = null; try { stopwatch.Restart(); conn.Open(); trans = conn.BeginTransaction(); string sql = "SELECT cnl_num, time_stamp, val, stat FROM " + queryBuilder.CurrentTable; NpgsqlCommand cmd = new NpgsqlCommand(sql, conn, trans); List <int> cnlsToDelete = new List <int>(); int pointCnt = 0; using (NpgsqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int cnlNum = reader.GetInt32(0); int cnlIndex = curData.GetCnlIndex(cnlNum); if (cnlIndex >= 0) { curData.Timestamps[cnlIndex] = reader.GetDateTimeUtc(1); curData.CnlData[cnlIndex] = new CnlData { Val = reader.GetDouble(2), Stat = reader.GetInt32(3) }; pointCnt++; } else { cnlsToDelete.Add(cnlNum); } } } // delete data of unused channels if (cnlsToDelete.Count > 0) { sql = $"DELETE FROM {queryBuilder.CurrentTable} WHERE cnl_num = @cnlNum"; cmd = new NpgsqlCommand(sql, conn, trans); NpgsqlParameter cnlNumParam = cmd.Parameters.Add("cnlNum", NpgsqlDbType.Integer); foreach (int cnlNum in cnlsToDelete) { cnlNumParam.Value = cnlNum; cmd.ExecuteNonQuery(); } } trans.Commit(); completed = true; hasError = false; stopwatch.Stop(); arcLog?.WriteAction(ServerPhrases.ReadingPointsCompleted, pointCnt, stopwatch.ElapsedMilliseconds); } catch { trans?.Rollback(); completed = false; hasError = true; } finally { conn.Close(); } }
/// <summary> /// Processes new data. /// </summary> /// <remarks>Returns true if the data has been written to the archive.</remarks> public abstract bool ProcessData(ICurrentData curData);
/// <summary> /// Writes the current data. /// </summary> public abstract void WriteData(ICurrentData curData);
/// <summary> /// Reads the current data. /// </summary> public abstract void ReadData(ICurrentData curData, out bool completed);