コード例 #1
0
        private static GoogleSpreadsheetReference GetDefinesReference()
        {
            var zGoogleSpreadSheetReference = GoogleSpreadsheetReference.parseSpreadsheetOnlyReference(
                (string.IsNullOrEmpty(ProjectManager.Instance.LoadedProject.overrideDefineReferenceName)
                    ? Path.GetFileNameWithoutExtension(ProjectManager.Instance.ProjectFilePath)
                    : ProjectManager.Instance.LoadedProject.overrideDefineReferenceName)
                );

            zGoogleSpreadSheetReference.SheetName = DEFAULT_DEFINES_SHEET_NAME;
            return(zGoogleSpreadSheetReference);
        }
コード例 #2
0
 public override void GetReferenceData(ProjectLayoutReference zReference, List <List <string> > listReferenceData)
 {
     GetData(GoogleSpreadsheetReference.parse(ReferencePath), listReferenceData, false);
 }
コード例 #3
0
 public override void GetDefineData(ProjectLayoutReference zReference, List <List <string> > listDefineData)
 {
     GetData(GoogleSpreadsheetReference.parse(ReferencePath), listDefineData, true, Deck.DEFINES_DATA_POSTFIX);
 }
コード例 #4
0
        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;
            }
        }