Ejemplo n.º 1
0
        public static FuncRefInfo FromXML(XmlElement elem, ScriptInfo si)
        {
            string sfDefinitionPath = elem.GetAttribute("sfPath");
            string name             = elem.GetAttribute("name");
            int    charIndex        = Int32.Parse(elem.GetAttribute("charIndex"));
            int    charLength       = Int32.Parse(elem.GetAttribute("charLength"));
            string codePart         = elem.GetAttribute("codePart");
            bool   isCall           = Boolean.Parse(elem.GetAttribute("isCall"));

            ScriptFile sfDefinition = si.SF.Manager.GetSF(sfDefinitionPath);

            if (sfDefinition == null)
            {
                si.SF.Manager.Trace.TraceEvent(TraceEventType.Warning, 0, "Could not find SF '{0}', reference '{1}' in '{2}' at '{3}'", sfDefinitionPath, name, si.SF.SFPath, charIndex);
                return(null);
            }

            FuncRefInfo funcRef = new FuncRefInfo(si.SF, sfDefinition, name, charIndex, charLength, codePart, isCall);

            if (isCall)
            {
                foreach (XmlNode node in elem.ChildNodes)
                {
                    if (node is XmlElement && node.Name == "funcRefArg")
                    {
                        funcRef.AddArgument(FuncRefArgInfo.FromXML((XmlElement)node, si));
                    }
                }
            }

            return(funcRef);
        }
Ejemplo n.º 2
0
        public static ScriptInfo ReadFromFile(ScriptFile SF, string fileFullPath, out bool successfully)
        {
            ScriptInfo SI = new ScriptInfo(SF);

            SI.CreateTime = DateTime.Now;

            XmlDocument doc = new XmlDocument();

            doc.Load(fileFullPath);

            successfully = true;

            foreach (XmlNode curNode in doc.DocumentElement.ChildNodes)
            {
                if (!(curNode is XmlElement))
                {
                    continue;
                }

                XmlElement curElem = (XmlElement)curNode;

                if (curElem.Name == "settings")
                {
                    SI.IsGlobal = Boolean.Parse(curElem.GetAttribute("global"));

                    string successfullyStr = curElem.GetAttribute("successfully");
                    successfully = (String.IsNullOrEmpty(successfullyStr) || successfullyStr == "True");

                    string isCompiledStr = curElem.GetAttribute("compiled");
                    SI.IsCompiled = String.IsNullOrEmpty(isCompiledStr) ? false : Boolean.Parse(isCompiledStr);

                    foreach (XmlNode settingNode in curElem.ChildNodes)
                    {
                        if (!(settingNode is XmlElement))
                        {
                            continue;
                        }

                        XmlElement settingElem = (XmlElement)settingNode;

                        if (settingElem.Name == "name")
                        {
                            SI.Name = settingElem.InnerText;
                        }
                        else
                        {
                            throw new XmlException("Unknown ScriptInfo settings node '" + settingElem.Name + "'");
                        }
                    }
                }
                else if (curElem.Name == "content")
                {
                    foreach (XmlNode contentNode in curElem.ChildNodes)
                    {
                        if (!(contentNode is XmlElement))
                        {
                            continue;
                        }

                        XmlElement contentElem = (XmlElement)contentNode;

                        IReferenceInfo refInfo;
                        switch (contentElem.Name)
                        {
                        case "include":
                            ReadInclude(SI, contentElem);
                            break;

                        case "using":
                            ReadUsing(SI, contentElem);
                            break;

                        case "const":
                            ReadConst(SI, contentElem);
                            break;

                        case "func":
                            ReadFunc(SI, contentElem);
                            break;

                        case "usingRef":
                            refInfo = UsingRefInfo.FromXML(contentElem, SI);
                            if (refInfo != null)
                            {
                                SI.References.Add(refInfo);
                            }

                            break;

                        case "constRef":
                            refInfo = ConstRefInfo.FromXML(contentElem, SI);
                            if (refInfo != null)
                            {
                                SI.References.Add(refInfo);
                            }

                            break;

                        case "funcRef":
                            refInfo = FuncRefInfo.FromXML(contentElem, SI);
                            if (refInfo != null)
                            {
                                SI.References.Add(refInfo);
                            }

                            break;

                        case "error":
                            Error error = Error.FromXML(contentElem, SF);
                            if (error != null)
                            {
                                SF.Errors.Add(error);
                            }

                            break;

                        default:
                            throw new XmlException("Unknown ScriptInfo content node '" + contentElem.Name + "'");
                        }
                    }
                }
                else
                {
                    throw new XmlException("Unknown ScriptInfo node '" + curElem.Name + "'");
                }
            }
            return(SI);
        }