public void CreateFromXMLFile(string path) { //StreamReader reader = new StreamReader(path); //StreamWriter writer = new StreamWriter(Path.GetFileNameWithoutExtension(path) + "2" + Path.GetExtension(path)); //string line = null; //while((line = reader.ReadLine()) != null) //{ // if(line.Contains("<message ")) // { // var pos = line.IndexOf("type=\""); // var type = line.Substring(pos + 6, 6); // pos = line.IndexOf("direction=\""); // line = line.Insert(pos, "name=\"" + types[type] + "\" category=\"" + cats[type] + "\" "); // } // writer.WriteLine(line); //} //writer.Close(); //return; XDocument doc = XDocument.Load(path); foreach (XElement e in doc.Elements()) { if (e.Name == "schema" && Version.Parse(e.Attribute("version").Value) >= schemaVersion) { ProcessSchema(e); } else { throw new Exception("schema missing or version below minimum required: " + schemaVersion); } } MessageFactoryBuilder.Build(); }
public TemplateWriter(string OutputPath) { if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); } enumBuilder = new EnumBuilder(OutputPath); typeBuilder = new TypeBuilder("Templates/Types.tcs", OutputPath, "Types", "Types"); headerBuilder = new TypeBuilder("Templates/Headers.tcs", OutputPath, "Packets\\Headers", "Packets.Headers"); messageBuilder = new MessageBuilder(OutputPath); MessageFactoryBuilder.Initialize(OutputPath); }
public MessageInstance(string OutputPath, string TemplateContent, XElement node) { outputPath = OutputPath; content = TemplateContent; baseNode = node; type = node.GetAttribute("type"); baseName = node.GetAttribute("name"); category = node.GetAttribute("category"); direction = node.GetAttribute("direction"); ordered = node.GetAttribute("ordered"); queue = node.GetAttribute("queue"); // Provide Type Summary if present content = node.BuildSummaryFrom("text", content, "//MessageSummary\r\n", 1); baseName = baseName + direction; // Set Type name content = content.Replace("MessageName", baseName); content = content.Replace("MessageBaseClass", ordered.ToLower() == "true" ? "OrderedMessage" : "Message"); string baseParameters = "(MessageType)" + type; baseParameters += ", " + (direction.ToUpper() == "S2C" ? "MessageDirection.ServerToClient" : "MessageDirection.ClientToServer"); baseParameters += ", " + "(Queues)" + GetQueue(queue); content = content.Replace("BaseParameters", baseParameters); ProcessChildElements(node); // Insert properties content = content.Replace("//PropertyList", properties.ToString()); // Create Unpack content = content.Replace("//UnpackList", unpack.ToString()); // Create Pack content = content.Replace("//PackList", pack.ToString()); // Functions for Collections content = content.Replace("//CollectionFunctions", collectionFunctions.ToString()); MessageFactoryBuilder.AddName(type, baseName, direction); }