978 lines · 33.9 KB · C#
RawDownload
//******************************************************************************************************//  ReportViewModelBase.cs - Gbtc////  Copyright © 2015, 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://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://  ----------------------------------------------------------------------------------------------------//  06/08/2015 - J. Ritchie Carroll//       Generated original version of source code.////****************************************************************************************************** using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Diagnostics;using System.Globalization;using System.IO;using System.Linq;using System.Text.RegularExpressions;using System.Threading;using System.Windows;using System.Windows.Input;using System.Windows.Threading;using GSF.Console;using GSF.ServiceProcess;using GSF.TimeSeries.UI.Commands;using Microsoft.Win32; namespace GSF.TimeSeries.UI.ViewModels{    /// <summary>    /// View model for reporting user controls.    /// </summary>    public class ReportViewModel : ViewModelBase, IDisposable    {        #region [ Members ]         // Nested Types         /// <summary>        /// Represents a generated report that is available for download from the service.        /// </summary>        public class AvailableReport        {            #region [ Members ]             // Fields            private readonly ReportViewModel m_parent;             private string m_date;            private string m_status;            private ICommand m_getReportCommand;             #endregion             #region [ Constructors ]             /// <summary>            /// Creates a new instance of the <see cref="AvailableReport"/> class.            /// </summary>            internal AvailableReport(ReportViewModel parent)            {                m_parent = parent;            }             #endregion             #region [ Properties ]             /// <summary>            /// Gets or sets the name of the report.            /// </summary>            public string Date            {                get                {                    return m_date;                }                set                {                    m_date = value;                }            }             /// <summary>            /// Gets or sets the status of the report.            /// </summary>            public string Status            {                get                {                    return m_status;                }                set                {                    m_status = value;                }            }             /// <summary>            /// Gets the command that retrieves the report from the service.            /// </summary>            public ICommand GetReportCommand            {                get                {                    return m_getReportCommand ?? (m_getReportCommand = new RelayCommand(GetReport, () => true));                }            }             #endregion             #region [ Methods ]             private void GetReport()            {                DateTime reportDate;                 if (DateTime.TryParse(Date, out reportDate))                    m_parent.GetReport(reportDate);            }             #endregion        }         // Fields        private Visibility m_connectivityMessageVisibility;        private bool m_serviceConnected;        private bool m_reportingEnabled;        private string m_reportType;        private string m_scheduledProcessName;        private string m_reportTitle;        private string m_reportingConfiguration;        private string m_originalReportLocation;        private string m_reportLocation;        private string m_reportGenerationTimeText;        private DateTime m_originalReportGenerationTime;        private DateTime m_reportGenerationTime;        private DateTime m_reportDate;        private double m_originalIdleReportLifetime;        private double m_idleReportLifetime;         private readonly ObservableCollection<AvailableReport> m_availableReports;        private readonly ObservableCollection<string> m_pendingReports;        private byte[] m_reportData;         private readonly DispatcherTimer m_listReportsTimer;        private string m_responseMessage;        private ManualResetEventSlim m_responseComplete;        private ICommand m_changeReportingEnabledCommand;        private ICommand m_generateReportCommand;        private ICommand m_applyReportingConfigCommand;         private bool m_disposed;        private string m_listReportsErrorMessage;         #endregion         #region [ Constructors ]         /// <summary>        /// Creates a new instance of the <see cref="ReportViewModel"/> class.        /// </summary>        public ReportViewModel()        {            ReportGenerationTime = new DateTime(1, 1, 1, 0, 0, 0);            m_originalReportGenerationTime = m_reportGenerationTime;             ReportLocation = "Reports";            OriginalReportLocation = m_reportLocation;             IdleReportLifetime = 14.0D;            OriginalIdleReportLifetime = m_idleReportLifetime;             ReportDate = DateTime.Now - TimeSpan.FromDays(1);            m_availableReports = new ObservableCollection<AvailableReport>();            m_pendingReports = new ObservableCollection<string>();            m_responseComplete = new ManualResetEventSlim(false);            m_listReportsTimer = new DispatcherTimer(TimeSpan.FromSeconds(5), DispatcherPriority.ApplicationIdle, (sender, args) => ListReports(), Dispatcher.CurrentDispatcher);        }         #endregion         #region [ Properties ]         /// <summary>        /// Gets or sets a flag to indicate whether the service is connected.        /// </summary>        public bool ServiceConnected        {            get            {                return m_serviceConnected;            }            set            {                WindowsServiceClient serviceClient;                 m_serviceConnected = value;                m_listReportsTimer.IsEnabled = value;                m_connectivityMessageVisibility = value ? Visibility.Collapsed : Visibility.Visible;                OnPropertyChanged("ServiceConnected");                OnPropertyChanged("ConnectivityMessageVisibility");                 serviceClient = CommonFunctions.GetWindowsServiceClient();                 if ((object)serviceClient != null && (object)serviceClient.Helper != null)                {                    serviceClient.Helper.ReceivedServiceUpdate += Helper_ReceivedServiceUpdate;                    serviceClient.Helper.ReceivedServiceResponse += Helper_ReceivedServiceResponse;                }                 if (m_serviceConnected)                {                    GetSchedules();                    GetReportingConfiguration();                    ListReports();                }            }        }         /// <summary>        /// Gets a value that determines whether the connectivity message should be displayed.        /// </summary>        public Visibility ConnectivityMessageVisibility        {            get            {                return m_connectivityMessageVisibility;            }        }         /// <summary>        /// Gets report type, i.e., basically the report name associated with this reporting process.        /// </summary>        /// <remarks>        /// This value is passed to StatHistorianReportGenerator as "reportType" parameter.        /// </remarks>        public string ReportType        {            get            {                return m_reportType;            }            set            {                if (string.IsNullOrEmpty(value))                    throw new ArgumentNullException("value");                 m_reportType = value;                OnPropertyChanged("ReportType");                 if (string.IsNullOrEmpty(m_scheduledProcessName))                    ScheduledProcessName = string.Format("{0}Reporting", m_reportType);            }        }         /// <summary>        /// Gets or sets scheduled process name for the current report.        /// </summary>        public string ScheduledProcessName        {            get            {                return m_scheduledProcessName;            }            set            {                m_scheduledProcessName = value;                OnPropertyChanged("ScheduledProcessName");            }        }         /// <summary>        /// Gets or sets a flag that indicates whether reporting is currently enabled.        /// </summary>        public bool ReportingEnabled        {            get            {                return m_reportingEnabled;            }            set            {                m_reportingEnabled = value;                OnPropertyChanged("ReportingEnabled");            }        }         /// <summary>        /// Gets or sets the original report location since the last        /// time settings were applied, before the user changed it.        /// </summary>        public string OriginalReportLocation        {            get            {                return m_originalReportLocation;            }            set            {                m_originalReportLocation = value;                OnPropertyChanged("OriginalReportLocation");            }        }         /// <summary>        /// Gets or sets the location to which reports will be generated.        /// </summary>        public string ReportLocation        {            get            {                return m_reportLocation;            }            set            {                m_reportLocation = value;                OnPropertyChanged("ReportLocation");                 if (m_reportLocation.Any(c => Path.GetInvalidPathChars().Contains(c)))                    throw new FormatException("Invalid characters found in path: " + string.Join(", ", Path.GetInvalidPathChars().Where(c => m_reportLocation.Contains(c)).Select(c => string.Format("'{0}'", c))));            }        }         /// <summary>        /// Gets the original report generation time text since the last        /// time settings were applied, before the user changed it.        /// </summary>        public string OriginalReportGenerationTimeText        {            get            {                return m_originalReportGenerationTime.ToString("HH:mm");            }        }         /// <summary>        /// Gets or sets the original report generation time.        /// </summary>        public DateTime OriginalReportGenerationTime        {            get            {                return m_originalReportGenerationTime;            }            set            {                m_originalReportGenerationTime = value;                OnPropertyChanged("OriginalReportGenerationTime");            }        }         /// <summary>        /// Gets or sets the text used to display or modify the value of the <see cref="ReportGenerationTime"/> property.        /// </summary>        public string ReportGenerationTimeText        {            get            {                return m_reportGenerationTimeText;            }            set            {                DateTime reportGenerationTime;                 m_reportGenerationTimeText = value;                OnPropertyChanged("ReportGenerationTimeText");                 if (!DateTime.TryParseExact(value, "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out reportGenerationTime))                    throw new FormatException("Invalid time format. Use \"HH:mm\" format.");            }        }         /// <summary>        /// Gets or sets the report generation time.        /// </summary>        public DateTime ReportGenerationTime        {            get            {                return m_reportGenerationTime;            }            set            {                m_reportGenerationTime = value;                m_reportGenerationTimeText = m_reportGenerationTime.ToString("HH:mm");                OnPropertyChanged("ReportGenerationTime");                OnPropertyChanged("ReportGenerationTimeText");            }        }         /// <summary>        /// Gets or sets the date of the report to be generated manually.        /// </summary>        public DateTime ReportDate        {            get            {                return m_reportDate;            }            set            {                m_reportDate = value;                OnPropertyChanged("ReportDate");            }        }         /// <summary>        /// Gets or sets the original idle report lifetime since the last        /// time settings were applied, before the user changed it.        /// </summary>        public double OriginalIdleReportLifetime        {            get            {                return m_originalIdleReportLifetime;            }            set            {                m_originalIdleReportLifetime = value;                OnPropertyChanged("OriginalIdleReportLifetime");            }        }         /// <summary>        /// Gets or sets the amount of time to pass since the last time a        /// report was accessed before the report is purged automatically.        /// </summary>        public double IdleReportLifetime        {            get            {                return m_idleReportLifetime;            }            set            {                m_idleReportLifetime = value;                OnPropertyChanged("IdleReportLifetime");            }        }         /// <summary>        /// Gets or sets the error message that displays when report listing fails.        /// </summary>        public string ListReportsErrorMessage        {            get            {                return m_listReportsErrorMessage;            }            set            {                m_listReportsErrorMessage = value.Trim();                OnPropertyChanged("ListReportsErrorMessage");            }        }         /// <summary>        /// Gets the list of available reports.        /// </summary>        public ObservableCollection<AvailableReport> AvailableReports        {            get            {                return m_availableReports;            }        }         /// <summary>        /// Gets the list of pending reports.        /// </summary>        public ObservableCollection<string> PendingReports        {            get            {                return m_pendingReports;            }        }         /// <summary>        /// Gets the command to change the enabled state of reporting services.        /// </summary>        public ICommand ChangeReportingEnabledCommand        {            get            {                return m_changeReportingEnabledCommand ?? (m_changeReportingEnabledCommand = new RelayCommand(ChangeReportingEnabled, () => true));

Lines 1–500 of 978.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t