Пример #1
0
 public SessionContext(SessionServer sessionServer)
 {
     Token      = sessionServer.SessionToken.Token;
     ExpiryTime = DateTime.Now.AddSeconds(GetSessionTimeout(sessionServer));
     UserId     = GetUserId(sessionServer);
     SetUser(sessionServer.GetUserReference());
 }
Пример #2
0
        private static int GetUserId(SessionServer sessionServer)
        {
            if (sessionServer.UserCompany != null && sessionServer.UserApiKey == null && sessionServer.UserPerson == null)
            {
                Debug.Assert(sessionServer.UserCompany.Id != null, ErrorSessionserverUsercompanyIdNull);

                return(sessionServer.UserCompany.Id.Value);
            }
            else if (sessionServer.UserPerson != null && sessionServer.UserApiKey == null && sessionServer.UserCompany == null)
            {
                Debug.Assert(sessionServer.UserPerson.Id != null, ErrorsessionserverUserpersonIdNull);

                return(sessionServer.UserPerson.Id.Value);
            }
            else if (sessionServer.UserApiKey != null && sessionServer.UserCompany == null && sessionServer.UserPerson == null)
            {
                Debug.Assert(sessionServer.UserApiKey.Id != null, ErrorSessionserverUserapikeyIdNull);

                return(sessionServer.UserApiKey.Id.Value);
            }
            else
            {
                throw new BunqException(ErrorCouldNotDetermineUserId);
            }
        }
Пример #3
0
 /// <summary>
 /// Summary:
 /// Performs application-defined tasks associated with freeing, releasing, or
 /// resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (_localServer != null)
     {
         _localServer.Dispose();
         _localServer = null;
     }
 }
Пример #4
0
        /// <summary>
        /// 获取SessionServer的实例
        /// </summary>
        /// <returns></returns>
        public static ISessionServer GetSessionServer()
        {
            ISessionServer sessionServer = CallContext.LogicalGetData("SessionServer") as ISessionServer;

            if (sessionServer == null)
            {
                sessionServer = new SessionServer();
                CallContext.LogicalSetData("SessionServer", sessionServer);
            }
            return(sessionServer);
        }
Пример #5
0
    Action <IProtocol, TcpClientHandler> createAction(IProtocol dummyProtocol)
    {
        Action <IProtocol, TcpClientHandler> action = null;

        if (dummyProtocol is Login)
        {
            action = (IProtocol protocol, TcpClientHandler handler) => {
                var temp = protocol as Login;
                SessionServer.GetInstance().SendPacketAll(protocol);
            };
        }

        return(action);
    }
Пример #6
0
        private static double GetSessionTimeout(SessionServer sessionServer)
        {
            if (sessionServer.UserCompany != null && sessionServer.UserCompany.SessionTimeout != null)
            {
                return((double)sessionServer.UserCompany.SessionTimeout);
            }

            if (sessionServer.UserPerson != null && sessionServer.UserPerson.SessionTimeout != null)
            {
                return((double)sessionServer.UserPerson.SessionTimeout);
            }

            return(SESSION_TIMEOUT_DEFAULT);
        }
Пример #7
0
        static server()
        {
            PersonFetchHandler handler = personId => {
                return(new Person {
                    Id = 1,
                    Enabled = true,
                    Name = "刘铭",
                    Sex = 1,
                    Username = "******"
                });
            };

            SessionSington = new SessionServer(handler);
        }
Пример #8
0
    static void Main(string[] args)
    {
        ProtocolManager.GetInstance().Register();
        ProtocolHandler.GetInstance().Register();
        SessionServer.GetInstance().Start();

        bool gameRunning = true;

        //ThreadManager.GetInstance().RegisterWork(() => {
        //    Console.WriteLine("Test");
        //});

        while (gameRunning)
        {
        }
    }
Пример #9
0
 private static double GetSessionTimeout(SessionServer sessionServer)
 {
     if (sessionServer.UserApiKey != null && sessionServer.UserCompany == null && sessionServer.UserPerson == null)
     {
         return(GetSesisonTimeOutForUser(sessionServer.UserApiKey.RequestedByUser.GetReferencedObject()));
     }
     else if (sessionServer.UserCompany != null && sessionServer.UserApiKey == null && sessionServer.UserPerson == null)
     {
         return(GetSesisonTimeOutForUser(sessionServer.UserCompany));
     }
     else if (sessionServer.UserPerson != null && sessionServer.UserApiKey == null && sessionServer.UserCompany == null)
     {
         return(GetSesisonTimeOutForUser(sessionServer.UserPerson));
     }
     else
     {
         throw new BunqException(ErrorCouldNotDetermineSessionTimeout);
     }
 }
