本文整理汇总了C#中DreamContext.AsPublicUri方法的典型用法代码示例。如果您正苦于以下问题:C# DreamContext.AsPublicUri方法的具体用法?C# DreamContext.AsPublicUri怎么用?C# DreamContext.AsPublicUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DreamContext
的用法示例。
在下文中一共展示了DreamContext.AsPublicUri方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetServices
internal Yield GetServices(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
XDoc result = new XDoc("services");
result.WithXslTransform(context.AsPublicUri(context.Env.Self).At("resources", "services.xslt").Path);
lock(_services) {
result.Attr("count", _services.Count);
foreach(KeyValuePair<string, ServiceEntry> entry in _services) {
result.Start("service");
result.Elem("path", entry.Key);
result.Elem("uri", entry.Value.Uri);
if(entry.Value.Owner != null) {
result.Elem("uri.owner", entry.Value.Owner);
}
if(entry.Value.SID != null) {
result.Elem("sid", entry.Value.SID);
}
result.Elem("type", entry.Value.Service.GetType().FullName);
result.End();
}
}
response.Return(DreamMessage.Ok(result));
yield break;
}
示例2: GetServiceInfo
public virtual Yield GetServiceInfo(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
XDoc blueprint = Blueprint;
string title = blueprint["name"].AsText ?? "Service Blueprint";
XDoc result = new XDoc("html").Attr("xmlns", "http://www.w3.org/1999/xhtml")
.Start("head")
.Elem("title", title)
.Start("meta").Attr("http-equiv", "content-type").Attr("content", "text/html;charset=utf-8").End()
.Start("meta").Attr("http-equiv", "Content-Style-Type").Attr("content", "text/css").End()
.End();
if(blueprint.IsEmpty) {
result.Elem("body", "Missing service blueprint");
} else {
result.Start("body")
.Elem("h1", title)
.Start("p")
.Value(blueprint["copyright"].Contents)
.Value(" ")
.Start("a").Attr("href", blueprint["info"].Contents).Value("(more)").End()
.Value(" ")
.Start("a").Attr("href", Self.Uri.At("@blueprint").Path).Value("(blueprint)").End()
.End();
// show configuration information
XDoc config = blueprint["configuration"];
if(!config.IsEmpty) {
result.Elem("h2", "Configuration");
result.Start("ul");
foreach(XDoc entry in config["entry"]) {
result.Start("li");
if(entry["valuetype"].Contents != string.Empty) {
result.Value(string.Format("{0} = {1} : {2}", entry["name"].Contents, entry["valuetype"].Contents, entry["description"].Contents));
} else {
result.Value(string.Format("{0} : {1}", entry["name"].Contents, entry["description"].Contents));
}
result.End();
}
result.End();
}
// sort features by signature then verb
blueprint["features"].Sort(delegate(XDoc first, XDoc second) {
string[] firstPattern = first["pattern"].Contents.Split(new[] { ':' }, 2);
string[] secondPattern = second["pattern"].Contents.Split(new[] { ':' }, 2);
int cmp = firstPattern[1].CompareInvariantIgnoreCase(secondPattern[1]);
if(cmp != 0) {
return cmp;
}
return firstPattern[0].CompareInvariant(secondPattern[0]);
});
// display features
XDoc features = blueprint["features/feature"];
if(!features.IsEmpty) {
result.Elem("h2", "Features");
List<string> modifiers = new List<string>();
foreach(XDoc feature in features) {
modifiers.Clear();
// add modifiers
string modifier = feature["access"].AsText;
if(modifier != null) {
modifiers.Add(modifier);
}
modifier = feature["obsolete"].AsText;
if(modifier != null) {
modifiers.Add("OBSOLETE => " + modifier);
}
if(modifiers.Count > 0) {
modifier = " (" + string.Join(", ", modifiers.ToArray()) + ")";
} else {
modifier = string.Empty;
}
// check if feature has GET verb and no path parameters
string pattern = feature["pattern"].Contents;
if(pattern.StartsWithInvariantIgnoreCase(Verb.GET + ":") && (pattern.IndexOfAny(new[] { '{', '*', '?' }) == -1)) {
string[] parts = pattern.Split(new[] { ':' }, 2);
result.Start("h3")
.Start("a").Attr("href", context.AsPublicUri(Self.Uri.AtPath(parts[1])))
.Value(feature["pattern"].Contents)
.End()
.Value(modifier)
.End();
} else {
result.Elem("h3", feature["pattern"].Contents + modifier);
}
result.Start("p")
.Value(feature["description"].Contents)
.Value(" ")
.Start("a").Attr("href", feature["info"].Contents).Value("(more)").End();
XDoc paramlist = feature["param"];
if(!paramlist.IsEmpty) {
result.Start("ul");
foreach(XDoc param in paramlist) {
result.Start("li");
if(param["valuetype"].Contents != string.Empty) {
result.Value(string.Format("{0} = {1} : {2}", param["name"].Contents, param["valuetype"].Contents, param["description"].Contents));
} else {
result.Value(string.Format("{0} : {1}", param["name"].Contents, param["description"].Contents));
//.........这里部分代码省略.........
示例3: GetStatus
private Yield GetStatus(DreamContext context, DreamMessage request, Result<DreamMessage> response)
{
DateTime now = DateTime.UtcNow;
XDoc result = new XDoc("status");
result.WithXslTransform(context.AsPublicUri(context.Env.Self).At("resources", "status.xslt").Path);
XUri self = Self.Uri.With("apikey", context.GetParam("apikey", null));
// host information
double age = Math.Max((now - _created).TotalSeconds, 1);
result.Start("host").Attr("created", _created).Attr("age", age).Attr("requests", _requestCounter).Attr("rate", _requestCounter / age);
result.Elem("uri.local", _localMachineUri.ToString());
result.Elem("uri.public", _publicUri);
// host/aliases
result.Start("aliases").Attr("count", _aliases.Count).Attr("href", self.At("status", "aliases")).End();
// connections
result.Start("connections").Attr("count", _connectionCounter).Attr("limit", _connectionLimit).End();
// activities
lock(_activities) {
result.Start("activities").Attr("count", _activities.Count).Attr("href", self.At("status", "activities"));
foreach(Tuplet<DateTime, string> description in _activities.Values) {
result.Start("description").Attr("created", description.Item1).Attr("age", (now - description.Item1).TotalSeconds).Value(description.Item2).End();
}
result.End();
}
// infos
lock(_infos) {
result.Start("infos").Attr("count", _infos.Count);
foreach(KeyValuePair<string, Tuplet<int, string>> entry in _infos) {
result.Start("info").Attr("source", entry.Key).Attr("hits", entry.Value.Item1).Attr("rate", entry.Value.Item1 / age).Value(entry.Value.Item2).End();
}
result.End();
}
// host/services information
result.Start("services").Attr("count", _services.Count).Attr("href", self.At("services")).End();
// host/features
result.Start("features").Attr("href", self.At("status", "features")).End();
// host/cache
long size = 0;
int count = 0;
lock(_responseCache) {
foreach(Dictionary<object, DreamMessage> cache in _responseCache.Values) {
count += cache.Count;
foreach(DreamMessage message in cache.Values) {
size += message.ToBytes().LongLength;
}
}
}
result.Start("cache").Attr("count", count).Attr("size", size).Attr("hits", _responseCacheHits).Attr("misses", _responseCacheMisses).End();
// end host information
result.End();
// system information
result.Start("system");
// system/memory information
result.Elem("memory.used", GC.GetTotalMemory(false));
// system/thread information
int workerThreads;
int completionThreads;
int dispatcherThreads;
Async.GetAvailableThreads(out workerThreads, out completionThreads, out dispatcherThreads);
int maxWorkerThreads;
int maxCompletionThreads;
int maxDispatcherThreads;
Async.GetMaxThreads(out maxWorkerThreads, out maxCompletionThreads, out maxDispatcherThreads);
result.Elem("workerthreads.max", maxWorkerThreads);
result.Elem("workerthreads.used", maxWorkerThreads - workerThreads);
result.Elem("completionthreads.max", maxCompletionThreads);
result.Elem("completionthreads.used", maxCompletionThreads - completionThreads);
result.Elem("dispatcherthreads.max", maxDispatcherThreads);
result.Elem("dispatcherthreads.used", maxDispatcherThreads - dispatcherThreads);
// timer information
var taskTimerStats = TaskTimerFactory.GetStatistics();
result.Start("timers.queued").Attr("href", self.At("status", "timers")).Value(taskTimerStats.QueuedTimers).End();
result.Start("timers.pending").Attr("href", self.At("status", "timers")).Value(taskTimerStats.PendingTimers).End();
result.Elem("timers.counter", taskTimerStats.Counter);
result.Elem("timers.last", taskTimerStats.Last);
// rendez-vous events
result.Start("async").Attr("count", RendezVousEvent.PendingCounter + AResult.PendingCounter);
lock(RendezVousEvent.Pending) {
foreach(var entry in RendezVousEvent.Pending.Values) {
result.Start("details");
if(entry.Key != null) {
var dc = entry.Key.GetState<DreamContext>();
if(dc != null) {
result.Elem("verb", dc.Verb);
result.Elem("uri", dc.Uri);
}
}
//.........这里部分代码省略.........