当前位置: 首页>>代码示例>>C#>>正文


C# HttpServer.Subscribe方法代码示例

本文整理汇总了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);
            });
        }
开发者ID:rfutata,项目名称:WorkflowServer,代码行数:38,代码来源:ServerHelper.cs

示例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();
            }
        }
开发者ID:rfutata,项目名称:WorkflowServer,代码行数:72,代码来源:Program.cs


注:本文中的HttpServer.Subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。