//******************************************************************************************************// HistorianViewUserControl.xaml.cs - Gbtc//// Copyright © 2010, Grid Protection Alliance. All Rights Reserved.//// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See// the NOTICE file distributed with this work for additional information regarding copyright ownership.// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may// not use this file except in compliance with the License. You may obtain a copy of the License at://// http://www.opensource.org/licenses/MIT//// Unless agreed to in writing, the subject software distributed under the License is distributed on an// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the// License for the specific language governing permissions and limitations.//// Code Modification History:// ----------------------------------------------------------------------------------------------------// 12/22/2011 - Aniket Salver// Generated original version of source code.////****************************************************************************************************** using System;using System.Collections.Generic;using System.ComponentModel;using System.IO;using System.Linq;using System.Reflection;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Input;using System.Xml;using GSF.Collections;using GSF.Configuration;using GSF.Historian;using GSF.Historian.Files;using GSF.IO;using GSF.PhasorProtocols.UI.Modal;using Microsoft.Win32; namespace GSF.PhasorProtocols.UI.UserControls{ /// <summary> /// Interaction logic for HistorianViewUserControl.xaml /// </summary> public partial class HistorianViewUserControl : UserControl { #region [ Members ] // Nested Types /// <summary> /// This is a wrapper around a MetadataRecord that allows auto-generation /// of columns in the data grid based on the public properties of this class. /// </summary> public class MetadataWrapper { private readonly MetadataRecord m_metadata; /// <summary> /// Creates a new instance of the <see cref="MetadataWrapper"/> class. /// </summary> /// <param name="metadata">The <see cref="MetadataRecord"/> to be wrapped.</param> public MetadataWrapper(MetadataRecord metadata) { m_metadata = metadata; } /// <summary> /// Determines whether the measurement represented by this metadata record /// should be exported to CSV by the Historian Data Viewer. /// </summary> public bool Export { get; set; } /// <summary> /// Determines whether the measurement represented by this metadata record /// should be displayed on the Historian Data Viewer graph. /// </summary> public bool Display { get; set; } /// <summary> /// Gets the point number of the measurement. /// </summary> public int PointNumber { get { return m_metadata.HistorianID; } } /// <summary> /// Gets the name of the measurement. /// </summary> public string Name { get { return m_metadata.Name; } } /// <summary> /// Gets the description of the measurement. /// </summary> public string Description { get { return m_metadata.Description; } } /// <summary> /// Gets the first alternate name for the measurement. /// </summary> public string Synonym1 { get { return m_metadata.Synonym1; } } /// <summary> /// Gets the second alternate name for the measurement. /// </summary> public string Synonym2 { get { return m_metadata.Synonym2; } } /// <summary> /// Gets the third alternate name for the measurement. /// </summary> public string Synonym3 { get { return m_metadata.Synonym3; } } /// <summary> /// Gets the system name. /// </summary> public string System { get { return m_metadata.SystemName; } } /// <summary> /// Gets the low range of the measurement. /// </summary> public Single LowRange { get { return m_metadata.Summary.LowRange; } } /// <summary> /// Gets the high range of the measurement. /// </summary> public Single HighRange { get { return m_metadata.Summary.HighRange; } } /// <summary> /// Gets the engineering units used to measure the values. /// </summary> public string EngineeringUnits { get { return m_metadata.AnalogFields.EngineeringUnits; } } /// <summary> /// Gets the unit number of the measurement. /// </summary> public int Unit { get { return m_metadata.UnitNumber; } } /// <summary> /// Returns the wrapped <see cref="MetadataRecord"/>. /// </summary> /// <returns>The wrapped metadata record.</returns> public MetadataRecord GetMetadata() { return m_metadata; } } // Fields private string m_currentSessionPath; private ICollection<ArchiveFile> m_archiveFiles; private readonly List<MetadataWrapper> m_metadata; private DateTime m_startTime; private DateTime m_endTime; private readonly ICollection<MenuItem> m_contextMenuItems; private readonly ICollection<string> m_visibleColumns; private ChartWindowUserControl m_chartWindow; private HistorianViewChart m_historianViewChart; #endregion #region [ Constructors ] /// <summary> /// Creates a new instance of the <see cref="HistorianViewUserControl"/> class. /// </summary> public HistorianViewUserControl() { m_archiveFiles = new List<ArchiveFile>(); m_metadata = new List<MetadataWrapper>(); m_contextMenuItems = new List<MenuItem>(); m_visibleColumns = new HashSet<string>(); InitializeComponent(); InitializeChartWindow(); StartTime = TimeTag.Parse("*-5M").ToDateTime(); EndTime = TimeTag.Parse("*").ToDateTime(); m_currentTimeCheckBox.IsChecked = true; string[] lastArchiveLocations = ConfigurationFile.Current.Settings.General["ArchiveLocations", true].ValueAs("").Split('|').Where(archiveLocation => !string.IsNullOrWhiteSpace(archiveLocation) && File.Exists(archiveLocation)).ToArray(); if (lastArchiveLocations == null || lastArchiveLocations.Length == 0) { // See if a local archive folder exists with a valid archive string defaultArchiveLocation = FilePath.GetAbsolutePath("Archive"); if (Directory.Exists(defaultArchiveLocation)) lastArchiveLocations = Directory.GetFiles(defaultArchiveLocation, "*_archive.d"); if (lastArchiveLocations == null || lastArchiveLocations.Length == 0) { // See if a local statistics folder exists with a valid archive defaultArchiveLocation = FilePath.GetAbsolutePath("Statistics"); if (Directory.Exists(defaultArchiveLocation)) lastArchiveLocations = Directory.GetFiles(defaultArchiveLocation, "*_archive.d"); } } if (lastArchiveLocations != null && lastArchiveLocations.Length > 0) OpenArchives(lastArchiveLocations); } #endregion #region [ Properties ] /// <summary> /// Gets or sets a boolean that determines whether an archive is open or not. /// </summary> public bool ArchiveIsOpen { get { return m_saveButton.IsEnabled; } set { m_saveButton.IsEnabled = value; m_saveMenuItem.IsEnabled = value; m_saveAsMenuItem.IsEnabled = value; m_trendButton.IsEnabled = value; m_trendMenuItem.IsEnabled = value; m_exportButton.IsEnabled = value; m_exportMenuItem.IsEnabled = value; } } /// <summary> /// Gets or sets the start time to be displayed on the graph or exported to CSV. /// </summary> public DateTime StartTime { get { return m_startTime; } set { m_startTime = value; m_startTimeDatePicker.SelectedDate = value; m_startTimeTextBox.Text = value.ToString("HH:mm:ss.fff"); } } /// <summary> /// Gets or sets the end time to be displayed on the graph or exported to CSV. /// </summary> public DateTime EndTime { get { return m_endTime; } set { m_endTime = value; m_endTimeDatePicker.SelectedDate = value; m_endTimeTextBox.Text = value.ToString("HH:mm:ss.fff"); } } #endregion #region [ Methods ] // Initializes the chart window. private void InitializeChartWindow() { if (m_chartWindow == null) { m_chartWindow = new ChartWindowUserControl(); m_chartWindow.ChartUpdated += ChartWindow_ChartUpdated; m_chartWindow.Unloaded += m_chartWindow_Unloaded; //+= ChildWindow_Closing; TrySetChartInterval(null); } } void m_chartWindow_Unloaded(object sender, RoutedEventArgs e) { } // Gets a string representation of the start time to be used when reading from the archive. private string GetStartTime() { StringBuilder startTimeBuilder = new StringBuilder(); if (!m_currentTimeCheckBox.IsChecked.Value) startTimeBuilder.Append(m_startTime.ToString("MM/dd/yyyy HH:mm:ss.fff")); else { startTimeBuilder.Append("*-"); startTimeBuilder.Append(m_currentTimeTextBox.Text); startTimeBuilder.Append(m_currentTimeComboBox.SelectionBoxItem.ToString()[0]); } return startTimeBuilder.ToString(); } // Gets a string representation of the end time to be used when reading from the archive. private string GetEndTime() { StringBuilder endTimeBuilder = new StringBuilder(); if (m_currentTimeCheckBox.IsChecked.Value) return "*"; else return m_endTime.ToString("MM/dd/yyyy HH:mm:ss.fff"); } private void OpenArchive(string fileName) { OpenArchives(new[] { fileName }); } private void OpenArchives(string[] fileNames) { ClearArchives(); foreach (string fileName in fileNames) { if (File.Exists(fileName)) m_archiveFiles.Add(OpenArchiveFile(fileName)); } foreach (ArchiveFile file in m_archiveFiles) { foreach (MetadataRecord record in file.MetadataFile.Read()) { if (record.GeneralFlags.Enabled) m_metadata.Add(new MetadataWrapper(record)); } } ArchiveIsOpen = true; FilterBySearchResults(); m_chartWindow.ArchiveFiles = m_archiveFiles; TrySetChartInterval(null); m_chartWindow.UpdateChart(); } // Prompts the user to open one or more archive files. private void ShowOpenArchiveFileDialog() { OpenFileDialog archiveDialog = new OpenFileDialog(); archiveDialog.Filter = "Archive files|*_archive.d"; archiveDialog.CheckFileExists = true; archiveDialog.Multiselect = true; if (archiveDialog.ShowDialog() == true) OpenArchives(archiveDialog.FileNames); } // Prompts the user to open a previously saved session file. private void ShowOpenSessionDialog() { OpenFileDialog openSessionDialog = new OpenFileDialog(); openSessionDialog.Filter = "Historian Data Viewer files|*.hdv"; openSessionDialog.CheckFileExists = true; if (openSessionDialog.ShowDialog() == true) OpenSessionFile(openSessionDialog.FileName); } // Prompts the user for the location to save the current session. private void ShowSaveSessionDialog() { string errorMessage = "Unable to save current time interval." + " Please enter a start time that is less than or equal to the end time."; if (TrySetChartInterval(errorMessage)) { SaveFileDialog saveSessionDialog = new SaveFileDialog(); saveSessionDialog.Filter = "Historian Data Viewer files|*.hdv"; saveSessionDialog.DefaultExt = "hdv"; saveSessionDialog.AddExtension = true; saveSessionDialog.CheckPathExists = true; if (saveSessionDialog.ShowDialog() == true) SaveCurrentSession(saveSessionDialog.FileName); this.Focus(); } } // Opens an archive file and returns the ArchiveFile object. private ArchiveFile OpenArchiveFile(string fileName) { string m_archiveLocation = FilePath.GetDirectoryName(fileName); string instance = fileName.Substring(0, fileName.LastIndexOf('_')); ArchiveFile file = new ArchiveFile(); file.FileName = fileName; file.FileAccessMode = FileAccess.Read; file.StateFile = new StateFile(); file.StateFile.FileAccessMode = FileAccess.Read; file.StateFile.FileName = string.Format("{0}_startup.dat", instance); file.IntercomFile = new IntercomFile(); file.IntercomFile.FileAccessMode = FileAccess.Read; file.IntercomFile.FileName = string.Format("{0}scratch.dat", m_archiveLocation); file.MetadataFile = new MetadataFile(); file.MetadataFile.FileAccessMode = FileAccess.Read; file.MetadataFile.FileName = string.Format("{0}_dbase.dat", instance); file.MetadataFile.LoadOnOpen = true; file.Open(); return file; } // Opens a previously saved session file. private void OpenSessionFile(string filePath) { XmlDocument doc = new XmlDocument(); XmlNode root;Lines 1–500 of 1225. Load more
//****************************************************************************************************** // HistorianViewUserControl.xaml.cs - Gbtc // // Copyright © 2010, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 12/22/2011 - Aniket Salver // Generated original version of source code. // //****************************************************************************************************** using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Xml; using GSF.Collections; using GSF.Configuration; using GSF.Historian; using GSF.Historian.Files; using GSF.IO; using GSF.PhasorProtocols.UI.Modal; using Microsoft.Win32; namespace GSF.PhasorProtocols.UI.UserControls { /// <summary> /// Interaction logic for HistorianViewUserControl.xaml /// </summary> public partial class HistorianViewUserControl : UserControl { #region [ Members ] // Nested Types /// <summary> /// This is a wrapper around a MetadataRecord that allows auto-generation /// of columns in the data grid based on the public properties of this class. /// </summary> public class MetadataWrapper { private readonly MetadataRecord m_metadata; /// <summary> /// Creates a new instance of the <see cref="MetadataWrapper"/> class. /// </summary> /// <param name="metadata">The <see cref="MetadataRecord"/> to be wrapped.</param> public MetadataWrapper(MetadataRecord metadata) { m_metadata = metadata; } /// <summary> /// Determines whether the measurement represented by this metadata record /// should be exported to CSV by the Historian Data Viewer. /// </summary> public bool Export { get; set; } /// <summary> /// Determines whether the measurement represented by this metadata record /// should be displayed on the Historian Data Viewer graph. /// </summary> public bool Display { get; set; } /// <summary> /// Gets the point number of the measurement. /// </summary> public int PointNumber { get { return m_metadata.HistorianID; } } /// <summary> /// Gets the name of the measurement. /// </summary> public string Name { get { return m_metadata.Name; } } /// <summary> /// Gets the description of the measurement. /// </summary> public string Description { get { return m_metadata.Description; } } /// <summary> /// Gets the first alternate name for the measurement. /// </summary> public string Synonym1 { get { return m_metadata.Synonym1; } } /// <summary> /// Gets the second alternate name for the measurement. /// </summary> public string Synonym2 { get { return m_metadata.Synonym2; } } /// <summary> /// Gets the third alternate name for the measurement. /// </summary> public string Synonym3 { get { return m_metadata.Synonym3; } } /// <summary> /// Gets the system name. /// </summary> public string System { get { return m_metadata.SystemName; } } /// <summary> /// Gets the low range of the measurement. /// </summary> public Single LowRange { get { return m_metadata.Summary.LowRange; } } /// <summary> /// Gets the high range of the measurement. /// </summary> public Single HighRange { get { return m_metadata.Summary.HighRange; } } /// <summary> /// Gets the engineering units used to measure the values. /// </summary> public string EngineeringUnits { get { return m_metadata.AnalogFields.EngineeringUnits; } } /// <summary> /// Gets the unit number of the measurement. /// </summary> public int Unit { get { return m_metadata.UnitNumber; } } /// <summary> /// Returns the wrapped <see cref="MetadataRecord"/>. /// </summary> /// <returns>The wrapped metadata record.</returns> public MetadataRecord GetMetadata() { return m_metadata; } } // Fields private string m_currentSessionPath; private ICollection<ArchiveFile> m_archiveFiles; private readonly List<MetadataWrapper> m_metadata; private DateTime m_startTime; private DateTime m_endTime; private readonly ICollection<MenuItem> m_contextMenuItems; private readonly ICollection<string> m_visibleColumns; private ChartWindowUserControl m_chartWindow; private HistorianViewChart m_historianViewChart; #endregion #region [ Constructors ] /// <summary> /// Creates a new instance of the <see cref="HistorianViewUserControl"/> class. /// </summary> public HistorianViewUserControl() { m_archiveFiles = new List<ArchiveFile>(); m_metadata = new List<MetadataWrapper>(); m_contextMenuItems = new List<MenuItem>(); m_visibleColumns = new HashSet<string>(); InitializeComponent(); InitializeChartWindow(); StartTime = TimeTag.Parse("*-5M").ToDateTime(); EndTime = TimeTag.Parse("*").ToDateTime(); m_currentTimeCheckBox.IsChecked = true; string[] lastArchiveLocations = ConfigurationFile.Current.Settings.General["ArchiveLocations", true].ValueAs("").Split('|').Where(archiveLocation => !string.IsNullOrWhiteSpace(archiveLocation) && File.Exists(archiveLocation)).ToArray(); if (lastArchiveLocations == null || lastArchiveLocations.Length == 0) { // See if a local archive folder exists with a valid archive string defaultArchiveLocation = FilePath.GetAbsolutePath("Archive"); if (Directory.Exists(defaultArchiveLocation)) lastArchiveLocations = Directory.GetFiles(defaultArchiveLocation, "*_archive.d"); if (lastArchiveLocations == null || lastArchiveLocations.Length == 0) { // See if a local statistics folder exists with a valid archive defaultArchiveLocation = FilePath.GetAbsolutePath("Statistics"); if (Directory.Exists(defaultArchiveLocation)) lastArchiveLocations = Directory.GetFiles(defaultArchiveLocation, "*_archive.d"); } } if (lastArchiveLocations != null && lastArchiveLocations.Length > 0) OpenArchives(lastArchiveLocations); } #endregion #region [ Properties ] /// <summary> /// Gets or sets a boolean that determines whether an archive is open or not. /// </summary> public bool ArchiveIsOpen { get { return m_saveButton.IsEnabled; } set { m_saveButton.IsEnabled = value; m_saveMenuItem.IsEnabled = value; m_saveAsMenuItem.IsEnabled = value; m_trendButton.IsEnabled = value; m_trendMenuItem.IsEnabled = value; m_exportButton.IsEnabled = value; m_exportMenuItem.IsEnabled = value; } } /// <summary> /// Gets or sets the start time to be displayed on the graph or exported to CSV. /// </summary> public DateTime StartTime { get { return m_startTime; } set { m_startTime = value; m_startTimeDatePicker.SelectedDate = value; m_startTimeTextBox.Text = value.ToString("HH:mm:ss.fff"); } } /// <summary> /// Gets or sets the end time to be displayed on the graph or exported to CSV. /// </summary> public DateTime EndTime { get { return m_endTime; } set { m_endTime = value; m_endTimeDatePicker.SelectedDate = value; m_endTimeTextBox.Text = value.ToString("HH:mm:ss.fff"); } } #endregion #region [ Methods ] // Initializes the chart window. private void InitializeChartWindow() { if (m_chartWindow == null) { m_chartWindow = new ChartWindowUserControl(); m_chartWindow.ChartUpdated += ChartWindow_ChartUpdated; m_chartWindow.Unloaded += m_chartWindow_Unloaded; //+= ChildWindow_Closing; TrySetChartInterval(null); } } void m_chartWindow_Unloaded(object sender, RoutedEventArgs e) { } // Gets a string representation of the start time to be used when reading from the archive. private string GetStartTime() { StringBuilder startTimeBuilder = new StringBuilder(); if (!m_currentTimeCheckBox.IsChecked.Value) startTimeBuilder.Append(m_startTime.ToString("MM/dd/yyyy HH:mm:ss.fff")); else { startTimeBuilder.Append("*-"); startTimeBuilder.Append(m_currentTimeTextBox.Text); startTimeBuilder.Append(m_currentTimeComboBox.SelectionBoxItem.ToString()[0]); } return startTimeBuilder.ToString(); } // Gets a string representation of the end time to be used when reading from the archive. private string GetEndTime() { StringBuilder endTimeBuilder = new StringBuilder(); if (m_currentTimeCheckBox.IsChecked.Value) return "*"; else return m_endTime.ToString("MM/dd/yyyy HH:mm:ss.fff"); } private void OpenArchive(string fileName) { OpenArchives(new[] { fileName }); } private void OpenArchives(string[] fileNames) { ClearArchives(); foreach (string fileName in fileNames) { if (File.Exists(fileName)) m_archiveFiles.Add(OpenArchiveFile(fileName)); } foreach (ArchiveFile file in m_archiveFiles) { foreach (MetadataRecord record in file.MetadataFile.Read()) { if (record.GeneralFlags.Enabled) m_metadata.Add(new MetadataWrapper(record)); } } ArchiveIsOpen = true; FilterBySearchResults(); m_chartWindow.ArchiveFiles = m_archiveFiles; TrySetChartInterval(null); m_chartWindow.UpdateChart(); } // Prompts the user to open one or more archive files. private void ShowOpenArchiveFileDialog() { OpenFileDialog archiveDialog = new OpenFileDialog(); archiveDialog.Filter = "Archive files|*_archive.d"; archiveDialog.CheckFileExists = true; archiveDialog.Multiselect = true; if (archiveDialog.ShowDialog() == true) OpenArchives(archiveDialog.FileNames); } // Prompts the user to open a previously saved session file. private void ShowOpenSessionDialog() { OpenFileDialog openSessionDialog = new OpenFileDialog(); openSessionDialog.Filter = "Historian Data Viewer files|*.hdv"; openSessionDialog.CheckFileExists = true; if (openSessionDialog.ShowDialog() == true) OpenSessionFile(openSessionDialog.FileName); } // Prompts the user for the location to save the current session. private void ShowSaveSessionDialog() { string errorMessage = "Unable to save current time interval." + " Please enter a start time that is less than or equal to the end time."; if (TrySetChartInterval(errorMessage)) { SaveFileDialog saveSessionDialog = new SaveFileDialog(); saveSessionDialog.Filter = "Historian Data Viewer files|*.hdv"; saveSessionDialog.DefaultExt = "hdv"; saveSessionDialog.AddExtension = true; saveSessionDialog.CheckPathExists = true; if (saveSessionDialog.ShowDialog() == true) SaveCurrentSession(saveSessionDialog.FileName); this.Focus(); } } // Opens an archive file and returns the ArchiveFile object. private ArchiveFile OpenArchiveFile(string fileName) { string m_archiveLocation = FilePath.GetDirectoryName(fileName); string instance = fileName.Substring(0, fileName.LastIndexOf('_')); ArchiveFile file = new ArchiveFile(); file.FileName = fileName; file.FileAccessMode = FileAccess.Read; file.StateFile = new StateFile(); file.StateFile.FileAccessMode = FileAccess.Read; file.StateFile.FileName = string.Format("{0}_startup.dat", instance); file.IntercomFile = new IntercomFile(); file.IntercomFile.FileAccessMode = FileAccess.Read; file.IntercomFile.FileName = string.Format("{0}scratch.dat", m_archiveLocation); file.MetadataFile = new MetadataFile(); file.MetadataFile.FileAccessMode = FileAccess.Read; file.MetadataFile.FileName = string.Format("{0}_dbase.dat", instance); file.MetadataFile.LoadOnOpen = true; file.Open(); return file; } // Opens a previously saved session file. private void OpenSessionFile(string filePath) { XmlDocument doc = new XmlDocument(); XmlNode root;