private async Task <HttpResponseMessage> ExecuteActualRequest(HttpControllerContext controllerContext, CancellationToken cancellationToken, MixedModeRequestAuthorizer authorizer) { HttpResponseMessage authMsg; if (authorizer.TryAuthorize(this, out authMsg) == false) { return(authMsg); } if (IsInternalRequest == false) { RequestManager.IncrementRequestCount(); } var fileSystemInternal = await CountersLandlord.GetCounterInternal(CountersName); if (fileSystemInternal == null) { var msg = "Could not find a counters named: " + CountersName; return(GetMessageWithObject(new { Error = msg }, HttpStatusCode.ServiceUnavailable)); } var sp = Stopwatch.StartNew(); var result = await base.ExecuteAsync(controllerContext, cancellationToken); sp.Stop(); AddRavenHeader(result, sp); return(result); }
public async Task <HttpResponseMessage> GetCounterNames(string counterStorageName, int skip, int take) { var counter = await CountersLandlord.GetResourceInternal(counterStorageName).ConfigureAwait(false); if (counter == null) { return(GetMessageWithString(string.Format("Counter storage with name {0} not found.", counterStorageName), HttpStatusCode.NotFound)); } using (var reader = counter.CreateReader()) { var groupsAndNames = reader.GetCounterGroups(0, int.MaxValue) .SelectMany(group => reader.GetCounterSummariesByGroup(group.Name, 0, int.MaxValue) .Select(x => new CounterNameGroupPair { Name = x.CounterName, Group = group.Name })); return(GetMessageWithObject(new { Stats = counter.CreateStats(), HasMore = groupsAndNames.Count() > skip + take, GroupsAndNames = groupsAndNames.Skip(skip).Take(take) })); } }
public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) { throw new ArgumentNullException("configuration"); } try { HttpEndpointRegistration.RegisterHttpEndpointTarget(); if (db == null) { systemDatabase = new DocumentDatabase(configuration); systemDatabase.SpinBackgroundWorkers(); } else { systemDatabase = db; } fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); } catch { if (systemDatabase != null) { systemDatabase.Dispose(); } throw; } }
protected override void InnerInitialization(HttpControllerContext controllerContext) { base.InnerInitialization(controllerContext); landlord = (CountersLandlord)controllerContext.Configuration.Properties[typeof(CountersLandlord)]; requestManager = (RequestManager)controllerContext.Configuration.Properties[typeof(RequestManager)]; var values = controllerContext.Request.GetRouteData().Values; if (values.ContainsKey("MS_SubRoutes")) { var routeDatas = (IHttpRouteData[])controllerContext.Request.GetRouteData().Values["MS_SubRoutes"]; var selectedData = routeDatas.FirstOrDefault(data => data.Values.ContainsKey("counterName")); if (selectedData != null) { CountersName = selectedData.Values["counterName"] as string; } } else { if (values.ContainsKey("cou")) { CountersName = values["counterName"] as string; } } if (CountersName == null) { throw new InvalidOperationException("Could not find counter name for this request"); } }
public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) throw new ArgumentNullException("configuration"); try { HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); if (db == null) { configuration.UpdateDataDirForLegacySystemDb(); systemDatabase = new DocumentDatabase(configuration); systemDatabase.SpinBackgroundWorkers(); } else { systemDatabase = db; } fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); } catch { if (systemDatabase != null) systemDatabase.Dispose(); throw; } }
public HttpResponseMessage Delete(string id) { var docKey = "Raven/Counters/" + id; var configuration = CountersLandlord.CreateTenantConfiguration(id); if (configuration == null) { return(GetEmptyMessage()); } if (!IsCounterStorageNameExists(id)) { return(GetMessageWithString(string.Format("Counter Storage {0} doesn't exist!", id), HttpStatusCode.NotFound)); } Database.Documents.Delete(docKey, null, null); bool isHardDeleteNeeded = CheckQueryStringParameterResult("hard-delete"); if (isHardDeleteNeeded) { IOExtensions.DeleteDirectory(configuration.CountersDataDirectory); } return(GetEmptyMessage()); }
public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) { throw new ArgumentNullException("configuration"); } try { ThreadPool.SetMinThreads(configuration.MinThreadPoolWorkerThreads, configuration.MinThreadPoolCompletionThreads); HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); if (db == null) { configuration.UpdateDataDirForLegacySystemDb(); systemDatabase = new DocumentDatabase(configuration, null); systemDatabase.SpinBackgroundWorkers(false); } else { systemDatabase = db; } WebSocketBufferPool.Initialize(configuration.WebSockets.InitialBufferPoolSize); fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); timeSeriesLandlord = new TimeSeriesLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); systemDatabase.RequestManager = requestManager; ClusterManager = new Reference <ClusterManager>(); systemDatabase.ClusterManager = ClusterManager; mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); serverStartupTasks = configuration.Container.GetExportedValues <IServerStartupTask>(); foreach (var task in serverStartupTasks) { toDispose.Add(task); try { task.Execute(this); } catch (Exception e) { systemDatabase.LogErrorAndAddAlertOnStartupTaskException(task.GetType().FullName, e); } } } catch (Exception) { if (systemDatabase != null) { systemDatabase.Dispose(); } throw; } }
public WebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix) { DatabasesLandlord = databasesLandlord; this.countersLandlord = countersLandlord; this.fileSystemsLandlord = fileSystemsLandlord; this.authorizer = authorizer; this.expectedRequestSuffix = expectedRequestSuffix; }
public async Task <HttpResponseMessage> GetCounterMetrics(string counterStorageName) { var counter = await CountersLandlord.GetResourceInternal(counterStorageName).ConfigureAwait(false); if (counter == null) { return(GetMessageWithString(string.Format("Counter storage with name {0} not found.", counterStorageName), HttpStatusCode.NotFound)); } return(GetMessageWithObject(counter.CreateMetrics())); }
public override async Task <HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) { if (ForceClusterAwareness == false) { var clusterAwareHeader = GetClusterHeader(controllerContext, Constants.Cluster.ClusterAwareHeader); bool clusterAware; if (clusterAwareHeader == null || bool.TryParse(clusterAwareHeader, out clusterAware) == false || clusterAware == false) { return(await base.ExecuteAsync(controllerContext, cancellationToken).ConfigureAwait(false)); } } InnerInitialization(controllerContext); if (CounterStorage == null || ClusterManager.IsActive() == false) { return(await base.ExecuteAsync(controllerContext, cancellationToken).ConfigureAwait(false)); } if (CountersName != null && await CountersLandlord.GetResourceInternal(CountersName).ConfigureAwait(false) == null) { var msg = "Could not find a counter named: " + CountersName; return(GetMessageWithObject(new { Error = msg }, HttpStatusCode.ServiceUnavailable)); } if (CounterStorage.IsClusterDatabase() == false) { return(await base.ExecuteAsync(controllerContext, cancellationToken).ConfigureAwait(false)); } if (ClusterManager.IsLeader()) { return(await base.ExecuteAsync(controllerContext, cancellationToken).ConfigureAwait(false)); } if (IsReadRequest(controllerContext)) { var clusterReadBehaviorHeader = GetClusterHeader(controllerContext, Constants.Cluster.ClusterReadBehaviorHeader); if (string.Equals(clusterReadBehaviorHeader, "All", StringComparison.OrdinalIgnoreCase)) { return(await base.ExecuteAsync(controllerContext, cancellationToken).ConfigureAwait(false)); } } var clusterFailoverBehaviorHeader = GetClusterHeader(controllerContext, Constants.Cluster.ClusterFailoverBehaviorHeader); bool clusterFailoverBehavior; if (bool.TryParse(clusterFailoverBehaviorHeader, out clusterFailoverBehavior) && clusterFailoverBehavior) { return(await base.ExecuteAsync(controllerContext, cancellationToken).ConfigureAwait(false)); } return(RedirectToLeader(controllerContext.Request)); }
public StreamContent(CountersLandlord landlord, Func <Stream, IOutputWriter> getWriter, IEnumerable <RavenJObject> content, Action <string> contentTypeSetter, CounterStorage.Reader reader) { headers = CurrentOperationContext.Headers.Value; user = CurrentOperationContext.User.Value; this.landlord = landlord; this.getWriter = getWriter; this.content = content; outputContentTypeSetter = contentTypeSetter; this.reader = reader; }
public async Task <HttpResponseMessage> Backup() { var backupRequest = await ReadJsonObjectAsync <CounterStorageBackupRequest>().ConfigureAwait(false); var incrementalBackup = ParseBoolQueryString("incremental"); if (backupRequest.CounterStorageDocument == null && Counters.Name != null) { var jsonDocument = DatabasesLandlord.SystemDatabase.Documents.Get(Constants.Counter.Prefix + Counters.Name, null); if (jsonDocument != null) { backupRequest.CounterStorageDocument = jsonDocument.DataAsJson.JsonDeserialization <CounterStorageDocument>(); CountersLandlord.Unprotect(backupRequest.CounterStorageDocument); backupRequest.CounterStorageDocument.Id = Counters.Name; } } using (var reader = Counters.CreateReader()) { var backupStatus = reader.GetBackupStatus(); if (backupStatus != null && backupStatus.IsRunning) { throw new InvalidOperationException("Backup is already running"); } } if (incrementalBackup && Counters.Configuration.Storage.Voron.AllowIncrementalBackups == false) { throw new InvalidOperationException("In order to run incremental backups using Voron you must have the appropriate setting key (Raven/Voron/AllowIncrementalBackups) set to true"); } using (var writer = Counters.CreateWriter()) { writer.SaveBackupStatus(new BackupStatus { Started = SystemTime.UtcNow, IsRunning = true, }); } var backupOperation = new BackupOperation(Counters, DatabasesLandlord.SystemDatabase.Configuration.DataDirectory, backupRequest.BackupLocation, Counters.Environment, incrementalBackup, backupRequest.CounterStorageDocument); #pragma warning disable 4014 Task.Factory.StartNew(backupOperation.Execute); #pragma warning restore 4014 return(GetEmptyMessage(HttpStatusCode.Accepted)); }
public RavenDBOptions(RavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) { throw new ArgumentNullException("configuration"); } try { HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); if (db == null) { systemDatabase = new DocumentDatabase(configuration, null); systemDatabase.SpinBackgroundWorkers(false); } else { systemDatabase = db; } WebSocketBufferPool.Initialize((int)configuration.WebSockets.InitialBufferPoolSize.GetValue(SizeUnit.Bytes)); fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); timeSeriesLandlord = new TimeSeriesLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); systemDatabase.RequestManager = requestManager; ClusterManager = new Reference <ClusterManager>(); mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); serverStartupTasks = configuration.Container.GetExportedValues <IServerStartupTask>(); foreach (var task in serverStartupTasks) { toDispose.Add(task); task.Execute(this); } } catch (Exception) { if (systemDatabase != null) { systemDatabase.Dispose(); } throw; } }
private async Task <HttpResponseMessage> GetNamesAndGroups(string id, int skip, int take) { MessageWithStatusCode nameFormateErrorMsg; if (IsValidName(id, Counters.Configuration.Counter.DataDirectory, out nameFormateErrorMsg) == false) { return(GetMessageWithObject(new { Error = nameFormateErrorMsg.Message }, nameFormateErrorMsg.ErrorCode)); } if (Authentication.IsLicensedForCounters == false) { return(GetMessageWithObject(new { Error = "Your license does not allow the use of Counters!" }, HttpStatusCode.BadRequest)); } var counterStorage = await CountersLandlord.GetResourceInternal(id).ConfigureAwait(false); if (counterStorage == null) { return(GetMessageWithObject(new { Message = $"Didn't find counter storage (name = {id})" }, HttpStatusCode.NotFound)); } var counterNameGroupPairs = new List <CounterNameGroupPair>(); using (var reader = counterStorage.CreateReader()) { var groupsAndNames = reader.GetCounterGroups(0, int.MaxValue) .SelectMany(group => reader.GetCounterSummariesByGroup(group.Name, 0, int.MaxValue) .Select(x => new CounterNameGroupPair { Name = x.CounterName, Group = group.Name })).Skip(skip).Take(take); counterNameGroupPairs.AddRange(groupsAndNames); } return(GetMessageWithObject(counterNameGroupPairs)); }
public HttpResponseMessage GetCounterStoragesInfo() { var infos = new List <CounterDebugInfo>(); CountersLandlord.ForAllCounters(counterStorage => infos.Add(new CounterDebugInfo { ReplicationActiveTasksCount = counterStorage.ReplicationTask.GetActiveTasksCount(), ReplicationDestinationStats = counterStorage.ReplicationTask.DestinationStats, LastWrite = counterStorage.LastWrite, ServerId = counterStorage.ServerId, Summary = counterStorage.CreateStats(), ExtensionsState = counterStorage.ExtensionsState })); return(GetMessageWithObject(infos)); }
public RavenDBOptions(InMemoryRavenConfiguration configuration, DocumentDatabase db = null) { if (configuration == null) throw new ArgumentNullException("configuration"); try { HttpEndpointRegistration.RegisterHttpEndpointTarget(); HttpEndpointRegistration.RegisterAdminLogsTarget(); ThreadPool.SetMinThreads(configuration.MinThreadPoolWorkerThreads, configuration.MinThreadPoolCompletionThreads); if (db == null) { configuration.UpdateDataDirForLegacySystemDb(); systemDatabase = new DocumentDatabase(configuration); systemDatabase.SpinBackgroundWorkers(false); } else { systemDatabase = db; } WebSocketBufferPool.Initialize(configuration.WebSockets.InitialBufferPoolSize); fileSystemLandlord = new FileSystemsLandlord(systemDatabase); databasesLandlord = new DatabasesLandlord(systemDatabase); countersLandlord = new CountersLandlord(systemDatabase); requestManager = new RequestManager(databasesLandlord); mixedModeRequestAuthorizer = new MixedModeRequestAuthorizer(); mixedModeRequestAuthorizer.Initialize(systemDatabase, new RavenServer(databasesLandlord.SystemDatabase, configuration)); serverStartupTasks = configuration.Container.GetExportedValues<IServerStartupTask>(); foreach (var task in serverStartupTasks) { toDispose.Add(task); task.Execute(this); } } catch { if (systemDatabase != null) systemDatabase.Dispose(); throw; } }
public async Task <HttpResponseMessage> Put(string id) { MessageWithStatusCode nameFormatErrorMsg; if (IsValidName(id, SystemConfiguration.Counter.DataDirectory, out nameFormatErrorMsg) == false) { return(GetMessageWithObject(new { Error = nameFormatErrorMsg.Message }, nameFormatErrorMsg.ErrorCode)); } if (Authentication.IsLicensedForCounters == false) { return(GetMessageWithObject(new { Error = "Your license does not allow the use of Counters!" }, HttpStatusCode.BadRequest)); } var docKey = Constants.Counter.Prefix + id; var isCounterStorageUpdate = ParseBoolQueryString("update"); var counterStorage = SystemDatabase.Documents.Get(docKey, null); if (counterStorage != null && isCounterStorageUpdate == false) { return(GetMessageWithString($"Counter Storage {id} already exists!", HttpStatusCode.Conflict)); } var dbDoc = await ReadJsonObjectAsync <CounterStorageDocument>().ConfigureAwait(false); CountersLandlord.Protect(dbDoc); var json = RavenJObject.FromObject(dbDoc); json.Remove("Id"); SystemDatabase.Documents.Put(docKey, null, json, new RavenJObject(), null); return(GetEmptyMessage(HttpStatusCode.Created)); }
public async Task <HttpResponseMessage> Put(string id) { var docKey = "Raven/Counters/" + id; bool isCounterStorageUpdate = CheckQueryStringParameterResult("update"); if (IsCounterStorageNameExists(id) && !isCounterStorageUpdate) { return(GetMessageWithString(string.Format("Counter Storage {0} already exists!", id), HttpStatusCode.Conflict)); } var dbDoc = await ReadJsonObjectAsync <DatabaseDocument>(); CountersLandlord.Protect(dbDoc); var json = RavenJObject.FromObject(dbDoc); json.Remove("Id"); Database.Documents.Put(docKey, null, json, new RavenJObject(), null); return(GetEmptyMessage(HttpStatusCode.Created)); }
private MessageWithStatusCode DeleteCounterStorage(string id, bool isHardDeleteNeeded) { //get configuration even if the counters is disabled var configuration = CountersLandlord.CreateTenantConfiguration(id, true); if (configuration == null) { return new MessageWithStatusCode { ErrorCode = HttpStatusCode.NotFound, Message = "Counter storage wasn't found" } } ; var docKey = Constants.Counter.Prefix + id; SystemDatabase.Documents.Delete(docKey, null, null); if (isHardDeleteNeeded && configuration.RunInMemory == false) { IOExtensions.DeleteDirectory(configuration.Counter.DataDirectory); } return(new MessageWithStatusCode()); }
public WatchTrafficWebSocketsRequestParser(DatabasesLandlord databasesLandlord, TimeSeriesLandlord timeSeriesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix) : base(databasesLandlord, timeSeriesLandlord, countersLandlord, fileSystemsLandlord, authorizer, expectedRequestSuffix) { }
private async Task <HttpResponseMessage> GetSummary(string counterStorageId, int shouldSkip, int shouldTake) { MessageWithStatusCode nameFormateErrorMsg; if (IsValidName(counterStorageId, Counters.Configuration.Counter.DataDirectory, out nameFormateErrorMsg) == false) { return(GetMessageWithObject(new { Error = nameFormateErrorMsg.Message }, nameFormateErrorMsg.ErrorCode)); } if (Authentication.IsLicensedForCounters == false) { return(GetMessageWithObject(new { Error = "Your license does not allow the use of Counters!" }, HttpStatusCode.BadRequest)); } var counterStorage = await CountersLandlord.GetResourceInternal(counterStorageId).ConfigureAwait(false); if (counterStorage == null) { return(GetMessageWithObject(new { Message = $"Didn't find counter storage (name = {counterStorageId})" }, HttpStatusCode.NotFound)); } var counterSummaries = new List <CounterSummary>(); using (var reader = counterStorage.CreateReader()) { int skipped = 0; int taken = 0; foreach (var group in reader.GetCounterGroups(0, int.MaxValue)) { int leftToSkip = (shouldSkip - skipped); if (leftToSkip > group.Count) { skipped += (int)group.Count; continue; } if (taken >= shouldTake) { break; } int toTake; if (leftToSkip <= group.Count) { toTake = (int)group.Count - leftToSkip; toTake = AdjustToTake(shouldTake, taken, toTake); counterSummaries.AddRange(reader.GetCounterSummariesByGroup(group.Name, leftToSkip, toTake)); taken += toTake; skipped += leftToSkip; continue; } toTake = (int)group.Count; toTake = AdjustToTake(shouldTake, taken, toTake); counterSummaries.AddRange(reader.GetCounterSummariesByGroup(group.Name, 0, toTake)); taken += toTake; } } return(GetMessageWithObject(counterSummaries)); }
public HttpResponseMessage ResourceDrives(string name, string type) { ResourceType resourceType; if (Enum.TryParse(type, out resourceType) == false) { return(GetMessageWithString("Unknown resourceType:" + type, HttpStatusCode.BadRequest)); } string[] drives = null; InMemoryRavenConfiguration config; switch (resourceType) { case ResourceType.Database: config = DatabasesLandlord.CreateTenantConfiguration(name); if (config == null) { return(GetMessageWithString("Unable to find database named: " + name, HttpStatusCode.NotFound)); } drives = FindUniqueDrives(new[] { config.IndexStoragePath, config.Storage.Esent.JournalsStoragePath, config.Storage.Voron.JournalsStoragePath, config.DataDirectory }); break; case ResourceType.FileSystem: config = FileSystemsLandlord.CreateTenantConfiguration(name); if (config == null) { return(GetMessageWithString("Unable to find filesystem named: " + name, HttpStatusCode.NotFound)); } drives = FindUniqueDrives(new[] { config.FileSystem.DataDirectory, config.FileSystem.IndexStoragePath, config.Storage.Esent.JournalsStoragePath, config.Storage.Voron.JournalsStoragePath }); break; case ResourceType.Counter: config = CountersLandlord.CreateTenantConfiguration(name); if (config == null) { return(GetMessageWithString("Unable to find counter named: " + name, HttpStatusCode.NotFound)); } drives = FindUniqueDrives(new[] { config.Counter.DataDirectory, config.Storage.Esent.JournalsStoragePath, config.Storage.Voron.JournalsStoragePath, config.DataDirectory }); break; case ResourceType.TimeSeries: config = TimeSeriesLandlord.CreateTenantConfiguration(name); if (config == null) { return(GetMessageWithString("Unable to find time series named: " + name, HttpStatusCode.NotFound)); } drives = FindUniqueDrives(new[] { config.TimeSeries.DataDirectory, config.Storage.Esent.JournalsStoragePath, config.Storage.Voron.JournalsStoragePath, config.DataDirectory }); break; } return(GetMessageWithObject(drives)); }
public AdminLogsWebSocketsRequestParser(DatabasesLandlord databasesLandlord, CountersLandlord countersLandlord, FileSystemsLandlord fileSystemsLandlord, MixedModeRequestAuthorizer authorizer, string expectedRequestSuffix) : base(databasesLandlord, countersLandlord, fileSystemsLandlord, authorizer, expectedRequestSuffix) { }
protected override void InnerInitialization(HttpControllerContext controllerContext) { base.InnerInitialization(controllerContext); landlord = (CountersLandlord)controllerContext.Configuration.Properties[typeof(CountersLandlord)]; requestManager = (RequestManager)controllerContext.Configuration.Properties[typeof(RequestManager)]; var values = controllerContext.Request.GetRouteData().Values; if (values.ContainsKey("MS_SubRoutes")) { var routeDatas = (IHttpRouteData[])controllerContext.Request.GetRouteData().Values["MS_SubRoutes"]; var selectedData = routeDatas.FirstOrDefault(data => data.Values.ContainsKey("counterName")); if (selectedData != null) CountersName = selectedData.Values["counterName"] as string; } else { if (values.ContainsKey("cou")) CountersName = values["counterName"] as string; } if (CountersName == null) throw new InvalidOperationException("Could not find counter name for this request"); }