Пример #10
0
        static server()
        {
            PersonFetchHandler handler = personId => {
                return(new Person {
                    Id = 1,
                    Enabled = true,
                    Name = "刘铭",
                    Sex = 1,
                    Username = "******"
                });
            };

            SSOLoginHandler ssoHandler = (user, pwd) =>
            {
                return(1);
            };

            SessionSington = new SessionServer(handler, ssoHandler, "123456", null);
        }
Пример #11
0
        public async Task <BunqResponse> Initialize(string secret)
        {
            var data = new SessionServer()
            {
                Secret = secret,
            };

            var request = new HttpRequestMessage(HttpMethod.Post, ENDPOINT_URL_POST)
            {
                Content = new StringContent(BunqJsonConvert.SerializeObject(data), Encoding.UTF8),
            };

            var response = await Client.BunqSendAsync(request);

            var id         = response.Get <Model.BunqId>();
            var token      = response.Get <Model.InstallationToken>();
            var userPerson = response.Get <Model.UserPerson>();

            return(response);
        }
Пример #12
0
        /**
         * Class constructor
         */
        public Client(TransportClient transport, IClientListener clientListener)
        {
            this.clientListener = clientListener;

            dispatcher = new ChannelDispatcher();

            transport.SetChannelDispatcher(dispatcher);

            surfaceServer = new SurfaceServer(transport, this);
            dispatcher.RegisterChannel(surfaceServer);

            sessionServer = new SessionServer(transport, this);
            dispatcher.RegisterChannel(sessionServer);

            inputServer = new InputServer(transport, this);
            dispatcher.RegisterChannel(inputServer);

            transport.StartThread();

            dispatcher.OnConnect();
        }
Пример #13
0
        public void Stop()
        {
            lock (MainController.GetInstance())
            {
                if (confTimer != null)
                {
                    confTimer.Enabled = false;
                }

                if (Configuration.BlockScreenShot)
                {
                    ScreenShotContoller.Stop();
                }

                MyDLPEP.MiniFilterController.GetInstance().Stop();

                Engine.Stop();

                SessionServer.Stop();

                if (Configuration.UsbSerialAccessControl)
                {
                    Core.USBController.Deactive();
                }

                if (Configuration.PrinterMonitor)
                {
                    Service.PrinterController.getInstance().Stop();
                }

                if (Configuration.RemovableStorageEncryption)
                {
                    DiskCryptor.StopDcrypt();
                }

                Logger.GetInstance().Info("mydlpepwin service stopped");
            }
        }
Пример #14
0
        private static int GetUserId(SessionServer sessionServer)
        {
            if (sessionServer.UserCompany != null)
            {
                Debug.Assert(sessionServer.UserCompany.Id != null,
                             FIELD_ERROR_SESSION_SERVER_USER_COMPANY_ID_NULL);

                return(sessionServer.UserCompany.Id.Value);
            }

            if (sessionServer.UserPerson != null)
            {
                Debug.Assert(sessionServer.UserPerson.Id != null,
                             FIELD_ERROR_SESSION_SERVER_USER_PERSON_ID_NULL);

                return(sessionServer.UserPerson.Id.Value);
            }

            if (sessionServer.UserApiKey != null)
            {
                Debug.Assert(sessionServer.UserApiKey.Id != null,
                             FIELD_ERROR_SESSION_SERVER_USER_API_KEY_ID_NULL);

                return(sessionServer.UserApiKey.Id.Value);
            }

            if (sessionServer.UserPaymentServiceProvider != null)
            {
                Debug.Assert(
                    sessionServer.UserPaymentServiceProvider.Id != null,
                    FIELD_ERROR_SESSION_SERVER_USER_PAYMENT_SERVICE_PROVIDER_KEY_ID_NULL
                    );

                return(sessionServer.UserPaymentServiceProvider.Id.Value);
            }

            throw new BunqException(FIELD_ERROR_COULD_NOT_DETERMINE_USER_ID);
        }
Пример #15
0
        private static double GetSessionTimeout(SessionServer sessionServer)
        {
            if (sessionServer.UserApiKey != null)
            {
                return(GetSessionTimeOutForUser(sessionServer.UserApiKey.RequestedByUser.GetReferencedObject()));
            }

            if (sessionServer.UserCompany != null)
            {
                return(GetSessionTimeOutForUser(sessionServer.UserCompany));
            }

            if (sessionServer.UserPerson != null)
            {
                return(GetSessionTimeOutForUser(sessionServer.UserPerson));
            }

            if (sessionServer.UserPaymentServiceProvider != null)
            {
                return(GetSessionTimeOutForUser(sessionServer.UserPaymentServiceProvider));
            }

            throw new BunqException(FIELD_ERROR_COULD_NOT_DETERMINE_SESSION_TIMEOUT);
        }
