示例#1
0
        private operationresult HowAreYou(string curDate, string checksum)
        {
            status = "HowAreYou() was called";
            string calculatedMD5 = HashUtility.CalculateMD5(curDate);

            if (!calculatedMD5.Equals(checksum))
            {
                return(new operationresult(IntegerConstants.WRONG_CHECKSUM, "неправильная контрольная сумма", "CPMTcpServer.HowAreYou()"));
            }
            DateTime externalDate = DateTime.ParseExact(curDate, "yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture);
            DateTime now          = DateTime.Now;

            CPMPayAgentService.LoggingLayer.PayAgentLogger.Instance().logError("HOWYOU Now: " + now.ToString() + " curdate: " + externalDate.ToString() +
                                                                               (externalDate.CompareTo(now.AddMinutes(15)) < 0) + " " + (externalDate.CompareTo(now.AddMinutes(-15)) > 0));
            if (!(externalDate.CompareTo(now.AddMinutes(15)) < 0 && (externalDate.CompareTo(now.AddMinutes(-15)) > 0)))
            {
                return(new operationresult(IntegerConstants.WRONG_TIME, "неправильное время", "Server.HowAreYou()"));
            }

            long     diff     = DateTime.Now.Ticks - beginTime.Ticks;
            TimeSpan span     = new TimeSpan(diff);
            string   livetime = "" + span.Days + "d " + (int)span.Hours + "h " + span.Minutes + "m ";

            operationresult result = new operationresult();

            RegistrationResultItem item;

            try
            {
                item = OperationPerformer.Instance().getRegistrationResult();
            }
            catch (Exception e)
            {
                result.result     = IntegerConstants.SUCCESS;
                result.status     = "-500";
                result.statusNote = "Сервис не готов к работе! " + e.Message;
                result.livetime   = livetime;
                return(result);
            }

            switch (item)
            {
            case RegistrationResultItem.RegistrationFailed:
                result.result     = IntegerConstants.SUCCESS;
                result.status     = "-1";
                result.statusNote = "Сервис не готов к работе!";
                break;

            case RegistrationResultItem.RegistrationSuccefully:
                result.result     = IntegerConstants.SUCCESS;
                result.status     = "1";
                result.statusNote = "Сервис готов к работе!";
                break;

            case RegistrationResultItem.Unknown:
                result.result     = IntegerConstants.SUCCESS;
                result.status     = "-500";
                result.statusNote = "Сервис не готов к работе!";
                break;

            default:
                break;
            }

            result.livetime = livetime;
            return(result);
        }