Skip to content

jamesnet214/blazor-quiz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blazor Quiz

Blazor Quiz는 간단한 퀴즈를 풀 수 있는 Blazor-WebAssembly 기반 웹앱입니다.
👉 퀴즈 풀러가기

더 알아보기 »

Star License Activity
Github Stars License Commits-per-month

개발 환경

Blazor-WebAssembly


웹서버 호스팅

MS Azure WebApp 배포 (무료 F1)


데이터

별도 데이터베이스 없이 GitHub 레포지터리에서 YAML 파일 로드


Yaml Parsing

[ApiController]
[Route("[controller]")]
public class QuizDataController : ControllerBase
{
    private static string YamlDataUrl = "https://raw.githubusercontent.com/devncore/blazor-quiz/master/data/quiz-basic.yml";

    private readonly ILogger<WeatherForecastController> _logger;

    public QuizDataController(ILogger<WeatherForecastController> logger)
    {
	_logger = logger;
    }

    [HttpGet]
    public QuizModel[] Get()
    {
 	var yaml = new HttpClient().GetStringAsync(YamlDataUrl);
	var yamlData = yaml.Result;
	var quizs = ParsePlayer(yamlData);
	Shuffle<QuizModel>(quizs);

	foreach (var quiz in quizs)
	{
	    Shuffle<AnswerModel>(quiz.Answers);
	}

	return quizs.Take(5).ToArray();
    }

    public List<QuizModel> ParsePlayer(string ymlContents)
    {
	var deserializer = new DeserializerBuilder()
	  .WithNamingConvention(CamelCaseNamingConvention.Instance)
	  .Build();
	
	var result = deserializer.Deserialize<QuizPack>(ymlContents);
	return result.Quiz;
    }

    private void Shuffle<T>(IList<T> list)
    {
	Random rng = new Random();
	int n = list.Count;

	while (n > 1) 
	{
	    n--;
	    int k = rng.Next(n + 1);
	    T value = list[k];
	    list[k] = list[n];
	    list[n] = value;
	}
    }
}

스크린샷

문제풀이 정답풀이

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •