public void ResumeLogging() { if (state == LoggingState.paused) { state = LoggingState.logging; } }
public void Configure ( IWin32Window Parent, ServerSettings Settings, string ServerDirectory ) { using (LoggingModuleConfigurationManager configManager = new LoggingModuleConfigurationManager(false)) { configManager.Load(ServerDirectory); LoggingState state = configManager.GetLoggingState( ); EventLogOptions mainLoggingUI = new EventLogOptions( ); EventLogConfigurationPresenter presenter = new EventLogConfigurationPresenter( ); presenter.RunView(mainLoggingUI.EventLogConfigurationView, state); if (mainLoggingUI.ShowDialog( ) == DialogResult.OK) { presenter.UpdateState( ); configManager.SetLoggingState(state); configManager.Save( ); } else { presenter.ResetView( ); } } }
public async Task Execute(Message message) { // Read Message ReadMessage(message); try { // Get DataLakePath from user properties var datalakeFile = GetDatalakePath(message); // Read Payload CurrentEvent = TelemetryEvent.ServiceBus_Topic_Read; var payload = message.ReadAsString(); CurrentEvent = TelemetryEvent.DataLake_Write; await datalakeService.Write(payload, Convert.ToString(datalakeFile)); TrackInfo($"{datalakeFile} was successfully added to datalake.", TelemetryEvent.DataLake_Write, "Write Confirmation"); } catch (Exception ex) { // TODO: we need to consider how we will handle failed DataLake writes. My suggestion - mimic Microsoft's EventGrid implementation and have a backup Storage blob. Trace(ex.Message, CurrentEvent, "Failed"); LoggingState.AddException(ex); } finally { LogFunctionEnd(); Dispose(); } }
// IF YOU PAUSE, YOU HAVE TO BE CAREFUL ABOUT TIME ELAPSED BETWEEN PAUSES! public void PauseLogging() { if (state == LoggingState.logging) { state = LoggingState.paused; } }
static void Logger_Logged(object sender, LogEventArgs e) { try { DicomLogEntry entry = e.LogEntry as DicomLogEntry; if (entry != null && entry.DicomDataset != null) { LoggingModuleConfigurationManager loggingConfigManager = ServiceLocator.Retrieve <LoggingModuleConfigurationManager> ( ); if (null == loggingConfigManager) { return; } LoggingState state = loggingConfigManager.GetLoggingState( ); if (state.EnableLogging && state.EnableThreading && state.LogDicomDataSet && state.LogDicom) { try { entry.DicomDataset.Dispose(); } catch { } } } } catch {} }
// Experiment Descriptors are given and public void EndLogging() { if (state == LoggingState.logging) { Event_Experiment_Ended(); state = LoggingState.complete; } }
public void BeginLogging() { if (state == LoggingState.not_started || state == LoggingState.complete) { state = LoggingState.logging; InitializeAllValues(); } }
internal static LoggingState GetDefaultLoggingState( ) { LoggingState state; state = new LoggingState( ); state.EnableAutoSaveLog = false; return(state); }
public void CheckPermissions(LoggingState loggingState) { WindowsIdentity identity = WindowsIdentity.GetCurrent(); DirectorySecurity security; FileSystemRights rights; string message = string.Empty; try { if (Directory.Exists(loggingState.AutoSaveDirectory)) { security = Directory.GetAccessControl(loggingState.AutoSaveDirectory); rights = GetDirectoryRights(security, identity); message = string.Format("PERMISSIONS => Auto Log Location ({0}): \r\n{1}", loggingState.AutoSaveDirectory, rights); Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined, DateTime.Now, LogType.Information, MessageDirection.None, message, null, null); } else { message = string.Format("Auto Log directory ({0}) doesn't exist. Cannot determine permissions.", loggingState.AutoSaveDirectory); Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined, DateTime.Now, LogType.Information, MessageDirection.None, message, null, null); } } catch (Exception e) { Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined, DateTime.Now, LogType.Information, MessageDirection.None, e.Message, null, null); } try { if (Directory.Exists(loggingState.DataSetDirectory)) { security = Directory.GetAccessControl(loggingState.DataSetDirectory); rights = GetDirectoryRights(security, identity); message = string.Format("PERMISSIONS => Auto Log Dataset Location ({0}): \r\n{1}", loggingState.DataSetDirectory, rights); Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined, DateTime.Now, LogType.Information, MessageDirection.None, message, null, null); } else { message = string.Format("Auto Log dataset directory ({0}) doesn't exist. Cannot determine permissions.", loggingState.DataSetDirectory); Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined, DateTime.Now, LogType.Information, MessageDirection.None, message, null, null); } } catch (Exception e) { Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined, DateTime.Now, LogType.Information, MessageDirection.None, e.Message, null, null); } }
private void SetNextLogDate(DateTime nextLogDate, LoggingState logState, IOptionsDataAccessAgent optionsDataAccess) { nextLogDate = new DateTime(nextLogDate.Year, nextLogDate.Month, nextLogDate.Day, logState.AutoSaveTime.Hour, logState.AutoSaveTime.Minute, logState.AutoSaveTime.Second); optionsDataAccess.Set <string> (NextLogDateSettingsName, nextLogDate.ToString( ), new Type[0]); }
public static void ConfigureLogger(Logger logger, LoggingState loggingState, ILoggingDataAccessAgent2 dataAccess) { logger.Enabled = loggingState.EnableLogging; logger.EnableThreading = loggingState.EnableThreading; if (logger.Filter is EventLogFilter) { EventLogFilter filter = ( EventLogFilter )logger.Filter; filter.LogErrors = loggingState.LogErrors; filter.LogInformation = loggingState.LogInformation; filter.LogWarnings = loggingState.LogWarnings; filter.LogDebug = loggingState.LogDebug; filter.LogAudit = loggingState.LogAudit; } DataAccessLoggingChannel[] channels = logger.LoggingChannels.OfType <DataAccessLoggingChannel>().ToArray(); if (channels.Length > 0) { foreach (DataAccessLoggingChannel channel in logger.LoggingChannels.OfType <DataAccessLoggingChannel> ( )) { channel.LogDataAccessAgent = dataAccess; channel.LogDicomDataSet = loggingState.LogDicomDataSet; channel.LogDicomCommunication = loggingState.LogDicom; ConfigureLoggingChannel(channel, loggingState); } } else { DataAccessLoggingChannel channel = new DataAccessLoggingChannel(dataAccess); channel.LogDicomDataSet = loggingState.LogDicomDataSet; channel.LogDicomCommunication = loggingState.LogDicom; ConfigureLoggingChannel(channel, loggingState); logger.LoggingChannels.Clear( ); logger.LoggingChannels.Add(channel); } logger.Logging -= new EventHandler <LogEventArgs> (Logger_Logging); logger.Logged -= new EventHandler <LogEventArgs> (Logger_Logged); logger.Logging += new EventHandler <LogEventArgs> (Logger_Logging); logger.Logged += new EventHandler <LogEventArgs> (Logger_Logged); }
private static DateTime GetDueDate(LoggingState logState) { DateTime dueDate; dueDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, logState.AutoSaveTime.Hour, logState.AutoSaveTime.Minute, logState.AutoSaveTime.Second); if (DateTime.Now > dueDate) { dueDate = dueDate.AddDays(logState.AutoSaveDaysPeriod); } return(dueDate); }
public void SetLoggingState(LoggingState state) { string addInKeyName; string loggingStateKey; if (null == _advancedSettings) { throw new InvalidOperationException("Service has not been initialized. Call the Load method"); } addInKeyName = typeof(LoggingConfigurationSession).Name; loggingStateKey = typeof(LoggingState).Name; _advancedSettings.SetAddInCustomData <LoggingState> (addInKeyName, loggingStateKey, state); }
private static void StartStopService(LoggingState logState, CommandAsyncProcessor service) { if (service.Disposed) { return; } if (logState.EnableAutoSaveLog) { service.Start( ); } else { service.Stop( ); } }
private void ReadMessage(Message message) { message = message ?? new Message(new byte[0]); // Read state to remove previous run values. LoggingState.OperationName = GetType().Name; // TODO: Because DataLake function is used by our internal code, if we don't have a TransactionId, we have a SERIOUS problem. We should NOT be creating a NewGuid here! LoggingState.TransactionId = message.UserProperties.TryGetValue("transactionId", out object transactionId) ? transactionId.ToString() : Guid.NewGuid().ToString("D"); // This will jelp us to find if the message was processed by application or a User LoggingState.AddOrReplaceTelemetryProperty("UserName", message.UserProperties.TryGetValue("UserName", out object userName) ? userName.ToString() : "Unknown"); LoggingState.AddOrReplaceTelemetryProperty("MessageId", message.MessageId); LoggingState.ParentOperationName = message.UserProperties.TryGetValue("sourceSystem", out object _sourceSystem) ? _sourceSystem.ToString() : "Unknown"; LogFunctionStart(); }
private void ConfigureServiceIntervals ( LoggingState logState, CommandAsyncProcessor service, IOptionsDataAccessAgent optionsDataAccess ) { DateTime dueDate = GetDueDate(logState); SetNextLogDate(dueDate, logState, optionsDataAccess); TimeSpan due = dueDate.Subtract(DateTime.Now); TimeSpan interval = new TimeSpan(logState.AutoSaveDaysPeriod, 0, 0, 0); service.DueTime = due; service.Interval = interval; service.RefreshDueIntervalTimes( ); }
private CommandAsyncProcessor RegisterAutoSaveLogService(LoggingState logState) { AutoSaveLogCommand autoSaveCommand; CommandAsyncProcessor service = null; IOptionsDataAccessAgent optionsDataAccess = null; optionsDataAccess = DataAccessServices.GetDataAccessService <IOptionsDataAccessAgent>(); if (optionsDataAccess != null) { autoSaveCommand = new AutoSaveLogCommand(logState); service = new CommandAsyncProcessor(); if (logState.EnableAutoSaveLog) { string nextLogDate; nextLogDate = optionsDataAccess.Get <string>(NextLogDateSettingsName, null, new Type[0]); if (!string.IsNullOrEmpty(nextLogDate)) { DateTime nextLog = DateTime.Parse(nextLogDate); if (DateTime.Now > nextLog) { autoSaveCommand.Execute(); } } } service.Commands.Add(autoSaveCommand); ConfigureServiceIntervals(logState, service, optionsDataAccess); service.CommandsExecuted += new EventHandler(service_CommandsExecuted); ServiceLocator.Register <CommandAsyncProcessor>(service); } return(service); }
public void Unlock() { try { // this.IsLocked = LockState.Unlocked; //log state change in computer LoggingState.ComputerLogChangeState("CarUnlocked"); ///event for state change onStateChange("CarUnlocked"); } catch (Exception) { /// LoggingException.LogExceptionOccurs("There was an error unlocking the car!"); ///evnt for exception occur onExceptionOccur("There was an error unlocking the car!"); } }
private LoggingState GetLoggingStateInternal( ) { string addInName; string loggingStateKey; LoggingState state; if (null == _advancedSettings) { throw new InvalidOperationException("Service has not been initialized. Call the Load method"); } addInName = typeof(LoggingConfigurationSession).Name; loggingStateKey = typeof(LoggingState).Name; if (null == (state = _advancedSettings.GetAddInCustomData <LoggingState> (addInName, loggingStateKey))) { state = new LoggingState( ); } return(state); }
public AutoSaveLogCommand(LoggingState loggingState) { LoggingState = loggingState; }
public void SetLoggingState(LoggingState state) { logger.Trace("SetLoggingState {0}", state); }
private static void ConfigureLoggingChannel(DataAccessLoggingChannel channel, LoggingState logginState) { if (channel.LogDataAccessAgent is LoggingSqlDataAccessAgent) { LoggingSqlDataAccessAgent agent = (LoggingSqlDataAccessAgent)channel.LogDataAccessAgent; agent.CopyDicomDataSetOnDisk = true; agent.DataSetFolder = logginState.DataSetDirectory; } }
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel) { if (!Configuration.Enabled) { return(null); } //var via = channel.Via; //var inputSession = channel.InputSession; //var outputSession = channel.OutputSession; //var SessionId = channel.SessionId; //var LocalAddress = channel.LocalAddress; //var state = channel.State; var context = HttpContext.Current; var page = HttpContext.Current?.Handler as Page; var loggingState = new LoggingState() { Context = context, Page = page, GUID = LoggingHelper.GetInstanceGUID(context, () => Guid.NewGuid()).GetValueOrDefault(), SessionGUID = LoggingHelper.GetSessionGUID(context, page, () => new Guid()).GetValueOrDefault(), PageGUID = LoggingHelper.GetPageGUID(context, page, null).GetValueOrDefault(), BundleGUID = LoggingHelper.GetBundleGUID(context, () => Guid.NewGuid()).GetValueOrDefault(), Url = LoggingHelper.StripUrlForLRAP(channel.Via.ToString()), Action = request.Headers.Action, ServerGUID = LoggingHelper.GetServerGUID(HttpContext.Current, null, page?.Request?.Params) }; var logType = LogType.OnWCFServiceRequest; //OperationContext.Current.SessionId string messageBody = GetMessageBody(request); var newLogElement = new LogElementDTO( guid: loggingState.GUID, sessionGUID: loggingState.SessionGUID, pageGUID: loggingState.PageGUID, bundleGUID: loggingState.BundleGUID, progressGUID: null, unixTimestamp: TimeHelper.UnixTimestamp(), logType: logType, element: Path.GetFileName(loggingState.Action), element2: null, value: messageBody, times: 1, unixTimestampEnd: null, instanceTime: DateTime.Now, stackTrace: null ); if (LoggingHelper.IsPlaying(context, page?.Request.Params)) { if (LoggingHelper.FetchAndExecuteLogElement(loggingState.ServerGUID.Value, loggingState.SessionGUID, loggingState.PageGUID, logType, (logElement) => { TimeHelper.SetNow(context, logElement.InstanceTime); var loggedMessageBody = logElement.Value; if (loggedMessageBody != null && messageBody != null && loggedMessageBody != messageBody) { var useLoggedElement = PlayerCommunicationHelper.ReportDifference(loggingState.ServerGUID.Value, logElement, newLogElement); if (useLoggedElement) { messageBody = loggedMessageBody; } } PlayerCommunicationHelper.SetLogElementAsDone(loggingState.ServerGUID.Value, loggingState.SessionGUID, loggingState.PageGUID, logElement.GUID, new JobStatus() { Success = true }); //, async: false); })) { } } else { LoggingHelper.LogElement(newLogElement); } request = BuildMessage(messageBody, request); return(loggingState); }
public AdvancedTests() { // Statemachine 'a' LoggingState a1 = new LoggingState("a1"); LoggingState a2 = new LoggingState("a2"); LoggingState a3 = new LoggingState("a3"); Sub a = new LoggingSub("a", new StateMachine( a1, a2, a3 )); a1.AddHandler("TI", a1, TransitionKind.Internal, data => { log.Add("a1:action(TI)"); }); a1.AddHandler("T1", a2); a2.AddHandler("T2", a3, TransitionKind.External, data => { log.Add("a2:action(T2)"); sm.handleEvent("T3"); }); a3.AddHandler("T3", a1); // Statemachine 'b' var b1 = new LoggingState("b1"); var b21 = new LoggingState("b21"); var b22 = new LoggingState("b22"); var b2 = new LoggingSub("b2", new StateMachine( b21, b22 )); var b311 = new LoggingState("b311"); var b312 = new LoggingState("b312"); var b321 = new LoggingState("b321"); var b322 = new LoggingState("b322"); var b3 = new LoggingParallel("b3", new StateMachine(b311, b312), new StateMachine(b321, b322) ); var b = new LoggingSub("b", new StateMachine( b1, b2, b3 )); a.AddHandler("T4", b2); a.AddHandler("T5", b); b.AddHandler("T6", b22, TransitionKind.Local); b22.AddHandler("T7", b, TransitionKind.Local); a1.AddHandler("T8", b322); b311.AddHandler("T9", a1); a.AddHandler("T10", b3); b311.AddHandler("T11", b311, TransitionKind.Internal, data => { log.Add("b311:action(T11)"); }); b321.AddHandler("T11", b321, TransitionKind.Internal, data => { log.Add("b321:action(T11)"); }); b311.AddHandler("T12", b312, data => { return(data["v"] == null); }); b321.AddHandler("T12", b322, data => { return(data["v"] != null); }); sm = new StateMachine(a, b); }