本文整理汇总了C#中DreamContext.GetSuffixes方法的典型用法代码示例。如果您正苦于以下问题:C# DreamContext.GetSuffixes方法的具体用法?C# DreamContext.GetSuffixes怎么用?C# DreamContext.GetSuffixes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DreamContext
的用法示例。
在下文中一共展示了DreamContext.GetSuffixes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: GetHttp
public Yield GetHttp(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
yield return context.Relay(_redirect.At(context.GetSuffixes(UriPathFormat.Original)), request, response);
}
示例3: ProxyToService
public Yield ProxyToService(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.ADMIN);
//Private feature requires api-key
var identifier = context.GetParam("id");
ServiceRepository.IServiceInfo serviceInfo = null;
if(identifier.StartsWith("=")) {
serviceInfo = DekiContext.Current.Instance.RunningServices[XUri.Decode(identifier.Substring(1))];
} else {
uint serviceId;
if(uint.TryParse(identifier, out serviceId)) {
serviceInfo = DekiContext.Current.Instance.RunningServices[serviceId];
} else {
throw new DreamBadRequestException(string.Format("Invalid id '{0}'", identifier));
}
}
if(serviceInfo == null) {
response.Return(DreamMessage.NotFound(string.Format(DekiResources.SERVICE_NOT_FOUND, identifier)));
yield break;
}
var proxyUri = serviceInfo.ServiceUri.At(context.GetSuffixes(UriPathFormat.Original).Skip(1).ToArray());
yield return context.Relay(Plug.New(proxyUri), request, response);
}
示例4: GetFile
private DreamMessage GetFile(DreamContext context) {
DreamMessage message;
string[] parts = context.GetSuffixes(UriPathFormat.Decoded);
string filename = _resourcesPath;
foreach(string part in parts) {
if(part.EqualsInvariant("..")) {
_log.WarnFormat("attempted to access file outside of target folder: {0}", string.Join("/", parts));
throw new DreamBadRequestException("paths cannot contain '..'");
}
filename = Path.Combine(filename, part);
}
try {
message = DreamMessage.FromFile(filename, context.Verb == Verb.HEAD);
} catch(FileNotFoundException e) {
message = DreamMessage.NotFound("resource not found: " + String.Join("/", context.GetSuffixes(UriPathFormat.Decoded)));
} catch(Exception e) {
message = DreamMessage.BadRequest("invalid path");
}
return message;
}
示例5: GetFiles
public Yield GetFiles(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
if(_resourcesUri != null) {
yield return context.Relay(Plug.New(_resourcesUri).AtPath(string.Join("/", context.GetSuffixes(UriPathFormat.Original))), request, response);
} else {
response.Return(GetFile(context));
}
yield break;
}
示例6: PostPageMessage
public Yield PostPageMessage(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
if(UserBL.IsAnonymous(DekiContext.Current.User)) {
response.Return(DreamMessage.Forbidden("A logged-in user is required"));
yield break;
}
if(request.ContentLength > 128 * 1024) {
response.Return(DreamMessage.BadRequest("Content-length cannot exceed 128KB)"));
yield break;
}
PageBE page = PageBL_AuthorizePage(context, null, Permissions.READ, false);
XDoc body = new XDoc("body");
switch(request.ContentType.FullType) {
case "text/plain":
body.Attr("content-type", request.ContentType.ToString())
.Value(request.AsText());
break;
default:
body.Attr("content-type", request.ContentType.ToString())
.Add(request.ToDocument());
break;
}
string[] path = context.GetSuffixes(UriPathFormat.Original);
path = ArrayUtil.SubArray(path, 1);
DekiContext.Current.Instance.EventSink.PageMessage(DekiContext.Current.Now, page, DekiContext.Current.User, body, path);
response.Return(DreamMessage.Ok());
yield break;
}
示例7: GetPath
private string GetPath(DreamContext context)
{
string[] parts = context.GetSuffixes(UriPathFormat.Decoded);
string path = _path;
foreach(string part in parts) {
if(part.EqualsInvariant("..")) {
throw new DreamBadRequestException("paths cannot contain '..'");
}
path = Path.Combine(path, part);
}
if(_privateRoot && (parts.Length == 0 || (parts.Length == 1 && !Directory.Exists(path)))) {
throw new DreamForbiddenException("Root level access is forbidden for this storage service");
}
return path;
}
示例8: GetPath
private string GetPath(DreamContext context)
{
var parts = context.GetSuffixes(UriPathFormat.Decoded);
if(parts.Where(p => p.EqualsInvariant("..")).Any()) {
throw new DreamBadRequestException("paths cannot contain '..'");
}
if(_privateRoot && (parts.Length == 0 || (parts.Length == 1 && !context.Uri.TrailingSlash))) {
throw new DreamForbiddenException("Root level access is forbidden for this storage service");
}
return context.Uri.GetRelativePathTo(context.Service.Self.Uri).IfNullOrEmpty("/");
}