public override ReferenceReader Initialize() { LoadCache(); if (!IsAllDataCached() || CardMakerInstance.ForceDataCacheRefresh) { var zSpreadsheet = new GoogleSpreadsheet(CardMakerInstance.GoogleInitializerFactory); try { zSpreadsheet.MakeSimpleSpreadsheetRequest(); } catch (GoogleApiException e) { if (GoogleApi.IsAuthorizationError(e)) { CardMakerInstance.GoogleCredentialsInvalid = true; } } catch (Exception e) { Logger.AddLogLine("Google Access Error: {0}".FormatString(e.Message)); } } return(this); }
public GoogleReferenceReader() { LoadCache(); if (!IsAllDataCached() || CardMakerInstance.ForceDataCacheRefresh) { var zSpreadsheet = new GoogleSpreadsheet(CardMakerInstance.GoogleInitializerFactory); try { zSpreadsheet.MakeSimpleSpreadsheetRequest(); } catch (GoogleApiException e) { if (GoogleApi.IsAuthorizationError(e)) { CardMakerInstance.GoogleCredentialsInvalid = true; } } } }
public void GetData(GoogleSpreadsheetReference zReference, List <List <string> > listData, bool bRemoveFirstRow, string sNameAppend = "") { var sCacheKey = GetCacheKey(zReference.generateFullReference(), sNameAppend); List <List <string> > listCacheData; if (!CardMakerInstance.ForceDataCacheRefresh && m_dictionaryDataCache.TryGetValue(sCacheKey, out listCacheData)) { ProgressReporter.AddIssue("Loading {0} from local cache".FormatString(sCacheKey)); listData.AddRange(listCacheData); return; } var sSpreadsheetName = zReference.SpreadsheetName; var sSheetName = zReference.SheetName + sNameAppend; var bAuthorizationError = false; var bError = false; List <List <string> > listGoogleData = null; try { var zGoogleSpreadsheet = new GoogleSpreadsheet(CardMakerInstance.GoogleInitializerFactory); if (string.IsNullOrWhiteSpace(zReference.SpreadsheetId)) { ProgressReporter.AddIssue("WARNING: The reference {0}.{1} is missing the Spreadsheet ID. Please reconfigure this reference." .FormatString(zReference.SpreadsheetName, zReference.SheetName)); listGoogleData = zGoogleSpreadsheet.GetSheetContentsBySpreadsheetName(sSpreadsheetName, sSheetName); } else { listGoogleData = zGoogleSpreadsheet.GetSheetContentsBySpreadsheetId(zReference.SpreadsheetId, sSheetName); } // blank data just means an empty or non-existent sheet (generally okay) if (listGoogleData == null) { listGoogleData = new List <List <string> >(); } } catch (GoogleApiException e) { ProgressReporter.AddIssue("Google Spreadsheet access exception: " + e.Message); bAuthorizationError = GoogleApi.IsAuthorizationError(e); } catch (Exception e) { ProgressReporter.AddIssue("General exception: " + e.Message); listGoogleData = null; bError = true; } if (bAuthorizationError || bError || listGoogleData == null) { ProgressReporter.AddIssue("Failed to load any data from Google Spreadsheet." + "[" + sSpreadsheetName + "," + sSheetName + "]" + (bAuthorizationError ? " Google reported a problem with your credentials." : String.Empty)); } else { if (bRemoveFirstRow && listGoogleData.Count > 0) { listGoogleData.RemoveAt(0); } listData.AddRange(listGoogleData); if (m_dictionaryDataCache.ContainsKey(sCacheKey)) { m_dictionaryDataCache.Remove(sCacheKey); } m_dictionaryDataCache.Add(sCacheKey, listGoogleData); m_bCacheUpdated = true; } }