Пример #16
0
        internal RequestHandle(IPlugin plugin)
        {
            this._plugin = plugin;


            PersonFetchHandler ph = a =>
            {
                return(new Person
                {
                    Id = a,
                    Name = "用户A"
                });
            };

            SSOLoginHandler lh = (usr, pwd) =>
            {
                return(1);
            };

            ISessionSet set = SessionManager.GetDefaultSessionSet();

            this._serve = new SessionServer(set, ph, lh, "123456", "tmpsso");
            this._serve.RegisterClient("http://localhost:8001/sso_api");
        }
Пример #17
0
 public SessionServerResponse(SessionServer server, string communicateToken)
 {
     this._server           = server;
     this._communicateToken = communicateToken;
 }
Пример #18
0
 /// <summary>
 /// Constructor for the provider to initialize the Session Server with the specified parameters
 /// </summary>
 /// <param name="sessionTimeOut">The timeout to expire the session, in minutes</param>
 /// <param name="pollingSeconds">The seconds to poll the sessions to expire</param>
 /// <param name="connStringName">The connection string name</param>
 public LocalSharedSessionServerProvider(int sessionTimeOut, int pollingSeconds, string connStringName)
 {
     _localServer = new SessionServer(sessionTimeOut, pollingSeconds, connStringName);
 }
