public async Task HandleCreateCentralManagementServerRequest(CreateCentralManagementServerParams createCmsParams, RequestContext <ListRegisteredServersResult> requestContext) { Logger.Write(TraceEventType.Verbose, "HandleCreateCentralManagementServerRequest"); try { CmsTask = Task.Run(async() => { try { //Validate params and connect ServerConnection conn = await ValidateAndCreateConnection(createCmsParams.ConnectParams); // Get Current Reg Servers on CMS RegisteredServersStore store = new RegisteredServersStore(conn); ServerGroup parentGroup = store.DatabaseEngineServerGroup; ListRegisteredServersResult result = GetChildrenfromParentGroup(parentGroup); if (result != null) { await requestContext.SendResult(result); return; } } catch (Exception ex) { // Exception related to connection/creation will only be caught here. Note that the outer catch will not catch them await requestContext.SendError(ex); } }); } catch (Exception e) { // Exception related to run task will be captured here await requestContext.SendError(e); } }
public async Task HandleRemoveServerGroupRequest(RemoveServerGroupParams removeServerGroupParams, RequestContext <bool> requestContext) { Logger.Write(TraceEventType.Verbose, "HandleRemoveServerGroupRequest"); try { CmsTask = Task.Run(async() => { try { ServerConnection serverConn = ValidateAndCreateConnection(removeServerGroupParams.ParentOwnerUri); if (serverConn != null) { RegisteredServersStore store = new RegisteredServersStore(serverConn); ServerGroup parentGroup = NavigateToServerGroup(store, removeServerGroupParams.RelativePath, false); ServerGroup serverGrouptoRemove = parentGroup.ServerGroups.OfType <ServerGroup>().FirstOrDefault(r => r.Name == removeServerGroupParams.GroupName); // since duplicates are not allowed serverGrouptoRemove?.Drop(); await requestContext.SendResult(true); } else { await requestContext.SendResult(false); } } catch (Exception e) { await requestContext.SendError(e); } }); } catch (Exception e) { await requestContext.SendError(e); } }
private ServerGroup NavigateToServerGroup(RegisteredServersStore store, string relativePath, bool alreadyParent = true) { if (string.IsNullOrEmpty(relativePath)) { return(store.DatabaseEngineServerGroup); } // Get key chain from URN Urn urn = new Urn(relativePath); SfcKeyChain keyChain = alreadyParent ? new SfcKeyChain(urn, store as ISfcDomain) : new SfcKeyChain(urn, store as ISfcDomain).Parent; ServerGroup parentGroup = GetNodeFromKeyChain(keyChain, store.DatabaseEngineServerGroup); return(parentGroup); }
public async Task HandleAddServerGroupRequest(AddServerGroupParams addServerGroupParams, RequestContext <bool> requestContext) { Logger.Write(TraceEventType.Verbose, "HandleAddServerGroupRequest"); try { CmsTask = Task.Run(async() => { try { ServerConnection serverConn = ValidateAndCreateConnection(addServerGroupParams.ParentOwnerUri); if (serverConn != null) { ServerGroup parentGroup; RegisteredServersStore store = new RegisteredServersStore(serverConn); // It's a CMS server if (string.IsNullOrEmpty(addServerGroupParams.RelativePath)) { parentGroup = store.DatabaseEngineServerGroup; } else { parentGroup = NavigateToServerGroup(store, addServerGroupParams.RelativePath); } // Add the new group (intentionally not cheching existence to reuse the exception message) ServerGroup serverGroup = new ServerGroup(parentGroup, addServerGroupParams.GroupName) { Description = addServerGroupParams.GroupDescription }; serverGroup.Create(); await requestContext.SendResult(true); } else { await requestContext.SendResult(false); } } catch (Exception e) { await requestContext.SendError(e); } }); } catch (Exception e) { await requestContext.SendError(e); } }
public async Task HandleAddRegisteredServerRequest(AddRegisteredServerParams cmsCreateParams, RequestContext <bool> requestContext) { Logger.Write(TraceEventType.Verbose, "HandleAddRegisteredServerRequest"); try { CmsTask = Task.Run(async() => { try { ServerConnection serverConn = ValidateAndCreateConnection(cmsCreateParams.ParentOwnerUri); if (serverConn != null) { // Get Current Reg Servers RegisteredServersStore store = new RegisteredServersStore(serverConn); ServerGroup parentGroup = NavigateToServerGroup(store, cmsCreateParams.RelativePath); RegisteredServerCollection servers = parentGroup.RegisteredServers; // Add the new server (intentionally not cheching existence to reuse the exception message) RegisteredServer registeredServer = new RegisteredServer(parentGroup, cmsCreateParams.RegisteredServerName); registeredServer.Description = cmsCreateParams.RegisteredServerDescription; registeredServer.ConnectionString = serverConn.ConnectionString; registeredServer.ServerName = cmsCreateParams.RegisteredServerConnectionDetails.ServerName; registeredServer.Create(); await requestContext.SendResult(true); } else { await requestContext.SendResult(false); } } catch (Exception e) { await requestContext.SendError(e); } }); } catch (Exception e) { await requestContext.SendError(e); } }
public async Task HandleListRegisteredServersRequest(ListRegisteredServersParams listServerParams, RequestContext <ListRegisteredServersResult> requestContext) { Logger.Write(TraceEventType.Verbose, "HandleListRegisteredServersRequest"); try { CmsTask = Task.Run(async() => { try { //Validate and create connection ServerConnection serverConn = ValidateAndCreateConnection(listServerParams.ParentOwnerUri); if (serverConn != null) { // Get registered Servers RegisteredServersStore store = new RegisteredServersStore(serverConn); ServerGroup parentGroup = NavigateToServerGroup(store, listServerParams.RelativePath); ListRegisteredServersResult result = GetChildrenfromParentGroup(parentGroup); await requestContext.SendResult(result); } else { await requestContext.SendResult(null); } } catch (Exception e) { await requestContext.SendError(e); } }); } catch (Exception e) { await requestContext.SendError(e); } }