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


C# AppDelegate类代码示例

本文整理汇总了C#中AppDelegate的典型用法代码示例。如果您正苦于以下问题:C# AppDelegate类的具体用法?C# AppDelegate怎么用?C# AppDelegate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AppDelegate类属于命名空间,在下文中一共展示了AppDelegate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Middleware

        public static AppDelegate Middleware(AppDelegate app)
        {
            return
                (env, result, fault) =>
                    app(
                        env,
                        (status, headers, body) =>
                        {
                            if (IsStatusWithNoNoEntityBody(status) ||
                                headers.ContainsKey("Content-Length") ||
                                headers.ContainsKey("Transfer-Encoding"))
                            {
                                result(status, headers, body);
                            }
                            else
                            {
                                var token = CancellationToken.None;
                                object obj;
                                if (env.TryGetValue(typeof(CancellationToken).FullName, out obj) && obj is CancellationToken)
                                    token = (CancellationToken)obj;

                                var buffer = new DataBuffer();
                                body(
                                    buffer.Add,
                                    ex =>
                                    {
                                        buffer.End(ex);
                                        headers["Content-Length"] = new[] { buffer.GetCount().ToString() };
                                        result(status, headers, buffer.Body);
                                    },
                                    token);
                            }
                        },
                        fault);
        }
开发者ID:ArloL,项目名称:gate,代码行数:35,代码来源:ContentLength.cs

示例2: Connection

 public Connection(IServerTrace trace, AppDelegate app, ISocket socket, Action<ISocket> disconnected)
 {
     _trace = trace;
     _app = app;
     _socket = socket;
     _disconnected = disconnected;
 }
开发者ID:friesencr,项目名称:dragonfly,代码行数:7,代码来源:Connection.cs

示例3: OAuthContext

 public OAuthContext(AppDelegate next, IDictionary<string, object> env, ResultDelegate result, Action<Exception> fault)
 {
     m_next = next;
      m_env = env;
      m_result = result;
      m_fault = fault;
 }
开发者ID:dustyburwell,项目名称:vow,代码行数:7,代码来源:OAuthContext.cs

示例4: Middleware

        public static AppDelegate Middleware(AppDelegate app)
        {
            return call =>
            {
                return app(call).Then<ResultParameters, ResultParameters>(
                    result =>
                    {
                        if (IsStatusWithNoNoEntityBody(result.Status)
                            || result.Headers.ContainsKey("Content-Length")
                            || result.Headers.ContainsKey("Transfer-Encoding"))
                        {
                            return TaskHelpers.FromResult(result);
                        }

                        if (result.Body == null)
                        {
                            result.Headers.SetHeader("Content-Length", "0");
                            return TaskHelpers.FromResult(result);
                        }

                        // Buffer the body
                        MemoryStream buffer = new MemoryStream();
                        return result.Body(buffer).Then<ResultParameters>(
                            () =>
                            {
                                buffer.Seek(0, SeekOrigin.Begin);
                                result.Headers.SetHeader("Content-Length", buffer.Length.ToString(CultureInfo.InvariantCulture));
                                result.Body = output => buffer.CopyToAsync(output);

                                return TaskHelpers.FromResult(result);
                            });

                    });
            };
        }
开发者ID:dragan,项目名称:gate,代码行数:35,代码来源:ContentLength.cs

示例5: Create

        public static IDisposable Create(AppDelegate app, int port, TextWriter output)
        {
            app = ExecutionContextPerRequest.Middleware(app);
            var endPoint = new IPEndPoint(IPAddress.Any, port);

            var schedulerDelegate = new NullSchedulerDelegate(output);
            var scheduler = KayakScheduler.Factory.Create(schedulerDelegate);

            var context = new Dictionary<string, object>
            {
                {"gate.Output", output},
            };
            var channel = new GateRequestDelegate(app, context);

            var server = KayakServer.Factory.CreateHttp(channel, scheduler);
            var listen = server.Listen(endPoint);

            var thread = new Thread(_ => scheduler.Start());
            thread.Start();

            return new Disposable(() =>
            {
                scheduler.Stop();
                thread.Join(5000);
                listen.Dispose();
                server.Dispose();
            });
        }
