using System;
using System.Xml;
using System.Diagnostics;
using System.Collections;
using System.CodeDom.Compiler;
using AnticipatingMinds.Genesis.CodeDOM;
namespace AnticipatingMinds.Genesis.CodeParser{
/// <summary>
/// Summary description for Class1.
/// </summary>
[System.Security.Permissions.StrongNameIdentityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand,
PublicKey=
"00240000048000009400000006020000002400005253413100040000010001009D309779C258129573FC313836474C75C4CE9F4" +
"107524FA0B9A6DB2E52754459C5A8946E4CBD5B98ACDB2413C5AFD38C1DF00C9A946713E867237B47F9D9CC473D4A853EACBEAB" +
"799EC0A271B468D4B6D52301A414A7772F05FEBD2BA7D0A2835F0D45E401C3C37F9E7B991D29F07DA88E20BB3839A34A2739AB6" +
"56B5204C8BC")]
public class ResourceParser : CodeParser
{
public ResourceParser(string sourceCode,string fileName,CodeAssembly codeAssembly):base(sourceCode,fileName,codeAssembly)
{
//
// TODO: Add constructor logic here
//
}
public override CompilerErrorCollection Errors
{
get
{
return errors;
}
}
public override CodeAssemblyFile Parse(System.Threading.ManualResetEvent cancelEvent)
{
CodeResourceFile resourceFile = new CodeResourceFile();
resourceFile.SourceFileName = FileName;
//A secret value! Tsssss, don't tell anyone!
if(CodeAssembly != null)
resourceFile.Namespace = CodeAssembly.ApplicationData["DefaultNamespace"] as string;
if(SourceCode.Length != 0)
{
try
{
XmlDocument resDoc = new XmlDocument();
resDoc.LoadXml(SourceCode);
XmlNodeList resourceNodes = resDoc.SelectNodes("/root/data");
foreach(XmlNode resourceNode in resourceNodes)
{
XmlElement resourceElement = resourceNode as XmlElement;
if(resourceElement == null)
continue;
CodeResource codeResource = new CodeResource();
codeResource.Name = resourceElement.GetAttribute("name");
codeResource.TypeName = resourceElement.GetAttribute("type");
codeResource.Value = resourceElement["value"] != null ? resourceElement["value"].InnerText : String.Empty;
codeResource.CompileUnit = resourceFile;
resourceFile.Resources.Add(codeResource);
}
}
catch(Exception e)
{
CompilerError error = new CompilerError();
error.ErrorText = e.ToString();
OnParsingError(error);
errors.Add(error);
}
}
resourceFile.Language = CodeLanguage.Resx;
return resourceFile;
}
CompilerErrorCollection errors = new CompilerErrorCollection();
}
}
|