Exemplo n.º 1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     _writer                = new StreamWriter(_ms);
     _writer.AutoFlush      = true;
     _watcher               = new StreamWatcher(_ms);
     _watcher.DataReceived += _watcher_ReceivedData;
 }
Exemplo n.º 2
0
        public override void BeginRequest()
        {
            //如果模块不可用直接就返回了
            if (!config.IsEnabled)
            {
                return;
            }
            //处理是否为Debug的请求
            base.HandleDebugInfo();
            if (base.DebugRequest)
            {
                return;
            }

            //如果启用URL过滤器
            if (((ApiCallGathererConfig)config).UseFilter && ((ApiCallGathererConfig)config).UrlFilter != null)
            {
                //如果不是需要处理的URL
                if (!((ApiCallGathererConfig)config).UrlFilter.IsAllowed(context.Request.RawUrl))
                {
                    this.skipRequest = true;
                    return;
                }
            }
            //启动定时器
            watch = new Stopwatch();
            watch.Start();
            ////添加输出流观察器
            StreamWatcher streamWatcher = new StreamWatcher(context.Response.Filter, writeBytes);

            context.Response.Filter = streamWatcher;
        }
Exemplo n.º 3
0
        private void DoGBAK()
        {
            textBox1.Clear();
            string args = txtGBAKParameters.Text.Replace("****", _dbReg.Password);
            var    psi  = new ProcessStartInfo($@"{_dbReg.FirebirdBinaryPath}\gbak.exe", args);

            psi.RedirectStandardOutput = true;
            psi.UseShellExecute        = false;
            psi.CreateNoWindow         = true;
            textBox1.AppendText($@"Starting of GBAK{Environment.NewLine}");

            backgroundWorker1 = new BackgroundWorker();

            backgroundWorker1.WorkerReportsProgress = true;
            backgroundWorker1.ProgressChanged      += backgroundWorker1_ProgressChanged;
            backgroundWorker1.DoWork                    += backgroundWorker1_DoWork;
            backgroundWorker1.RunWorkerCompleted        += backgroundWorker1_RunWorkerCompleted;
            backgroundWorker1.WorkerSupportsCancellation = true;
            backgroundWorker1.RunWorkerAsync();


            ps                     = new Process();
            ps.StartInfo           = psi;
            ps.EnableRaisingEvents = true;
            ps.Exited             += Ps_Exited;
            ps.Start();

            sw = new StreamWatcher(ps.StandardOutput.BaseStream);
            sw.MessageAvailable += Sw_MessageAvailable;
        }
Exemplo n.º 4
0
            public void Close()
            {
                _streamWatcher.DataAvailible -= StreamWatcherOnDataAvailible;
                _streamWatcher.Stop();
                _streamWatcher = null;

                _socket.Dispose();
            }
Exemplo n.º 5
0
 private void Ps_Exited(object sender, EventArgs e)
 {
     backgroundWorker1.CancelAsync();
     if (sw != null)
     {
         sw.MessageAvailable -= Sw_MessageAvailable;
     }
     sw = null;
 }
Exemplo n.º 6
0
            public async Task OpenAsync()
            {
                try
                {
                    await _socket.ConnectAsync(_PeerInformation.HostName, "1");

                    _streamWatcher = new StreamWatcher(_socket.InputStream);
                    _streamWatcher.DataAvailible += StreamWatcherOnDataAvailible;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                }
            }
Exemplo n.º 7
0
        public override void EndRequest()
        {
            //当模块不被启用, DEBUG请求 或是需要跳过的请求时, 直接Return
            if (!config.IsEnabled || DebugRequest || this.skipRequest)
            {
                return;
            }

            long duration = 0L;

            //获取执行时间
            if (watch.IsRunning)
            {
                watch.Stop();
                duration = watch.ElapsedMilliseconds;
            }
            watch.Reset();

            //获取请求地址
            string callUrl      = base.GetPureUrl(context.Request.RawUrl);
            long   requestSize  = context.Request.CountRequestSize();
            long   responseSize = 0;

            //当IIS版本为IIS7和IIS8时
            if (IISVersion == WebServerType.IIS7 || IISVersion == WebServerType.IIS8)
            {
                responseSize = context.Response.GetCombineHeaders(true).Length;
            }

            if (context.Response.Filter is StreamWatcher)
            {
                StreamWatcher watcher = (StreamWatcher)context.Response.Filter;
                responseSize += watcher.Length;
            }
            else if (context.Response.Filter is GZipStream || context.Response.Filter is DeflateStream)
            {
                this.writeBytes.ForEach(o => { responseSize += o; });
            }

            string accesstoken = "", callAccesstoken = "";
            int    callAppId = 0;

            GetAccessTokenAndCallAccessToken(out accesstoken, out callAccesstoken, out callAppId);

            //推送数据
            GathererContext.Current.AppendApiCall(
                accesstoken, callAccesstoken, callAppId,
                callUrl, context.Response.StatusCode,
                responseTime: duration, requestSize: requestSize, responseSize: responseSize);
        }
