private static string GetConnectionString(InternalCollectionServer server, string user, string password) { return string.Format( ConfigurationManager.ConnectionStrings["Collection"].ConnectionString, server.Address, server.Port, server.Catalog, user, password ); }
public async Task<IContext> CreateContextAsync(InternalCollectionServer server, string user, string password) { try { var ctx = new Collection.Collection(GetConnectionString(server, user, password)); // Force immediate connection to validate settings await ctx.Database.Connection.OpenAsync(); return new CollectionContext( Kernel, ctx ); } catch (Exception ex) { // TODO Log return null; } }
private void ExtractCollection( HttpActionContext actionContext, out InternalCollectionServer server) { server = null; var request = actionContext.Request; var routeData = request.GetRouteData(); if (routeData == null) { SetErrorResponse(actionContext, HttpStatusCode.InternalServerError, "No Route Data Available"); return; } if (routeData.Values.ContainsKey(CollectionAPI.COLLECTION)) { var collection = routeData.Values[CollectionAPI.COLLECTION].ToString(); int collectionId; if (!int.TryParse(collection, out collectionId)) { SetErrorResponse(actionContext, HttpStatusCode.BadRequest, "URL Component {collection} must be an integer"); return; } var servers = Configuration.GetCollectionServers(); server = servers.FirstOrDefault(x => x.Id == collectionId); if (server == null) { SetErrorResponse(actionContext, HttpStatusCode.NotFound, string.Format("Collection Server with id {0} not found", collection)); return; } } }