Exemplo n.º 1
0
        /// <summary>
        /// What to do when a file changes.
        /// </summary>
        /// <param name="e"></param>
        private static void onChanged(FileSystemEventArgs e)
        {
            switch (GetFileType(e))
            {
            case filetype.CS:
            {
                xmlOverrideData d = Instance.getObjectByCsFilePath(e.FullPath);
                if (d != null)
                {
                    Instance.UnRegisterScriptXml(d.XmlFileName);
                    if (d.ScriptType == xmlOverrideData.ScriptTypes.Classes)
                    {
                        Omni.self.DeIndexClass(d.IResult);
                    }
                    Instance.ProcessXML(d.XmlFileName);
                }
                break;
            }

            case filetype.XML:
            {
                xmlOverrideData d = Instance.getObjectByXmlFilePath(e.FullPath);
                if (d != null)
                {
                    Instance.UnRegisterScriptXml(e.FullPath);
                    if (d.ScriptType == xmlOverrideData.ScriptTypes.Classes)
                    {
                        Omni.self.DeIndexClass(d.IResult);
                    }
                }
                Instance.ProcessXML(d != null ? d.XmlFileName : e.FullPath);
                break;
            }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Registers an Override with the engine.
 /// </summary>
 /// <param name="xmlfilename"></param>
 /// <param name="dta"></param>
 private void RegisterScriptXml(string xmlfilename, xmlOverrideData dta)
 {
     xmlfilename = xmlfilename.ToLower();
     UnRegisterScriptXml(xmlfilename);
     _lastIndex++;
     _overrideData.Add(_lastIndex, dta);
     _overrideXmlFilenameIndex.Add(xmlfilename, _lastIndex);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Registers an Override with the engine.
 /// </summary>
 /// <param name="xmlfilename"></param>
 /// <param name="dta"></param>
 private void RegisterScriptXml(string xmlfilename, xmlOverrideData dta)
 {
     xmlfilename = xmlfilename.ToLower();
     UnRegisterScriptXml(xmlfilename);
     _lastIndex++;
     _overrideData.Add(_lastIndex, dta);
     _overrideXmlFilenameIndex.Add(xmlfilename, _lastIndex);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Reads the specified XML file and creates the Override Definition
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        private bool ProcessXML(string filename)
        {
            xmlOverrideData data     = new xmlOverrideData();
            bool            readFile = false;
            XDocument       doc      = null;

            while (!readFile)
            {
                try
                {
                    doc      = XDocument.Load(filename);
                    readFile = true;
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            if (doc.Root.Name != "OverrideConfig")
            {
                return(false);
            }

            data.XmlFileName = filename;

            if (doc.Root.HasAttributes)
            {
                foreach (XAttribute attr in doc.Root.Attributes().Where(attr => attr.Name == "Type"))
                {
                    switch (attr.Value.ToLower())
                    {
                    case "memberconsolefunctionoverride":
                        data.ScriptType = xmlOverrideData.ScriptTypes.MemberFunction;
                        break;

                    case "classes":
                        data.ScriptType = xmlOverrideData.ScriptTypes.Classes;
                        break;

                    default:
                        data.ScriptType = xmlOverrideData.ScriptTypes.Undefined;
                        break;
                    }
                }
            }
            if (data.ScriptType == xmlOverrideData.ScriptTypes.Undefined)
            {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' Reason: Unknown ScriptType.");
                return(false);

                #endregion
            }

            #region "Read Rest of XML"

            foreach (XElement el in doc.Root.Elements())
            {
                if (el.Name == "NameSpace")
                {
                    data.NameSpace = el.Value;
                }

                else if (el.Name == "Files")
                {
                    foreach (XElement element in el.Elements())
                    {
                        data.CsFileNames.Add(Path.Combine(_location, element.Value));
                    }
                }

                else if (el.Name == "ClassName")
                {
                    data.ClassName = el.Value;
                }

                else if (el.Name == "ReferencedAssemblies")
                {
                    foreach (XElement element in el.Elements())
                    {
                        data.ReferencedAssemblies.Add(element.Value);
                    }
                }

                else if (el.Name == "FunctionOverrides")
                {
                    foreach (XElement element in el.Elements())
                    {
                        data.FunctionOverrides.Add(new CustomClassFunctDef(element.Value));
                    }
                }
            }

            #endregion

            if (data.NameSpace == "" && data.ScriptType != xmlOverrideData.ScriptTypes.Classes)
            {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' Reason: NameSpace Not Resolved.");
                return(false);

                #endregion
            }

            if (data.CsFileNames.Count == 0)
            {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' Reason: No C# File Set.");
                return(false);

                #endregion
            }

            if (data.ClassName == "" && data.ScriptType != xmlOverrideData.ScriptTypes.Classes)
            {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' Reason: No ClassName Not Set.");
                return(false);

                #endregion
            }

            if (data.ReferencedAssemblies.Count == 0)
            {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::WARNING: Script XML File: '" + filename + "' Reason: No Referenced Assemblies.");

                #endregion
            }

            if (data.FunctionOverrides.Count == 0 && data.ScriptType != xmlOverrideData.ScriptTypes.Classes)
            {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::WARNING: Script XML File: '" + filename + "' Reason: No Function Overrides Defined.");

                #endregion
            }

            #region

//#if DEBUG
            lock (Omni.self.tick)
                Omni.self.Warn(">>csFactory::INFO: Adding Script XML File: '" + filename + "'.");

            foreach (CustomClassFunctDef s in data.FunctionOverrides)
            {
                lock (Omni.self.tick)
                    Omni.self.Warn(">>csFactory::INFO::DETAIL: Adding Function Override: '" + s.mFunctName + "'");
            }
//#endif

            #endregion

            #region

            bool haderror = false;
            foreach (string f in data.CsFileNames)
            {
                if (!File.Exists(f))
                {
                    lock (Omni.self.tick)
                    {
                        Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' C# Script file '" + f + "' does not exist.");
                        haderror = true;
                    }
                }
            }

            if (haderror)
            {
                return(false);
            }

            #endregion

            if (!data.Compile())
            {
                return(false);
            }

            if (data.ScriptType == xmlOverrideData.ScriptTypes.Classes)
            {
                data.IResult = Omni.self.IndexAssembly(data.CompiledAssembly);
                foreach (string f in data.IResult.ClassesFound)
                {
                    lock (Omni.self.tick)
                        Omni.self.Warn(">>csFactory::INFO: Registered Class '" + f + "'.");
                }
                foreach (string f in data.IResult.GlobalFunctsFound)
                {
                    lock (Omni.self.tick)
                        Omni.self.Warn(">>csFactory::INFO: Registered Global Function '" + f + "'.");
                }
            }
            RegisterScriptXml(data.XmlFileName, data);
            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads the specified XML file and creates the Override Definition
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        private bool ProcessXML(string filename)
        {
            xmlOverrideData data = new xmlOverrideData();
            bool readFile = false;
            XDocument doc = null;
            while (!readFile)
                {
                try
                    {
                    doc = XDocument.Load(filename);
                    readFile = true;
                    }
                catch (Exception)
                    {
                    return false;
                    }
                }

            if (doc.Root.Name != "OverrideConfig")
                return false;

            data.XmlFileName = filename;

            if (doc.Root.HasAttributes)
                {
                foreach (XAttribute attr in doc.Root.Attributes().Where(attr => attr.Name == "Type"))
                    {
                    switch (attr.Value.ToLower())
                        {
                            case "memberconsolefunctionoverride":
                                data.ScriptType = xmlOverrideData.ScriptTypes.MemberFunction;
                                break;
                            case "classes":
                                data.ScriptType = xmlOverrideData.ScriptTypes.Classes;
                                break;
                            default:
                                data.ScriptType = xmlOverrideData.ScriptTypes.Undefined;
                                break;
                        }
                    }
                }
            if (data.ScriptType == xmlOverrideData.ScriptTypes.Undefined)
                {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' Reason: Unknown ScriptType.");
                return false;

                #endregion
                }

            #region "Read Rest of XML"

            foreach (XElement el in doc.Root.Elements())
                {
                if (el.Name == "NameSpace")
                    data.NameSpace = el.Value;

                else if (el.Name == "Files")
                    {
                    foreach (XElement element in el.Elements())
                        data.CsFileNames.Add(Path.Combine(_location, element.Value));
                    }

                else if (el.Name == "ClassName")
                    data.ClassName = el.Value;

                else if (el.Name == "ReferencedAssemblies")
                    {
                    foreach (XElement element in el.Elements())
                        data.ReferencedAssemblies.Add(element.Value);
                    }

                else if (el.Name == "FunctionOverrides")
                    {
                    foreach (XElement element in el.Elements())
                        data.FunctionOverrides.Add(new CustomClassFunctDef(element.Value));
                    }
                }

            #endregion

            if (data.NameSpace == "" && data.ScriptType != xmlOverrideData.ScriptTypes.Classes)
                {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' Reason: NameSpace Not Resolved.");
                return false;

                #endregion
                }

            if (data.CsFileNames.Count == 0)
                {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' Reason: No C# File Set.");
                return false;

                #endregion
                }

            if (data.ClassName == "" && data.ScriptType != xmlOverrideData.ScriptTypes.Classes)
                {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' Reason: No ClassName Not Set.");
                return false;

                #endregion
                }

            if (data.ReferencedAssemblies.Count == 0)
                {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::WARNING: Script XML File: '" + filename + "' Reason: No Referenced Assemblies.");

                #endregion
                }

            if (data.FunctionOverrides.Count == 0 && data.ScriptType != xmlOverrideData.ScriptTypes.Classes)
                {
                #region

                lock (Omni.self.tick)
                    Omni.self.Error(">>csFactory::WARNING: Script XML File: '" + filename + "' Reason: No Function Overrides Defined.");

                #endregion
                }

            #region

//#if DEBUG
            lock (Omni.self.tick)
                Omni.self.Warn(">>csFactory::INFO: Adding Script XML File: '" + filename + "'.");

            foreach (CustomClassFunctDef s in data.FunctionOverrides)
                {
                lock (Omni.self.tick)
                    Omni.self.Warn(">>csFactory::INFO::DETAIL: Adding Function Override: '" + s.mFunctName + "'");
                }
//#endif

            #endregion

            #region

            bool haderror = false;
            foreach (string f in data.CsFileNames)
                {
                if (!File.Exists(f))
                    {
                    lock (Omni.self.tick)
                        {
                        Omni.self.Error(">>csFactory::Error Processing C# Script XML File: '" + filename + "' C# Script file '" + f + "' does not exist.");
                        haderror = true;
                        }
                    }
                }

            if (haderror)
                return false;

            #endregion

            if (!data.Compile())
                return false;

            if (data.ScriptType == xmlOverrideData.ScriptTypes.Classes)
                {
                data.IResult = Omni.self.IndexAssembly(data.CompiledAssembly);
                foreach (string f in data.IResult.ClassesFound)
                    {
                    lock (Omni.self.tick)
                        Omni.self.Warn(">>csFactory::INFO: Registered Class '" + f + "'.");
                    }
                foreach (string f in data.IResult.GlobalFunctsFound)
                    {
                    lock (Omni.self.tick)
                        Omni.self.Warn(">>csFactory::INFO: Registered Global Function '" + f + "'.");
                    }
                }
            RegisterScriptXml(data.XmlFileName, data);
            return true;
        }