Example #1
0
 public Yield DeleteRecord(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     string name = context.GetSuffix(0, UriPathFormat.Normalized);
     DeleteRecord(name);
     response.Return(DreamMessage.Ok());
     yield break;
 }
Example #2
0
 public Yield GetBlueprints(DreamContext context, DreamMessage request, Result<DreamMessage> response)
 {
     string sid = context.GetSuffix(0, UriPathFormat.Original);
     XDoc result = null;
     Dictionary<string, XDoc> blueprints = _blueprints;
     if(blueprints != null) {
         lock(blueprints) {
             blueprints.TryGetValue(sid, out result);
         }
     }
     if(result != null) {
         response.Return(DreamMessage.Ok(result));
     } else {
         response.Return(DreamMessage.NotFound(string.Format("could not find blueprint for {0}", sid)));
     }
     yield break;
 }
Example #3
0
        public Yield GetRecord(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            XDoc doc = null;
            string name = context.GetSuffix(0, UriPathFormat.Normalized);
            lock(_directory) {
                DirectoryRecord record;
                if(_directory.TryGetValue(name, out record)) {
                    doc = record.Value;
                }
            }

            // check if we should look into a parent directory
            if(doc == null) {
                if(_parent != null) {
                    Result<DreamMessage> result;
                    yield return result = _parent.At("records", context.GetSuffix(0, UriPathFormat.Normalized)).Get(new Result<DreamMessage>(TimeSpan.MaxValue));
                    if(!result.Value.IsSuccessful) {

                        // respond with the error code we received
                        response.Return(result.Value);
                        yield break;
                    }
                    doc = result.Value.ToDocument();
                } else {
                    response.Return(DreamMessage.NotFound("record not found"));
                    yield break;
                }
            }
            response.Return(DreamMessage.Ok(doc));
            yield break;
        }
Example #4
0
        public Yield PutRecord(DreamContext context, DreamMessage request, Result<DreamMessage> response)
        {
            DirectoryRecord record = new DirectoryRecord();
            record.Name = context.GetSuffix(0, UriPathFormat.Normalized);
            record.Value = request.ToDocument();
            int ttl = context.GetParam<int>(TIME_TO_LIVE, -1);
            if(ttl >= 0) {
                record.Expiration = DateTime.UtcNow.AddSeconds(ttl);
            }

            // add value to directory
            InsertRecord(record);
            response.Return(DreamMessage.Ok());
            yield break;
        }