本文整理汇总了C#中DreamMessage类的典型用法代码示例。如果您正苦于以下问题:C# DreamMessage类的具体用法?C# DreamMessage怎么用?C# DreamMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DreamMessage类属于命名空间,在下文中一共展示了DreamMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileHandler
public Yield GetFileHandler(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
string suffixPath = string.Join("" + Path.DirectorySeparatorChar, context.GetSuffixes(UriPathFormat.Decoded));
string filename = Path.Combine(_path, suffixPath);
if(Directory.Exists(filename)) {
XDoc ret = new XDoc("files");
string pattern = context.GetParam("pattern", "");
AddDirectories(new DirectoryInfo(filename), pattern, ret);
AddFiles(new DirectoryInfo(filename), pattern, ret);
response.Return(DreamMessage.Ok(ret));
yield break;
}
DreamMessage message;
try {
message = DreamMessage.FromFile(filename, StringUtil.EqualsInvariant(context.Verb, "HEAD"));
} catch(FileNotFoundException) {
message = DreamMessage.NotFound("file not found");
} catch(Exception) {
message = DreamMessage.BadRequest("invalid path");
}
// open file and stream it to the requester
response.Return(message);
}
示例2: DeleteRecord
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;
}
示例3: GetEntries
public Yield GetEntries(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
XAtomFeed feed = _feed;
if(feed != null) {
response.Return(DreamMessage.Ok(MimeType.ATOM, _feed));
} else {
throw new DreamBadRequestException("not initialized");
}
yield break;
}
示例4: GetAllRecords
public Yield GetAllRecords(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
XDoc result = new XDoc("list");
lock(_directory) {
foreach(KeyValuePair<string, DirectoryRecord> entry in _directory) {
result.Add(entry.Value.ToXDoc());
}
}
response.Return(DreamMessage.Ok(result));
yield break;
}
示例5: DeleteQueue
internal Yield DeleteQueue(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
var name = context.GetParam("queuename");
lock(_queues) {
ITransactionalQueue<XDoc> queue;
if(_queues.TryGetValue(name, out queue)) {
queue.Dispose();
Directory.Delete(Path.Combine(_rootPath, name),true);
_queues.Remove(name);
}
}
response.Return(DreamMessage.Ok());
yield break;
}
示例6: Can_clone_a_memory_stream_message
public void Can_clone_a_memory_stream_message()
{
var text = "blah";
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(text);
writer.Flush();
stream.Position = 0;
var m = new DreamMessage(DreamStatus.Ok, new DreamHeaders().Add("foo", "bar"), MimeType.TEXT, stream.Length, stream);
m.Headers.Add("baz", "blah");
_log.Debug("about to clone");
var m2 = m.Clone();
var reader = new StreamReader(m2.ToStream());
Assert.AreEqual(text, reader.ReadToEnd());
Assert.AreEqual(m.ContentType.ToString(), m2.ContentType.ToString());
Assert.AreEqual(m.Headers["foo"], m2.Headers["foo"]);
Assert.AreEqual(m.Headers["baz"], m2.Headers["baz"]);
}
示例7: GetEntry
public Yield GetEntry(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
string id = context.GetParam("id");
XAtomEntry entry = null;
// get feed
XAtomFeed feed = _feed;
if(feed != null) {
lock(feed) {
entry = new XAtomEntry(feed[string.Format("entry[id='{0}']", Self.At(id).Uri)]);
}
} else {
throw new DreamBadRequestException("not initialized");
}
if(entry.IsEmpty) {
response.Return(DreamMessage.NotFound("entry not found"));
} else {
response.Return(DreamMessage.Ok(MimeType.ATOM, entry));
}
yield break;
}
示例8: CreateSubscriptionSet
internal Yield CreateSubscriptionSet(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
XDoc subscriptionSet = request.ToDocument();
Tuplet<PubSubSubscriptionSet, bool> set = _dispatcher.RegisterSet(subscriptionSet);
XUri locationUri = Self.At("subscribers", set.Item1.Location).Uri.AsPublicUri();
DreamMessage msg = null;
if(set.Item2) {
// existing subs cause a Conflict with ContentLocation of the sub
msg = DreamMessage.Conflict("The specified owner already has a registered subscription set");
msg.Headers.ContentLocation = locationUri;
} else {
// new subs cause a Created with Location of the sub, plus XDoc containing the location
XDoc responseDoc = new XDoc("subscription-set")
.Elem("uri.location", locationUri)
.Elem("access-key", set.Item1.AccessKey);
msg = DreamMessage.Created(locationUri, responseDoc);
msg.Headers.Location = locationUri.With("access-key", set.Item1.AccessKey);
}
response.Return(msg);
yield break;
}
示例9: DetermineAccess
public override DreamAccess DetermineAccess(DreamContext context, DreamMessage request)
{
if(context.Feature.Signature.StartsWith("subscribers/")) {
var location = context.GetParam("location", null);
var set = _dispatcher[location];
if(set != null) {
var accessKey = context.GetParam("access-key", null);
if(string.IsNullOrEmpty(accessKey)) {
var cookie = DreamCookie.GetCookie(request.Cookies, "access-key");
if(cookie != null) {
accessKey = cookie.Value;
}
}
if(set.AccessKey.EqualsInvariant(accessKey)) {
return DreamAccess.Private;
}
_log.DebugFormat("no matching access-key in query or cookie for location '{0}'", location);
} else {
_log.DebugFormat("no subscription set for location '{0}'", location);
}
}
return base.DetermineAccess(context, request);
}
示例10: convert
public Yield convert(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
string methodStr = context.GetParam("method", string.Empty);
string aliasStr = context.GetParam("id", string.Empty);
XUri secPage = new XUri( context.ServerUri ).At( "deki", "pages", "=Convert:" + methodStr );
Plug _dekiSec = Plug.New( secPage );
XDoc secDoc = _dekiSec.Get().ToDocument();
string userURL = secDoc["user.author/@href"].AsInnerText;
Plug _dekiUser = Plug.New( userURL );
XDoc userDoc = _dekiUser.Get().ToDocument();
string perms = userDoc["permissions.user"]["operations"].AsInnerText;
if ( !perms.Contains("UNSAFECONTENT") ) {
response.Return( DreamMessage.Forbidden("UNSAFECONTENT not enabled") );
yield break;
}
XUri codePage = new XUri( context.ServerUri ).At( "deki","pages", "=Convert:" + methodStr,"contents");
Plug _deki = Plug.New( codePage, new TimeSpan(0,0,15) );
string bodyText = _deki.With("format", "xhtml").Get().ToDocument()["body"]["pre"].Contents;
for ( int i = 0; i < toHTML.GetLength(0); i++ ) {
bodyText = Regex.Replace( bodyText, toHTML[i,0], toHTML[i,1] );
}
//string codeStr = HttpUtility.HtmlDecode( bodyText );
//XDoc doc = XDocFactory.From( codeStr, MimeType.ANY );
//response.Return( DreamMessage.Ok( MimeType.TEXT, bodyText ) );
Assembly scriptCode = CompileCode( bodyText, response );
if ( scriptCode != null ) {
XmlDocument outDoc = runScript( scriptCode, aliasStr );
response.Return( DreamMessage.Ok( MimeType.XML, new XDoc(outDoc) ) );
}
yield break;
}
示例11: CheckPrologue
public Yield CheckPrologue(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
_log.DebugFormat("checking prologue data in Env #{0}", TaskEnv.Current.GetHashCode());
if(string.IsNullOrEmpty(PrologueData)) {
throw new Exception("no prologue data in slot");
}
if(PrologueData != context.GetState<string>("prologue")) {
throw new Exception("state from prologue didn't make it to feature");
}
response.Return(DreamMessage.Ok());
yield break;
}
示例12: CheckEpilogue
public Yield CheckEpilogue(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
EpilogueData = StringUtil.CreateAlphaNumericKey(8);
_log.DebugFormat("setting epilogue data in Env #{0}", TaskEnv.Current.GetHashCode());
context.SetState("epilogue", EpilogueData);
response.Return(DreamMessage.Ok());
yield break;
}
示例13: TestCreateTtlExpire
public Yield TestCreateTtlExpire(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
// add a file
Storage.AtPath(TEST_FILE_URI).With("ttl", "2").Put(DreamMessage.Ok(MimeType.TEXT, TEST_CONTENTS));
_log.DebugFormat("File stored at: {0}", DateTime.UtcNow);
// get file and compare contents
string contents = Storage.AtPath(TEST_FILE_URI).Get().ToText();
Assert.AreEqual(TEST_CONTENTS, contents);
_log.DebugFormat("check file at: {0}", DateTime.UtcNow);
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(4));
// get file and compare contents
_log.DebugFormat("Checking for expired file at: {0}", DateTime.UtcNow);
DreamMessage getResponse = Storage.AtPath(TEST_FILE_URI).GetAsync().Wait();
Assert.AreEqual(DreamStatus.NotFound, getResponse.Status);
response.Return(DreamMessage.Ok());
yield break;
}
示例14: TestCreateRetrieveDelete
public Yield TestCreateRetrieveDelete(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
string filename = Path.GetTempFileName();
using(Stream s = File.OpenWrite(filename)) {
byte[] data = Encoding.UTF8.GetBytes(TEST_CONTENTS);
s.Write(data, 0, data.Length);
}
_log.Debug("created file");
// add a file
_log.DebugFormat("storage path: {0}", Storage.Uri);
Storage.AtPath(TEST_FILE_URI).Put(DreamMessage.FromFile(filename, false));
File.Delete(filename);
_log.Debug("put file");
// get file and compare contents
string contents = Storage.AtPath(TEST_FILE_URI).Get().ToText();
Assert.AreEqual(TEST_CONTENTS, contents);
_log.Debug("got file");
// delete file
Storage.AtPath(TEST_FILE_URI).Delete();
_log.Debug("deleted file");
response.Return(DreamMessage.Ok());
yield break;
}
示例15: Prologue
private Yield Prologue(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
_log.Debug("in prologue");
if("disposal".EqualsInvariant(context.Feature.Signature) && context.IsTaskEnvDisposed) {
throw new Exception("context disposed in prologue");
}
PrologueData = StringUtil.CreateAlphaNumericKey(8);
_log.DebugFormat("setting prologue data in Env #{0}", TaskEnv.Current.GetHashCode());
context.SetState("prologue", PrologueData);
response.Return(DreamMessage.Ok());
yield break;
}