public void OnGUI(XmlBuilderConfig config, ref ProcessQueue processQueue) { _config = config; _buttonWidth = GUILayout.Width(128.0f); _DoOnGUI(ref processQueue); }
protected virtual async Task ReQueueItem(T t) { Logger.LogDebug($"Holding pattern. Wait 3, then back to Queue, {t.Id}"); await Task.Delay(3000); await ProcessQueue.SendAsync(t); }
public void Test3() { ProcessQueue <Item> queue = new ProcessQueue <Item>(); Processor processor = new Processor(); queue.RegisterProcessor(processor.Process); Item item1 = new Item("Scotty", 1, DateTime.Now); Item item2 = new Item("Bones", 2, DateTime.Now); Item item3 = new Item("Spock", 3, DateTime.Now); Item item4 = new Item("Kirk", 4, DateTime.Now); queue.Enqueue(item1); queue.Enqueue(item2); queue.Start(); queue.Stop(); queue.Enqueue(item2); queue.Enqueue(item3); queue.Enqueue(item4); Assert.AreEqual(3, queue.Count); Assert.AreEqual(2, processor.ProcessCount); queue.Start(); queue.Stop(); Assert.AreEqual(0, queue.Count); Assert.AreEqual(5, processor.ProcessCount); }
/// <summary> /// Constructs a new instance of the <see cref="OutputAdapterBase"/>. /// </summary> protected OutputAdapterBase() { m_metadataRefreshOperation = new LongSynchronizedOperation(ExecuteMetadataRefresh) { IsBackground = true }; m_measurementQueue = ProcessQueue <IMeasurement> .CreateRealTimeQueue(ProcessMeasurements); m_measurementQueue.ProcessException += m_measurementQueue_ProcessException; m_connectionTimer = new Timer(); m_connectionTimer.Elapsed += m_connectionTimer_Elapsed; m_connectionTimer.AutoReset = false; m_connectionTimer.Interval = 2000; m_connectionTimer.Enabled = false; m_monitorTimer = new Timer(); m_monitorTimer.Elapsed += m_monitorTimer_Elapsed; // We monitor total number of unarchived measurements every 5 seconds - this is a useful statistic to monitor, if // total number of unarchived measurements gets very large, measurement archival could be falling behind m_monitorTimer.Interval = 5000; m_monitorTimer.AutoReset = true; m_monitorTimer.Enabled = false; }
// Static Constructor static ConfigurationFrame() { s_configurationCacheQueue = ProcessQueue <Tuple <IConfigurationFrame, Action <Exception>, string> > .CreateRealTimeQueue(CacheConfigurationFile); s_configurationCacheQueue.SynchronizedOperationType = SynchronizedOperationType.LongBackground; s_configurationCacheQueue.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="LogFile"/> class. /// </summary> public LogFile() { m_fileName = DefaultFileName; m_fileSize = DefaultFileSize; m_fileFullOperation = DefaultFileFullOperation; m_logFilesDuration = DefaultLogFilesDuration; m_persistSettings = DefaultPersistSettings; m_settingsCategory = DefaultSettingsCategory; m_textEncoding = Encoding.Default; m_operationWaitHandle = new ManualResetEvent(true); m_savedFilesWithTime = new Dictionary <DateTime, string>(); m_logEntryQueue = ProcessQueue <string> .CreateRealTimeQueue(WriteLogEntries); if (OptimizationOptions.PreferDedicatedThreads) { m_logEntryQueue.SynchronizedOperationType = SynchronizedOperationType.DedicatedForeground; } else { m_logEntryQueue.SynchronizedOperationType = SynchronizedOperationType.Long; } m_flushTimer = new Timer(); m_flushTimerInterval = 10.0D; m_fileStreamLock = new object(); this.FileFull += LogFile_FileFull; m_logEntryQueue.ProcessException += ProcessExceptionHandler; m_flushTimer.Elapsed += FlushTimer_Elapsed; m_flushTimer.AutoReset = false; }
public override void _DoOnGUI(ref ProcessQueue processQueue) { var config = _config.android; _LeaveSpace(); _DrawOpenFilePanel("apktool:", "Selection Location", ref config.apktoolPath); _DrawOpenFilePanel("adb:", "Selection Location", ref config.adbPath); if (os.isWindows) { _DrawOpenFilePanel("jarsigner", "Selection Location", ref config.jarsignerPath); } _DrawSaveFilePanel("Apk Location:", "Selection Location", ref config.apkPath, "apk"); _DrawAndroid_KeystoreName(config); _DrawAndroid_KeytorePass(config); config.builtinResources = GUILayout.Toggle(config.builtinResources, "Builtin Resources"); config.autoInstall = GUILayout.Toggle(config.autoInstall, "Auto Install"); var options = _DrawBuildOptions(config); _LeaveSpace(); using (new LayoutHorizontalScope(0)) { _DrawBuild(config, options, ref processQueue); _DrawInstallApk(ref processQueue); } }
public AbstractLeadProcessor(int leadNumber, AmoAccount acc, ProcessQueue processQueue, Log log, CancellationToken token) { _leadRepo = acc.GetRepo <Lead>(); _processQueue = processQueue; _token = token; _acc = acc; _leadNumber = leadNumber; _log = log; custom_fields_values = new(); tags = new(); try { Thread.Sleep((int)TimeSpan.FromSeconds(3).TotalMilliseconds); lead = _leadRepo.GetById(leadNumber); if (lead is not null && lead._embedded is not null && lead._embedded.tags is not null) { tags = lead._embedded.tags; } } catch (Exception e) { _processQueue.Stop(leadNumber.ToString()); _processQueue.Remove(leadNumber.ToString()); _log.Add($"Error: Unable to create leadProcessor {leadNumber}: {e.Message}"); } }
public GSheetsController(Amo amo, ProcessQueue processQueue, GSheets gSheets, Log log) { _amo = amo; _processQueue = processQueue; _gSheets = gSheets; _log = log; }
private Dictionary <FlScriptExecutionContext, Dictionary <Bitmap, byte[]> > _proc(Action onFinish = null) { //window = new GameWindow(100, 100, GraphicsMode.Default, "FLRunner"); //window.MakeCurrent(); Dictionary <FlScriptExecutionContext, Dictionary <Bitmap, byte[]> > ret = new Dictionary <FlScriptExecutionContext, Dictionary <Bitmap, byte[]> >(); while (ProcessQueue.Count != 0) { FlScriptExecutionContext fle = ProcessQueue.Dequeue(); Dictionary <string, byte[]> texUpdate = Process(fle); Dictionary <Bitmap, byte[]> texMap = new Dictionary <Bitmap, byte[]>(); foreach (KeyValuePair <string, byte[]> bytese in texUpdate) { if (fle.TextureMap.ContainsKey(bytese.Key)) { texMap.Add(fle.TextureMap[bytese.Key], bytese.Value); } } ret.Add(fle, texMap); } //window.Dispose(); onFinish?.Invoke(); return(ret); }
public SiteFormController(Amo amo, ProcessQueue processQueue, Log log, GSheets gSheets) { _amo = amo; _processQueue = processQueue; _log = log; _gSheets = gSheets; _path = $@"logs\siteform\{DateTime.Today.Year}-{DateTime.Today.Month}-{DateTime.Today.Day}.log"; }
public WebhookController(Amo amo, ProcessQueue processQueue, Log log, RecentlyUpdatedEntityFilter filter, GSheets gSheets) { _amo = amo; _processQueue = processQueue; _log = log; _filter = filter; _gSheets = gSheets; }
// Static Constructor static FaultEmailWriter() { QueuedEventIDs = new HashSet <int>(); ProcessQueue = ProcessQueue <Action> .CreateRealTimeQueue(action => action()); ProcessQueue.ProcessException += (sender, args) => Log.Error(args.Argument.Message, args.Argument); ProcessQueue.Start(); }
public RetailCourseProcessor(Amo amo, ProcessQueue processQueue, CancellationToken token, int leadNumber, Log log) { _repo = amo.GetAccountById(28395871).GetRepo <Lead>(); _processQueue = processQueue; _token = token; _leadNumber = leadNumber; _log = log; }
public MsgProcessor(IMsgProcessor msgProcessor) { _msgProcessor = msgProcessor; _queue = new ProcessQueue(); _worker = new Task(() => { ReadingPushedMsgs(); }); _id = _worker.Id; _worker.Start(); }
/// <summary> /// Run the Shortest Job First scheduler on the data /// </summary> /// <param name="testData"></param> /// <returns>Average turnaround time</returns> public int Run(string testData) { ReadTestData(testData); ProcessQueue.Sort(new SmallestBurstTime()); AddBurstTimes(); return(GetAvgTurnAroundTime()); }
/// <summary> /// Begin a session. Must be called whenever a page loads. /// </summary> /// <param name="usUserName">The username to initialize a session for.</param> /// <param name="request">The request from the user's browser.</param> /// <returns>True if the session was initialized successfully, false otherwise.</returns> public static bool BeginSession(string usUserName, HttpRequest request, OCUserInfo userInfo = null) { try { // Check existence of session HttpSessionState session = HttpContext.Current.Session; if (session == null) { return(false); } User user = new User(); bool isTest = false; //CHECK DEVELOPMENT/TEST ENVIRONMENT string hostname = request.Url.Authority; if (hostname == "10.0.0.245:30658") { isTest = true; } #if DEBUG isTest = true; #endif if (userInfo != null) { isTest = userInfo.IsTest; } if (!GetUserInfo(user, usUserName, isTest)) { return(false); } if (userInfo != null) { for (int i = 0; i < user.PartnerList.Count; i++) { if (user.PartnerList[i].ID == userInfo.ActivePartner) { user.PartnerIndex = i; break; } } } session[SKeys.User] = user; session[SKeys.IsTest] = isTest; session[SKeys.LandingPg] = "Default.aspx"; session[SKeys.TokenSet] = new HashSet <string>(); session[SKeys.TrxDict] = ProcessQueue.GetReqTypeDict(user); session[SKeys.IsOCSession] = userInfo != null; return(true); } catch (Exception e) { ProgramLog.LogError(usUserName, "EDIO", "EDIO", "SessionHandler", "BeginSession", e.Message); return(false); } }
public Integration1CController(Amo amo, ProcessQueue processQueue, Log log, Cred1C cred1C, RecentlyUpdatedEntityFilter filter) { _amo = amo; _processQueue = processQueue; _log = log; _cred1C = cred1C; _filter = filter; _path = $@"logs\1c\{DateTime.Today.Year}-{DateTime.Today.Month}-{DateTime.Today.Day}.log"; }
public GSheetsProcessor(int leadnumber, Amo amo, GSheets gSheets, ProcessQueue processQueue, Log log, CancellationToken token) { _processQueue = processQueue; _token = token; _log = log; _amo = amo; _leadNumber = leadnumber; _service = gSheets.GetService(); }
public SmilarcompaniesCheckProcessor(int companyNumber, AmoAccount acc, ProcessQueue processQueue, Log log, CancellationToken token, RecentlyUpdatedEntityFilter filter) { _companyNumber = companyNumber; _compRepo = acc.GetRepo <Company>(); _token = token; _log = log; _filter = filter; _processQueue = processQueue; }
private void _DrawInstallApk(ref ProcessQueue processQueue) { var isInstall = GUILayout.Button("Install Apk", _buttonWidth); if (isInstall) { processQueue = new ProcessQueue(); processQueue.Enqueue(_InstallApk); } }
public AbstractLeadProcessor(AmoAccount acc, ProcessQueue processQueue, Log log, CancellationToken token) { _leadRepo = acc.GetRepo <Lead>(); _processQueue = processQueue; _token = token; _acc = acc; _log = log; custom_fields_values = new(); tags = new(); }
public void Start_QueueAction_RunProcedure() { //arrange iOperationFactoryMock.Setup(f => f.GetOperation(ApiConstants.PoolActionType.Queues)).Returns(iOperaionMock.Object); //act ProcessQueue processQueue = new ProcessQueue(iOperationFactoryMock.Object); processQueue.Start(); //assert }
public TestingController(Amo amo, ProcessQueue processQueue, GSheets gSheets, Log log, Cred1C cred1C, RecentlyUpdatedEntityFilter filter, Uber uber) { _amo = amo; _processQueue = processQueue; _gSheets = gSheets; _log = log; _cred1C = cred1C; _filter = filter; locker = new(); _uber = uber; }
private object _proc() { while (ProcessQueue.Count != 0) { FlScriptExecutionContext fle = ProcessQueue.Dequeue(); FLProgram texUpdate = Process(fle); fle.OnFinishCallback?.Invoke(texUpdate); } OnFinishQueue?.Invoke(); return(new object()); }
public RetailRespProcessor(Amo amo, ProcessQueue processQueue, CancellationToken token, int entityNumber, Log log, Type type, int oldResp, int modResp) { _leadRepo = amo.GetAccountById(28395871).GetRepo <Lead>(); _contRepo = amo.GetAccountById(28395871).GetRepo <Contact>(); _processQueue = processQueue; _token = token; _entityNumber = entityNumber; _log = log; _type = type; _oldResp = oldResp; _modResp = modResp; }
public MainForm() { Queues = new List<ProcessQueue<IPAddress>>(); for (int i = 0; i < 200; i++) { var q = new ProcessQueue<IPAddress>(); q.Process += Queue_Process; Queues.Add(q); } InitializeComponent(); }
private bool m_disposed; // Flag that determines if class is disposed #endregion #region [ Constructors ] /// <summary> /// Creates a new <see cref="PIOutputAdapter"/> /// </summary> public PIOutputAdapter() { m_mappedPIPoints = new ConcurrentDictionary <MeasurementKey, PIPoint>(); m_archiveQueue = ProcessQueue <AFValue> .CreateAsynchronousQueue(ArchiveAFValues, 1.0D, Environment.ProcessorCount, Timeout.Infinite, false, false); m_mapRequestQueue = ProcessQueue <MeasurementKey> .CreateAsynchronousQueue(EstablishPIPointMappings, Environment.ProcessorCount); m_restartConnection = new ShortSynchronizedOperation(Start); m_tagMap = new ConcurrentDictionary <Guid, string>(); m_pendingMappings = new HashSet <MeasurementKey>(); m_lastMetadataRefresh = DateTime.MinValue; }
public virtual async Task Enqueue(T entity) { if (entity == null || entity.Id.IsEmpty()) { throw new NotFoundException(); } if (Validate(entity)) { await ProcessQueue.SendAsync(entity); } }
/// <summary> /// Creates a new instance of the <see cref="MultiSourceFrameImageParserBase{TSourceIdentifier,TTypeIdentifier,TOutputType}"/> class. /// </summary> protected MultiSourceFrameImageParserBase() { m_bufferQueue = CreateBufferQueue(); m_bufferQueue.ProcessException += ProcessExceptionHandler; if (ProtocolUsesSyncBytes) { m_sourceInitialized = new ConcurrentDictionary <TSourceIdentifier, bool>(); } m_unparsedBuffers = new ConcurrentDictionary <TSourceIdentifier, byte[]>(); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (Queue != null) { Queue.Process -= Queue_Process; Queue.Dispose(); Queue = null; } } }
/// <summary> /// Constructs a new instance of the <see cref="OutputAdapterBase"/>. /// </summary> protected OutputAdapterBase() { m_measurementQueue = ProcessQueue<IMeasurement>.CreateRealTimeQueue(StartMeasurementProcessing); m_measurementQueue.ProcessException += m_measurementQueue_ProcessException; m_connectionTimer = new System.Timers.Timer(); m_connectionTimer.Elapsed += m_connectionTimer_Elapsed; m_connectionTimer.AutoReset = false; m_connectionTimer.Interval = 2000; m_connectionTimer.Enabled = false; m_monitorTimer = new System.Timers.Timer(); m_monitorTimer.Elapsed += m_monitorTimer_Elapsed; // We monitor total number of unarchived measurements every 5 seconds - this is a useful statistic to monitor, if // total number of unarchived measurements gets very large, measurement archival could be falling behind m_monitorTimer.Interval = 5000; m_monitorTimer.AutoReset = true; m_monitorTimer.Enabled = false; }
public static void Main(string[] args) { Console.WriteLine("Press c to exit"); bool work = true; var process = new ProcessQueue(); CancellationTokenSource tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; Task t = Task.Run(() => process.Execute(), token ); while (work) { var c = Console.Read(); if (c == 'c') work = false; } tokenSource.Cancel(); t.Wait(); }
// Static Constructor static EventEmailWriter() { QueuedEventIDs = new HashSet<int>(); ProcessQueue = ProcessQueue<Action>.CreateRealTimeQueue(action => action()); ProcessQueue.ProcessException += (sender, args) => Log.Error(args.Argument.Message, args.Argument); ProcessQueue.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="LocalOutputAdapter"/> class. /// </summary> public LocalOutputAdapter() { m_autoRefreshMetadata = true; m_archive = new ArchiveFile(); m_archive.MetadataFile = new MetadataFile(); m_archive.StateFile = new StateFile(); m_archive.IntercomFile = new IntercomFile(); MetadataRefreshOperation.IsBackground = false; m_badDataMessageInterval = 900; m_orphanCounts = new Dictionary<int, ulong>(); m_orphanQueue = ProcessQueue<IDataPoint>.CreateRealTimeQueue(HandleOrphanData); m_badTimestampCounts = new Dictionary<int, ulong>(); m_badTimestampQueue = ProcessQueue<IDataPoint>.CreateRealTimeQueue(HandleBadTimestampData); m_outOfSequenceCounts = new Dictionary<int, ulong>(); m_outOfSequenceQueue = ProcessQueue<IDataPoint>.CreateRealTimeQueue(HandleOutOfSequenceData); }
/// <summary> /// Initializes a new instance of the <see cref="LogFile"/> class. /// </summary> public LogFile() { m_fileName = DefaultFileName; m_fileSize = DefaultFileSize; m_fileFullOperation = DefaultFileFullOperation; m_logFilesDuration = DefaultLogFilesDuration; m_persistSettings = DefaultPersistSettings; m_settingsCategory = DefaultSettingsCategory; m_textEncoding = Encoding.Default; m_operationWaitHandle = new ManualResetEvent(true); m_savedFilesWithTime = new Dictionary<DateTime, string>(); m_logEntryQueue = ProcessQueue<string>.CreateRealTimeQueue(WriteLogEntries); m_logEntryQueue.SynchronizedOperationType = SynchronizedOperationType.Long; m_flushTimer = new Timer(); m_flushTimerInterval = 10.0D; m_fileStreamLock = new object(); this.FileFull += LogFile_FileFull; m_logEntryQueue.ProcessException += ProcessExceptionHandler; m_flushTimer.Elapsed += FlushTimer_Elapsed; m_flushTimer.AutoReset = false; }
/// <summary> /// Creates a new instance of the <see cref="FileProcessor"/> class. /// </summary> /// <param name="processorID">Identifies the file processor so that it can locate its processed file cache.</param> public FileProcessor(Guid processorID) { m_processorID = processorID; m_filter = DefaultFilter; m_trackChanges = DefaultTrackChanges; m_cachePath = DefaultCachePath; m_internalBufferSize = DefaultInternalBufferSize; m_fileWatchersLock = new object(); m_fileWatchers = new List<SafeFileWatcher>(); m_processingQueue = ProcessQueue<Action>.CreateRealTimeQueue(action => action()); m_processingQueue.SynchronizedOperationType = SynchronizedOperationType.LongBackground; m_processingQueue.ProcessException += (sender, args) => OnError(args.Argument); m_fileWatchTimer = new Timer(15000); m_fileWatchTimer.Elapsed += FileWatchTimer_Elapsed; m_waitObject = new ManualResetEvent(false); m_touchedFiles = new Dictionary<string, DateTime>(StringComparer.OrdinalIgnoreCase); m_processedFiles = new FileBackedHashSet<string>(Path.Combine(m_cachePath, m_processorID.ToString()), StringComparer.OrdinalIgnoreCase); }
/// <summary> /// Releases all the resources used by the <see cref="FileProcessor"/> object. /// </summary> public void Dispose() { if (!m_disposed) { try { ClearTrackedDirectories(); if ((object)m_processingQueue != null) { m_processingQueue.Dispose(); m_processingQueue = null; } if ((object)m_fileWatchTimer != null) { m_fileWatchTimer.Dispose(); m_fileWatchTimer = null; } if ((object)m_processedFiles != null) { m_processedFiles.Dispose(); m_processedFiles = null; } if ((object)m_waitObject != null) { m_waitObject.Set(); m_waitObject.Dispose(); m_waitObject = null; } } finally { m_disposed = true; // Prevent duplicate dispose. } } }
/// <summary> /// Initializes a new instance of the <see cref="LogFile"/> class. /// </summary> public LogFile() : base() { m_fileName = DefaultFileName; m_fileSize = DefaultFileSize; m_fileFullOperation = DefaultFileFullOperation; m_persistSettings = DefaultPersistSettings; m_settingsCategory = DefaultSettingsCategory; m_textEncoding = Encoding.Default; m_operationWaitHandle = new ManualResetEvent(true); m_logEntryQueue = ProcessQueue<string>.CreateSynchronousQueue(WriteLogEntries); this.FileFull += LogFile_FileFull; m_logEntryQueue.ProcessException += ProcessExceptionHandler; }
// Static Constructor static ConfigurationFrame() { s_configurationCacheQueue = ProcessQueue<Tuple<IConfigurationFrame, Action<Exception>, string>>.CreateRealTimeQueue(CacheConfigurationFile); s_configurationCacheQueue.SynchronizedOperationType = SynchronizedOperationType.LongBackground; s_configurationCacheQueue.Start(); }
private void Initialize(object state) { // In case we are reinitializing class, we shutdown any prior queue operations and close any existing network connections... Shutdown(); // Set up a synchronous process queue to handle exports that will limit total export time to export interval m_exportQueue = ProcessQueue<byte[]>.CreateSynchronousQueue(WriteExportFiles, 10, m_exportTimeout, false, false); m_exportQueue.ProcessException += m_exportQueue_ProcessException; lock (m_destinationLock) { // Retrieve any specified default export destinations m_exportDestinations = (ExportDestination[])state; // We provide a simple default set of export destinations as a configuration file // example if no others are specified if (m_exportDestinations == null) m_exportDestinations = new ExportDestination[] { new ExportDestination("C:\\filename.txt", false, "domain", "username", "password") }; } // Load export settings (this loads a new set of destinations in m_exportDestinations) LoadSettings(); // Connect to network shares if necessary ExportDestination[] destinations; lock (m_destinationLock) { // Cache a local copy of export destinations to reduce lock time, // network share authentication may take some time destinations = m_exportDestinations; } for (int x = 0; x < destinations.Length; x++) { if (destinations[x].ConnectToShare) { // Attempt connection to external network share try { UpdateStatus(string.Format("Attempting network share authentication for user {0}\\{1} to {2}...", destinations[x].Domain, destinations[x].UserName, destinations[x].Share)); FilePath.ConnectToNetworkShare(destinations[x].Share, destinations[x].UserName, destinations[x].Password, destinations[x].Domain); UpdateStatus(string.Format("Network share authentication to {0} succeeded.", destinations[x].Share)); } catch (Exception ex) { // Something unexpected happened during attempt to connect to network share - so we'll report it... UpdateStatus(string.Format("Network share authentication to {0} failed due to exception: {1}", destinations[x].Share, ex.Message)); } } } // Start export queue m_exportQueue.Start(); }
public LogFile() { m_name = DefaultName; m_size = DefaultSize; m_autoOpen = DefaultAutoOpen; m_fileFullOperation = DefaultFileFullOperation; m_persistSettings = DefaultPersistSettings; m_settingsCategoryName = DefaultSettingsCategoryName; m_operationWaitHandle = new ManualResetEvent(true); m_logEntryQueue = ProcessQueue<string>.CreateSynchronousQueue(WriteLogEntries); m_logEntryQueue.ProcessException += m_logEntryQueue_ProcessException; m_textEncoding = Encoding.Default; }
/// <summary> /// Initializes a new instance of the <see cref="ServiceHelper"/> class. /// </summary> public ServiceHelper() : base() { m_telnetSessionPassword = "******"; m_logStatusUpdates = DefaultLogStatusUpdates; m_maxStatusUpdatesLength = DefaultMaxStatusUpdatesLength; m_maxStatusUpdatesFrequency = DefaultMaxStatusUpdatesFrequency; m_monitorServiceHealth = DefaultMonitorServiceHealth; m_healthMonitorInterval = DefaultHealthMonitorInterval; m_requestHistoryLimit = DefaultRequestHistoryLimit; m_supportTelnetSessions = DefaultSupportTelnetSessions; m_supportSystemCommands = DefaultSupportSystemCommands; m_secureRemoteInteractions = DefaultSecureRemoteInteractions; m_persistSettings = DefaultPersistSettings; m_settingsCategory = DefaultSettingsCategory; m_processes = new List<ServiceProcess>(); m_remoteClients = new List<ClientInfo>(); m_clientRequestHistory = new List<ClientRequestInfo>(); m_serviceComponents = new List<object>(); m_clientRequestHandlers = new List<ClientRequestHandler>(); m_componentEnabledStates = new Dictionary<ISupportLifecycle, bool>(); // Components m_statusUpdateQueue = ProcessQueue<StatusUpdate>.CreateSynchronousQueue(ProcessStatusUpdates); m_statusUpdateQueue.Name = "StatusUpdateQueue"; m_statusUpdateQueue.ProcessException += StatusUpdateQueue_ProcessException; m_statusLog = new LogFile(); m_statusLog.FileName = "StatusLog.txt"; m_statusLog.SettingsCategory = "StatusLog"; m_statusLog.LogException += StatusLog_LogException; m_processScheduler = new ScheduleManager(); m_processScheduler.SettingsCategory = "ProcessScheduler"; m_processScheduler.ScheduleDue += Scheduler_ScheduleDue; m_errorLogger = new ErrorLogger(); m_errorLogger.ExitOnUnhandledException = false; m_errorLogger.SettingsCategory = "ErrorLogger"; m_errorLogger.ErrorLog.SettingsCategory = "ErrorLog"; m_errorLogger.LoggingException += ErrorLogger_LoggingException; }
/// <summary> /// Releases the unmanaged resources used by the <see cref="LogFile"/> object and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!m_disposed) { try { if (disposing) { if (m_logEntryQueue != null) { // Flush any unwritten log records Close(true); m_logEntryQueue.Dispose(); } m_logEntryQueue = null; if (m_fileStream != null) { m_fileStream.Dispose(); } m_fileStream = null; if (m_operationWaitHandle != null) { m_operationWaitHandle.Close(); } m_operationWaitHandle = null; SaveSettings(); // Saves settings to the config file. } } finally { base.Dispose(disposing); // Call base class Dispose(). m_disposed = true; // Prevent duplicate dispose. } } }
/// <summary> /// Initializes the <see cref="ServiceBusService"/>. /// </summary> /// <exception cref="NotSupportedException">The specified <see cref="ProcessingMode"/> is not supported.</exception> public override void Initialize() { base.Initialize(); if (m_publishQueue == null) { // Instantiate the process queue. if (m_processingMode == MessageProcessingMode.Parallel) m_publishQueue = ProcessQueue<PublishContext>.CreateAsynchronousQueue(PublishMessages); else if (m_processingMode == MessageProcessingMode.Sequential) m_publishQueue = ProcessQueue<PublishContext>.CreateRealTimeQueue(PublishMessages); else throw new NotSupportedException(string.Format("Processing mode '{0}' is not supported", m_processingMode)); // Start the process queue. m_publishQueue.ProcessException += OnProcessException; m_publishQueue.Start(); } }
/// <summary> /// Logs encountered <see cref="Exception"/> to the database. /// </summary> /// <param name="exception"><see cref="Exception"/> that was encountered.</param> protected virtual void ExceptionToDatabase(Exception exception) { // Log if enabled. if (m_logToDatabase) { m_logToDatabaseOK = false; // Make sure a database processing queue exists to process items every two seconds if ((object)m_databaseErrorQueue == null) { m_databaseErrorQueue = ProcessQueue<Tuple<string, string, string, string>>.CreateSynchronousQueue(ProcessExceptionsToDatabase, 2.0D, 30, false, false); m_databaseErrorQueue.ProcessException += m_databaseErrorQueue_ProcessException; m_databaseErrorQueue.Start(); } // Make sure table size curtailment timer exists to maintain error log table size if ((object)m_tableSizeCurtailmentTimer == null) { m_tableSizeCurtailmentTimer = new Timer(); m_tableSizeCurtailmentTimer.AutoReset = false; m_tableSizeCurtailmentTimer.Interval = 15000; m_tableSizeCurtailmentTimer.Enabled = false; m_tableSizeCurtailmentTimer.Elapsed += m_tableSizeCurtailmentTimer_Elapsed; } // Queue up exception to be logged into the database - we only process database inserts once every two // seconds in case there are many errors, this way database thrashing is kept to a minimum m_databaseErrorQueue.Add(new Tuple<string, string, string, string>( exception.Source.ToNonNullNorEmptyString("No Source"), exception.GetType().FullName, exception.Message.ToNonNullNorEmptyString("No Message"), GetExceptionInfo(exception, true))); m_logToDatabaseOK = true; } }
/// <summary> /// Initializes a new instance of the <see cref="MultipleDestinationExporter"/> class. /// </summary> /// <param name="settingsCategory">The config file settings category under which the export destinations are defined.</param> /// <param name="exportTimeout">The total allowed time in milliseconds for all exports to execute.</param> public MultipleDestinationExporter(string settingsCategory, int exportTimeout) { m_exportTimeout = exportTimeout; m_settingsCategory = settingsCategory; m_persistSettings = DefaultPersistSettings; m_textEncoding = Encoding.Default; // We use default ANSI page encoding for text based exports... m_destinationLock = new object(); // Set up a synchronous process queue to handle exports that will limit total export time to export interval m_exportQueue = ProcessQueue<byte[]>.CreateSynchronousQueue(WriteExportFiles, 10, m_exportTimeout, false, false); m_exportQueue.ProcessException += m_exportQueue_ProcessException; }
/// <summary> /// Releases the unmanaged resources used by the <see cref="ErrorLogger"/> object and optionally releases the /// managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!m_disposed) { try { // This will be done regardless of whether the object is finalized or disposed. Unregister(); if (disposing) { // This will be done only when the object is disposed by calling Dispose(). SaveSettings(); if ((object)m_errorLog != null) m_errorLog.Dispose(); if ((object)m_tableSizeCurtailmentTimer != null) { m_tableSizeCurtailmentTimer.Elapsed -= m_tableSizeCurtailmentTimer_Elapsed; m_tableSizeCurtailmentTimer.Dispose(); m_tableSizeCurtailmentTimer = null; } if ((object)m_databaseErrorQueue != null) { m_databaseErrorQueue.ProcessException -= m_databaseErrorQueue_ProcessException; m_databaseErrorQueue.Dispose(); } m_databaseErrorQueue = null; } } finally { m_enabled = false; // Mark as disabled. m_disposed = true; // Prevent duplicate dispose. base.Dispose(disposing); // Call base class Dispose(). } } }
/// <summary> /// Initializes a new instance of the <see cref="ArchiveFile"/> class. /// </summary> public ArchiveFile() { m_fileName = DefaultFileName; m_fileType = DefaultFileType; m_fileSize = DefaultFileSize; m_fileAccessMode = DefaultFileAccessMode; m_dataBlockSize = DefaultDataBlockSize; m_rolloverPreparationThreshold = DefaultRolloverPreparationThreshold; m_archiveOffloadLocation = DefaultArchiveOffloadLocation; m_archiveOffloadCount = DefaultArchiveOffloadCount; m_archiveOffloadThreshold = DefaultArchiveOffloadThreshold; m_archiveOffloadMaxAge = DefaultArchiveOffloadMaxAge; m_maxHistoricArchiveFiles = DefaultMaxHistoricArchiveFiles; m_leadTimeTolerance = DefaultLeadTimeTolerance; m_compressData = DefaultCompressData; m_discardOutOfSequenceData = DefaultDiscardOutOfSequenceData; m_cacheWrites = DefaultCacheWrites; m_conserveMemory = DefaultConserveMemory; m_monitorNewArchiveFiles = DefaultMonitorNewArchiveFiles; m_persistSettings = DefaultPersistSettings; m_settingsCategory = DefaultSettingsCategory; m_delayedAlarmProcessing = new Dictionary<int, decimal>(); m_rolloverWaitHandle = new ManualResetEvent(true); m_rolloverPreparationThread = new Thread(PrepareForRollover); m_buildHistoricFileListThread = new Thread(BuildHistoricFileList); m_conserveMemoryTimer = new Timer(); m_conserveMemoryTimer.Elapsed += ConserveMemoryTimer_Elapsed; m_currentDataQueue = ProcessQueue<IDataPoint>.CreateRealTimeQueue(WriteToCurrentArchiveFile); m_currentDataQueue.ProcessException += CurrentDataQueue_ProcessException; m_historicDataQueue = ProcessQueue<IDataPoint>.CreateRealTimeQueue(WriteToHistoricArchiveFile); m_historicDataQueue.ProcessException += HistoricDataQueue_ProcessException; m_outOfSequenceDataQueue = ProcessQueue<IDataPoint>.CreateRealTimeQueue(InsertInCurrentArchiveFile); m_outOfSequenceDataQueue.ProcessException += OutOfSequenceDataQueue_ProcessException; }
/// <summary> /// Event handler for service starting operations. /// </summary> /// <param name="sender">Event source.</param> /// <param name="e">Event arguments containing command line arguments passed into service at startup.</param> /// <remarks> /// Time-series framework uses this handler to load settings from configuration file as service is starting. /// </remarks> protected virtual void ServiceStartingHandler(object sender, EventArgs<string[]> e) { ShutdownHandler.Initialize(); // Define a run-time log m_runTimeLog = new RunTimeLog(); m_runTimeLog.FileName = "RunTimeLog.txt"; m_runTimeLog.ProcessException += ProcessExceptionHandler; m_runTimeLog.Initialize(); // Initialize Iaon session m_iaonSession = new IaonSession(); m_iaonSession.StatusMessage += StatusMessageHandler; m_iaonSession.ProcessException += ProcessExceptionHandler; m_iaonSession.ConfigurationChanged += ConfigurationChangedHandler; // Create a handler for unobserved task exceptions TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; // Make sure default service settings exist ConfigurationFile configFile = ConfigurationFile.Current; string servicePath = FilePath.GetAbsolutePath(""); string cachePath = string.Format("{0}{1}ConfigurationCache{1}", servicePath, Path.DirectorySeparatorChar); string defaultLogPath = string.Format("{0}{1}Logs{1}", servicePath, Path.DirectorySeparatorChar); // System settings CategorizedSettingsElementCollection systemSettings = configFile.Settings["systemSettings"]; systemSettings.Add("ConfigurationType", "Database", "Specifies type of configuration: Database, WebService, BinaryFile or XmlFile"); systemSettings.Add("ConnectionString", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=IaonHost.mdb", "Configuration database connection string"); systemSettings.Add("DataProviderString", "AssemblyName={System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089};ConnectionType=System.Data.OleDb.OleDbConnection;AdapterType=System.Data.OleDb.OleDbDataAdapter", "Configuration database ADO.NET data provider assembly type creation string"); systemSettings.Add("ConfigurationCachePath", cachePath, "Defines the path used to cache serialized configurations"); systemSettings.Add("LogPath", defaultLogPath, "Defines the path used to archive log files"); systemSettings.Add("MaxLogFiles", DefaultMaxLogFiles, "Defines the maximum number of log files to keep"); systemSettings.Add("CachedConfigurationFile", "SystemConfiguration.xml", "File name for last known good system configuration (only cached for a Database or WebService connection)"); systemSettings.Add("UniqueAdaptersIDs", "True", "Set to true if all runtime adapter ID's will be unique to allow for easier adapter specification"); systemSettings.Add("ProcessPriority", "High", "Sets desired process priority: Normal, AboveNormal, High, RealTime"); systemSettings.Add("AllowRemoteRestart", "True", "Controls ability to remotely restart the host service."); systemSettings.Add("MinThreadPoolWorkerThreads", DefaultMinThreadPoolSize, "Defines the minimum number of allowed thread pool worker threads."); systemSettings.Add("MaxThreadPoolWorkerThreads", DefaultMaxThreadPoolSize, "Defines the maximum number of allowed thread pool worker threads."); systemSettings.Add("MinThreadPoolIOPortThreads", DefaultMinThreadPoolSize, "Defines the minimum number of allowed thread pool I/O completion port threads (used by socket layer)."); systemSettings.Add("MaxThreadPoolIOPortThreads", DefaultMaxThreadPoolSize, "Defines the maximum number of allowed thread pool I/O completion port threads (used by socket layer)."); systemSettings.Add("ConfigurationBackups", DefaultConfigurationBackups, "Defines the total number of older backup configurations to maintain."); systemSettings.Add("PreferCachedConfiguration", "False", "Set to true to try the cached configuration first, before loading database configuration - typically used when cache is updated by external process."); systemSettings.Add("LocalCertificate", $"{ServiceName}.cer", "Path to the local certificate used by this server for authentication."); systemSettings.Add("RemoteCertificatesPath", @"Certs\Remotes", "Path to the directory where remote certificates are stored."); systemSettings.Add("DefaultCulture", "en-US", "Default culture to use for language, country/region and calendar formats."); // Example connection settings CategorizedSettingsElementCollection exampleSettings = configFile.Settings["exampleConnectionSettings"]; exampleSettings.Add("SqlServer.ConnectionString", "Data Source=serverName; Initial Catalog=databaseName; User ID=userName; Password=password", "Example SQL Server database connection string"); exampleSettings.Add("SqlServer.DataProviderString", "AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.SqlClient.SqlConnection; AdapterType=System.Data.SqlClient.SqlDataAdapter", "Example SQL Server database .NET provider string"); exampleSettings.Add("MySQL.ConnectionString", "Server=serverName;Database=databaseName; Uid=root; Pwd=password; allow user variables = true;", "Example MySQL database connection string"); exampleSettings.Add("MySQL.DataProviderString", "AssemblyName={MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d}; ConnectionType=MySql.Data.MySqlClient.MySqlConnection; AdapterType=MySql.Data.MySqlClient.MySqlDataAdapter", "Example MySQL database .NET provider string"); exampleSettings.Add("Oracle.ConnectionString", "Data Source=tnsName; User ID=schemaUserName; Password=schemaPassword", "Example Oracle database connection string"); exampleSettings.Add("Oracle.DataProviderString", "AssemblyName={Oracle.DataAccess, Version=2.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342}; ConnectionType=Oracle.DataAccess.Client.OracleConnection; AdapterType=Oracle.DataAccess.Client.OracleDataAdapter", "Example Oracle database .NET provider string"); exampleSettings.Add("SQLite.ConnectionString", "Data Source=databaseName.db; Version=3; Foreign Keys=True; FailIfMissing=True", "Example SQLite database connection string"); exampleSettings.Add("SQLite.DataProviderString", "AssemblyName={System.Data.SQLite, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139}; ConnectionType=System.Data.SQLite.SQLiteConnection; AdapterType=System.Data.SQLite.SQLiteDataAdapter", "Example SQLite database .NET provider string"); exampleSettings.Add("OleDB.ConnectionString", "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=databaseName.mdb", "Example Microsoft Access (via OleDb) database connection string"); exampleSettings.Add("OleDB.DataProviderString", "AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.OleDb.OleDbConnection; AdapterType=System.Data.OleDb.OleDbDataAdapter", "Example OleDb database .NET provider string"); exampleSettings.Add("Odbc.ConnectionString", "Driver={SQL Server Native Client 10.0}; Server=serverName; Database=databaseName; Uid=userName; Pwd=password;", "Example ODBC database connection string"); exampleSettings.Add("Odbc.DataProviderString", "AssemblyName={System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}; ConnectionType=System.Data.Odbc.OdbcConnection; AdapterType=System.Data.Odbc.OdbcDataAdapter", "Example ODBC database .NET provider string"); exampleSettings.Add("WebService.ConnectionString", "http://localhost/ConfigSource/SystemConfiguration.xml", "Example web service connection string"); exampleSettings.Add("XmlFile.ConnectionString", "SystemConfiguration.xml", "Example XML configuration file connection string"); // Attempt to set default culture try { string defaultCulture = systemSettings["DefaultCulture"].ValueAs("en-US"); CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(defaultCulture); // Defaults for date formatting, etc. CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture(defaultCulture); // Culture for resource strings, etc. } catch (Exception ex) { DisplayStatusMessage("Failed to set default culture due to exception, defaulting to \"{1}\": {0}", UpdateType.Alarm, ex.Message, CultureInfo.CurrentCulture.Name.ToNonNullNorEmptyString("Undetermined")); LogException(ex); } // Retrieve application log path as defined in the config file string logPath = FilePath.GetAbsolutePath(systemSettings["LogPath"].Value); // Make sure log directory exists try { if (!Directory.Exists(logPath)) Directory.CreateDirectory(logPath); } catch (Exception ex) { // Attempt to default back to common log file path if (!Directory.Exists(defaultLogPath)) { try { Directory.CreateDirectory(defaultLogPath); } catch { defaultLogPath = servicePath; } } DisplayStatusMessage("Failed to create logging directory \"{0}\" due to exception, defaulting to \"{1}\": {2}", UpdateType.Alarm, logPath, defaultLogPath, ex.Message); LogException(ex); logPath = defaultLogPath; } int maxLogFiles = systemSettings["MaxLogFiles"].ValueAs(DefaultMaxLogFiles); try { Logger.FileWriter.SetPath(logPath); Logger.FileWriter.SetLoggingFileCount(maxLogFiles); } catch (Exception ex) { DisplayStatusMessage("Failed to set logging path \"{0}\" or max file count \"{1}\" due to exception: {2}", UpdateType.Alarm, logPath, maxLogFiles, ex.Message); LogException(ex); } // Retrieve configuration cache directory as defined in the config file cachePath = FilePath.GetAbsolutePath(systemSettings["ConfigurationCachePath"].Value); // Make sure configuration cache directory exists try { if (!Directory.Exists(cachePath)) Directory.CreateDirectory(cachePath); } catch (Exception ex) { DisplayStatusMessage("Failed to create configuration cache directory \"{0}\" due to exception: {1}", UpdateType.Alarm, cachePath, ex.Message); LogException(ex); } try { Directory.SetCurrentDirectory(servicePath); } catch (Exception ex) { DisplayStatusMessage("Failed to set current directory to execution path \"{0}\" due to exception: {1}", UpdateType.Alarm, servicePath, ex.Message); LogException(ex); } // Initialize system settings m_configurationType = systemSettings["ConfigurationType"].ValueAs<ConfigurationType>(); m_cachedXmlConfigurationFile = FilePath.AddPathSuffix(cachePath) + systemSettings["CachedConfigurationFile"].Value; m_cachedBinaryConfigurationFile = FilePath.AddPathSuffix(cachePath) + FilePath.GetFileNameWithoutExtension(m_cachedXmlConfigurationFile) + ".bin"; m_configurationBackups = systemSettings["ConfigurationBackups"].ValueAs(DefaultConfigurationBackups); m_uniqueAdapterIDs = systemSettings["UniqueAdaptersIDs"].ValueAsBoolean(true); m_allowRemoteRestart = systemSettings["AllowRemoteRestart"].ValueAsBoolean(true); m_preferCachedConfiguration = systemSettings["PreferCachedConfiguration"].ValueAsBoolean(false); m_reloadConfigQueue = ProcessQueue<Tuple<string, Action<bool>>>.CreateSynchronousQueue(ExecuteReloadConfig, 500.0D, Timeout.Infinite, false, false); m_reloadConfigQueue.ProcessException += m_iaonSession.ProcessExceptionHandler; m_configurationCacheOperation = new LongSynchronizedOperation(ExecuteConfigurationCache) { IsBackground = true }; // Setup default thread pool size try { ThreadPool.SetMinThreads(systemSettings["MinThreadPoolWorkerThreads"].ValueAs(DefaultMinThreadPoolSize), systemSettings["MinThreadPoolIOPortThreads"].ValueAs(DefaultMinThreadPoolSize)); ThreadPool.SetMaxThreads(systemSettings["MaxThreadPoolWorkerThreads"].ValueAs(DefaultMaxThreadPoolSize), systemSettings["MaxThreadPoolIOPortThreads"].ValueAs(DefaultMaxThreadPoolSize)); } catch (Exception ex) { DisplayStatusMessage("Failed to set desired thread pool size due to exception: {0}", UpdateType.Alarm, ex.Message); LogException(ex); } // Define guid with query string delimiters according to database needs if (string.IsNullOrWhiteSpace(m_nodeIDQueryString)) m_nodeIDQueryString = "'" + m_iaonSession.NodeID + "'"; // Set up the configuration loader switch (m_configurationType) { case ConfigurationType.Database: m_configurationLoader = new DatabaseConfigurationLoader { ConnectionString = systemSettings["ConnectionString"].Value, DataProviderString = systemSettings["DataProviderString"].Value, NodeIDQueryString = m_nodeIDQueryString }; break; case ConfigurationType.WebService: m_configurationLoader = new WebServiceConfigurationLoader { URI = systemSettings["ConnectionString"].Value }; break; case ConfigurationType.BinaryFile: m_configurationLoader = new BinaryFileConfigurationLoader { FilePath = systemSettings["ConnectionString"].Value }; break; case ConfigurationType.XmlFile: m_configurationLoader = new XMLConfigurationLoader { FilePath = systemSettings["ConnectionString"].Value }; break; } m_binaryCacheConfigurationLoader = new BinaryFileConfigurationLoader { FilePath = m_cachedBinaryConfigurationFile }; m_xmlCacheConfigurationLoader = new XMLConfigurationLoader { FilePath = m_cachedXmlConfigurationFile }; m_configurationLoader.StatusMessage += (o, args) => DisplayStatusMessage(args.Argument, UpdateType.Information); m_binaryCacheConfigurationLoader.StatusMessage += (o, args) => DisplayStatusMessage(args.Argument, UpdateType.Information); m_xmlCacheConfigurationLoader.StatusMessage += (o, args) => DisplayStatusMessage(args.Argument, UpdateType.Information); m_configurationLoader.ProcessException += ConfigurationLoader_ProcessException; m_binaryCacheConfigurationLoader.ProcessException += ConfigurationLoader_ProcessException; m_xmlCacheConfigurationLoader.ProcessException += ConfigurationLoader_ProcessException; m_reloadConfigQueue.Start(); #if !MONO try { // Attempt to assign desired process priority. Note that process will require SeIncreaseBasePriorityPrivilege or // Administrative privileges to make this change Process.GetCurrentProcess().PriorityClass = systemSettings["ProcessPriority"].ValueAs<ProcessPriorityClass>(); } catch (Exception ex) { LogException(ex); } #endif }
/// <summary> /// Initializes a new instance of the <see cref="ArchiveFile"/> class. /// </summary> public ArchiveFile() : base() { m_fileName = DefaultFileName; m_fileType = DefaultFileType; m_fileSize = DefaultFileSize; m_fileAccessMode = DefaultFileAccessMode; m_dataBlockSize = DefaultDataBlockSize; m_rolloverOnFull = DefaultRolloverOnFull; m_rolloverPreparationThreshold = DefaultRolloverPreparationThreshold; m_fileOffloadLocation = DefaultFileOffloadLocation; m_fileOffloadCount = DefaultFileOffloadCount; m_fileOffloadThreshold = DefaultFileOffloadThreshold; m_leadTimeTolerance = DefaultLeadTimeTolerance; m_compressData = DefaultCompressData; m_discardOutOfSequenceData = DefaultDiscardOutOfSequenceData; m_cacheWrites = DefaultCacheWrites; m_conserveMemory = DefaultConserveMemory; m_persistSettings = DefaultPersistSettings; m_settingsCategory = DefaultSettingsCategory; m_delayedAlarmProcessing = new Dictionary<int, double>(); m_rolloverWaitHandle = new ManualResetEvent(true); m_rolloverPreparationThread = new Thread(PrepareForRollover); m_buildHistoricFileListThread = new Thread(BuildHistoricFileList); m_conserveMemoryTimer = new System.Timers.Timer(DataBlockCheckInterval); m_conserveMemoryTimer.Elapsed += ConserveMemoryTimer_Elapsed; m_historicDataQueue = ProcessQueue<ArchiveData>.CreateRealTimeQueue(WriteToHistoricArchiveFile); m_historicDataQueue.ProcessException += HistoricDataQueue_ProcessException; m_outOfSequenceDataQueue = ProcessQueue<ArchiveData>.CreateRealTimeQueue(InsertInCurrentArchiveFile); m_outOfSequenceDataQueue.ProcessException += OutOfSequenceDataQueue_ProcessException; m_currentLocationFileWatcher = new FileSystemWatcher(); m_currentLocationFileWatcher.IncludeSubdirectories = true; m_currentLocationFileWatcher.Renamed += FileWatcher_Renamed; m_currentLocationFileWatcher.Deleted += FileWatcher_Deleted; m_currentLocationFileWatcher.Created += FileWatcher_Created; m_offloadLocationFileWatcher = new FileSystemWatcher(); m_offloadLocationFileWatcher.IncludeSubdirectories = true; m_offloadLocationFileWatcher.Renamed += FileWatcher_Renamed; m_offloadLocationFileWatcher.Deleted += FileWatcher_Deleted; m_offloadLocationFileWatcher.Created += FileWatcher_Created; }
/// <summary> /// Event handler for service stopping operation. /// </summary> /// <param name="sender">Event source.</param> /// <param name="e">Event arguments.</param> /// <remarks> /// Time-series framework uses this handler to un-wire events and dispose of system objects. /// </remarks> protected virtual void ServiceStoppingHandler(object sender, EventArgs e) { // Dispose system health exporter if ((object)m_healthExporter != null) { m_healthExporter.Enabled = false; m_serviceHelper.ServiceComponents.Remove(m_healthExporter); m_healthExporter.Dispose(); m_healthExporter.StatusMessage -= m_iaonSession.StatusMessageHandler; m_healthExporter.ProcessException -= m_iaonSession.ProcessExceptionHandler; m_healthExporter = null; } // Dispose system status exporter if ((object)m_statusExporter != null) { m_statusExporter.Enabled = false; m_serviceHelper.ServiceComponents.Remove(m_statusExporter); m_statusExporter.Dispose(); m_statusExporter.StatusMessage -= m_iaonSession.StatusMessageHandler; m_statusExporter.ProcessException -= m_iaonSession.ProcessExceptionHandler; m_statusExporter = null; } // Dispose reload config queue if ((object)m_reloadConfigQueue != null) { m_reloadConfigQueue.ProcessException -= m_iaonSession.ProcessExceptionHandler; m_reloadConfigQueue.Dispose(); m_reloadConfigQueue = null; } // Dispose reporting processes if ((object)m_reportingProcesses != null) { m_serviceHelper.ServiceComponents.Remove(m_reportingProcesses); m_reportingProcesses = null; } // Dispose Iaon session if ((object)m_iaonSession != null) { m_serviceHelper.ServiceComponents.Remove(m_iaonSession.InputAdapters); m_serviceHelper.ServiceComponents.Remove(m_iaonSession.ActionAdapters); m_serviceHelper.ServiceComponents.Remove(m_iaonSession.OutputAdapters); m_iaonSession.Dispose(); m_iaonSession.StatusMessage -= StatusMessageHandler; m_iaonSession.ProcessException -= ProcessExceptionHandler; m_iaonSession.ConfigurationChanged -= ConfigurationChangedHandler; m_iaonSession = null; } // Dispose of run-time log if ((object)m_runTimeLog != null) { m_serviceHelper.ServiceComponents.Remove(m_runTimeLog); m_runTimeLog.ProcessException -= ProcessExceptionHandler; m_runTimeLog.Dispose(); m_runTimeLog = null; } m_serviceHelper.ServiceStarting -= ServiceStartingHandler; m_serviceHelper.ServiceStarted -= ServiceStartedHandler; m_serviceHelper.ServiceStopping -= ServiceStoppingHandler; m_serviceHelper.UpdatedStatus -= UpdatedStatusHandler; m_serviceHelper.LoggedException -= LoggedExceptionHandler; if ((object)m_serviceHelper.StatusLog != null) { m_serviceHelper.StatusLog.Flush(); m_serviceHelper.StatusLog.LogException -= LogExceptionHandler; } if ((object)m_serviceHelper.ErrorLogger != null && (object)m_serviceHelper.ErrorLogger.ErrorLog != null) { m_serviceHelper.ErrorLogger.ErrorLog.Flush(); m_serviceHelper.ErrorLogger.ErrorLog.LogException -= LogExceptionHandler; } // Detach from handler for unobserved task exceptions TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException; ShutdownHandler.InitiateSafeShutdown(); }
/// <summary> /// Releases the unmanaged resources used by the <see cref="OutputAdapterBase"/> object and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!m_disposed) { try { if (disposing) { if (m_connectionTimer != null) { m_connectionTimer.Elapsed -= m_connectionTimer_Elapsed; m_connectionTimer.Dispose(); } m_connectionTimer = null; if (m_monitorTimer != null) { m_monitorTimer.Elapsed -= m_monitorTimer_Elapsed; m_monitorTimer.Dispose(); } m_monitorTimer = null; if (m_measurementQueue != null) { m_measurementQueue.ProcessException -= m_measurementQueue_ProcessException; m_measurementQueue.Dispose(); } m_measurementQueue = null; } } finally { m_disposed = true; // Prevent duplicate dispose. base.Dispose(disposing); // Call base class Dispose(). } } }
// This is all of the needed dispose functionality, but since the class can be re-initialized this is a separate method private void Shutdown() { if (m_exportQueue != null) { m_exportQueue.ProcessException -= m_exportQueue_ProcessException; m_exportQueue.Dispose(); } m_exportQueue = null; lock (m_destinationLock) { // We'll be nice and disconnect network shares when this class is disposed... if (m_exportDestinations != null) { for (int x = 0; x < m_exportDestinations.Length; x++) { if (m_exportDestinations[x].ConnectToShare) { try { FilePath.DisconnectFromNetworkShare(m_exportDestinations[x].Share); } catch (Exception ex) { // Something unexpected happened during attempt to disconnect from network share - so we'll report it... UpdateStatus(string.Format("Network share disconnect from {0} failed due to exception: {1}", m_exportDestinations[x].Share, ex.Message)); } } } } m_exportDestinations = null; } }
/// <summary> /// Constructs a new instance of the <see cref="OutputAdapterBase"/>. /// </summary> protected OutputAdapterBase() { m_metadataRefreshOperation = new LongSynchronizedOperation(ExecuteMetadataRefresh) { IsBackground = true }; m_measurementQueue = ProcessQueue<IMeasurement>.CreateRealTimeQueue(ProcessMeasurements); m_measurementQueue.ProcessException += m_measurementQueue_ProcessException; m_connectionOperation = new LongSynchronizedOperation(AttemptConnectionOperation) { IsBackground = true }; m_connectionTimer = Common.TimerScheduler.CreateTimer(2000); m_connectionTimer.Elapsed += m_connectionTimer_Elapsed; m_connectionTimer.AutoReset = false; m_connectionTimer.Enabled = false; // We monitor total number of unarchived measurements every 5 seconds - this is a useful statistic to monitor, if // total number of unarchived measurements gets very large, measurement archival could be falling behind m_monitorTimer = Common.TimerScheduler.CreateTimer(5000); m_monitorTimer.Elapsed += m_monitorTimer_Elapsed; m_monitorTimer.AutoReset = true; m_monitorTimer.Enabled = false; }
/// <summary> /// Initializes a new instance of the exporter. /// </summary> /// <param name="name">Name of the exporter.</param> protected ExporterBase(string name) { m_name = name; m_exports = new ObservableCollection<Export>(); m_exports.CollectionChanged += Exports_CollectionChanged; m_listeners = new ObservableCollection<DataListener>(); m_listeners.CollectionChanged += Listeners_CollectionChanged; m_exportTimer = new Timer(1000); m_exportTimer.Elapsed += ExportTimer_Elapsed; m_realTimeExportQueue = ProcessQueue<RealTimeData>.CreateRealTimeQueue(ProcessRealTimeExports); m_nonRealTimeExportQueue = ProcessQueue<Export>.CreateRealTimeQueue(ProcessExport); m_exportTimer.Start(); m_realTimeExportQueue.Start(); m_nonRealTimeExportQueue.Start(); }
/// <summary> /// Releases the unmanaged resources used by the <see cref="LogFile"/> object and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!m_disposed) { try { // This will be done regardless of whether the object is finalized or disposed. if (disposing) { // This will be done only when the object is disposed by calling Dispose(). SaveSettings(); this.FileFull -= LogFile_FileFull; if ((object)m_operationWaitHandle != null) { m_operationWaitHandle.Close(); m_operationWaitHandle = null; } if ((object)m_flushTimer != null) { m_flushTimer.Elapsed -= FlushTimer_Elapsed; m_flushTimer.Dispose(); m_flushTimer = null; } if ((object)m_fileStream != null) { m_fileStream.Dispose(); m_fileStream = null; } if ((object)m_logEntryQueue != null) { m_logEntryQueue.ProcessException -= ProcessExceptionHandler; m_logEntryQueue.Dispose(); m_logEntryQueue = null; } } } finally { m_disposed = true; // Prevent duplicate dispose. base.Dispose(disposing); // Call base class Dispose(). } } }
private bool m_disposed; // Flag that determines if class is disposed #endregion #region [ Constructors ] /// <summary> /// Creates a new <see cref="PIOutputAdapter"/> /// </summary> public PIOutputAdapter() { m_mappedPIPoints = new ConcurrentDictionary<MeasurementKey, PIPoint>(); m_archiveQueues = new ProcessQueue<AFValue>[Environment.ProcessorCount]; for (int i = 0; i < m_archiveQueues.Length; i++) m_archiveQueues[i] = ProcessQueue<AFValue>.CreateRealTimeQueue(ArchiveAFValues, Timeout.Infinite, false, false); m_mapRequestQueue = ProcessQueue<MeasurementKey>.CreateAsynchronousQueue(EstablishPIPointMappings, Environment.ProcessorCount); m_restartConnection = new ShortSynchronizedOperation(Start); m_tagMap = new ConcurrentDictionary<Guid, string>(); m_pendingMappings = new HashSet<MeasurementKey>(); m_lastMetadataRefresh = DateTime.MinValue; RunMetadataSync = true; AutoCreateTags = true; AutoUpdateTags = true; }