Ejemplo n.º 1
0
        public Task Invoke(HttpContext context)
        {
            var options           = context.RequestServices.GetRequiredService <IOptions <SessionOptions> >();
            var sessionMiddleware = new SessionMiddleware(_next, _loggerFactory, _dataProtectionProvider, _sessionStore, options);

            return(sessionMiddleware.Invoke(context));
        }
Ejemplo n.º 2
0
 public virtual ProxyBuilder UseSession(bool distributed = false, IErrorHandling errorHandling = null)
 {
     _sessionMiddleware = new SessionMiddleware(_configuration.SessionHandler, errorHandling ?? _configuration.ErrorHandling)
     {
         UseDistributedSession = distributed
     };
     return(this);
 }
Ejemplo n.º 3
0
 public override void Dispose()
 {
     lock (this) {
         base.Dispose ();
         if (_server != null) _server.Dispose ();
         if (_app != null) _app.Dispose ();
         if (_sessionMiddleware != null) _sessionMiddleware.Dispose ();
         _server = null;
         _app = null;
         _sessionMiddleware = null;
     }
 }
Ejemplo n.º 4
0
 DebugNode(int idx, Interrupters ints, ITcpListener listener, IDatagramEventSocket bindedDgramSock, IPEndPoint bindTcpEp, IPEndPoint bindUdpEp, int gw_port, string dbpath)
     : base(ints, bindedDgramSock, listener, dbpath, (ushort)bindUdpEp.Port, (ushort)bindTcpEp.Port)
 {
     _idx = idx;
     _bindTcpEP = bindTcpEp;
     _imPrivateKey = ECKeyPair.Create (DefaultAlgorithm.ECDomainName);
     _imPublicKey = Key.Create (_imPrivateKey);
     _name = "Node-" + idx.ToString ("x");
     _app = new WebApp (this, ints);
     _is_gw = gw_port > 0;
     if (_is_gw) {
         _sessionMiddleware = new SessionMiddleware (MMLC.CreateDBConnection, _app);
         _server = HttpServer.CreateEmbedHttpServer (_sessionMiddleware, null, true, true, false, gw_port, 16);
     }
 }
Ejemplo n.º 5
0
        public void Run()
        {
            _running = true;
            try {
                if (!LoadConfig (_config)) {
                    throw new ConfigFileInitializedException ();
                }

                ushort bindUdp = (ushort)_config.GetValue<int> (ConfigFields.NetBindUdp);
                ushort bindTcp = (ushort)_config.GetValue<int> (ConfigFields.NetBindTcp);
                int gwBindTcp = _config.GetValue<int> (ConfigFields.GwBindTcp);
                _url = string.Format ("http://127.0.0.1:{0}/", gwBindTcp);
                using (IDatagramEventSocket dgramSock = UdpSocket.CreateIPv4 ())
                using (TcpListener listener = new TcpListener ()) {
                    dgramSock.Bind (new IPEndPoint (IPAddress.Any, bindUdp));
                    listener.Bind (new IPEndPoint (IPAddress.Any, bindTcp));
                    listener.ListenStart ();
                    CreateDatabaseConnectionDelegate create_session_db = delegate () {
                        IDbConnection connection = new Mono.Data.Sqlite.SqliteConnection ();
                        connection.ConnectionString = "Data Source=http-session.sqlite,DateTimeFormat=Ticks,Pooling=False";
                        connection.Open ();
                        return connection;
                    };
                    using (Interrupters ints = new Interrupters ())
                    using (Node node = new Node (ints, dgramSock, listener, "database.sqlite", bindUdp, bindTcp))
                    using (WebApp app = new WebApp (node, ints))
                    using (SessionMiddleware mid1 = new SessionMiddleware (create_session_db, app))
                    using (HttpServer.CreateEmbedHttpServer (mid1, null, true, true, _config.GetValue<bool> (ConfigFields.GwBindAny), gwBindTcp, 16)) {
                        InitNodeList initNodeList = new InitNodeList (node.PortOpenChecker);
                        _app = app;
                        _node = node;
                        _startupWaitHandle.Set ();
                        if (Started != null) {
                            try {
                                Started (this, EventArgs.Empty);
                            } catch {}
                        }
                        initNodeList.Load ();
                        app.ExitWaitHandle.WaitOne ();
                        initNodeList.Save ();
                        app.CreateStatisticsXML ().Save ("statistics-" + DateTime.Now.ToString ("yyyyMMddHHmmss") + ".xml");
                        _waitHandle.Set ();
                    }
                }
            } finally {
                _running = false;
                _startupWaitHandle.Set ();
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 得到Session信息
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public static IDictionary <String, Object> GetSession(this IOwinContext context)
 {
     return(SessionMiddleware.GetSession(context));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 得到Session Id信息
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public static string GetSessionId(this IOwinContext context)
 {
     return(SessionMiddleware.GetSessionId(context));
 }