コード例 #1
0
ファイル: HttpSession.cs プロジェクト: blockspacer/niveum
        private void OnExecute(HttpVirtualTransportServerHandleResult r, Action OnSuccess, Action OnFailure)
        {
            if (r.OnCommand)
            {
                var CommandName = r.Command.CommandName;

                Action a = () =>
                {
                    var CurrentTime = DateTime.UtcNow;
                    Context.RequestTime = CurrentTime;
                    if (Server.ServerContext.EnableLogPerformance)
                    {
                        var sw = new Stopwatch();
                        sw.Start();
                        Action OnSuccessInner = () =>
                        {
                            sw.Stop();
                            Server.ServerContext.RaiseSessionLog(new SessionLogEntry {
                                Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "Time", Name = CommandName, Message = String.Format("{0}μs", (sw.ElapsedTicks * 1000000) / Stopwatch.Frequency)
                            });
                            ssm.NotifyWrite(new Unit());
                            OnSuccess();
                        };
                        Action <Exception> OnFailureInner = ex =>
                        {
                            RaiseUnknownError(CommandName, ex, new StackTrace(true));
                            OnSuccess();
                        };
                        r.Command.ExecuteCommand(OnSuccessInner, OnFailureInner);
                    }
                    else
                    {
                        Action OnSuccessInner = () =>
                        {
                            ssm.NotifyWrite(new Unit());
                            OnSuccess();
                        };
                        Action <Exception> OnFailureInner = ex =>
                        {
                            RaiseUnknownError(CommandName, ex, new StackTrace(true));
                            OnSuccess();
                        };
                        r.Command.ExecuteCommand(OnSuccessInner, OnFailureInner);
                    }
                };

                ssm.AddToActionQueue(a);
            }
            else if (r.OnBadCommand)
            {
                var CommandName = r.BadCommand.CommandName;

                NumBadCommands += 1;

                // Maximum allowed bad commands exceeded.
                if (Server.MaxBadCommands != 0 && NumBadCommands > Server.MaxBadCommands)
                {
                    RaiseError(CommandName, "Too many bad commands, closing transmission channel.");
                    OnFailure();
                }
                else
                {
                    RaiseError(CommandName, "Not recognized.");
                    OnSuccess();
                }
            }
            else if (r.OnBadCommandLine)
            {
                var CommandLine = r.BadCommandLine.CommandLine;

                NumBadCommands += 1;

                // Maximum allowed bad commands exceeded.
                if (Server.MaxBadCommands != 0 && NumBadCommands > Server.MaxBadCommands)
                {
                    RaiseError("", String.Format(@"""{0}"": Too many bad commands, closing transmission channel.", CommandLine));
                    OnFailure();
                }
                else
                {
                    RaiseError("", String.Format(@"""{0}"":  recognized.", CommandLine));
                    OnSuccess();
                }
            }
            else
            {
                throw new InvalidOperationException();
            }
        }