public static void WriteFileOldName(ConstructFile file, string oldName) { if (file == null) { return; } string configPath = ConstructConfig.CONSTUCT_FOLD_PATH + "/" + file.Name + ".xml"; if (!File.Exists(configPath)) { return; } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configPath); XmlNode root = xmlDoc.SelectSingleNode(ConstructConfig.DOC_ROOT_STR); // foreach (XmlElement childElement in root.ChildNodes.OfType <XmlElement>()) { if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_OLD_NAME) { childElement.InnerText = oldName; break; } } xmlDoc.Save(configPath); }
public void CreateNewFile(string name) { ConstructFile file = new ConstructFile(name); AddFile(file); ModifyFiles.Add(file.Name); }
public static void ReadContentFile(ConstructFile construct) { ContentFile contentFile = new ContentFile(construct); contentFile.Name = construct.Name; contentFile.IsInit = true; ReadContentFile(construct, ref contentFile); }
public static void WriteFile(string name) { ConstructFile file = ConstructFold.Instance.ConstructFiles.GetByName(name) as ConstructFile; if (file != null) { WriteFile(file); } }
private void MenuItem_Remove(object sender, RoutedEventArgs e) { ConstructFile fileInfo = LinkList.SelectedItem as ConstructFile; if (fileInfo == null) { return; } ConstructFold.Instance.RemoveFile(fileInfo.Name); }
public static void WriteDirectroy(ConstructFile file) { string[] pathNames = file.Path.Split('\\'); for (int i = 0; i < pathNames.Length - 1; ++i) { if (string.IsNullOrEmpty(pathNames[i])) { continue; } } }
public static void ReadFile(FileInfo fileInfo) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(fileInfo.FullName); string fileName = fileInfo.Name.Remove(fileInfo.Name.LastIndexOf(".")); ConstructFile file = new ConstructFile(fileName, false); ConstructFold.Instance.AddFile(file); XmlNode root = xmlDoc.SelectSingleNode(ConstructConfig.DOC_ROOT_STR); foreach (XmlElement childElement in root.ChildNodes.OfType<XmlElement>()) { if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_CLASS) { file.Class = childElement.InnerText; } else if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_DESC) { file.Desc = childElement.InnerText; } else if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_OLD_NAME) { file.OldName = childElement.InnerText; } else if(childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_COLUMN) { ConstructItem item = ReadColumn(childElement); if (item != null) { file.ConstructItems.AddNewItem(item); //重置写标记 item.WriteFlag = false; } } } //重置写标记 file.ConstructItems.WriteFlag = false; file.WriteFlag = false; } catch (Exception e) { } }
public void ShowContent(object param) { ConstructFile fileInfo = param as ConstructFile; if (fileInfo == null) return; _ConstructFile = fileInfo; //ItemAttrPanel.Visibility = System.Windows.Visibility.Collapsed; LinkList.ItemsSource = _ConstructFile.ConstructItems; //InitItemType1(); ContentTransition.ChangeContent(null, PathContentTranstitionType.NO_ANIM); }
public static void ReadFile(FileInfo fileInfo) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(fileInfo.FullName); string fileName = fileInfo.Name.Remove(fileInfo.Name.LastIndexOf(".")); ConstructFile file = new ConstructFile(fileName, false); ConstructFold.Instance.AddFile(file); file.Path = fileInfo.FullName.Replace(_ConstructPath, "").Replace(fileInfo.Name, ""); XmlNode root = xmlDoc.SelectSingleNode(ConstructConfig.DOC_ROOT_STR); foreach (XmlElement childElement in root.ChildNodes.OfType <XmlElement>()) { if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_CLASS) { file.Class = childElement.InnerText; } else if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_DESC) { file.Desc = childElement.InnerText; } else if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_OLD_NAME) { file.OldName = childElement.InnerText; } else if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_COLUMN) { ConstructItem item = ReadColumn(childElement); if (item != null) { file.ConstructItems.AddNewItem(item); //重置写标记 item.WriteFlag = false; } } } //重置写标记 file.ConstructItems.WriteFlag = false; file.WriteFlag = false; } catch (Exception e) { } }
private void MenuItem_Rename(object sender, RoutedEventArgs e) { ConstructFile fileInfo = LinkList.SelectedItem as ConstructFile; if (fileInfo == null) { return; } string newName = DialogMessage.DialogString(fileInfo.Name); if (!string.IsNullOrEmpty(newName)) { ConstructFold.Instance.RenameFile(fileInfo.Name, newName); } }
public void RenameFile(string orgName, string newName) { ConstructFile file = ConstructFiles.GetByName(orgName) as ConstructFile; if (file != null) { if (string.IsNullOrEmpty(file.OldName)) { file.OldName = file.Name; //WriteConstruct.WriteFileOldName(file, file.OldName); } file.Name = newName; RemoveFiles.Add(orgName); ModifyFiles.Add(newName); } }
public void ShowContent(object param) { ConstructFile fileInfo = param as ConstructFile; if (fileInfo == null) { return; } _ConstructFile = fileInfo; //ItemAttrPanel.Visibility = System.Windows.Visibility.Collapsed; LinkList.ItemsSource = _ConstructFile.ConstructItems; //InitItemType1(); ContentTransition.ChangeContent(null, PathContentTranstitionType.NO_ANIM); }
public static void ReadDirect(DirectoryInfo directInfo) { ConstructFile file = new ConstructFile(directInfo.Name, false); foreach (FileInfo fileInfo in directInfo.GetFiles()) { if (fileInfo.Extension == ".xml") { ReadFile(fileInfo); } } foreach (DirectoryInfo direct in directInfo.GetDirectories()) { ReadDirect(direct); } }
private void LinkList_SelectionChanged(object sender, SelectionChangedEventArgs e) { ConstructFile fileInfo = LinkList.SelectedItem as ConstructFile; if (fileInfo == null) { return; } PathBaseFrame pathFrame = ParentBaseFrame as PathBaseFrame; if (pathFrame == null) { return; } pathFrame.PushPage(PathItem, fileInfo.Name, typeof(ConstructItemInfo), fileInfo); }
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; }
public static void ReadContentFile(ConstructFile construct, ref ContentFile contentFile) { string path = TableGlobalConfig.Instance.ResTablePath + "/" + construct.Name + ".csv"; if (!string.IsNullOrEmpty(construct.OldName)) { path = TableGlobalConfig.Instance.ResTablePath + "/" + construct.OldName + ".csv"; } if (!File.Exists(path)) { CreateNewFile(construct); 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); } }
private void CSCreateTableFile(ConstructFile constructFile, string filePath) { var builder = new StringBuilder(); var itemInit = new StringBuilder(); //record builder.Append("using System;\n"); builder.Append("using System.IO;\n"); builder.Append("using System.Text;\n"); builder.Append("using System.Collections.Generic;\n"); builder.Append("using Kent.Boogaart.KBCsv;\n\n"); builder.Append("using UnityEngine;\n\n"); builder.Append("namespace Tables\n"); builder.Append("{\n"); builder.Append(" public partial class " + constructFile.Name + "Record : TableRecordBase\n"); builder.Append(" {\n"); builder.Append(" public DataRecord ValueStr;\n\n"); foreach(ConstructItem constructItem in constructFile.ConstructItems) { string typeCode = CSTableItemTypeCode(constructItem); builder.Append(" public " + typeCode + " " + constructItem.ItemCode + " { get; set; }\n"); if (typeCode.Contains("List")) { itemInit.Append(" " + constructItem.ItemCode + " = new " + typeCode + "();\n"); } } builder.Append(" public " + constructFile.Name + "Record(DataRecord dataRecord)\n"); builder.Append(" {\n"); builder.Append(" if (dataRecord != null)\n"); builder.Append(" {\n"); builder.Append(" ValueStr = dataRecord;\n"); builder.Append(" Id = ValueStr[0];\n\n"); builder.Append(" }\n"); builder.Append(itemInit); builder.Append(" }\n"); builder.Append(" public string[] GetRecordStr()\n"); builder.Append(" {\n"); builder.Append(" List<string> recordStrList = new List<string>();\n"); for (int i = 0; i < constructFile.ConstructItems.Count; ++i) { var constructItem = constructFile.ConstructItems[i] as ConstructItem; if (constructItem.ItemRepeat > 1) { builder.Append(" foreach (var testTableItem in " + constructItem.ItemCode + ")\n"); builder.Append(" {\n"); if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_TABLE_ID && constructItem.ItemType2.Count == 1) { builder.Append(" if (testTableItem != null)\n"); builder.Append(" {\n"); builder.Append(" recordStrList.Add(testTableItem.Id);\n"); builder.Append(" }\n"); builder.Append(" else\n"); builder.Append(" {\n"); builder.Append(" recordStrList.Add(\"\");\n"); builder.Append(" }\n"); } else if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_ENUM) { builder.Append(" recordStrList.Add(((int)testTableItem).ToString());\n"); } else { builder.Append(" recordStrList.Add(TableWriteBase.GetWriteStr(testTableItem));\n"); } builder.Append(" }\n"); } else { if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_TABLE_ID && constructItem.ItemType2.Count == 1) { builder.Append(" if (" + constructItem.ItemCode + " != null)\n"); builder.Append(" {\n"); builder.Append(" recordStrList.Add(" + constructItem.ItemCode + ".Id);\n"); builder.Append(" }\n"); builder.Append(" else\n"); builder.Append(" {\n"); builder.Append(" recordStrList.Add(\"\");\n"); builder.Append(" }\n"); } else if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_ENUM) { builder.Append(" recordStrList.Add(((int)" + constructItem.ItemCode + ").ToString());\n"); } else { builder.Append(" recordStrList.Add(TableWriteBase.GetWriteStr(" + constructItem.ItemCode + "));\n"); } } } builder.Append("\n return recordStrList.ToArray();\n"); builder.Append(" }\n"); builder.Append(" }\n\n"); //for info builder.Append(" public partial class " + constructFile.Name + " : TableFileBase\n"); builder.Append(" {\n"); builder.Append(" public Dictionary<string, " + constructFile.Name + "Record> Records { get; internal set; }\n\n"); builder.Append(" public bool ContainsKey(string key)\n"); builder.Append(" {\n"); builder.Append(" return Records.ContainsKey(key);\n"); builder.Append(" }\n\n"); builder.Append(" public " + constructFile.Name + "Record GetRecord(string id)\n"); builder.Append(" {\n"); builder.Append(" try\n"); builder.Append(" {\n"); builder.Append(" return Records[id];\n"); builder.Append(" }\n"); builder.Append(" catch (Exception ex)\n"); builder.Append(" {\n"); builder.Append(" throw new Exception(\"" + constructFile.Name + "\" + \": \" + id, ex);\n"); builder.Append(" }\n"); builder.Append(" }\n\n"); builder.Append(" public " + constructFile.Name + "(string pathOrContent,bool isPath = true)\n"); builder.Append(" {\n"); builder.Append(" Records = new Dictionary<string, " + constructFile.Name + "Record>();\n"); builder.Append(" if(isPath)\n"); builder.Append(" {\n"); builder.Append(" string[] lines = File.ReadAllLines(pathOrContent, Encoding.Default);\n"); builder.Append(" lines[0] = lines[0].Replace(\"\\r\\n\", \"\\n\");\n"); builder.Append(" ParserTableStr(string.Join(\"\\n\", lines));\n"); builder.Append(" }\n"); builder.Append(" else\n"); builder.Append(" {\n"); builder.Append(" ParserTableStr(pathOrContent.Replace(\"\\r\\n\", \"\\n\"));\n"); builder.Append(" }\n"); builder.Append(" }\n\n"); builder.Append(" private void ParserTableStr(string content)\n"); builder.Append(" {\n"); builder.Append(" StringReader rdr = new StringReader(content);\n"); builder.Append(" using (var reader = new CsvReader(rdr))\n"); builder.Append(" {\n"); builder.Append(" HeaderRecord header = reader.ReadHeaderRecord();\n"); builder.Append(" while (reader.HasMoreRecords)\n"); builder.Append(" {\n"); builder.Append(" DataRecord data = reader.ReadDataRecord();\n"); builder.Append(" if (data[0].StartsWith(\"#\"))\n"); builder.Append(" continue;\n\n"); builder.Append(" " + constructFile.Name + "Record record = new " + constructFile.Name + "Record(data);\n"); builder.Append(" Records.Add(record.Id, record);\n"); builder.Append(" }\n"); builder.Append(" }\n"); builder.Append(" }\n\n"); builder.Append(" public void CoverTableContent()\n"); builder.Append(" {\n"); builder.Append(" foreach (var pair in Records)\n"); builder.Append(" {\n"); int dataIdx = 0; for (int i = 1; i < constructFile.ConstructItems.Count; ++i) { ++dataIdx; var constructItem = constructFile.ConstructItems[i] as ConstructItem; if (constructItem.ItemRepeat > 1) { for (int j = 0; j < constructItem.ItemRepeat; ++j) { builder.Append(CSTableItemParseCode(constructItem, dataIdx, j)); if (j != constructItem.ItemRepeat - 1) { ++dataIdx; } } } else { builder.Append(CSTableItemParseCode(constructItem, dataIdx, -1)); } } builder.Append(" }\n"); builder.Append(" }\n"); builder.Append(" }\n"); builder.Append("\n"); builder.Append("}"); File.WriteAllText(filePath, builder.ToString(), Encoding.UTF8); }
public static ContentRow ReadRow(ConstructFile construct, DataRecord data, ContentFile contentFile) { ContentRow row = new ContentRow(contentFile); try { row.IsInit = true; foreach (ConstructItem constructItem in construct.ConstructItems) { ReadItem(constructItem, data, ref row); } row.IsInit = false; //if (row.ContentItems.Count != 0) //{ // row.Name = row.ContentItems[0].Value.ToString(); //} } catch (Exception e) { throw new Exception("read exception:" + e); } row.WriteFlag = false; row._ContentItems.WriteFlag = false; return row; }
public static void WriteFileOldName(ConstructFile file, string oldName) { if (file == null) return; string configPath = ConstructConfig.CONSTUCT_FOLD_PATH + "/" + file.Name + ".xml"; if (!File.Exists(configPath)) { return; } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configPath); XmlNode root = xmlDoc.SelectSingleNode(ConstructConfig.DOC_ROOT_STR); // foreach (XmlElement childElement in root.ChildNodes.OfType<XmlElement>()) { if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_OLD_NAME) { childElement.InnerText = oldName; break; } } xmlDoc.Save(configPath); }
public static void CreateNewFile(ConstructFile construct) { ContentFile contentFile = new ContentFile(construct); contentFile.Name = construct.Name; ContentRow row = new ContentRow(contentFile); foreach (ConstructItem constructItem in construct.ConstructItems) { for (int i = 0; i < constructItem.ItemRepeat; ++i) { ContentItem contentItem = new ContentItem(row, constructItem, i + 1); if (constructItem.ItemCode == ConstructConfig.NEW_FILE_DEFAULT_ID_CODE) { contentItem.Value = ContentConfig.CONTENT_INIT_DEFAULT_ID; } else { contentItem.Value = ""; } row.AddContentItem(contentItem); } } contentFile.AddContentRow(row); TableContentManager.Instance.AddContentFile(contentFile); }
public void AddFile(ConstructFile file) { ConstructFiles.AddNewItem(file); }
public static void WriteFile(ConstructFile file) { if (file == null) { return; } if (!file.IsNeedWrite()) { return; } string configPath = ConstructConfig.CONSTUCT_FOLD_PATH + "/" + file.Name + ".xml"; XmlDocument xmlDoc = new XmlDocument(); if (!File.Exists(configPath)) { XmlDeclaration dec = xmlDoc.CreateXmlDeclaration(ConstructConfig.INIT_VERSION_STR, ConstructConfig.INIT_ENCODING_STR, null); xmlDoc.AppendChild(dec); XmlElement rootInit = xmlDoc.CreateElement(ConstructConfig.DOC_ROOT_STR); xmlDoc.AppendChild(rootInit); xmlDoc.Save(configPath); } else { xmlDoc.Load(configPath); } XmlNode root = xmlDoc.SelectSingleNode(ConstructConfig.DOC_ROOT_STR); root.RemoveAll(); //表格信息 XmlElement xmlTableClass = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_CLASS); xmlTableClass.InnerText = file.Class; root.AppendChild(xmlTableClass); XmlElement xmlTableDesc = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_DESC); xmlTableDesc.InnerText = file.Desc; root.AppendChild(xmlTableDesc); XmlElement xmlTableOldName = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_OLD_NAME); xmlTableOldName.InnerText = file.OldName; root.AppendChild(xmlTableOldName); //项信息 XmlElement xmlItem = null; foreach (ConstructItem item in file.ConstructItems) { XmlElement xmlColumn = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_COLUMN); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_NAME); xmlItem.InnerText = item.Name; xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_CODE); xmlItem.InnerText = item.ItemCode; xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE1); xmlItem.InnerText = item.ItemType1; xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE2); foreach (TableBaseItem type2s in item.ItemType2) { XmlElement type2Ele = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE2); type2Ele.InnerText = type2s.Name; xmlItem.AppendChild(type2Ele); } xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_DEFAULT); xmlItem.InnerText = item.ItemDefault; xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_REPEAT); xmlItem.InnerText = item.ItemRepeat.ToString(); xmlColumn.AppendChild(xmlItem); root.AppendChild(xmlColumn); } xmlDoc.Save(configPath); file.AlreadyWrite(); file.NeedReloadContent = true; }
public static void WriteFile(ConstructFile file) { if (file == null) return; if (!file.IsNeedWrite()) return; string configPath = ConstructConfig.CONSTUCT_FOLD_PATH + "/" + file.Name + ".xml"; XmlDocument xmlDoc = new XmlDocument(); if (!File.Exists(configPath)) { XmlDeclaration dec = xmlDoc.CreateXmlDeclaration(ConstructConfig.INIT_VERSION_STR, ConstructConfig.INIT_ENCODING_STR, null); xmlDoc.AppendChild(dec); XmlElement rootInit = xmlDoc.CreateElement(ConstructConfig.DOC_ROOT_STR); xmlDoc.AppendChild(rootInit); xmlDoc.Save(configPath); } else { xmlDoc.Load(configPath); } XmlNode root = xmlDoc.SelectSingleNode(ConstructConfig.DOC_ROOT_STR); root.RemoveAll(); //表格信息 XmlElement xmlTableClass = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_CLASS); xmlTableClass.InnerText = file.Class; root.AppendChild(xmlTableClass); XmlElement xmlTableDesc = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_DESC); xmlTableDesc.InnerText = file.Desc; root.AppendChild(xmlTableDesc); XmlElement xmlTableOldName = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_TABLE_OLD_NAME); xmlTableOldName.InnerText = file.OldName; root.AppendChild(xmlTableOldName); //项信息 XmlElement xmlItem = null; foreach (ConstructItem item in file.ConstructItems) { XmlElement xmlColumn = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_COLUMN); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_NAME); xmlItem.InnerText = item.Name; xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_CODE); xmlItem.InnerText = item.ItemCode; xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE1); xmlItem.InnerText = item.ItemType1; xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE2); foreach (TableBaseItem type2s in item.ItemType2) { XmlElement type2Ele = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_TYPE2); type2Ele.InnerText = type2s.Name; xmlItem.AppendChild(type2Ele); } xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_DEFAULT); xmlItem.InnerText = item.ItemDefault; xmlColumn.AppendChild(xmlItem); xmlItem = xmlDoc.CreateElement(ConstructConfig.CONSTRUCT_ELEMENT_REPEAT); xmlItem.InnerText = item.ItemRepeat.ToString(); xmlColumn.AppendChild(xmlItem); root.AppendChild(xmlColumn); } xmlDoc.Save(configPath); file.AlreadyWrite(); file.NeedReloadContent = true; }
public ContentFile(ConstructFile construct) { _ConstuctFile = construct; }