private void InsertRecord(DirectoryRecord record) { // add value to directory lock (_directory) { _directory[record.Name] = record; } // check if value has an expiration time if (record.HasExpiration) { TimerFactory.New(record.Expiration, OnExpire, record.Name, TaskEnv.New()); } SaveToFileSystem(record.Name, record.Value); // notify event channel XDoc notify = new XDoc("insert").Attr("name", record.Name); if (record.HasExpiration) { notify.Attr("expire", record.Expiration); } notify.Add(record.Value); _events.Post(notify, new Result <DreamMessage>(TimeSpan.MaxValue)); }
internal Yield PostEntries(DreamContext context, DreamMessage request, Result <DreamMessage> response) { if (request.ToDocument().Name != "entry") { throw new DreamBadRequestException("invalid format"); } // prepare entry XAtomEntry entry = new XAtomEntry(request.ToDocument()); int number = System.Threading.Interlocked.Increment(ref _counter); XUri link = Self.At(number.ToString()); entry.Id = link; entry.AddLink(link, XAtomBase.LinkRelation.Edit, null, 0, null); // update feed XAtomFeed feed = _feed; if (feed != null) { lock (feed) { feed.Add(entry); } } else { throw new DreamBadRequestException("not initialized"); } // schedule entry deletion double seconds = context.GetParam <double>("ttl", _defaultTTL); if (seconds > 0) { TimerFactory.New(TimeSpan.FromSeconds(seconds), AutoDeletePost, number, TaskEnv.Clone()); } // return updated entry response.Return(DreamMessage.Created(link, entry)); yield break; }