public static AttributeObject ConvertAttributesToEmojiString(DinnCard card) { var attObj = new AttributeObject(); attObj.Att1 = Emojis.Where(x => x.Name.Equals(card.Attribute1, StringComparison.OrdinalIgnoreCase)).First(); attObj.Att2 = Emojis.Where(x => x.Name.Equals(card.Attribute2, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); attObj.Att3 = Emojis.Where(x => x.Name.Equals(card.Attribute3, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); return(attObj); //builder.AddField("Attribute 1", Emojis.Where(x => x.Name.Equals(card.Attribute1, StringComparison.OrdinalIgnoreCase)).First(), true); //if(card.Attribute2 != null) // builder.AddField("Attribute 2", Emojis.Select(x => x.Name.Equals(card.Attribute2, StringComparison.OrdinalIgnoreCase)).First(), true); //if(card.Attribute3 != null) // builder.AddField("Attribute 3", Emojis.Select(x => x.Name.Equals(card.Attribute3, StringComparison.OrdinalIgnoreCase)).First(), true); //return builder; }
public static void LoadDatabase() { //DinnCards = JsonConvert.DeserializeObject<List<DinnCard>>(File.ReadAllText("DinnCards.json")); UserCredential credential; Console.WriteLine($"{DateTime.Now} - Updating DINN Card Database from Google Sheets."); using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { string credPath = "token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; } var service = new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); String spreadsheetId = "1YoOdowodbPv_QGvuvPcwvGA1yqyZjZBmuY0TlbUi56I"; string range = "Master Card List!A:J"; SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadsheetId, range); ValueRange response = request.Execute(); IList <IList <Object> > values = response.Values; try { DinnCards.Clear(); for (int i = 0; i < values.Count; i++) { if (i == 0) { //Skip first row as headers; continue; } try { var card = new DinnCard(); card.Name = values[i][0].ToString(); card.Type = values[i][1].ToString(); var attribute1 = values[i][2].ToString(); if (attribute1.Length > 1) { card.Attribute1 = attribute1; } var attribute2 = values[i][3].ToString(); if (attribute2.Length > 1) { card.Attribute2 = attribute2; } var attribute3 = values[i][4].ToString(); if (attribute3.Length > 1) { card.Attribute3 = attribute3; } var heartValueS = values[i][5].ToString(); var basePowerS = values[i][6].ToString(); if (heartValueS.Length > 0) { card.HeartValue = Int32.Parse(heartValueS); } if (basePowerS.Length > 0) { card.BasePower = Int32.Parse(basePowerS); } card.cardText = values[i][7].ToString(); card.Released = values[i][8].ToString(); card.ImageURL = values[i][9].ToString(); DinnCards.Add(card); } catch (Exception ex) { Console.WriteLine(ex); } } } catch (Exception ex) { Console.WriteLine(ex); } }