Пример #19
0
        public void StartBackground()
        {
            lock (MainController.GetInstance())
            {
                //notify logger that we are in main service
                Logger.GetInstance().InitializeMainLogger(serviceLogger);
                SvcController.StopMyDLP = new SvcController.StopMyDLPDelegate(Stop);

                //Keep watchdog tied up during debugging
                if (System.Environment.UserInteractive == false)
                {
                    ServiceController service = new ServiceController("mydlpepwatchdog");
                    try
                    {
                        if (!service.Status.Equals(ServiceControllerStatus.Running) && !service.Status.Equals(ServiceControllerStatus.StartPending))
                        {
                            Logger.GetInstance().Info("Starting mydlpepwatchdog at start up");
                            SvcController.StartServiceNonBlocking("mydlpepwatchdog", 10000);
                            Logger.GetInstance().Info("Starting mydlpepwatchdog at start up finished");
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.GetInstance().Error("Unable to start watchdog" + e);
                    }
                    //enable watchdog check

                    Logger.GetInstance().Info("Watchdog check enabled");
                    watchdogTimer          = new System.Timers.Timer(watchdogTimerPeriod);
                    watchdogTimer.Elapsed += new ElapsedEventHandler(OnTimedWatchdogEvent);
                    watchdogTimer.Enabled  = true;
                }



                if (Configuration.GetAppConf() == false)
                {
                    Logger.GetInstance().Error("Unable to get configuration exiting!");
                    //Environment.Exit(1);
                }
                else
                {
                    //start backend engine

                    Configuration.GetUserConf();
                    Configuration.StartTime = DateTime.Now;

                    SessionManager.Start();

                    Engine.GetPhysicalMemory = new Engine.GetPhysicalMemoryDelegate(GetPhysicalMemory);
                    Engine.Start();
                    Configuration.SetPids();

                    Logger.GetInstance().Debug("mydlpepwin tries to install mydlpmf");
                    MyDLPEP.MiniFilterController.GetInstance().Start();

                    MyDLPEP.FilterListener.getInstance().StartListener();
                    Logger.GetInstance().Info("mydlpepwin service started");

                    bool testSuccess = false;
                    for (int i = 0; i < 10; i++)
                    {
                        testSuccess = SeapClient.SeapConnectionTest();
                        if (testSuccess)
                        {
                            break;
                        }
                        Logger.GetInstance().Debug("Seap connection test attempt:" + i);
                        System.Threading.Thread.Sleep(3000);
                    }

                    if (!testSuccess)
                    {
                        Logger.GetInstance().Error("Seap connection test failed");
                        Stop();
                    }

                    if (Configuration.BlockScreenShot)
                    {
                        ScreenShotContoller.Start();
                    }

                    SessionServer.Start();

                    if (Configuration.PrinterMonitor)
                    {
                        Service.PrinterController.getInstance().Start();
                    }

                    if (Configuration.RemovableStorageEncryption)
                    {
                        DiskCryptor.StartDcrypt();
                    }

                    if (Configuration.UsbSerialAccessControl)
                    {
                        Core.USBController.Activate();
                        Core.USBController.GetUSBStorages();
                    }
                }

                //initialize configuration timer
                Logger.GetInstance().Info("Configuration check enabled");
                confTimer          = new System.Timers.Timer(confCheckTimerPeriod);
                confTimer.Elapsed += new ElapsedEventHandler(OnTimedConfCheckEvent);
                confTimer.Enabled  = true;

                Logger.GetInstance().Info("mydlpepwin service started");
            }
        }
Пример #20
0
 public SessionContext(SessionServer sessionServer)
 {
     Token      = sessionServer.SessionToken.Token;
     ExpiryTime = DateTime.Now.AddSeconds(GetSessionTimeout(sessionServer));
 }
Пример #21
0
 public override bool SendMessage(Message msg)
 {
     return(SessionServer.SendMessage(msg, this.EndPoint));
 }
        private void ProcessWebSocketQuery()
        {
            while (true)
            {
                Request     = "";
                ByteRequest = new byte[1024];
                #region "Прием запросов"
                //Ожидает 5 секунд запрос от клиента
                DateTime timerStart   = DateTime.Now;
                DateTime timerCurrent = DateTime.Now;
                TimeSpan dTime        = TimeSpan.Zero;
                while (!Stream.DataAvailable)
                {
                    timerCurrent = DateTime.Now;
                    dTime        = timerCurrent - timerStart;
                    if (dTime.TotalMilliseconds > 5000)
                    {
                        SessionServer.FinalizeSession();
                        if (PlayerOwner is null)
                        {
                            Debug.WriteLine(">> UNKNOWN_PLAYER close socket and stream<<");
                        }
                        else
                        {
                            Debug.WriteLine(">>" + PlayerOwner.PlayerNumber + " close socket and stream<<");
                        }
                        return;
                    }
                }

                Stream.Read(ByteRequest, 0, ByteRequest.Length);
                Request = DecodeWebSocketMessage(ByteRequest);
                //по веб сокету приходят строки с '\r\n\r\n' в конце
                //отрезаем мусорную часть строки
                Request = Request.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries)[0];
                #endregion


                #region "Парсинг и обработка запросов"
                ParsedWSRequest = ParseWebSocketRequest(Request);

                //первый коннект-запрос
                if (ParsedWSRequest.ContainsKey("IsConnectedQuery"))
                {
                    int sessionId = int.Parse(ParsedWSRequest["SessionId"]);
                    int playerId  = int.Parse(ParsedWSRequest["PlayerNumber"]);
                    //устанавливаем игрока и его цвет
                    FirstQueryToConnect(sessionId, playerId);
                    ParsedWSRequest.Remove("IsConnectedQuery");
                }
                if (PlayerOwner.PlayerState == PlayerStates.Disconnected)
                {
                    break;
                }

                if (SessionServer.SessionInfo.Players.Count == 2)
                {
                    ParsedWSRequest["PlayerState"] = PlayerOwner.PlayerState.ToString();
                    //чья очередь ходить
                    if (PlayerOwner.PlayerState == PlayerStates.ActiveLeading)
                    {
                        SessionServer.SessionInfo.CommonDataHub = ParsedWSRequest["BoardState"];
                    }
                    if (PlayerOwner.PlayerState == PlayerStates.ActiveWaiting)
                    {
                        ParsedWSRequest["BoardState"] = SessionServer.SessionInfo.CommonDataHub;
                    }
                }
                else
                {
                    ParsedWSRequest["PlayerState"] = PlayerStates.WaitBegining.ToString();
                }
                #endregion


                #region "Отправка ответов"
                ByteResponse = EncodeWebSocketMessage(BuildWebSocketResponse(ParsedWSRequest));
                Stream.Write(ByteResponse, 0, ByteResponse.Length);
                Stream.Flush();
                #endregion
            }
        }
Пример #23
0
 /// <summary>
 /// Create a new session and its data in a SessionContext.
 /// </summary>
 private void InitializeSessionContext()
 {
     SessionContext = new SessionContext(SessionServer.Create(this).Value);
 }
Пример #24
0
 /// <summary>
 /// Default constructor for the provider to initialize the Session Server with the application configuration
 /// </summary>
 public LocalSharedSessionServerProvider()
 {
     _localServer = new SessionServer();
 }
Пример #25
0
        protected override ResultCode OpenSession(out SessionServer sessionServer)
        {
            sessionServer = new SessionServer(_context);

            return(ResultCode.Success);
        }
Пример #26
0
 internal static bool TestCase()
 {
     using (SessionServer server = new SessionServer()) return(server.IsListen && TestClient());
 }
Пример #27
0
 protected abstract ResultCode OpenSession(out SessionServer sessionServer);