Advertisement
OvidiuS

Program.cs

Jun 14th, 2014
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7. using System.Xml.Linq;
  8. using System.Xml.Serialization;
  9.  
  10. namespace ConsoleApplication6
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             XmlSerializer serializer = new XmlSerializer(typeof(NotepadPlus));
  17.             NotepadPlus pawnDeserialized;
  18.             StreamReader streamReader = new StreamReader("pawn.xml");
  19.  
  20.             using (XmlReader xmlReader = XmlReader.Create(streamReader))
  21.             {          
  22.                 pawnDeserialized = (NotepadPlus)serializer.Deserialize(xmlReader);
  23.             }
  24.  
  25.             int i = 1;
  26.             using (System.IO.StreamWriter file = new System.IO.StreamWriter("pawn.sublime-temp"))
  27.             {
  28.                 foreach (var e in pawnDeserialized.Items)
  29.                 {
  30.                     foreach (var x in e.KeyWord)
  31.                     {
  32.                         if (x.func != null)
  33.                         {
  34.                             file.Write("{ \"trigger\": " + "\"" + x.name);
  35.                             if (x.Overload != null)
  36.                             {
  37.                                 foreach (var c in x.Overload)
  38.                                 {
  39.                                     file.Write("\\t" + c.descr + "\", " + "\"contents\": \""+ x.name + "(");
  40.                                     foreach (var p in c.Param)
  41.                                     {
  42.                                         int cn = c.Param.Count();
  43.  
  44.                                         if (p.name != "" && cn != 0)
  45.                                         {
  46.                                             file.Write("${" + i + ":" + p.name);
  47.                                             file.Write(cn != i ? "}, " : "}");
  48.                                             i++;
  49.                                         }
  50.                                     }
  51.                                 }
  52.                             }
  53.                             i = 1;
  54.                             file.Write(")\" },\n");
  55.                         }
  56.                      
  57.                     }
  58.  
  59.                 }
  60.             }
  61.             Console.WriteLine("Jobs done!");
  62.  
  63.             /* EXTRACT functions to function.txt
  64.             var xdoc = XDocument.Load("pawn.xml");
  65.             var keyWord = from e in xdoc.Descendants("KeyWord")
  66.                           select new
  67.                           {
  68.                               name = e.Attribute("name"),
  69.                               isFunc = e.Attribute("func"),
  70.                           };
  71.  
  72.  
  73.             using (System.IO.StreamWriter file = new System.IO.StreamWriter("function.txt"))
  74.             {
  75.                 foreach (var functions in keyWord)
  76.                 {
  77.                     if (functions.isFunc != null)
  78.                     {
  79.                         Console.WriteLine("Function name: " + functions.name.Value);
  80.                         file.Write(functions.name.Value + "|");
  81.                     }
  82.                 }
  83.             }
  84.             */
  85.             Console.ReadLine();
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement