コード例 #1
0
        private CancellationTokenSource m_cancellationTokenSource; // For cancelling thread awaiting rider start



        public MainForm(IServiceProvider serviceProvider, IConfiguration configuration, ZPMonitorService zpMonitorService, ILoggerFactory loggerFactory)
        {
            m_logger           = loggerFactory.CreateLogger <MainForm>();;
            m_serviceProvider  = serviceProvider;
            m_zpMonitorService = zpMonitorService;
            m_loggerFactory    = loggerFactory;

            m_maCollection  = new Dictionary <DurationType, MovingAverageWrapper>();
            m_summaryHelper = new SummaryHelper(new SummaryListViewItem(new SummaryItem()));
            //m_labelUnits = new Dictionary<string, string>();

            //m_labelHelpers = new List<LabelHelper>();

            m_normalizedPower = new NormalizedPower(zpMonitorService, loggerFactory);
            m_normalizedPower.NormalizedPowerChangedEvent += NormalizedPowerChangedEventHandler;
            m_normalizedPower.MetricsChangedEvent         += MetricsChangedEventHandler;

            InitializeComponent();

            // This rounds the edges of the borderless window
            this.Region = System.Drawing.Region.FromHrgn(ZAMsettings.CreateRoundRectRgn(0, 0, Width, Height, 15, 15));
            btnClose.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); //transparent

            //MainForm.colorListViewHeader(ref lvViewer, lvViewer.BackColor, Color.White); // transparent ListView headers
            //MainForm.colorListViewHeader(ref lvOverall, lvOverall.BackColor, Color.White); // transparent ListView headers
            SetListViewHeaderColor(ref lvViewer, Color.FromArgb(255, 243, 108, 61), Color.White);  // Orange ListView headers
            SetListViewHeaderColor(ref lvOverall, Color.FromArgb(255, 243, 108, 61), Color.White); // Orange ListView headers
        }
コード例 #2
0
        public static Task Main(string[] args)
        {
            var executableLocation = Path.GetDirectoryName(typeof(Program).Assembly.Location);

            var host = new HostBuilder()
                       .ConfigureWinForms <MainForm>()
                       //.ConfigureWinForms<MonitorStatistics>()
                       .ConfigureConfiguration(args)
                       .ConfigureLogging()
                       .ConfigureSingleInstance(builder =>
            {
                builder.MutexId = "{80B16FA8-ECAE-4DD8-9F8A-FE7E6780A825}";
                builder.WhenNotFirstInstance = (hostingEnvironment, logger) =>
                {
                    // This is called when an instance was already started, this is in the second instance
                    logger.LogWarning("Application {0} already running.", hostingEnvironment.ApplicationName);
                };
            })
                       //.ConfigurePlugins(pluginBuilder =>
                       //{
                       //    if (executableLocation == null)
                       //    {
                       //        return;
                       //    }

                       //    var runtime = Path.GetFileName(executableLocation);
                       //    var parentDirectory = Directory.GetParent(executableLocation).FullName;
                       //    var configuration = Path.GetFileName(parentDirectory);
                       //    var basePath = Path.Combine(executableLocation, @"..\..\..\..\");
                       //    // Specify the location from where the Dll's are "globbed"
                       //    pluginBuilder.AddScanDirectories(basePath);
                       //    // Add the framework libraries which can be found with the specified globs
                       //    pluginBuilder.IncludeFrameworks(@$"**\bin\{configuration}\netstandard2.0\*.FrameworkLib.dll");
                       //    // Add the plugins which can be found with the specified globs
                       //    pluginBuilder.IncludePlugins(@$"**\bin\{configuration}\{runtime}\*.Sample.Plugin*.dll");
                       //})
                       .ConfigureServices(serviceCollection =>
            {
                // Add the ZwiftPacketMonitor extensions
                ZwiftPacketMonitor.RegistrationExtensions.AddZwiftPacketMonitoring(serviceCollection);

                // add our ZwiftPacketMonitor wrapper service
                serviceCollection.AddSingleton <ZPMonitorService>();

                serviceCollection.AddTransient <AdvancedOptions>();
                serviceCollection.AddTransient <ConfigurationOptions>();
                serviceCollection.AddSingleton <MonitorTimer>();
            })
                       .UseWinFormsLifetime()
                       .Build();

            ILoggerFactory   lf = host.Services.GetRequiredService <ILoggerFactory>();
            ZPMonitorService zp = host.Services.GetRequiredService <ZPMonitorService>();

            ZAMsettings.Initialize(lf, zp);


            return(host.RunAsync());
        }
コード例 #3
0
        public AdvancedOptions(ZPMonitorService zPMonitorService, ILogger <AdvancedOptions> logger)
        {
            m_zpMonitorService = zPMonitorService;
            m_logger           = logger;

            InitializeComponent();

            this.Icon = Properties.Resources.cycling1;
        }
コード例 #4
0
        public AdvancedOptions(ZPMonitorService zPMonitorService, ILogger <AdvancedOptions> logger)
        {
            m_zpMonitorService = zPMonitorService;
            m_logger           = logger;

            InitializeComponent();

            m_logger.LogInformation($"Class {this.GetType()} initialized.");
        }
