本文整理汇总了C#中DreamContext类的典型用法代码示例。如果您正苦于以下问题:C# DreamContext类的具体用法?C# DreamContext怎么用?C# DreamContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DreamContext类属于命名空间,在下文中一共展示了DreamContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostBans
public Yield PostBans(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN);
BanBE ban = BanningBL.SaveBan(request.ToDocument());
DekiContext.Current.Instance.EventSink.BanCreated(context.StartTime, ban);
response.Return(DreamMessage.Ok(BanningBL.GetBanXml(ban)));
yield break;
}
示例2: GetPageRating
public Yield GetPageRating(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
UserBE user = DekiContext.Current.User;
PageBE page = PageBL.AuthorizePage(user, Permissions.READ, false);
XDoc ret = RatingBL.GetRatingXml(page, user);
response.Return(DreamMessage.Ok(ret));
yield break;
}
示例3: Authenticate
protected user Authenticate(DreamContext context, DreamMessage request, DekiUserLevel level) {
user result = null;
// get username and password
string user;
string password;
if (!DreamUtil.GetAuthentication(context, request, out user, out password)) {
// anonymous access is always granted
if (level == DekiUserLevel.Anonymous) {
// TODO (steveb): missing code
throw new NotImplementedException("return anonymous user");
} else {
throw new DreamAbortException(DreamMessage.AccessDenied(AuthenticationRealm, "authentication failed"));
}
}
// validate username and password
result = MindTouch.Deki.user.GetUserByName(user);
if (result == null) {
throw new DreamAbortException(DreamMessage.AccessDenied(AuthenticationRealm, "authentication failed"));
}
if (!result.checkPassword(password)) {
throw new DreamAbortException(DreamMessage.AccessDenied(AuthenticationRealm, "authentication failed"));
}
if ((level == DekiUserLevel.Admin) && !result.isSysop()) {
throw new DreamAbortException(DreamMessage.AccessDenied(AuthenticationRealm, "authentication failed"));
}
return result;
}
示例4: GetContext
//--- Class Methods ---
public static DekiContext GetContext(DreamContext dreamContext) {
var context = dreamContext.GetState<DekiContext>();
if(context == null) {
throw new DekiContextAccessException("DekiContext.Current is not set, because the current DreamContext does not contain a reference");
}
return context;
}
示例5: 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;
}
示例6: GetContentHandler
public DreamMessage GetContentHandler(DreamContext context, DreamMessage message) {
user user = Authenticate(context, message, DekiUserLevel.User);
page page = Authorize(context, user, DekiAccessLevel.Read, "pageid");
DekiContext deki = new DekiContext(message, this.DekiConfig);
bool nofollow = (context.Uri.GetParam("nofollow", 0, null) != null);
string contents = page.getContent(nofollow);
string xml = string.Format(DekiWikiService.XHTML_LOOSE, contents);
XDoc doc = XDoc.FromXml(xml);
if (doc == null) {
LogUtils.LogWarning(_log, "GetContentHandler: null document page content", page.PrefixedName, contents);
throw new DreamAbortException(DreamMessage.BadRequest("null document"));
}
XDoc result = new XDoc("list");
string type = context.Uri.GetParam("type", 0, null);
string id = context.Uri.GetParam("id", 0, null);
if (id != null) {
XDoc widget = doc[string.Format("//default:span[@widgetid={0}]", id)];
if (widget.IsEmpty) {
LogUtils.LogWarning(_log, "GetContentHandler: widget not found for ID", id);
return DreamMessage.NotFound("");
}
LogUtils.LogTrace(_log, "GetContentHandler: widget by id (id, xspan)", id, widget);
result.Add(ConvertFromXSpan(widget));
} else if (type != null) {
foreach (XDoc widget in doc[string.Format("//default:span[@widgettype='{0}']", type)])
result.Add(ConvertFromXSpan(widget));
LogUtils.LogTrace(_log, "GetContentHandler: widget by type (type, #)", type, result.Count);
} else {
foreach (XDoc widget in doc["//default:span[@class='widget']"])
result.Add(ConvertFromXSpan(widget));
LogUtils.LogTrace(_log, "GetContentHandler: all widgets (#)", type, result.Count);
}
return DreamMessage.Ok(result);
}
示例7: GetTags
public Yield GetTags(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
string type = DreamContext.Current.GetParam("type", "");
string fromStr = DreamContext.Current.GetParam("from", "");
string toStr = DreamContext.Current.GetParam("to", "");
bool showPages = DreamContext.Current.GetParam("pages", false);
string partialName = DreamContext.Current.GetParam("q", "");
// parse type
TagType tagType = TagType.ALL;
if(!string.IsNullOrEmpty(type) && !SysUtil.TryParseEnum(type, out tagType)) {
throw new DreamBadRequestException("Invalid type parameter");
}
// check and validate from date
DateTime from = (tagType == TagType.DATE) ? DateTime.Now : DateTime.MinValue;
if(!string.IsNullOrEmpty(fromStr) && !DateTime.TryParse(fromStr, out from)) {
throw new DreamBadRequestException("Invalid from date parameter");
}
// check and validate to date
DateTime to = (tagType == TagType.DATE) ? from.AddDays(30) : DateTime.MaxValue;
if(!string.IsNullOrEmpty(toStr) && !DateTime.TryParse(toStr, out to)) {
throw new DreamBadRequestException("Invalid to date parameter");
}
// execute query
var tags = TagBL.GetTags(partialName, tagType, from, to);
XDoc doc = TagBL.GetTagListXml(tags, "tags", null, showPages);
response.Return(DreamMessage.Ok(doc));
yield break;
}
示例8: GetGroup
public Yield GetGroup(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.READ);
GroupBE group = GetGroupFromUrl();
DreamMessage responseMsg = DreamMessage.Ok(GroupBL.GetGroupXmlVerbose(group, null));
response.Return(responseMsg);
yield break;
}
示例9: Register
public Yield Register(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
string servicePath = context.GetParam("service-path");
string location = StringUtil.CreateAlphaNumericKey(8);
// register the script
XDoc config = new XDoc("config")
.Elem("manifest", servicePath)
.Elem("debug", true);
//create the script service
Result<Plug> res;
yield return res = CreateService(location, "sid://mindtouch.com/2007/12/dekiscript", config, new Result<Plug>());
Plug service = res.Value;
// register script functions in environment
XDoc manifest = service.Get().ToDocument();
string ns = manifest["namespace"].AsText;
foreach(XDoc function in manifest["function"]) {
string name = function["name"].AsText;
if(string.IsNullOrEmpty(ns)) {
_env.Vars.AddNativeValueAt(name, function["uri"].AsUri);
} else {
_env.Vars.AddNativeValueAt(ns + "." + name, function["uri"].AsUri);
}
}
response.Return(DreamMessage.Ok(MimeType.XML, manifest));
}
示例10: GetPage
public Yield GetPage(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
CheckResponseCache(context, false);
PageBE page = PageBL.GetPageFromUrl(true);
page = PageBL.AuthorizePage(DekiContext.Current.User, Permissions.READ, page, false);
response.Return(DreamMessage.Ok(PageBL.GetPageXmlVerbose(page, null)));
yield break;
}
示例11: GetSearchDescription
public Yield GetSearchDescription(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
XDoc description = new XDoc("OpenSearchDescription", "http://a9.com/-/spec/opensearch/1.1/");
description.Elem("ShortName", string.Format(DekiResources.OPENSEARCH_SHORTNAME, DekiContext.Current.Instance.SiteName))
.Elem("Description", DekiResources.OPENSEARCH_DESCRIPTION)
.Start("Query")
.Attr("role", "example")
.Attr("searchTerms", "Wiki")
.End();
// HACK HACK HACK: we can't use XUri because it encodes the "{}" characters
string uri = DekiContext.Current.ApiUri.At("site", "opensearch").ToString();
uri += "?q={searchTerms}&offset={startIndex}&limit={count?}&";
description.Start("Url")
.Attr("type", "text/html")
.Attr("indexOffset", 0)
.Attr("template", DekiContext.Current.UiUri.At("Special:Search").ToString() + "?search={searchTerms}&offset=0&limit={count?}&format=html")
.End()
.Start("Url")
.Attr("type", "application/atom+xml")
.Attr("indexOffset", 0)
.Attr("template", uri + "format=atom")
.End()
.Start("Url")
.Attr("type", "application/rss+xml")
.Attr("indexOffset", 0)
.Attr("template", uri + "format=rss")
.End()
.Start("Url")
.Attr("type", "application/x-suggestions+json")
.Attr("template", DekiContext.Current.ApiUri.At("site", "opensearch", "suggestions").ToString() + "?q={searchTerms}")
.End();
response.Return(DreamMessage.Ok(description));
yield break;
}
示例12: GetPageTags
public Yield GetPageTags(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
PageBE page = PageBL.AuthorizePage(DekiContext.Current.User, Permissions.READ, false);
XUri href = DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "tags");
XDoc doc = TagBL.GetTagListXml(TagBL.GetTagsForPage(page), "tags", href, false);
response.Return(DreamMessage.Ok(doc));
yield break;
}
示例13: GetArchiveFiles
public Yield GetArchiveFiles(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN);
IList<AttachmentBE> removedFiles = AttachmentBL.Instance.GetResources(DeletionFilter.DELETEDONLY, null, null);
XDoc responseXml = AttachmentBL.Instance.GetFileXml(removedFiles, true, "archive", null, null);
response.Return(DreamMessage.Ok(responseXml));
yield break;
}
示例14: PostNewComment
public static CommentBE PostNewComment(PageBE page, DreamMessage request, DreamContext context) {
ValidateCommentText(request.ContentType, request.AsText());
CommentBE comment = new CommentBE();
comment.Title = context.GetParam("title", string.Empty);
comment.PageId = page.ID;
comment.Content = request.AsText();
comment.ContentMimeType = request.ContentType.ToString();
comment.PosterUserId = DekiContext.Current.User.ID;
comment.CreateDate = DateTime.UtcNow;
//Note (MaxM): Replytoid/replies not yet exposed
//ulong replyToId = context.GetParam<ulong>("replyto", 0);
//if (replyToId == 0)
// newComment.ReplyToId = null;
//else
// newComment.ReplyToId = replyToId;
ushort commentNumber;
uint commentId = DbUtils.CurrentSession.Comments_Insert(comment, out commentNumber);
if (commentId == 0) {
return null;
} else {
comment.Id = commentId;
comment.Number = commentNumber;
PageBL.Touch(page, comment.CreateDate);
RecentChangeBL.AddCommentCreateRecentChange(comment.CreateDate, page, DekiContext.Current.User, string.Format(DekiResources.COMMENT_ADDED, comment.Number.ToString()), comment);
return comment;
}
}
示例15: GetCommentContent
public Yield GetCommentContent(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
PageBE page = null;
CommentBE comment = null;
GetCommentFromRequest(context, Permissions.READ, out page, out comment);
response.Return(DreamMessage.Ok(new MimeType(comment.ContentMimeType), comment.Content));
yield break;
}