Ejemplo n.º 1
0
        public void LoadFrom(string[] lines)
        {
            string fname = "UNKNOWN";

            for (int i = 0; i < lines.Length; i++)
            {
                string cline = lines[i].Trim();
                if (cline.StartsWith("/<FILE:"))
                {
                    fname = cline.Substring("/<FILE:".Length);
                }
                if (!cline.StartsWith("//"))
                {
                    continue;
                }
                if (cline.Length < 4)
                {
                    cline = "//  ";
                }
                cline = cline.Substring(3).Trim();
                if (cline.StartsWith("<--["))
                {
                    string  objtype = cline.Substring(4, cline.Length - 5).ToLower();
                    dObject nobj    = null;
                    switch (objtype)
                    {
                    case "action":
                        nobj = new dAction();
                        Actions.Add((dAction)nobj);
                        break;

                    case "example":
                    case "tutorial":
                        nobj = new dTutorial();
                        Tutorials.Add((dTutorial)nobj);
                        break;

                    case "mechanism":
                        nobj = new dMechanism();
                        Mechanisms.Add((dMechanism)nobj);
                        break;

                    case "tag":
                        nobj = new dTag();
                        Tags.Add((dTag)nobj);
                        break;

                    case "command":
                        nobj = new dCommand();
                        Commands.Add((dCommand)nobj);
                        break;

                    case "language":
                        nobj = new dLanguage();
                        Languages.Add((dLanguage)nobj);
                        break;

                    case "event":
                        nobj = new dEvent();
                        Events.Add((dEvent)nobj);
                        break;

                    case "requirement":
                        break;

                    default:
                        Logger.Output(LogType.ERROR, "Unknown object type " + objtype + " in " + fname);
                        break;
                    }
                    if (nobj == null)
                    {
                        continue;
                    }
                    nobj.FileName = fname;
                    Objects.Add(nobj);
                    i++;
                    while (i < lines.Length)
                    {
                        cline = lines[i].Trim();
                        if (!cline.StartsWith("//"))
                        {
                            Logger.Output(LogType.ERROR, "Found line <<" + cline + ">> in the middle of an object declaration in " + fname);
                            i++;
                            continue;
                        }
                        if (cline.Length < 4)
                        {
                            cline = "//  ";
                        }
                        cline = cline.Substring(3);
                        if (cline == "-->")
                        {
                            break;
                        }
                        if (!cline.StartsWith("@"))
                        {
                            Logger.Output(LogType.ERROR, "Found line '// " + cline + "' in the middle of an object declaration in " + fname);
                            i++;
                            continue;
                        }
                        string typer = cline.Substring(1);
                        string value = "";
                        if (typer.Contains(' '))
                        {
                            value += typer.Substring(typer.IndexOf(' ') + 1);
                            typer  = typer.Substring(0, typer.IndexOf(' '));
                        }
                        while (i + 1 < lines.Length)
                        {
                            cline = lines[i + 1].Trim();
                            if (cline.Length < 4)
                            {
                                cline = "//  ";
                            }
                            cline = cline.Substring(3);
                            if ((cline.StartsWith("@") && !cline.StartsWith("@ ")) || cline == "-->")
                            {
                                break;
                            }
                            value += "\n" + cline;
                            i++;
                        }
                        nobj.ApplyVar(typer.ToLower(), value);
                        i++;
                    }
                }
            }
        }
 public void LoadFrom(string[] lines)
 {
     string fname = "UNKNOWN";
     for (int i = 0; i < lines.Length; i++)
     {
         string cline = lines[i].Trim();
         if (cline.StartsWith("/<FILE:"))
         {
             fname = cline.Substring("/<FILE:".Length);
         }
         if (!cline.StartsWith("//"))
         {
             continue;
         }
         if (cline.Length < 4)
         {
             cline = "//  ";
         }
         cline = cline.Substring(3).Trim();
         if (cline.StartsWith("<--["))
         {
             string objtype = cline.Substring(4, cline.Length - 5).ToLower();
             dObject nobj = null;
             switch (objtype)
             {
                 case "action":
                     nobj = new dAction();
                     Actions.Add((dAction)nobj);
                     break;
                 case "example":
                 case "tutorial":
                     nobj = new dTutorial();
                     Tutorials.Add((dTutorial)nobj);
                     break;
                 case "mechanism":
                     nobj = new dMechanism();
                     Mechanisms.Add((dMechanism)nobj);
                     break;
                 case "tag":
                     nobj = new dTag();
                     Tags.Add((dTag)nobj);
                     break;
                 case "command":
                     nobj = new dCommand();
                     Commands.Add((dCommand)nobj);
                     break;
                 case "language":
                     nobj = new dLanguage();
                     Languages.Add((dLanguage)nobj);
                     break;
                 case "event":
                     nobj = new dEvent();
                     Events.Add((dEvent)nobj);
                     break;
                 case "requirement":
                     break;
                 default:
                     Logger.Output(LogType.ERROR, "Unknown object type " + objtype + " in " + fname);
                     break;
             }
             if (nobj == null)
             {
                 continue;
             }
             nobj.FileName = fname;
             Objects.Add(nobj);
             i++;
             while (i < lines.Length)
             {
                 cline = lines[i].Trim();
                 if (!cline.StartsWith("//"))
                 {
                     Logger.Output(LogType.ERROR, "Found line <<" + cline + ">> in the middle of an object declaration in " + fname);
                     i++;
                     continue;
                 }
                 if (cline.Length < 4)
                 {
                     cline = "//  ";
                 }
                 cline = cline.Substring(3);
                 if (cline == "-->")
                 {
                     break;
                 }
                 if (!cline.StartsWith("@"))
                 {
                     Logger.Output(LogType.ERROR, "Found line '// " + cline + "' in the middle of an object declaration in " + fname);
                     i++;
                     continue;
                 }
                 string typer = cline.Substring(1);
                 string value = "";
                 if (typer.Contains(' '))
                 {
                     value += typer.Substring(typer.IndexOf(' ') + 1);
                     typer = typer.Substring(0, typer.IndexOf(' '));
                 }
                 while (i + 1 < lines.Length)
                 {
                     cline = lines[i + 1].Trim();
                     if (cline.Length < 4)
                     {
                         cline = "//  ";
                     }
                     cline = cline.Substring(3);
                     if ((cline.StartsWith("@") && !cline.StartsWith("@ ")) || cline == "-->")
                     {
                         break;
                     }
                     value += "\n" + cline;
                     i++;
                 }
                 nobj.ApplyVar(typer.ToLower(), value);
                 i++;
             }
         }
     }
 }