private static void StartGame() { // Start the game Console.WriteLine("Welcome to animal guessing game!"); Console.WriteLine("By: Yudho Triadianto"); /*Please put the JSON DataSet in the same directory as the executable. * In this instance the filename of the datasets is hardcoded.*/ string workingDirectory = Directory.GetCurrentDirectory(); //Read the Json file in the project root string jsonFile = File.ReadAllText(workingDirectory + "/guessingDataSets.json"); //Parse Json file to the .NET objects JsonDataFormat dataSets = JsonConvert.DeserializeObject <JsonDataFormat>(jsonFile); RunGame(dataSets); }
//In this function, the function is called recursively until it reaches the answer private static void RunGame(JsonDataFormat dataSets) { if (dataSets.Yes != null || dataSets.No != null) { Console.WriteLine("Question = " + dataSets.Data); Console.WriteLine("Please write yes or no answer to the question"); String userType = Console.ReadLine(); if (userType.Equals("yes", StringComparison.OrdinalIgnoreCase)) { RunGame(dataSets.Yes); } else if (userType.Equals("no", StringComparison.OrdinalIgnoreCase)) { RunGame(dataSets.No); } else { Console.WriteLine("Invalid value"); RunGame(dataSets); } } // It reaches the leaf of the dataSets, which means it reaches the answer else { Console.WriteLine("The answer is =" + dataSets.Data); Console.WriteLine("Is the answer correct?"); Console.WriteLine("Please write yes or no answer to the question"); String userType = Console.ReadLine(); if (userType.Equals("yes", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Thank you for playing the game"); } else if (userType.Equals("no", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Oh sorry, apparantely my data is limited"); Console.WriteLine("Thank you for playing the game"); } } }
static void Main(string[] args) { // Set up data string initialDirectory = "C:\\Users\\eedee\\Documents"; string jsonSource = "test_json.json"; string jsonForDB = "test_db_json.json"; string excelSource = "testExcel.xlsx"; string apiSource = "http://ewhiting.eastus.cloudapp.azure.com/midterm/Classes/Genre/read.php"; // Basic demo List <string> attrs = new List <string>(); attrs.Add("name"); attrs.Add("job"); attrs.Add("age"); DataFormat excelDF = new ExcelDataFormat(initialDirectory + "\\" + jsonSource, attrs, SourceDataType.JSON); DataFormat jsonDF = new JsonDataFormat(initialDirectory + "\\" + excelSource, attrs, SourceDataType.Excel); excelDF.WriteData(initialDirectory, "excelTest"); jsonDF.WriteData(initialDirectory, "jsonTest"); // API demo List <string> apiAttrs = new List <string>(); apiAttrs.Add("id"); apiAttrs.Add("name"); apiAttrs.Add("picture_path"); DataFormat xmlDF = new XmlDataFormat(apiSource, apiAttrs, SourceDataType.API); xmlDF.WriteData(initialDirectory, "xmlTest"); // Bulk data actions demo List <DataFormat> dataFormats = new List <DataFormat>(); dataFormats.Add(xmlDF); dataFormats.Add(jsonDF); dataFormats.Add(excelDF); BulkActions.WriteDataFormatsToFile(dataFormats, initialDirectory, "bulktest"); // Generics Demo MultiDataFormat <DataFormat> jsonGeneric = new MultiDataFormat <DataFormat>(jsonSource, attrs, SourceDataType.JSON); MultiDataFormat <DataFormat> excelGeneric = new MultiDataFormat <DataFormat>(excelSource, attrs, SourceDataType.Excel); List <DataFormat> dfs = new List <DataFormat>(); List <MultiDataFormat <DataFormat> > genericDFs = new List <MultiDataFormat <DataFormat> >(); genericDFs.Add(jsonGeneric); genericDFs.Add(excelGeneric); DataFormat excelFromGeneric = BulkActions.FromMultipleSources(genericDFs, "excel"); excelFromGeneric.WriteData(initialDirectory, "GenericExcel"); // Database demo List <string> dbAttrs = new List <string>(); dbAttrs.Add("fname"); dbAttrs.Add("lname"); dbAttrs.Add("age"); string server = Environment.MachineName; string db = "LearningTest"; string user = "******"; string password = "******"; DatabaseDataFormat dbDF = new DatabaseDataFormat( server: server, catalog: db, username: user, password: password, dbSystem: "sqlserver", source: initialDirectory + "\\" + jsonForDB, KeepValues: dbAttrs, sourceDataType: SourceDataType.JSON ); dbDF.WriteData("", "People"); }
public void CreateReport(List <PageData> A11yData, List <PageData> MediaData, List <PageData> LinkData) { //Public method to create the report from any input (can put null in place of any of the lists if you only need a certain input). if (null != A11yData) { AddA11yData(A11yData); } if (null != MediaData) { AddMediaData(MediaData); } if (null != LinkData) { AddLinkData(LinkData); } //Need to make sure the destination directory exists var test_path = new DirectoryInfo(Path.GetDirectoryName(Destination)); if (!(test_path.Exists)) { test_path.Create(); } //Get a dynamicly named report just in case one of the same name already exists var i = 1; while (new FileInfo(Destination).Exists) { var new_destination = Destination.Replace(".xlsx", $"_V{i}.xlsx"); if (!(new FileInfo(new_destination).Exists)) { Destination = new_destination; } i++; } List <JsonDataFormat> json = new List <JsonDataFormat>(); var numIssues = 0; var row = 9; string dataDir = Options.JsonDataDir; Cells = Excel.Workbook.Worksheets[1].Cells; while (Cells[row, 2].Value != null && (String)Cells[row, 2].Value != "") { var data = new JsonDataFormat { Completed = (String)Cells[row, 2].Value == "Not Started" ? false : true, Location = (String)Cells[row, 3].Value, Url = Cells[row, 3]?.Hyperlink?.ToString(), IssueType = (String)Cells[row, 4].Value, DescriptiveError = (String)Cells[row, 5].Value, Notes = (String)Cells[row, 6].Value, html = (String)Cells[row, 10].Value }; json.Add(data); numIssues++; row++; } using (StreamWriter file = new StreamWriter(System.IO.Path.Combine(dataDir, System.IO.Path.GetFileName(Destination).Replace(".xlsx", ".json")), false)) { JsonSerializer serializer = new JsonSerializer { Formatting = Formatting.Indented }; serializer.Serialize(file, json); } //Save and dispose Excel.SaveAs(new FileInfo(Destination)); Excel.Dispose(); }