Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasbozdemir committed Mar 14, 2024
1 parent 5a3672f commit 2d82488
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 60 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Quiz Uygulaması

Bu uygulama, kullanıcıların çeşitli sınav kitapçıklarından soruları çözebilecekleri ve cevap anahtarlarını görüntüleyebilecekleri bir konsol uygulamasıdır.

## Uygulamanın Akışı
1. Kullanıcılar, JSON formatında örnek veri girerek soru verilerini uygulamaya aktarır.

2. Uygulama, girilen verileri kullanarak farklı zorluk seviyelerinde kitapçıklar oluşturur.
3. Oluşturulan kitapçıklar, içerdikleri soruları ve seçenekleri karışık bir şekilde düzenler.
4.Kullanıcılar, oluşturulan kitapçıkları dışa aktarabilir veya quiz moduna geçerek soruları çözebilirler.

## Nasıl Kullanılır

1. Uygulamayı çalıştırın (`quiz-console-app.exe` veya Visual Studio'da F5 tuşuna basarak).
2. Uygulama başlatıldığında, mevcut kitapçıklar listelenecek ve kullanıcı bir kitapçık seçmek için talimatlar alacak.
3. Kitapçık seçildikten sonra, kullanıcı soruları çözebilir.
4. Soruları çözdükten sonra, kullanıcı cevap anahtarlarını görüntüleyebilir.

## Özellikler

- Kullanıcı dostu arayüz
- Farklı zorluk seviyelerine sahip sorular
- Soruların ve cevap anahtarlarının XML ve JSON olarak dışa aktarılması
- XML verilerinin XSLT ile biçimlendirilerek tarayıcıda görüntülenmesi
- Hata işleme ve güvenilirlik

## Kullanılan Teknolojiler

- C#
- .NET Framework
- JSON.NET kütüphanesi

## Kurulum

1. Bu depoyu klonlayın: `https://github.com/ilyasBozdemir/quiz-console-app`
2. Visual Studio'da çözümü açın: `quiz-console-app.sln`
3. Uygulamayı derleyin ve çalıştırın.

## Katkıda Bulunma

1. Bu depoyu çatallayın (fork).
2. Yeni bir dal (branch) oluşturun: `git checkout -b new-feature`
3. Değişikliklerinizi yapın ve bunları işleyin (commit): `git commit -am 'Yeni özellik ekle'`
4. Dalınızı ana depoya gönderin (push): `git push origin yeni-ozellik`
5. Bir birleştirme isteği (pull request) gönderin.

## Lisans

Bu proje MIT lisansı altında lisanslanmıştır. Daha fazla bilgi için `LICENSE` dosyasına bakın.
10 changes: 10 additions & 0 deletions quiz-console-app/Exceptions/JsonLoadFailedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace quiz_console_app.Exceptions;

public class JsonLoadFailedException : Exception
{
public JsonLoadFailedException() : base("JSON dosyası yüklenirken bir hata oluştu.") { }

public JsonLoadFailedException(string message) : base(message) { }

public JsonLoadFailedException(string message, Exception innerException) : base(message, innerException) { }
}
12 changes: 12 additions & 0 deletions quiz-console-app/Helpers/ConsoleColors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace quiz_console_app.Helpers;
public static class ConsoleColors
{
public static readonly ConsoleColor Default = ConsoleColor.Gray;
public static readonly ConsoleColor Error = ConsoleColor.Red;
public static readonly ConsoleColor Success = ConsoleColor.Green;
public static readonly ConsoleColor Title = ConsoleColor.DarkGreen;
public static readonly ConsoleColor Info = ConsoleColor.DarkBlue;
public static readonly ConsoleColor Warning = ConsoleColor.Yellow;
public static readonly ConsoleColor Debug = ConsoleColor.Magenta;
public static readonly ConsoleColor Prompt = ConsoleColor.Cyan;
}
18 changes: 18 additions & 0 deletions quiz-console-app/Helpers/ConsoleHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace quiz_console_app.Helpers;

public static class ConsoleHelper
{
public static void WriteColoredLine(object text, ConsoleColor color)
{
Console.ForegroundColor = color;
Console.WriteLine(text);
Console.ResetColor();
}

public static void WriteColored(object text, ConsoleColor color)
{
Console.ForegroundColor = color;
Console.Write(text);
Console.ResetColor();
}
}
45 changes: 40 additions & 5 deletions quiz-console-app/Helpers/QuestionLoader.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
using Newtonsoft.Json;
using quiz_console_app.Exceptions;
using quiz_console_app.Models;

namespace quiz_console_app.Helpers;

public class QuestionLoader
{
public List<Question> LoadQuestionsFromJson(string jsonFilePath)
{
string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, jsonFilePath);
string json = File.ReadAllText(fullPath);
List<Question> questions = JsonConvert.DeserializeObject<List<Question>>(json);
return questions;
try
{
string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, jsonFilePath);
string json = File.ReadAllText(fullPath);
List<Question> questions = JsonConvert.DeserializeObject<List<Question>>(json);
return questions;
}
catch (JsonLoadFailedException ex)
{
throw new JsonLoadFailedException("JSON dosyası yüklenirken bir hata oluştu.", ex);
}
}
public async Task<List<Question>> LoadQuestionsFromUrl(Uri url)
{
try
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();

string contentType = response.Content.Headers.ContentType.MediaType;

if (contentType != "application/json")
throw new InvalidOperationException($"Beklenen JSON içeriği değil., alınan medya türü: {contentType}");


if (response.IsSuccessStatusCode)
return LoadQuestionsFromJson(await response.Content.ReadAsStringAsync());
else
throw new Exception("API'den veri alınamadı. Hata kodu: " + response.StatusCode);

}
}
catch (Exception ex)
{
throw new Exception("Hata oluştu: " + ex.Message);
}
}

}
4 changes: 2 additions & 2 deletions quiz-console-app/Helpers/QuestionShuffler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public static void ShuffleBookletQuestions(BookletViewModel booklet)

