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 DeleteRecord(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            string name = context.GetSuffix(0, UriPathFormat.Normalized);

            DeleteRecord(name);
            response.Return(DreamMessage.Ok());
            yield break;
        }
Example #3
0
        public DreamMessage GetCreateHandler(DreamContext context, DreamMessage message)
        {
            string widget = context.GetSuffix(0, UriPathFormat.Normalized);
            string id     = context.Uri.GetParam("id", "-1");

            LogUtils.LogTrace(_log, "GET create", widget, id);
            XDoc data = XDoc.FromXml(GetStorageContent(string.Format("{0}-data.xml", widget)));

            return(DreamMessage.Ok(MimeType.HTML, GetWidgetContent(context, widget, id, "edit", data)));
        }
Example #4
0
        public DreamMessage PostLoadHandler(DreamContext context, DreamMessage message)
        {
            string widget = context.GetSuffix(0, UriPathFormat.Normalized);
            XDoc   data   = message.Document;
            string mode   = context.Uri.GetParam("mode", "view");
            string id     = context.Uri.GetParam("id", "-1");

            LogUtils.LogTrace(_log, "POST load", widget, mode, data);
            return(DreamMessage.Ok(MimeType.HTML, GetWidgetContent(context, widget, id, mode, data)));
        }
Example #5
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 #6
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;
        }
Example #7
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 #8
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 #9
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;
        }