本文整理汇总了C#中HttpServer.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.Subscribe方法的具体用法?C# HttpServer.Subscribe怎么用?C# HttpServer.Subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServer
的用法示例。
在下文中一共展示了HttpServer.Subscribe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SubscribeProcessing
public static IDisposable SubscribeProcessing(HttpServer server, WorkflowServer workflowserver)
{
return server.Subscribe(ctx =>
{
var path = ctx.Request.LocalPath.ToLower();
Response response = null;
if (path == "/workflowapi")
{
if (!string.IsNullOrWhiteSpace(workflowserver.Parameters.ApiKey) &&
ctx.Request.HttpParams.QueryString["apikey"] != workflowserver.Parameters.ApiKey)
{
ctx.Respond(new StringResponse("APIKEY is not valid!"));
return;
}
if (workflowserver.Parameters.Log != null)
workflowserver.Parameters.Log(string.Format("Workflow API {0} ({2}): {1}",
ctx.Request.HttpMethod, ctx.Request.RawUrl, ctx.Request.ClientAddress));
response = workflowserver.WorkflowApiProcessing(ref ctx);
}
else if (path == "/designerapi")
{
if (workflowserver.Parameters.Log != null)
workflowserver.Parameters.Log(string.Format("Designer API {0} ({2}): {1}",
ctx.Request.HttpMethod, ctx.Request.RawUrl, ctx.Request.ClientAddress));
response = workflowserver.DesignerApiProcessing(ref ctx);
}
else
{
if (workflowserver.Parameters.Log != null)
workflowserver.Parameters.Log(string.Format("Get file ({1}): {0}", ctx.Request.RawUrl, ctx.Request.ClientAddress));
response = BackEndProcessing(ref ctx, workflowserver.Parameters);
}
ctx.Respond(response);
});
}
示例2: Main
static void Main(string[] args)
{
string defaulturl = "http://*:8078/";
string url = string.Empty;
if (args.Length == 0)
{
Console.Write(string.Format("Enter url for HTTPLister (example '{0}'):", defaulturl));
url = Console.ReadLine();
if (string.IsNullOrWhiteSpace(url))
url = defaulturl;
}
else
{
url = args[0];
}
using (var server = new HttpServer(url))
{
Console.WriteLine(string.Format("Waiting for a connection on {0}...", url));
var listeners = server.Subscribe(ctx =>
{
var request = ctx.Request;
var type = ctx.Request.HttpParams.FormParams["type"];
Console.WriteLine(string.Format("Request {0} form {1} {2}: {3}",
ctx.Request.HttpMethod, ctx.Request.ClientAddress, ctx.Request.LocalPath, type));
string data = string.Empty;
switch (type)
{
case "getactions":
data = "[\"Action1\", \"Action2\", \"Action3\"]";
break;
case "executeaction":
break;
case "executecondition":
data = "true";
break;
case "getrules":
data = "[\"Rule1\", \"Rule2\", \"Rule3\"]";
break;
case "check":
data = "true";
break;
case "getidentities":
data = "[\"UserID1\", \"UserID2\", \"UserID3\"]";
break;
case "generate":
data = request.HttpParams.FormParams["scheme"];
break;
default:
Console.WriteLine(string.Format("Response to {0}: Unknown type", ctx.Request.ClientAddress));
break;
}
ctx.Respond(new StringResponse(HttpUtility.UrlEncode(data)));
Console.WriteLine(string.Format("Response to {0}: {1}", ctx.Request.ClientAddress, data));
});
while (true)
{
Console.WriteLine("For exit please enter '^Q'.");
var command = Console.ReadLine();
if (command.ToUpper() == "^Q")
break;
}
listeners.Dispose();
}
}