Example #1
0
        private async Task HandleRegisterRaceEnd(QrCodeResult parsedResult)
        {
            try
            {
                var result = await DisplayAlert("Important", "You are about to finish the race and this cannot be undone. Are you sure you want to continue?", "Yes", "No");

                if (result)
                {
                    var response = await _raceVenturaApiClient.RegisterRaceEnd(parsedResult.RaceId, viewModel.Item.UniqueId);

                    await EndRace("You finished the race! Congratulations, now go take a well deserved shower!");
                }
            }
            catch (RaceVenturaApiException ex)
            {
                switch (ex.ErrorCode)
                {
                case ErrorCodes.RaceNotStarted:
                    await DisplayAlert("Error", "You cannot end this race because the race has not started yet!", "Ok");

                    break;

                case ErrorCodes.RaceEnded:
                    await EndRace("The race is over! Congratulations, now go take a well deserved shower!");

                    break;

                default:
                    throw new Exception("Unknown error code.");
                }
            }
        }
Example #2
0
        public void Insert(string result)
        {
            var example = new QrCodeResult {
                Result = result, DateTime = GetTimeDate()
            };

            _connection.Insert(example);
        }
        public override async Task <MpChannelDto> Create(MpChannelDto input)
        {
            var mpid = await _userMpAppService.GetDefaultMpId();

            input.MpID = mpid;
            if (input.IsMcChannel == 0)
            {
                if (!input.EventKey.StartsWith("qrcode."))
                {
                    input.EventKey = "qrcode." + input.EventKey;
                }
            }
            var isHave = await Repository.CountAsync(m => m.IsDeleted == false && m.EventKey == input.EventKey);

            if (isHave > 0)
            {
                throw new UserFriendlyException("对不起,您提交的二维码已存在,请检查。");
            }
            var          expireSeconds = 0;
            QrCodeResult data          = null;

            if (input.ChannelType == ChannelType.QR_STR_SCENE.ToString())
            {
                if (input.ValidityDay <= 0)
                {
                    throw new UserFriendlyException("临时二维码,请填写过期天数。");
                }
                if (input.ValidityDay > 0)
                {
                    expireSeconds   = input.ValidityDay * 24 * 60 * 60;
                    input.EndTime   = DateTime.Now.AddDays(input.ValidityDay);
                    input.StartTime = DateTime.Now;
                }
            }

            try
            {
                data = await _wxMediaAppService.SaveQrCode(input.MpID, input.Name, input.EventKey, input.ChannelType, expireSeconds);

                input.Ticket   = data.Ticket;
                input.FilePath = data.FilePath;
                input.FileUrl  = data.Url;
            }
            catch (System.Exception ex)
            {
                throw new UserFriendlyException(ex.Message);
            }

            CheckCreatePermission();

            var entity = MapToEntity(input);

            Repository.Insert(entity);

            return(MapToEntityDto(entity));
        }
        public override async Task <MpChannelDto> Update(MpChannelDto input)
        {
            if (input.IsMcChannel == 0)
            {
                if (!input.EventKey.StartsWith("qrcode."))
                {
                    input.EventKey = "qrcode." + input.EventKey;
                }
            }
            var isHave = await Repository.CountAsync(m => m.IsDeleted == false && m.EventKey == input.EventKey && m.Id != input.Id);

            if (isHave > 0)
            {
                throw new UserFriendlyException("对不起,您提交的二维码已存在,请检查。");
            }
            var          expireSeconds = 0;
            QrCodeResult data          = null;

            if (input.ChannelType == ChannelType.QR_STR_SCENE.ToString())
            {
                if (input.ValidityDay <= 0)
                {
                    throw new UserFriendlyException("临时二维码,请填写过期天数。");
                }
                if (input.ValidityDay > 0)
                {
                    expireSeconds = input.ValidityDay * 24 * 60 * 60;
                    input.EndTime = Convert.ToDateTime(input.StartTime).AddDays(input.ValidityDay);
                }
            }

            try
            {
                data = await _wxMediaAppService.SaveQrCode(input.MpID, input.Name, input.EventKey, input.ChannelType, expireSeconds);

                input.Ticket   = data.Ticket;
                input.FilePath = data.FilePath;
                input.FileUrl  = data.Url;

                await _cacheManager.GetCache(AppConsts.Cache_CallBack).ClearAsync();
            }
            catch (System.Exception ex)
            {
                throw new UserFriendlyException(ex.Message);
            }

            return(await base.Update(input));
        }