开发者ID:ArloL,项目名称:gate,代码行数:28,代码来源:ServerFactory.cs

示例6: Middleware

 public static AppDelegate Middleware(AppDelegate app)
 {
     return
         (call, callback) =>
             app(
                 call,
                 (result, error) =>
                 {
                     if (error != null ||
                         IsStatusWithNoNoEntityBody(result.Status) ||
                         result.Headers.ContainsKey("Content-Length") ||
                         result.Headers.ContainsKey("Transfer-Encoding"))
                     {
                         callback(result, error);
                     }
                     else
                     {
                         var buffer = new DataBuffer();
                         result.Body.Invoke(
                             buffer.Add,
                             ex =>
                             {
                                 buffer.End(ex);
                                 result.Headers.SetHeader("Content-Length", buffer.GetCount().ToString());
                                 result.Body = buffer.Body;
                                 callback(result, null);
                             },
                             call.CallDisposed);
                     }
                 });
 }
开发者ID:anurse,项目名称:gate,代码行数:31,代码来源:ContentLength.cs

示例7: Create

 public static WebServiceHost Create(Uri baseUri, AppDelegate app)
 {
     var host = new WebServiceHost(new GateWcfService(app), baseUri);
     host.AddServiceEndpoint(typeof (GateWcfService), new WebHttpBinding(), "");
     host.Open();
     return host;
 }
开发者ID:bvanderveen,项目名称:gate,代码行数:7,代码来源:GateWcfService.cs

示例8: Static

        public Static(AppDelegate app, string root = null, IEnumerable<string> urls = null)
        {
            this.app = app;

            if (root == null)
            {
                root = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "public");
            }

            if (!Directory.Exists(root))
            {
                throw new DirectoryNotFoundException(string.Format("Invalid root directory: {0}", root));
            }

            if (urls == null)
            {
                var rootDirectory = new DirectoryInfo(root);
                var files = rootDirectory.GetFiles("*").Select(fi => "/" + fi.Name);
                var directories = rootDirectory.GetDirectories().Select(di => "/" + di.Name);
                urls = files.Concat(directories);
            }

            this.urls = urls;

            fileServer = new FileServer(root);
        }
开发者ID:anurse,项目名称:gate,代码行数:26,代码来源:Static.cs

示例9: Server

 public Server(AppDelegate app, IPAddress ipAddress, int port)
 {
     _app = app;
     _ipAddress = ipAddress;
     _port = port;
     _listener = new TcpListener(_ipAddress, _port);
 }
开发者ID:markrendle,项目名称:Simple.WebServer,代码行数:7,代码来源:Server.cs

示例10: App

        static AppDelegate App(AppDelegate arg)
        {
            return call =>
            {
                ResultParameters result = new ResultParameters()
                {
                    Status = 200,
                    Headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase) { { "Content-Type", new[] { "text/plain" } } },
                    Properties = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase),
                    Body = stream =>
                    {
                        var bytes = Encoding.Default.GetBytes("This is a custom page");
                        stream.Write(bytes, 0, bytes.Length);

                        TaskCompletionSource<object> bodyTcs = new TaskCompletionSource<object>();
                        bodyTcs.TrySetResult(null);
                        return bodyTcs.Task;
                    }
                };

                TaskCompletionSource<ResultParameters> requestTcs = new TaskCompletionSource<ResultParameters>();
                requestTcs.TrySetResult(result);
                return requestTcs.Task;
            };
        }
开发者ID:dragan,项目名称:gate,代码行数:25,代码来源:Startup.cs

示例11: CollisionGame

        public CollisionGame()
        {
            // Set the title of the window
            Window.Title = "Cocos2D-XNA Tutorials: Collision Detection";

            graphics = new GraphicsDeviceManager(this);

            //#if MONOMAC
            //            Content.RootDirectory = "AngryNinjas/Content";
            //#else
            Content.RootDirectory = "Content";
            //#endif
            //
            //#if XBOX || OUYA
            //            graphics.IsFullScreen = true;
            //#else
            graphics.IsFullScreen = false;
            //#endif

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333 / 2);

            // Extend battery life under lock.
            //InactiveSleepTime = TimeSpan.FromSeconds(1);

            CCApplication application = new AppDelegate(this, graphics);
            Components.Add(application);
            //#if XBOX || OUYA
            //            CCDirector.SharedDirector.GamePadEnabled = true;
            //            application.GamePadButtonUpdate += new CCGamePadButtonDelegate(application_GamePadButtonUpdate);
            //#endif
        }
