本文整理汇总了C#中MindTouch.Dream.DreamMessage.ToText方法的典型用法代码示例。如果您正苦于以下问题:C# DreamMessage.ToText方法的具体用法?C# DreamMessage.ToText怎么用?C# DreamMessage.ToText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MindTouch.Dream.DreamMessage
的用法示例。
在下文中一共展示了DreamMessage.ToText方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePlay
public Yield CreatePlay(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
IPlay play = Context.Current.Instance.PlayController.FromJson(request.ToText());
Result<IPlay> result = new Result<IPlay>();
yield return Context.Current.Instance.PlayController.Insert(play, result);
response.Return(DreamMessage.Ok(MimeType.JSON, Context.Current.Instance.PlayController.ToJson(result.Value)));
}
示例2: UpdateSource
public Yield UpdateSource(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
ISource source = Context.Current.Instance.SourceController.FromJson(request.ToText());
Result<ISource> result = new Result<ISource>();
yield return Context.Current.Instance.SourceController.Update(context.GetParam("id"), context.GetParam("rev", null), source, result);
response.Return(DreamMessage.Ok(MimeType.JSON, Context.Current.Instance.SourceController.ToJson(result.Value)));
}
示例3: UpdateUser
public Yield UpdateUser(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
Result<IUser> result = new Result<IUser>();
yield return Context.Current.Instance.UserController.Update(context.GetParam("id"), context.GetParam("rev"), Context.Current.Instance.UserController.FromJson(request.ToText()), result);
response.Return(DreamMessage.Ok(MimeType.JSON, Context.Current.Instance.UserController.ToJson(result.Value)));
}
示例4: CreateUser
public Yield CreateUser(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
Result<IUser> result = new Result<IUser>();
IUser user = Context.Current.Instance.UserController.FromJson(request.ToText());
yield return Context.Current.Instance.UserController.Insert(user, result);
response.Return(DreamMessage.Ok(MimeType.JSON, Context.Current.Instance.UserController.ToJson(result.Value)));
}
示例5: UpdatePlay
public Yield UpdatePlay(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
string playId = context.GetParam("id");
string playRev = context.GetParam("rev");
IPlay play = Context.Current.Instance.PlayController.FromJson(request.ToText());
Result<IPlay> result = new Result<IPlay>();
yield return Context.Current.Instance.PlayController.Update(playId,playRev, play, result);
response.Return(DreamMessage.Ok(MimeType.JSON, Context.Current.Instance.PlayController.ToJson(result.Value)));
}
示例6: CouchException
public CouchException(DreamMessage msg)
: this(msg, msg.ToText())
{
}
示例7: GetRequestAsText
private static object GetRequestAsText(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
return request.ToText();
}
示例8: PrologueDreamIn
private static Yield PrologueDreamIn(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
string root = context.GetParam(DreamInParam.ROOT, "doc");
// check if we need to change the message format
string format = context.GetParam(DreamInParam.FORMAT, null);
if(format != null) {
switch(format.ToLowerInvariant()) {
case "json":
case "jsonp":
request = DreamMessage.NotImplemented("json(p) input format not supported");
break;
case "php":
request = DreamMessage.NotImplemented("php input format not supported");
break;
case "xpost":
if(request.ContentType.Match(MimeType.FORM_URLENCODED)) {
XDoc doc = XPostUtil.FromXPathValuePairs(XUri.ParseParamsAsPairs(request.ToText()), root);
request = new DreamMessage(request.Status, request.Headers, doc);
}
break;
case "versit":
if(!request.ContentType.Match(MimeType.XML)) {
XDoc doc = VersitUtil.FromVersit(request.ToTextReader().ReadToEnd(), root);
request = new DreamMessage(request.Status, request.Headers, doc);
}
break;
case "html":
if(!request.ContentType.Match(MimeType.XML)) {
XDoc doc = XDocFactory.From(request.ToTextReader(), MimeType.HTML);
request = new DreamMessage(request.Status, request.Headers, doc);
}
break;
case "xspan": {
XDoc doc = XSpanUtil.FromXSpan(request.ToDocument());
request = new DreamMessage(request.Status, request.Headers, doc);
}
break;
case "xhtml":
if(request.ContentType.Match(MimeType.XHTML)) {
request.Headers.ContentType = MimeType.XML;
}
break;
case "xml":
break;
default:
request = DreamMessage.BadRequest(string.Format("{0} input format not supported", format));
break;
}
} else if("base64".EqualsInvariantIgnoreCase(request.Headers.ContentEncoding)) {
byte[] bytes = Convert.FromBase64String(request.ToText());
request = new DreamMessage(request.Status, request.Headers, request.ContentType, bytes);
request.Headers.ContentEncoding = null;
}
response.Return(request);
yield break;
}
示例9: UpdateScore
public Yield UpdateScore(DreamContext aContext, DreamMessage aRequest, Result<DreamMessage> aResponse)
{
if (aContext.GetParam("rev") == null)
{
aResponse.Return(DreamMessage.BadRequest("no rev specified"));
yield break;
}
Result<IScore> result = new Result<IScore>();
if (aRequest.ContentType.IsXml)
{
Result<IScore> resultRetrieve = new Result<IScore>();
yield return Context.Current.Instance.ScoreController.Retrieve(aContext.GetParam("id"), resultRetrieve);
IScore score = resultRetrieve.Value;
yield return
Context.Current.Instance.ScoreController.AttachMusicXml(score, aRequest.ToDocument(),
aContext.GetParam("overwrite", true), result);
}
else
{
IScore score = Context.Current.Instance.ScoreController.FromJson(aRequest.ToText());
yield return
Context.Current.Instance.ScoreController.Update(aContext.GetParam("id"), aContext.GetParam("rev"), score, result);
}
aResponse.Return(DreamMessage.Ok(MimeType.JSON, Context.Current.Instance.ScoreController.ToJson(result.Value)));
}
示例10: CreateScore
public Yield CreateScore(DreamContext aContext, DreamMessage aRequest, Result<DreamMessage> aResponse)
{
Result<IScore> result = new Result<IScore>();
if (aRequest.ContentType.IsXml)
{
IScore score = Context.Current.Instance.ScoreController.CreateNew();
yield return Context.Current.Instance.ScoreController.AttachMusicXml(score, aRequest.ToDocument(), false, result);
}
else
{
IScore score = Context.Current.Instance.ScoreController.FromJson(aRequest.ToText());
yield return Context.Current.Instance.ScoreController.Insert(score, result);
}
aResponse.Return(DreamMessage.Ok(MimeType.JSON, Context.Current.Instance.ScoreController.ToJson(result.Value)));
}
示例11: CreateSourcePage
public Yield CreateSourcePage(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
if (request.ContentType.Match(MimeType.JSON))
{
ISourcePage page = Context.Current.Instance.SourcePageController.FromJson(request.ToText());
Result<ISourcePage> result = new Result<ISourcePage>();
yield return Context.Current.Instance.SourcePageController.Insert(page, result);
response.Return(DreamMessage.Ok(MimeType.JSON, Context.Current.Instance.SourcePageController.ToJson(result.Value)));
}
else // Bulk import based on ZIP file
{
Stream file = request.ToStream();
Result<bool> result = new Result<bool>();
yield return Context.Current.Instance.SourcePageController.BulkImportSourcePages(context.GetParam("sourceId"), file, result);
if (result.Value)
response.Return(DreamMessage.Ok());
else
response.Return(DreamMessage.BadRequest("Bad name format"));
}
}
示例12: PostUsersAllowed
public Yield PostUsersAllowed(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
var permissionMask = context.GetParam<ulong>("mask", 0);
var operationList = context.GetParam("operations", "");
var user = GetUserFromUrlMustExist();
var verbose = context.GetParam("verbose", true);
var invert = context.GetParam("invert", false);
// Use comma separated permission list or permissionmask from request.
var permissions = Permissions.NONE;
if(permissionMask != 0) {
permissions = (Permissions)permissionMask;
}
// Convert operation list to mask combined with provided mask
if(!string.IsNullOrEmpty(operationList)) {
try {
permissions |= (Permissions)PermissionsBL.MaskFromPermissionList(PermissionsBL.PermissionListFromString(operationList));
} catch {
throw new UserOperationListInvalidArgumentException();
}
}
IEnumerable<ulong> pageIds;
var textOutput = false;
if(request.HasDocument) {
if(!request.ToDocument().HasName("pages")) {
throw new UserExpectedRootNodePagesInvalidDocumentException();
}
pageIds = from pageIdXml in request.ToDocument()["page/@id"]
let pageId = pageIdXml.AsULong
where pageId.HasValue
select pageId.Value;
} else if(verbose) {
throw new UserPageFilterVerboseNotAllowedException();
} else if(!request.ContentType.Match(MimeType.TEXT)) {
throw new UserPageFilterInvalidInputException();
} else {
textOutput = true;
pageIds = request.ToText().CommaDelimitedToULong();
}
IEnumerable<ulong> filtered;
var allowedPages = PermissionsBL.FilterDisallowed(user, pageIds, false, out filtered, permissions);
if(textOutput) {
var output = invert
? filtered.ToCommaDelimitedString()
: allowedPages.ToCommaDelimitedString();
response.Return(DreamMessage.Ok(MimeType.TEXT, output ?? string.Empty));
} else {
var responseDoc = new XDoc("pages");
if(invert) {
foreach(var pageId in filtered) {
responseDoc.Start("page").Attr("id", pageId).End();
}
} else if(allowedPages.Any()) {
if(verbose) {
foreach(var page in PageBL.GetPagesByIdsPreserveOrder(allowedPages)) {
responseDoc.Add(PageBL.GetPageXml(page, null));
}
} else {
foreach(var pageId in allowedPages) {
responseDoc.Start("page").Attr("id", pageId).End();
}
}
}
response.Return(DreamMessage.Ok(responseDoc));
}
yield break;
}