コード例 #5
0
        public NormalizedPower(ZPMonitorService zpMonitorService, ILoggerFactory loggerFactory)
        {
            m_zpMonitorService = zpMonitorService;
            Logger             = loggerFactory.CreateLogger <NormalizedPower>();

            // Create a new 30 seconds moving average class, zero power reading numbers are INCLUDED (I asked support at TrainingPeaks about this).
            m_movingAvg = new MovingAverage(m_zpMonitorService, loggerFactory, DurationType.ThirtySeconds, false);
            m_movingAvg.MovingAverageCalculatedEvent += MovingAverageCalculatedEventHandler;
            m_movingAvg.MetricsCalculatedEvent       += MetricsCalculatedEventHandler;
        }
コード例 #6
0
        public MovingAverage(ZPMonitorService zpMonitorService, ILoggerFactory loggerFactory, DurationType durationType, bool excludeZeroPowerValues)
        {
            m_zpMonitorService       = zpMonitorService;
            Logger                   = loggerFactory.CreateLogger <MovingAverage>();
            m_durationType           = durationType;
            m_duration               = MovingAverage.GetDuration(durationType);
            m_excludeZeroPowerValues = excludeZeroPowerValues;

            m_statsQueue = new Queue <Statistics>();

            m_zpMonitorService.RiderStateEvent += RiderStateEventHandler;
        }
コード例 #7
0
        public static void Initialize(ILoggerFactory loggerFactory, ZPMonitorService zpMonitorService)
        {
            if (_initialized)
            {
                return;
            }

            _loggerFactory = loggerFactory;
            _logger        = loggerFactory.CreateLogger <ZAMsettings>();

            ZPMonitorService = zpMonitorService;

            JObject parsedJson     = null;
            bool    userFileExists = false;

            try
            {
                try
                {
                    // Try to load user .json file settings
                    string jsonStr = File.ReadAllText(FileName);
                    parsedJson = JObject.Parse(jsonStr);

                    userFileExists = true;

                    _logger.LogInformation($"Configuration cached from user settings file {FileName}.");
                }
                catch (FileNotFoundException)
                {
                    // User .json file not found.  Try to load default .json file settings
                    string jsonStr = File.ReadAllText(FileNameDefault);
                    parsedJson = JObject.Parse(jsonStr);

                    _logger.LogInformation($"Configuration cached from default settings file {FileNameDefault}.  User settings file {FileName} not found.");
                }

                // Configuration has been loaded and .json is good.  Now deserialize into the settings objects.
                _committedJsonStr = parsedJson.ToString();

                _committedZAMsettings = JsonConvert.DeserializeObject <ZAMsettings>(_committedJsonStr); // this could throw if settings don't match the .json

                _committedZAMsettings.m_readOnly = true;

                // Set current user according to default selection.  This value is not persisted in json file.
                _committedZAMsettings.CurrentUserProfile = _committedZAMsettings.DefaultUserProfile;

                _initialized = true;

                if (userFileExists)
                {
                    if (!Settings.Collectors.ContainsKey("6 min"))
                    {
                        BeginCachedConfiguration();
                        Collector c = new Collector()
                        {
                            Name            = "6 min",
                            DurationDesc    = "SixMinute",
                            DurationSecs    = 360,
                            FieldAvgDesc    = "Watts",
                            FieldAvgMaxDesc = "Wkg",
                            FieldFtpDesc    = "Hidden"
                        };
                        Settings.Collectors.Add("6 min", c);
                        CommitCachedConfiguration();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException($"Exception occurred while trying to load configuration.", ex);
            }


            // This version would first read the default json settings file, and merge the user json settings file into it.
            // Problem is things like UserProfiles would suddenly have Collectors from the default showing up as selected by the user.
            //try
            //{
            //    string defaultJsonStr = File.ReadAllText(FileNameDefault);
            //    JObject defaultJson = JObject.Parse(defaultJsonStr);

            //    try
            //    {
            //        string userJsonStr = File.ReadAllText(FileName);
            //        JObject userJson = JObject.Parse(userJsonStr);

            //        defaultJson.Merge(userJson, new JsonMergeSettings
            //        {
            //            // union array values together to avoid duplicates
            //            MergeArrayHandling = MergeArrayHandling.Union
            //        });

            //        _logger.LogInformation($"Configuration cached from default settings file {FileNameDefault} and merged with user settings file {FileName}.");
            //    }
            //    catch (FileNotFoundException)
            //    {
            //        // this is okay as defaults will be used
            //        _logger.LogInformation($"Configuration cached from default settings file {FileNameDefault}.  User settings file {FileName} not found.");
            //    }

            //    _committedJsonStr = defaultJson.ToString();

            //    _committedZAMsettings = JsonConvert.DeserializeObject<ZAMsettings>(_committedJsonStr);

            //    _committedZAMsettings.m_readOnly = true;

            //    // Set current user according to default selection.  This value is not persisted in json file.
            //    _committedZAMsettings.CurrentUserProfile = _committedZAMsettings.DefaultUserProfile;

            //    _initialized = true;

            //}
            //catch (Exception ex)
            //{
            //    throw new ApplicationException($"Exception occurred trying to load configuration from file: {FileName}", ex);
            //}
        }