泛型与基类

时间:2016-08-23 12:24:48

标签: c# asp.net .net

我很难找到最好的设置我的项目。我有一个GameSessionServer - 负责JSON请求处理和注册处理程序的类..现在我有基本套接字处理程序处理程序(类的一部分):

  public WebSocketResponse HandleRequest(RequestDto request, GameSessionServer server)
    {
        TrySetThreadCulture(request);
        EnsureUserStoredInSession(server.SessionContext, false, SlotIsEngineRNG(server.SessionContext.SystemGameId));

        // custom request handling
        WebSocketResponse wsr = HandleRequestInternal(request, server);

        // save the last handler
        server.SessionContext.Items[typeof(WebSocketHandler)] = this;
        return wsr;
    }

它应该是RequestDto基类参数还是通用RequestDto ?????? 在具体的处理程序中,我将RequestDto转换为特定类型,如下所示:

   protected override WebSocketResponse HandleRequestInternal(RequestDto request, GameSessionServer server)
    {
        CasinoSpinRequestDto spinRequest = request as CasinoSpinRequestDto;

        int TotalBetInCents = (spinRequest.SpinType != "free") ? spinRequest.TotalBet : 0;
        JsonResult JR = null;

        CasinoSpinResponseDto spinResponse = new CasinoSpinResponseDto();
        switch (spinRequest.SpinType)
        {
            case "regular":
                JR = PlayBetSpin(spinRequest, server);
                break;
            case "free":
                JR = PlayFreeSpin(spinRequest, server.SessionContext);
                break;
        }

        // set balance in cents
        spinResponse.Credit = JR.BalanceInCents;

        SlotEngineRNG engineRNG;
        sbyte[,] wheels = (JR is SpinJsonResult) ? ((SpinJsonResult) JR).Wheels : ((BonusJsonResult) JR).FreeSpin.Wheels;
        int rsId = (JR is SpinJsonResult) ? 0 : ((BonusJsonResult) JR).FreeSpin.ReelId;

        if (SlotIsEngineRNG(server.SessionContext.SystemGameId, out engineRNG))
        {
            GameSettingInfo gsi = DataBuffer.Instance.GetGameSetting(server.SessionContext.UserGroupId, (int) server.SessionContext.SystemGameId);
            spinResponse.Results = CalculateWheelPositionsRNG( wheels , rsId , engineRNG, gsi);
        }  else
        {
            int[] pos;
            PosHoldersFactory.GetSlotPositions(server.SessionContext.SystemGameId, wheels, rsId, out pos);
            spinResponse.Results = pos;
        }

................................

0 个答案:

没有答案