CPE_learningsite
This repository has no backups
This repository's network speed is throttled to 100KB/sec
Upgrade your account to fix these warnings, or use backups.vc for automated backups
4cd176a439ea516368a5d8827cdf8726027259a6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
using System; using System.Configuration; using System.Linq; using System.ServiceProcess; using System.Timers; using CPE.App.Notify.Extensions; using CPE.App.Notify.Helpers; using CPE.App.Notify.Models; using CPE.App.Notify.Models.Enums; namespace CPE.App.NotifyService { public partial class NotifyMonitor : ServiceBase { #region Delegates public delegate void AsyncMethodCaller(); #endregion /// <summary> /// Main service class for Windows service import. /// </summary> public NotifyMonitor() { _notifyConsoleFilePath = ConfigurationManager.AppSettings["NotifyFilePath"]; InitializeComponent(); } /// <summary> /// Is the service configured for debugging in the config file? /// </summary> private static bool debugging { get { return bool.Parse(ConfigurationManager.AppSettings["Debugging"]); } } /// <summary> /// Get the service interval for time in milliseconds for processing inbetween requests /// </summary> private static double serviceInterval { get { return double.Parse(ConfigurationManager.AppSettings["ServiceInterval"]); } } private static int poolCount { get { return int.Parse(ConfigurationManager.AppSettings["PoolCount"]); } } /// <summary> /// Thios is the method that is called by Windows service. /// </summary> /// <param name="args"></param> protected override void OnStart(string[] args) { _processTimer.Enabled = true; _processTimer.Elapsed += ProcessTimerOnElapsed; _processTimer.Start(); "Notify Monitor started...".Log(LoggingLevels.Info); $"Debugging is set to {debugging}".Log(); } /// <summary> /// Managed timer for processing notify candidates. /// </summary> /// <param name="sender"></param> /// <param name="elapsedEventArgs"></param> private void ProcessTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) { "Process timer elapsed...".Log(); // This is here to set the interval to 1 minute // If set to debug then initial start is 2 minutes to allow for attaching to process // The default start timeout is 100 so the service and begin processing right away _processTimer.Interval = serviceInterval; // Only process if all worker jobs are completed if((_workerCount < poolCount) && !_inProgress) { _inProgress = true; IQueryable<GetRecordingCandidatesResult> candidates = null; try { candidates = SessionHelper.getRecordingCandidates() .Log(); } catch (Exception exception) { exception.Log(LoggingLevels.Fatal); } if((candidates != null) && candidates.Any()) { foreach (var candidate in candidates) { _workerCount += 1; try { _notifyConsoleFilePath.Log(); candidate.Log(); new AsyncMethodCaller(new Worker(candidate.MeetingParticipantSessionKey, _notifyConsoleFilePath, debugging).Process).BeginInvoke(WorkerComplete, null); } catch (Exception exception) { exception.Log(LoggingLevels.Fatal); } } } else { _workerCount = 0; } _inProgress = false; } } /// <summary> /// Service stop /// </summary> protected override void OnStop() { _processTimer.Stop(); "Notify Monitor stopped...".Log(LoggingLevels.Info); } /// <summary> /// Service pause /// </summary> protected override void OnPause() { _processTimer.Stop(); "Notify Monitor paused...".Log(LoggingLevels.Info); } /// <summary> /// Service continue /// </summary> protected override void OnContinue() { _processTimer.Start(); "Notify Monitor continued...".Log(LoggingLevels.Info); } /// <summary> /// Service shutdown /// </summary> protected override void OnShutdown() { _processTimer.Stop(); "Notify Monitor shutdown...".Log(LoggingLevels.Info); } /// <summary> /// Notify process is complete /// </summary> /// <param name="asyncResult"></param> public void WorkerComplete(IAsyncResult asyncResult) { if(_workerCount > 0) { _workerCount -= 1; } } #region Private Variables private readonly string _notifyConsoleFilePath; private readonly Timer _processTimer = new Timer {Enabled = false, Interval = debugging ? 120000 : 100}; private bool _inProgress; private int _workerCount; #endregion } } |
Commits for CPE_learningsiteCPE/CPE.App/CPE.App.NotifyService/CPEMonitor.cs
Revision | Author | Commited | Message |
---|---|---|---|
4cd176 ... | v.shishlov | Fri 27 Aug, 2021 14:33:17 +0000 | initial commit |