Example #5
0
        public QrCodeResult ParseResult(string result)
        {
            var retVal = new QrCodeResult();

            var splitString = result.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in splitString)
            {
                var itemSplit = item.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                switch (itemSplit[0].Trim())
                {
                case "QrCodeType":
                    if (!Enum.TryParse <QrCodeType>(itemSplit[1].Trim(), out var qrCodeType))
                    {
                        throw new Exception($"Could not parse {itemSplit[1].Trim()} to QrCodeType");
                    }

                    retVal.QrCodeType = qrCodeType;
                    break;

                case "RaceId":
                    retVal.RaceId = Guid.Parse(itemSplit[1].Trim());
                    break;

                case "StageId":
                    retVal.StageId = Guid.Parse(itemSplit[1].Trim());
                    break;

                case "TeamId":
                    retVal.TeamId = Guid.Parse(itemSplit[1].Trim());
                    break;

                case "PointId":
                    retVal.PointId = Guid.Parse(itemSplit[1].Trim());
                    break;

                default:
                    throw new Exception("Unknown field in QR code result.");
                }
            }

            return(retVal);
        }
Example #6
0
        private async Task HandleRegisterStageEnd(QrCodeResult parsedResult)
        {
            try
            {
                var result = await DisplayAlert("Important", "You are about to finish a stage. Afterwards you cannot register anymore points for this stage and it cannot be undone. Are you sure you want to continue?", "Yes", "No");

                if (result)
                {
                    var response = await _raceVenturaApiClient.RegisterStageEnd(parsedResult.RaceId, viewModel.Item.UniqueId, parsedResult.StageId);

                    await DisplayAlert("Done", "The stage is closed, have fun with the next one!", "Ok");
                }
            }
            catch (RaceVenturaApiException ex)
            {
                switch (ex.ErrorCode)
                {
                case ErrorCodes.NotActiveStage:
                    await DisplayAlert("Error", "The QR code you scanned to end the stage is not the right code for the stage you are in now!", "Ok");

                    break;

                case ErrorCodes.RaceNotStarted:
                    await DisplayAlert("Error", "You cannot end this stage because the race has not started yet!", "Ok");

                    break;

                case ErrorCodes.RaceEnded:
                    await DisplayAlert("Error", "Your team has finished the race, you cannot register stage ends any more.", "Ok");

                    break;

                default:
                    throw new Exception("Unknown error code.");
                }
            }
        }
Example #7
0
        private async Task HandleRegisterPoint(QrCodeResult parsedResult)
        {
            var answer = string.Empty;

            try
            {
                var location = await _locationService.GetLocation();

                var response = await _raceVenturaApiClient.RegisterPoint(parsedResult.RaceId, viewModel.Item.UniqueId, parsedResult.PointId, location.Latitude, location.Longitude, string.Empty);

                if (response.Type == PointTypeViewModel.QuestionCheckPoint)
                {
                    answer = await DisplayPromptAsync("Question!", response.Message);

                    if (string.IsNullOrEmpty(answer))
                    {
                        throw new RaceVenturaApiException("No answer entered.", ErrorCodes.AnswerIncorrect);
                    }

                    await _raceVenturaApiClient.RegisterPoint(parsedResult.RaceId, viewModel.Item.UniqueId, parsedResult.PointId, location.Latitude, location.Longitude, answer);
                }
                else
                {
                    if (!string.IsNullOrEmpty(response.Message))
                    {
                        await DisplayAlert("Message", response.Message, "Ok");
                    }
                }

                await DisplayAlert("Congratulations", "Point registered! Good luck finding the next point!", "Ok");
            }
            catch (PermissionException)
            {
                await DisplayAlert("Error", "RaceVentura is not allowed to access your location. This is needed when registering points to check if you are on the right loction. Please go to settings and grant RaceVentura access to your location.", "Ok");
            }
            catch (RaceVenturaApiException ex)
            {
                switch (ex.ErrorCode)
                {
                case ErrorCodes.Duplicate:
                    await DisplayAlert("Error", "This point is already registered for your team! Quickly move on to the next point!", "Ok");

                    break;

                case ErrorCodes.CoordinatesIncorrect:
                    await DisplayAlert("Error", "You are not at the right location for this point. Make sure you are on the right spot!", "Ok");

                    break;

                case ErrorCodes.AnswerIncorrect:
                    await DisplayAlert("Error", $"The answer '{answer}' is incorrect!", "Ok");

                    break;

                case ErrorCodes.NotActiveStage:
                    await DisplayAlert("Error", "You cannot register this point because it is not in the stage you are doing right now!", "Ok");

                    break;

                case ErrorCodes.RaceNotStarted:
                    await DisplayAlert("Error", "You cannot register this point because the race did not start yet!", "Ok");

                    break;

                case ErrorCodes.RaceEnded:
                    await DisplayAlert("Error", "Your team has finished the race, you cannot register points any more.", "Ok");

                    break;

                default:
                    throw new Exception("Unknown error code.");
                }
            }
        }