コード例 #1
0
        static void ImportStringTable(MenuCommand command)
        {
            var table = command.context as StringTable;

            Assert.IsTrue(table != null, "Expected StringTable");

            var path = EditorUtility.OpenFilePanel($"Import CSV into {table.TableData}({table.LocaleIdentifier})", PreviousDirectory, "csv");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            EditorPrefs.SetString(kPrefFile, path);

            var collection = LocalizationEditorSettings.GetCollectionFromTable(table) as StringTableCollection;

            if (collection == null)
            {
                Debug.LogError("String Table must belong to a StringTableCollection.");
                return;
            }

            var cellMappings = new CsvColumns[] { new KeyIdColumns(), new LocaleColumns {
                                                      LocaleIdentifier = table.LocaleIdentifier
                                                  } };

            using (var stream = new StreamReader(path))
            {
                var reporter = TaskReporter.CreateDefaultReporter();
                reporter.Start("Importing " + path, string.Empty);
                Csv.ImportInto(stream, collection, cellMappings, true, reporter);
            }
        }
コード例 #2
0
        public string GetFieldFromSuperOfficeProject(CsvColumns superofficeId, CsvColumns field)
        {
            var reader = new XmlReader(path: Config.XmlFilePath);

            var projectids = reader.GetColumns(superofficeId).Select(x => Convert.ToInt32(x)).ToList();
            var fields     = reader.GetColumns(field);

            //Connect superoffice projectId to area
            var dict = projectids.Select((keys, index) => new { k = keys, v = fields[index] }).ToDictionary(x => x.k, x => x.v);

            var area = dict.FirstOrDefault(x => x.Key == _projectId).Value;

            return(area);
        }
コード例 #3
0
        private void fillComboBox(string path, char csvSeparator)
        {
            string headLine;

            CsvColumns.Clear();
            StreamReader sr = new StreamReader(path);

            headLine = sr.ReadLine();
            sr.Close();
            string[] columnsName;
            columnsName = headLine.Split(csvSeparator);
            foreach (string s in columnsName)
            {
                CsvColumns.Add(s);
            }
        }
コード例 #4
0
        private CsvColumns GetPublicFieldsAndProperties <T>()
        {
            if (!cache.ContainsKey(typeof(T)))
            {
                cache[typeof(T)] = new CsvColumns()
                {
                    Fields = typeof(T).GetFields(System.Reflection.BindingFlags.ExactBinding
                                                 | System.Reflection.BindingFlags.Public
                                                 | System.Reflection.BindingFlags.Instance),
                    Properties = typeof(T).GetProperties(System.Reflection.BindingFlags.ExactBinding
                                                         | System.Reflection.BindingFlags.Public
                                                         | System.Reflection.BindingFlags.Instance)
                };
            }

            return(cache[typeof(T)]);
        }
コード例 #5
0
        static void ExportTable(StringTable table, bool includeComments)
        {
            var collection = LocalizationEditorSettings.GetCollectionFromTable(table) as StringTableCollection;

            if (collection == null)
            {
                Debug.LogError("String Table must belong to a StringTableCollection.");
                return;
            }

            var cellMappings = new CsvColumns[] { new KeyIdColumns {
                                                      IncludeSharedComments = includeComments
                                                  }, new LocaleColumns {
                                                      LocaleIdentifier = table.LocaleIdentifier, IncludeComments = includeComments
                                                  } };

            Export(cellMappings, collection);
        }
コード例 #6
0
        public List <string> GetColumns(CsvColumns column)
        {
            var rows = new List <string>();

            using (var reader = new StreamReader(_path, Encoding.UTF8))
            {
                var file  = File.ReadAllLines(_path);
                var lines = file.Select(x => x.Split(";"));

                while (!reader.EndOfStream)
                {
                    var list   = reader.ReadLine();
                    var values = list.Split(';');
                    rows.Add(values[(int)column]);
                }
            }

            //Two first rows are names of the column and we will skip them
            return(rows.Skip(2).ToList());
        }
コード例 #7
0
        public string GetHeader <T>() where T : class, new()
        {
            CsvColumns csvColumns = GetPublicFieldsAndProperties <T>();

            StringBuilder text = new StringBuilder();

            bool prependComma = false;

            foreach (KeyValuePair <string, object> columnData in csvColumns.GetColumnEnumerator(null))
            {
                if (prependComma)
                {
                    text.Append(",");
                }
                text.Append(ToCsvSafe(columnData.Key));
                prependComma = true;
            }

            text.AppendLine();

            return(text.ToString());
        }
コード例 #8
0
 public ColumnEnumerator(CsvColumns csvColumns, object obj)
 {
     this.csvColumns = csvColumns;
     this.obj        = obj;
 }