internal DataQuery(DataCollection collection, string id) { _collection = collection; _id = id; _filters = null; _selectors = null; _sort = null; _skip = null; _take = null; }
private void LoadDataCollections() { string dataPath = Path.Join(_app.Options.Path, "data"); // TODO: Also check if its a directory if (FileSystem.ExistsSync(dataPath) == false) { Runtime.TraceWarning("Data directory '%s' was not found. No data collections were loaded.", dataPath); return; } foreach (string name in FileSystem.ReadDirectorySync(dataPath)) { string collectionPath = Path.Join(dataPath, name); string collectionConfigPath = Path.Join(collectionPath, "config.json"); Dictionary<string, object> collectionConfig = Configuration.Load(collectionConfigPath, /* createEmptyIfNeeded */ false); if (collectionConfig != null) { string sourceName = (string)collectionConfig["source"]; DataSource source = _dataSources[sourceName]; if (source != null) { _dataCollections[name] = new DataCollection(name, collectionPath, collectionConfig, source); Runtime.TraceInfo("Created data collection '%s' associated with data source named '%s'.", name, sourceName); } else { Runtime.Abort("Unable to find a data source named '%s' for '%s' data collection.", sourceName, name); } } else { Runtime.TraceError("Configuration not found in data collection directory named '%s'. Ignoring.", name); } } }
private Task<ServerResponse> ExecuteRequest(DataCollection collection, DataRequest request) { Deferred<ServerResponse> deferred = Deferred.Create<ServerResponse>(); Task<object> resultTask = collection.ExecuteRequest(request); resultTask.Done(delegate(object result) { deferred.Resolve(CreateServerResponse(request, result)); }) .Fail(delegate(Exception e) { deferred.Resolve(ServerResponse.CreateServerError(e.Message)); }); return deferred.Task; }
private DataRequest CreateDataRequest(ServerRequest serverRequest, DataCollection collection) { DataOperation operation; string id = serverRequest.UrlData.Query["id"]; string partition = serverRequest.UrlData.Query["partition"]; string operationName = serverRequest.Route.Parameters["operationName"]; switch (serverRequest.HttpRequest.Method) { case HttpVerb.GET: if (String.IsNullOrEmpty(id) == false) { operation = DataOperation.Lookup; } else { operation = DataOperation.Query; } break; case HttpVerb.POST: if (String.IsNullOrEmpty(operationName)) { operation = DataOperation.Update; } else { operation = DataOperation.Execute; } break; case HttpVerb.PUT: operation = DataOperation.Insert; break; case HttpVerb.DELETE: operation = DataOperation.Delete_; break; default: return null; } DataRequest dataRequest = new DataRequest(operation, operationName, serverRequest.UrlData.Query); dataRequest.Query = new DataQuery(collection, id); dataRequest.Partition = partition; return dataRequest; }