/*================================================================================================================================== * Public Methods *=================================================================================================================================*/ #region CRUD //---------------------------------------------------------------------------------------------------------------------------------- // CRUD //---------------------------------------------------------------------------------------------------------------------------------- public questStatus Read(BaseUserSessionViewModel baseUserSessionViewModel, out LogSettingsViewModel logSettingsViewModel) { // Initialize questStatus status = null; logSettingsViewModel = null; // Read Quest.Functional.Logging.LogSetting logSetting = null; LogSettingsMgr logSettingsMgr = new LogSettingsMgr(this.UserSession); status = logSettingsMgr.Read(out logSetting); if (!questStatusDef.IsSuccess(status)) { return(status); } // Transfer model. logSettingsViewModel = new LogSettingsViewModel(this.UserSession, baseUserSessionViewModel); BufferMgr.TransferBuffer(logSetting, logSettingsViewModel); return(new questStatus(Severity.Success)); }
public ActionResult Index(BaseUserSessionViewModel baseUserSessionViewModel) { // Initialize questStatus status = null; /*---------------------------------------------------------------------------------------------------------------------------------- * Log Operation *---------------------------------------------------------------------------------------------------------------------------------*/ status = LogOperation(); if (!questStatusDef.IsSuccess(status)) { baseUserSessionViewModel.questStatus = status; return(View("Index", baseUserSessionViewModel)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Authorize *---------------------------------------------------------------------------------------------------------------------------------*/ status = Authorize(baseUserSessionViewModel._ctx); if (!questStatusDef.IsSuccess(status)) { baseUserSessionViewModel.questStatus = status; return(View("Index", baseUserSessionViewModel)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Return view. *---------------------------------------------------------------------------------------------------------------------------------*/ LogSettingsViewModel logSettingsViewModel = new LogSettingsViewModel(this.UserSession, baseUserSessionViewModel); return(View(logSettingsViewModel)); }
static LogSettingsViewModel CreateLogSettingViewModel() { XmlConfigurator.ConfigureAndWatch(new FileInfo("Settings.config")); var loggingSettingsTo = new LoggingSettingsTo { FileLoggerLogSize = 50, FileLoggerLogLevel = "TRACE" }; var _resourceRepo = new Mock <IResourceRepository>(); var env = new Mock <IServer>(); var expectedServerSettingsData = new ServerSettingsData { ExecutionLogLevel = LogLevel.DEBUG.ToString(), Sink = "AuditingSettingsData" }; _resourceRepo.Setup(res => res.GetServerSettings(env.Object)).Returns(expectedServerSettingsData); var dependency = new Depends(Depends.ContainerType.AnonymousElasticsearch); var hostName = "http://" + dependency.Container.IP; var elasticsearchSource = new ElasticsearchSource { AuthenticationType = AuthenticationType.Anonymous, Port = dependency.Container.Port, HostName = hostName, SearchIndex = "warewolflogstests" }; var jsonSource = JsonConvert.SerializeObject(elasticsearchSource); var auditingSettingsData = new AuditingSettingsData { Endpoint = "ws://127.0.0.1:5000/ws", EncryptDataSource = true, LoggingDataSource = new NamedGuidWithEncryptedPayload { Name = "Auditing Data Source", Value = Guid.Empty, Payload = jsonSource }, }; _resourceRepo.Setup(res => res.GetAuditingSettings <AuditingSettingsData>(env.Object)).Returns(auditingSettingsData); var selectedAuditingSourceId = Guid.NewGuid(); var mockAuditingSource = new Mock <IResource>(); mockAuditingSource.Setup(source => source.ResourceID).Returns(selectedAuditingSourceId); var auditingSources = new Mock <IResource>(); var expectedList = new List <IResource> { mockAuditingSource.Object, auditingSources.Object }; _resourceRepo.Setup(resourceRepository => resourceRepository.FindResourcesByType <IAuditingSource>(env.Object)).Returns(expectedList); env.Setup(a => a.ResourceRepository).Returns(_resourceRepo.Object); var logSettingsViewModel = new LogSettingsViewModel(loggingSettingsTo, env.Object); return(logSettingsViewModel); }
/// <summary> /// Saves the settings. /// </summary> /// <returns></returns> bool SaveSettings() { if (CurrentEnvironment.IsConnected) { if (CurrentEnvironment.AuthorizationService.IsAuthorized(AuthorizationContext.Administrator, null)) { Tracker.TrackEvent(TrackerEventGroup.Settings, TrackerEventName.SaveClicked); // Need to reset sub view models so that selecting something in them fires our OnIsDirtyPropertyChanged() ClearErrors(); if (SecurityViewModel.HasDuplicateResourcePermissions()) { IsSaved = false; IsDirty = true; ShowError(StringResources.SaveSettingErrorPrefix, StringResources.SaveSettingsDuplicateResourcePermissions); return(false); } if (SecurityViewModel.HasDuplicateServerPermissions()) { IsSaved = false; IsDirty = true; ShowError(StringResources.SaveSettingErrorPrefix, StringResources.SaveSettingsDuplicateServerPermissions); return(false); } SecurityViewModel.Save(Settings.Security); if (LogSettingsViewModel.IsDirty) { LogSettingsViewModel.Save(Settings.Logging); } if (PerfmonViewModel.IsDirty) { PerfmonViewModel.Save(Settings.PerfCounters); } var isWritten = WriteSettings(); if (isWritten) { ResetIsDirtyForChildren(); IsSaved = true; IsDirty = false; ClearErrors(); } else { IsSaved = false; IsDirty = true; } return(IsSaved); } ShowError(StringResources.SaveSettingErrorPrefix, StringResources.SaveSettingsPermissionsErrorMsg); return(false); } ShowError(StringResources.SaveSettingErrorPrefix, StringResources.SaveSettingsNotReachableErrorMsg); return(false); }
protected virtual LogSettingsViewModel CreateLoggingViewModel() { if (Settings.Logging != null) { var logSettingsViewModel = new LogSettingsViewModel(Settings.Logging, CurrentEnvironment); logSettingsViewModel.SetItem(logSettingsViewModel); return(logSettingsViewModel); } return(null); }
static LogSettingsViewModel CreateLogSettingViewModel() { XmlConfigurator.ConfigureAndWatch(new FileInfo("Settings.config")); var loggingSettingsTo = new LoggingSettingsTo { LogSize = 50, LogLevel = "TRACE" }; var logSettingsViewModel = new LogSettingsViewModel(loggingSettingsTo, new Mock <IEnvironmentModel>().Object); return(logSettingsViewModel); }
private bool SaveLogSettingsChanges() { if (LogSettingsViewModel.IsDirty) { LogSettingsViewModel.Save(Settings.Logging); if (!LogSettingsViewModel.HasAuditFilePathMoved) { return(false); } } return(true); }
public ActionResult Read(BaseUserSessionViewModel baseUserSessionViewModel) { // Initialize questStatus status = null; /*---------------------------------------------------------------------------------------------------------------------------------- * Log Operation *---------------------------------------------------------------------------------------------------------------------------------*/ status = LogOperation(); if (!questStatusDef.IsSuccess(status)) { // TODO throw new Exception("LogOperation failed"); } /*---------------------------------------------------------------------------------------------------------------------------------- * Authorize *---------------------------------------------------------------------------------------------------------------------------------*/ status = Authorize(baseUserSessionViewModel._ctx); if (!questStatusDef.IsSuccess(status)) { // TODO throw new Exception("Authorize failed"); } /*---------------------------------------------------------------------------------------------------------------------------------- * Perform operation. *---------------------------------------------------------------------------------------------------------------------------------*/ LogSettingsViewModel logSettingsViewModel = null; LogSettingsEditorModeler logSettingsEditorModeler = new LogSettingsEditorModeler(this.Request, this.UserSession); status = logSettingsEditorModeler.Read(baseUserSessionViewModel, out logSettingsViewModel); if (!questStatusDef.IsSuccess(status)) { logSettingsViewModel.questStatus = status; return(Json(logSettingsViewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Return result. *---------------------------------------------------------------------------------------------------------------------------------*/ status = new questStatus(Severity.Success); logSettingsViewModel.questStatus = status; return(Json(logSettingsViewModel, JsonRequestBehavior.AllowGet)); }
public ActionResult Save(LogSettingsViewModel logSettingsViewModel) { questStatus status = null; /*---------------------------------------------------------------------------------------------------------------------------------- * Log Operation *---------------------------------------------------------------------------------------------------------------------------------*/ status = LogOperation(); if (!questStatusDef.IsSuccess(status)) { logSettingsViewModel.questStatus = status; return(Json(logSettingsViewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Authorize *---------------------------------------------------------------------------------------------------------------------------------*/ status = Authorize(logSettingsViewModel._ctx); if (!questStatusDef.IsSuccess(status)) { logSettingsViewModel.questStatus = status; return(Json(logSettingsViewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Perform operation. *---------------------------------------------------------------------------------------------------------------------------------*/ LogSettingsEditorModeler logSettingsEditorModeler = new LogSettingsEditorModeler(this.Request, this.UserSession); status = logSettingsEditorModeler.Save(logSettingsViewModel); if (!questStatusDef.IsSuccess(status)) { logSettingsViewModel.questStatus = status; return(Json(logSettingsViewModel, JsonRequestBehavior.AllowGet)); } /*---------------------------------------------------------------------------------------------------------------------------------- * Return result. *---------------------------------------------------------------------------------------------------------------------------------*/ status = new questStatus(Severity.Success, "Log settings successfully saved"); logSettingsViewModel.questStatus = status; return(Json(logSettingsViewModel, JsonRequestBehavior.AllowGet)); }
static LogSettingsViewModel CreateLogSettingViewModel() { XmlConfigurator.ConfigureAndWatch(new FileInfo("Settings.config")); var loggingSettingsTo = new LoggingSettingsTo { FileLoggerLogSize = 50, FileLoggerLogLevel = "TRACE" }; var _resourceRepo = new Mock <IResourceRepository>(); var env = new Mock <IServer>(); var serverSettingsData = new ServerSettingsData { AuditFilePath = "somePath" }; _resourceRepo.Setup(res => res.GetServerSettings(env.Object)).Returns(serverSettingsData); env.Setup(a => a.ResourceRepository).Returns(_resourceRepo.Object); var logSettingsViewModel = new LogSettingsViewModel(loggingSettingsTo, env.Object); return(logSettingsViewModel); }
public questStatus Save(LogSettingsViewModel logSettingsViewMode) { // Initialize questStatus status = null; // Transfer model Quest.Functional.Logging.LogSetting logSetting = new Functional.Logging.LogSetting(); BufferMgr.TransferBuffer(logSettingsViewMode, logSetting); // Update LogSettingsMgr logSettingsMgr = new LogSettingsMgr(this.UserSession); status = logSettingsMgr.Update(logSetting); if (!questStatusDef.IsSuccess(status)) { FormatErrorMessage(status, logSettingsViewMode); return(status); } return(new questStatus(Severity.Success)); }
public LogsViewModel( IWindowManager windowManager, LogSettingsViewModel logSettingsViewModel, LogSink logSink) { _windowManager = windowManager; _logSettingsViewModel = logSettingsViewModel; LogSink = logSink; LogLevels = new BindableCollection <LogEventLevel> { LogEventLevel.Fatal, LogEventLevel.Error, LogEventLevel.Warning, LogEventLevel.Information, LogEventLevel.Debug }; MinimumLogLevel = LogEventLevel.Debug; LogSink.Logs.CollectionChanged += LogsChanged; }
static LogSettingsViewModel CreateLogSettingViewModel(string sink, Mock <IResourceRepository> _resourceRepo = null) { XmlConfigurator.ConfigureAndWatch(new FileInfo("Settings.config")); var loggingSettingsTo = new LoggingSettingsTo { FileLoggerLogSize = 50, FileLoggerLogLevel = "TRACE", EventLogLoggerLogLevel = "DEBUG" }; var env = new Mock <IServer>(); if (_resourceRepo is null) { _resourceRepo = new Mock <IResourceRepository>(); } var expectedServerSettingsData = new ServerSettingsData { Sink = sink, ExecutionLogLevel = LogLevel.DEBUG.ToString() }; _resourceRepo.Setup(res => res.GetServerSettings(env.Object)).Returns(expectedServerSettingsData); var selectedAuditingSourceId = Guid.NewGuid(); if (sink == "LegacySettingsData") { var legacySettingsData = new LegacySettingsData() { AuditFilePath = "somePath" }; _resourceRepo.Setup(res => res.GetAuditingSettings <LegacySettingsData>(env.Object)).Returns(legacySettingsData); _resourceRepo.Setup(res => res.SaveAuditingSettings(env.Object, legacySettingsData)).Verifiable(); } else { var dependency = new Depends(Depends.ContainerType.AnonymousElasticsearch); var hostName = "http://" + dependency.Container.IP; var elasticsearchSource = new ElasticsearchSource { AuthenticationType = AuthenticationType.Anonymous, Port = dependency.Container.Port, HostName = hostName, SearchIndex = "warewolflogstests" }; var serializer = new Dev2JsonSerializer(); var payload = serializer.Serialize(elasticsearchSource); var encryptedPayload = DpapiWrapper.Encrypt(payload); var auditingSettingsData = new AuditingSettingsData { Endpoint = "ws://127.0.0.1:5000/ws", EncryptDataSource = true, LoggingDataSource = new NamedGuidWithEncryptedPayload { Name = "Auditing Data Source", Value = selectedAuditingSourceId, Payload = encryptedPayload }, }; _resourceRepo.Setup(res => res.GetAuditingSettings <AuditingSettingsData>(env.Object)).Returns(auditingSettingsData); _resourceRepo.Setup(res => res.SaveAuditingSettings(env.Object, auditingSettingsData)).Verifiable(); } IResource mockAuditingSource = new ElasticsearchSource { ResourceID = selectedAuditingSourceId, ResourceName = "Auditing Data Source" }; var expectedList = new List <IResource>(); expectedList.Add(mockAuditingSource); _resourceRepo.Setup(resourceRepository => resourceRepository.FindResourcesByType <IAuditingSource>(env.Object)).Returns(expectedList); env.Setup(a => a.ResourceRepository).Returns(_resourceRepo.Object); var logSettingsViewModel = new LogSettingsViewModel(loggingSettingsTo, env.Object); return(logSettingsViewModel); }