开发者ID:blueshirt13,项目名称:Cocos2D-XNA-Tutorials,代码行数:32,代码来源:CollisionGame.cs

示例12: Connection

 public Connection(IFireflyService services, AppDelegate app, ISocket socket, Action<ISocket> disconnected)
 {
     _services = services;
     _app = app;
     _socket = socket;
     _socketSender = new SocketSender(_services, _socket);
     _disconnected = disconnected;
 }
开发者ID:ktairov,项目名称:firefly,代码行数:8,代码来源:Connection.cs

示例13: Start

        public static void Start(ISchedulerDelegate schedulerDelegate, IPEndPoint listenEP, AppDelegate app, IDictionary<string, object> context)
        {
            var scheduler = KayakScheduler.Factory.Create(schedulerDelegate);
            var server = KayakServer.Factory.CreateGate(app, scheduler, context);

            using (server.Listen(listenEP))
                scheduler.Start();
        }
开发者ID:bvanderveen,项目名称:gate,代码行数:8,代码来源:HttpServerExtensions.cs

示例14: Middleware

        public static AppDelegate Middleware(AppDelegate app)
        {
            return call =>
            {
                Action<Exception, Action<byte[]>> showErrorMessage =
                    (ex, write) =>
                        ErrorPage(call, ex, text =>
                        {
                            var data = Encoding.ASCII.GetBytes(text);
                            write(data);
                        });

                Func<Exception, Task<ResultParameters>> showErrorPage = ex =>
                {
                    var response = new Response() { Status = "500 Internal Server Error", ContentType = "text/html" };
                    showErrorMessage(ex, data => response.Write(data));
                    return response.EndAsync();
                };

                try
                {
                    return app(call)
                        .Then(result =>
                        {
                            if (result.Body != null)
                            {
                                var nestedBody = result.Body;
                                result.Body = stream =>
                                {
                                    try
                                    {
                                        return nestedBody(stream).Catch(
                                            errorInfo =>
                                            {
                                                showErrorMessage(errorInfo.Exception, data => stream.Write(data, 0, data.Length));
                                                return errorInfo.Handled();
                                            });
                                    }
                                    catch (Exception ex)
                                    {
                                        showErrorMessage(ex, data => stream.Write(data, 0, data.Length));
                                        return TaskHelpers.Completed();
                                    }
                                };
                            }
                            return result;
                        })
                        .Catch(errorInfo =>
                        {
                            return errorInfo.Handled(showErrorPage(errorInfo.Exception).Result);
                        });
                }
                catch (Exception exception)
                {
                    return showErrorPage(exception);
                }
            };
        }
开发者ID:dragan,项目名称:gate,代码行数:58,代码来源:ShowExceptions.cs

示例15: Middleware

        public static AppDelegate Middleware(AppDelegate app, Action<Exception> logError)
        {
            return (env, result, fault) =>
            {
                Action<Exception> onError = ex =>
                {
                    logError(ex);
                    result(
                        "500 Internal Server Error",
                        ResponseHeaders,
                        (write, end, cancel) =>
                        {
                            try
                            {
                                write(Body, null);
                                end(null);
                            }
                            catch (Exception error)
                            {
                                end(error);
                            }
                        });
                };

                try
                {
                    app(
                        env,
                        (status, headers, body) =>
                        {
                            // errors send from inside the body are
                            // logged, but not passed to the host. it's too
                            // late to change the status or send an error page.
                            onError = logError;
                            result(
                                status,
                                headers,
                                (write, end, cancel) =>
                                    body(
                                        write,
                                        ex =>
                                        {
                                            if (ex != null)
                                            {
                                                logError(ex);
                                            }
                                            end(ex);
                                        },
                                        cancel));
                        },
                        ex => onError(ex));
                }
                catch (Exception ex)
                {
                    onError(ex);
                }
            };
        }
开发者ID:ArloL,项目名称:gate,代码行数:58,代码来源:ErrorPage.cs


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