Esempio n. 1
0
        public void ReadDataFromSheet(ExportConfig exportConfig)
        {
            dataKeys   = ExtractDataFromSheet(service, appConfig.spreadSheetId, exportConfig.sheetTab, exportConfig.keyRange);
            dataValues = ExtractDataFromSheet(service, appConfig.spreadSheetId, exportConfig.sheetTab, exportConfig.valueRange);

            if (dataKeys == null || dataValues == null)
            {
                throw new Exception("[GoogleSheet2Json] keys or values are null, please check that the inputted data is correct");
            }
        }
Esempio n. 2
0
 public void Lex(IList <object> keys, IList <IList <object> > dataValues, ExportConfig exportConfig)
 {
     if (keys != null && dataValues != null)
     {
         if (exportConfig.isArrayOfObjects)
         {
             LexArrayOfValues(keys, dataValues, exportConfig);
         }
         else if (exportConfig.isSingleObject)
         {
             LexSingleObjectValues(dataValues, exportConfig);
         }
     }
 }
Esempio n. 3
0
        private void LexSingleObjectValues(IList <IList <object> > dataValues, ExportConfig exportConfig)
        {
            parser.StartSingleObject();

            IList <object> propDefinition = new List <object>();
            IList <object> propValues     = new List <object>();

            foreach (var values in dataValues)
            {
                // object is only a key value pair between property definition and its value
                if (values.Count >= 2)
                {
                    propDefinition.Add(values[0]);
                    propValues.Add(values[1]);
                }
            }

            for (int i = 0; i < propDefinition.Count; i++)
            {
                var key   = propDefinition[i].ToString().Trim();
                var value = propValues[i];

                if (!string.Equals(key, StringConstants.COMMENT_ANNOTATION))
                {
                    Logger.DebugLogLine($"Lexing data with key: {key} and value: {value}");

                    parser.StartField();

                    LexKey(key);

                    if (exportConfig.literalKeys.Contains(key))
                    {
                        parser.Name(value.ToString());
                    }
                    else
                    {
                        LexValue(value.ToString());
                    }

                    parser.EndField();

                    Logger.DebugLogLine("Data lexed successfully.");
                }
            }

            parser.End();
        }
Esempio n. 4
0
        public void Initialise(ExportConfig exportConfig)
        {
            if (string.IsNullOrEmpty(exportConfig.configPath))
            {
                throw new ArgumentNullException("[ConfigReader] config path is empty");
            }

            StreamReader file = new StreamReader(exportConfig.configPath);

            using (file)
            {
                appConfig = JsonConvert.DeserializeObject <AppConfig>(file.ReadToEnd());
                if (!string.IsNullOrEmpty(exportConfig.outputDir))
                {
                    appConfig.outputDirectory = exportConfig.outputDir;
                }

                Logger.DebugLogLine($"[ConfigReader] Start app with config {appConfig}");
            }
        }
Esempio n. 5
0
        private void LexArrayOfValues(IList <object> keys, IList <IList <object> > dataValues, ExportConfig exportConfig)
        {
            parser.StartArrayOfObjects();
            // define property container
            parser.Name("root");

            foreach (var values in dataValues)
            {
                if (values.Count > 0)
                {
                    parser.StartProperty();

                    for (int i = 0; i < keys.Count; i++)
                    {
                        if (i < values.Count)
                        {
                            var key   = keys[i].ToString().Trim();
                            var value = values[i];

                            if (!string.Equals(key, StringConstants.COMMENT_ANNOTATION) && !string.IsNullOrEmpty(value.ToString()))
                            {
                                Logger.DebugLogLine($"Lexing data with key: {key} and value: {value}");

                                parser.StartField();

                                LexKey(key);

                                if (exportConfig.literalKeys.Contains(key))
                                {
                                    parser.Name(value.ToString());
                                }
                                else
                                {
                                    LexValue(value.ToString());
                                }

                                parser.EndField();

                                Logger.DebugLogLine("Data lexed successfully.");
                            }
                        }
                    }

                    parser.EndProperty();
                }
            }

            parser.End();
        }
Esempio n. 6
0
 public ArgumentReader(bool checkErrors = true)
 {
     this.checkErrors = checkErrors;
     exportConfig     = new ExportConfig();
 }