Пример #1
0
        //deletion from room algorthm
        private void DeleteUserFromRoomAlgorithmMethod(LeavingTheRoomWindowType windowType)
        {
            LeaveTheRoomRequest   request = null;
            IMakaoGameHostService proxy   = null;

            try //try to connect to service host - may be problem when didin't connect before and endpoint is not assigned
            {
                if (makaoGameHostEndpoint == null)
                {
                    AssignHostEndpoint(MakaoGameHostServiceEndpointObtainer.GetHostEndpointWhileBeeingHost());
                }
                ChannelFactory <IMakaoGameHostService> factory = new ChannelFactory <IMakaoGameHostService>(new BasicHttpBinding(),
                                                                                                            new EndpointAddress(MakaoGameHostEndpoint));

                //creating request
                request = new LeaveTheRoomRequest()
                {
                    IsHostPlayer     = IsHostPlayer,
                    PlayerID         = PlayerID,
                    PlayerName       = SavedDataPlaceholder.CurrentPlayerName,
                    PlayerNumber     = PlayerNumber,
                    ClosedWindowType = windowType,
                };
                proxy = factory.CreateChannel();
            }
            catch (Exception ex)
            {
                var logger = NLog.LogManager.GetCurrentClassLogger();
                logger.Error("Error while making attemp to connect to host to delete player " + ex.Message + ex.StackTrace);
            }

            bool response = false;

            try
            {
                response = proxy.DeletePlayerFromRoom(request);
            }
            catch (Exception ex)
            {
                var logger = NLog.LogManager.GetCurrentClassLogger();
                logger.Error("Error while obtaning response from host about deletion of player: " + ex.Message + ex.StackTrace);
            }

            if (response)
            {
                var logger = NLog.LogManager.GetCurrentClassLogger();
                logger.Info("Current player was deleted from room");
            }

            if (IsHostPlayer == true)
            {
                Task.Run(() => StopTheHostServiceWithDelay(3));
            }
        }
Пример #2
0
        //constructing method
        public static void EngineHostHandlerConstructor(int localTimeout, int notLocalTimeout, string serviceName, string inputPassword, bool startAsHost)
        {
            password                = inputPassword;
            internalLocalTimeout    = localTimeout;
            internalNotLocalTimeout = notLocalTimeout;
            internalServiceName     = serviceName;
            //assign Host endpoint to property in MainWindow
            if (startAsHost)
            {
                MainWindow.AssignHostEndpoint(MakaoGameHostServiceEndpointObtainer.GetHostEndpointWhileBeeingHost());
            }
            //create new channel factory
            factory = new ChannelFactory <IMakaoGameHostService>(new BasicHttpBinding(),
                                                                 new EndpointAddress(MainWindow.MakaoGameHostEndpoint));

            //set flag that informs of the fact that this methos was fired
            constructed = true;

            var logger = NLog.LogManager.GetCurrentClassLogger();

            logger.Info("EngineHostHandler constructed.");
        }