Exemple #1
0
        private static bool IsHeaderMatch(ConstructFile constructFile, HeaderRecord fileHeader)
        {
            var titles = constructFile.GetColumnTitles();

            for (int i = 0; i < fileHeader.Count; ++i)
            {
                if (i < titles.Length)
                {
                    if (titles[i] != fileHeader[i])
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        public static void ReadContentFile(ConstructFile construct, ref ContentFile contentFile)
        {
            string path = TableGlobalConfig.Instance.ResTablePath + "\\" + construct.Path + construct.Name + ".csv";

            if (!string.IsNullOrEmpty(construct.OldName))
            {
                path = TableGlobalConfig.Instance.ResTablePath + "\\" + construct.Path + construct.OldName + ".csv";
            }

            if (!File.Exists(path))
            {
                //CreateNewFile(construct);
                TableContentManager.Instance.AddContentFile(contentFile);
                return;
            }

            string[] lines = File.ReadAllLines(path, Encoding.Default);
            if (lines.Length == 0)
            {
                return;
            }

            contentFile.ContentRow.Clear();
            lines[0] = lines[0].Replace("\r\n", "\n");
            StringReader rdr = new StringReader(string.Join("\n", lines));

            using (var reader = new CsvReader(rdr))
            {
                HeaderRecord header = reader.ReadHeaderRecord();
                //string curGourpName = "";
                //string curClassName = "";



                var columnTitles = construct.GetColumnTitles();
                while (reader.HasMoreRecords)
                {
                    DataRecord data = reader.ReadDataRecord();
                    //if (data[0].StartsWith("###"))
                    //{
                    //    curGourpName = data[0].TrimStart('#');
                    //    continue;
                    //}

                    //if (data[0].StartsWith("##"))
                    //{
                    //    curClassName = data[0].TrimStart('#');
                    //    continue;
                    //}

                    ContentRow clumn = ReadRow(construct, data, contentFile);
                    contentFile.AddContentRow(clumn);
                }

                if (IsHeaderMatch(construct, header))
                {
                    contentFile.WriteFlag = false;
                }
                else
                {
                    contentFile.WriteFlag = true;
                }
                contentFile.IsInit = false;
                TableContentManager.Instance.AddContentFile(contentFile);
            }
        }