public static List<Question> ShuffleQuestionOptions(List<Question> questions)
{
Random random = new Random();


foreach (var question in questions)
{
List<QuestionOption> shuffledOptions = ShuffleOptions(question.QuestionOptions, random);
Expand All @@ -31,6 +30,7 @@ public static List<Question> ShuffleQuestionOptions(List<Question> questions)
return questions;
}


private static List<QuestionOption> ShuffleOptions(List<QuestionOption> options, Random random)
{
for (int i = options.Count - 1; i > 0; i--)
Expand Down
59 changes: 59 additions & 0 deletions quiz-console-app/Helpers/QuizDisplay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using quiz_console_app.ViewModels;

namespace quiz_console_app.Helpers;

public class QuizDisplay
{
public static void DisplayBooklets(List<BookletViewModel> booklets)
{
foreach (var booklet in booklets)
{
Console.WriteLine();
ConsoleHelper.WriteColored("Kitapçık Id: ", ConsoleColors.Info);
ConsoleHelper.WriteColoredLine(booklet.Id, ConsoleColors.Default);

ConsoleHelper.WriteColored("Kitapçık Adı: ", ConsoleColors.Info);
ConsoleHelper.WriteColoredLine(booklet.BookletName, ConsoleColors.Default);

foreach (var question in booklet.Questions)
DisplayQuestion(question);

Console.WriteLine();
}
}

private static void DisplayQuestion(QuestionViewModel question)
{
Console.WriteLine();
ConsoleHelper.WriteColored("Soru : ", ConsoleColors.Prompt);
ConsoleHelper.WriteColoredLine(question.AskText, ConsoleColors.Default);

foreach (var questionOption in question.QuestionOptions)
{
Console.Write(questionOption.Text + " ");
}
Console.WriteLine();
}

public static void DisplayAnswerKeys(List<AnswerKeyViewModel> answerKeys)
{
if (answerKeys == null || answerKeys.Count == 0)
{
ConsoleHelper.WriteColoredLine("Cevap anahtarları bulunamadı.", ConsoleColors.Error);
return;
}

ConsoleHelper.WriteColored("Cevap Anahtarları:", ConsoleColors.Info);
foreach (var answerKey in answerKeys)
{
ConsoleHelper.WriteColored("Kitapçık Id: ", ConsoleColors.Info);
ConsoleHelper.WriteColoredLine(answerKey.BookletId, ConsoleColors.Default);

ConsoleHelper.WriteColored(" Soru Id: ", ConsoleColors.Info);
ConsoleHelper.WriteColoredLine(answerKey.QuestionId, ConsoleColors.Default);

ConsoleHelper.WriteColored(" Doğru Seçenek Id: ", ConsoleColors.Info);
ConsoleHelper.WriteColoredLine(answerKey.CorrectOptionId, ConsoleColors.Default);
}
}
}
24 changes: 12 additions & 12 deletions quiz-console-app/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using quiz_console_app.Helpers;
using quiz_console_app.Models;
using quiz_console_app.Services;
using quiz_console_app.ViewModels;

class Program
{
static void Main(string[] args)
{
List<Question> questions = new QuestionLoader().LoadQuestionsFromJson("software_questions.json");
List<BookletViewModel> shuffledBooklets = QuizService.GenerateBooklets(questions, 2);
QuizDisplay.DisplayBooklets(shuffledBooklets);
Console.ReadLine();
}
}

QuizService quizService = new QuizService();


List<Question> questions = new QuestionLoader().LoadQuestionsFromJson("software_questions.json"); // default path : {root-project}/bin/Debug/net8.0/software_questions.json

quizService.GenerateBooklets(questions, 1);

QuizDisplay.DisplayBooklets(quizService.Booklets);
QuizDisplay.DisplayAnswerKeys(quizService.AnswerKeys);

Console.ReadLine();
140 changes: 140 additions & 0 deletions quiz-console-app/Services/ExportService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using quiz_console_app.ViewModels;
using System.Xml;

namespace quiz_console_app.Services;

public class ExportService
{
public void ExportToXml(List<BookletViewModel> booklets, string xmlFilePath)
{
XmlDocument xmlDoc = CreateXmlDocument(booklets);

xmlDoc.Save(xmlFilePath);
}

public void ExportAnswerKeyToXsl(string xslFilePath)
{
string xslContent = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">
<xsl:template match=""/"">
<html>
<head>
<title>Answer Key Report</title>
</head>
<body>
<h1>Answer Key Report</h1>
<xsl:apply-templates select=""AnswerKeys""/>
</body>
</html>
</xsl:template>
<xsl:template match=""AnswerKeys"">
<xsl:for-each select=""AnswerKey"">
<div>
<h2><xsl:value-of select=""BookletId""/></h2>
<p>Soru Id: <xsl:value-of select=""QuestionId""/></p>
<p>Doğru Seçenek Id: <xsl:value-of select=""CorrectOptionId""/></p>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>";

File.WriteAllText(xslFilePath, xslContent);
}

public void ExportAnswerKeyToXsd(string xsdFilePath)
{
string xsdContent = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
<xs:element name=""AnswerKeys"">
<xs:complexType>
<xs:sequence>
<xs:element name=""AnswerKey"" maxOccurs=""unbounded"">
<xs:complexType>
<xs:sequence>
<xs:element name=""BookletId"" type=""xs:int""/>
<xs:element name=""QuestionId"" type=""xs:int""/>
<xs:element name=""CorrectOptionId"" type=""xs:int""/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>";

File.WriteAllText(xsdFilePath, xsdContent);
}


public void ExportToXsl(string xslFilePath)
{
string xslContent = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"">
<xsl:template match=""/"">
<html>
<head>
<title>Booklets Report</title>
</head>
<body>
<h1>Booklets Report</h1>
<xsl:apply-templates select=""Booklets""/>
</body>
</html>
</xsl:template>
<xsl:template match=""Booklets"">
<xsl:for-each select=""Booklet"">
<div>
<h2><xsl:value-of select=""BookletName""/></h2>
<!-- Diğer kitapçık bilgileri burada eklenebilir -->
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>";

File.WriteAllText(xslFilePath, xslContent);
}

public void ExportToXsd(string xsdFilePath)
{
string xsdContent = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<xs:schema xmlns:xs=""http://www.w3.org/2001/XMLSchema"">
<xs:element name=""Booklets"">
<xs:complexType>
<xs:sequence>
<xs:element name=""Booklet"" maxOccurs=""unbounded"">
<xs:complexType>
<xs:sequence>
<!-- Kitapçık veri alanları burada tanımlanabilir -->
<xs:element name=""BookletName"" type=""xs:string""/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>";

File.WriteAllText(xsdFilePath, xsdContent);
}


private XmlDocument CreateXmlDocument(List<BookletViewModel> booklets)
{
XmlDocument xmlDoc = new XmlDocument();

XmlElement rootElement = xmlDoc.CreateElement("Booklets");
xmlDoc.AppendChild(rootElement);

// Her bir kitapçık için XML elementi oluştur ve kök elemente ekle
foreach (var booklet in booklets)
{
XmlElement bookletElement = xmlDoc.CreateElement("Booklet");
// Kitapçık verilerini XML elementine ekleme işlemi burada yapılabilir
rootElement.AppendChild(bookletElement);
}

return xmlDoc;
}
}
Loading

0 comments on commit 2d82488

Please sign in to comment.