Exemplo n.º 8
0
    public void Init(HttpApplication context)
    {
        context.BeginRequest += (o, e) =>
        {
            _watcher = new StreamWatcher(context.Response.Filter);
            context.Response.Filter = _watcher;
        };


        context.EndRequest += (o, e) =>
        {
            string value = _watcher.ToString();
            Trace.WriteLine(regex.Match(value).Value.Trim());
        };
    }
        private void Context_BeginRequest(object sender, EventArgs e)
        {
            _watcher = new StreamWatcher(_context.Response.Filter);
            _context.Response.Filter = _watcher;

            StringBuilder lstrHeader = new StringBuilder();

            foreach (string h in _context.Request.Headers.AllKeys)
            {
                lstrHeader.AppendLine(h + ":" + _context.Request.Headers.GetValues(h)[0]);
            }
            Guid lstrRequestID = Guid.NewGuid();

            RequestID = lstrRequestID.ToString();
            _context.Response.Headers.Add("RequestID", RequestID);
            string lstrBody = GetRequestBody(_context.Request);

            System.Threading.ThreadPool.QueueUserWorkItem(_ => Logger.LogRequest(_context.Request.Url.ToString(), lstrHeader.ToString(), lstrBody, lstrRequestID));
        }
Exemplo n.º 10
0
        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;

            if (context.Request.RequestType.Equals("post", StringComparison.CurrentCultureIgnoreCase))
            {
                System.Diagnostics.Debug.WriteLine("Total-Bytes:" + context.Request.TotalBytes);
                System.Diagnostics.Debug.WriteLine("Input-Bytes:" + context.Request.InputStream.Length);
                System.Diagnostics.Debug.WriteLine("Count-Request-Size:" + CountRequestSize(context.Request));
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Total-Bytes:" + context.Request.TotalBytes);
                System.Diagnostics.Debug.WriteLine("Count-Request-Size:" + CountRequestSize(context.Request));
            }

            watcher = new StreamWatcher(context.Response.Filter);
            context.Response.Filter = watcher;
        }
Exemplo n.º 11
0
        private void DoGBAK()
        {
            FileInfo fi = new FileInfo($@"{_dbReg.GetFirebirdBinaryPath()}\gbak.exe");

            if (!fi.Exists)
            {
                object[] p = { fi.FullName, Environment.NewLine };
                SEMessageBox.ShowMDIDialog(FbXpertMainForm.Instance(), "FileNotExistsCaption", "FileNotExists", FormStartPosition.CenterScreen, SEMessageBoxButtons.OK, SEMessageBoxIcon.Exclamation, null, p);
                return;
            }
            fctGBAKOutput.Clear();
            string args = txtGBAKParameters.Text.Replace("****", _dbReg.Password);
            var    psi  = new ProcessStartInfo($@"{_dbReg.GetFirebirdBinaryPath()}\gbak.exe", args);

            psi.RedirectStandardOutput = true;
            psi.RedirectStandardError  = true;
            psi.UseShellExecute        = false;
            psi.CreateNoWindow         = true;
            fctGBAKOutput.AppendText($@"Starting of GBAK{Environment.NewLine}");

            backgroundWorker1 = new BackgroundWorker();
            backgroundWorker1.WorkerReportsProgress = true;
            backgroundWorker1.ProgressChanged      += backgroundWorker1_ProgressChanged;
            backgroundWorker1.DoWork                    += backgroundWorker1_DoWork;
            backgroundWorker1.RunWorkerCompleted        += backgroundWorker1_RunWorkerCompleted;
            backgroundWorker1.WorkerSupportsCancellation = true;
            backgroundWorker1.RunWorkerAsync();

            ps                     = new Process();
            ps.StartInfo           = psi;
            ps.EnableRaisingEvents = true;
            ps.Exited             += Ps_Exited;

            ps.Start();
            sw = new StreamWatcher(ps.StandardOutput.BaseStream);
            sw.MessageAvailable       += Sw_MessageAvailable;
            sw_error                   = new StreamWatcher(ps.StandardError.BaseStream);
            sw_error.MessageAvailable += Sw_MessageAvailable;
        }
Exemplo n.º 12
0
 protected UnixInputDriver(string device)
 {
     Device        = device;
     _eventWatcher = new StreamWatcher <EvEvent>(File.OpenRead(Device), 16);
     _eventWatcher.DataAvailable += DataAvailable;
 }
Exemplo n.º 13
0
        public override void BeginRequest()
        {
            //如果模块不可用直接就返回了
            if (!config.IsEnabled)
                return;
            //处理是否为Debug的请求
            base.HandleDebugInfo();
            if (base.DebugRequest)
                return;

            //如果启用URL过滤器
            if (((ApiCallGathererConfig)config).UseFilter && ((ApiCallGathererConfig)config).UrlFilter != null)
            {
                //如果不是需要处理的URL
                if (!((ApiCallGathererConfig)config).UrlFilter.IsAllowed(context.Request.RawUrl))
                {
                    this.skipRequest = true;
                    return;
                }
            }
            //启动定时器
            watch = new Stopwatch();
            watch.Start();
            ////添加输出流观察器
            StreamWatcher streamWatcher = new StreamWatcher(context.Response.Filter, writeBytes);
            context.Response.Filter = streamWatcher;
        }