Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="assemblySearchFolders">Folders to search for referenced assemblies.</param>
        public void Init(XmlDocument doc, string[] assemblySearchFolders)
        {
            #region Referenced Assemblies
            AssemblySearchPaths = assemblySearchFolders;
            bool asssemblyFound = false;
            ReferencedAssemblyPaths = doc.SelectSingleNode("ROOT/referencedfiles").InnerText.Split(',');

            for (int i = 0; i < ReferencedAssemblyPaths.Length; i++)
            {
                if (string.IsNullOrEmpty(ReferencedAssemblyPaths[i]))
                {
                    continue;
                }
                ReferencedAssemblyPaths[i] = ReferencedAssemblyPaths[i].Split('|')[0];
                ReferencedAssemblyPaths[i] = ReferencedAssemblyPaths[i].Substring(ReferencedAssemblyPaths[i].LastIndexOf(@"\") + 1);
                asssemblyFound             = false;
                string pathsSearched = "";

                foreach (string searchPath in assemblySearchFolders)
                {
                    pathsSearched += pathsSearched.Length > 0 ? ", " + searchPath : searchPath;
                    string filePath = System.IO.Path.Combine(searchPath, ReferencedAssemblyPaths[i]);

                    if (System.IO.File.Exists(filePath))
                    {
                        asssemblyFound             = true;
                        ReferencedAssemblyPaths[i] = filePath;
                        break;
                    }
                }
                if (!asssemblyFound)
                {
                    throw new System.IO.FileNotFoundException(string.Format("Referenced assembly not found: {0}\n\nPaths searched: {1}", ReferencedAssemblyPaths[i], pathsSearched));
                }
            }
            #endregion

            this.Name        = doc.SelectSingleNode("ROOT/config/project/name").InnerText;
            this.Description = doc.SelectSingleNode("ROOT/config/project/description").InnerText;

            #region User Options
            XmlNodeList nodes = doc.SelectNodes("ROOT/config/project/options/option");
            this.Options = new Option[nodes.Count];

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode subNode = nodes[i];
                this.Options[i]         = new Option();
                Options[i].Description  = subNode.SelectSingleNode("description").InnerText;
                Options[i].Text         = subNode.SelectSingleNode("text").InnerText;
                Options[i].VariableName = subNode.SelectSingleNode("variablename").InnerText;
                Options[i].VarType      = GetTypeFromReferencedAssemblies(subNode.SelectSingleNode("type").InnerText, true);
                Options[i].Category     = subNode.SelectSingleNode("category").InnerText;
                Options[i].DefaultValue = subNode.SelectSingleNode("defaultvalue") != null?subNode.SelectSingleNode("defaultvalue").InnerText : "";

                Options[i].DefaultValueIsFunction = subNode.SelectSingleNode("defaultvalueisfunction") != null?bool.Parse(subNode.SelectSingleNode("defaultvalueisfunction").InnerText) : false;

                Options[i].IteratorName = subNode.SelectSingleNode("iteratorname") != null?subNode.SelectSingleNode("iteratorname").InnerText : "";

                Options[i].DisplayToUser = subNode.SelectSingleNode("displaytouser").InnerText != null?subNode.SelectSingleNode("displaytouser").InnerText : "true";

                Options[i].DisplayToUserIsFunction = subNode.SelectSingleNode("displaytouserisfunction").InnerText != null?bool.Parse(subNode.SelectSingleNode("displaytouserisfunction").InnerText) : false;

                Options[i].ValidatorFunction = subNode.SelectSingleNode("validatorfunction") != null?subNode.SelectSingleNode("validatorfunction").InnerText : "";

                XmlNodeList valueNodes = subNode.SelectNodes("values/value");
                Options[i].Values = new string[valueNodes.Count];

                for (int x = 0; x < valueNodes.Count; x++)
                {
                    Options[i].Values[x] = valueNodes[x].InnerText;
                }
            }
            #endregion

            #region Default Value Functions
            nodes = doc.SelectNodes("ROOT/config/project/defaultvaluefunctions/defaultvaluefunction");
            this.DefaultValueFunctions = new List <IDefaultValueFunction>();

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode subNode = nodes[i];
                ArchAngel.Providers.Database.Model.DefaultValueFunction defaultValueFunction = new ArchAngel.Providers.Database.Model.DefaultValueFunction();
                defaultValueFunction.ObjectType    = GetTypeFromReferencedAssemblies(subNode.SelectSingleNode("objecttype").InnerText, true);
                defaultValueFunction.PropertyName  = subNode.SelectSingleNode("propertyname").InnerText;
                defaultValueFunction.UseCustomCode = bool.Parse(subNode.SelectSingleNode("usecustomcode").InnerText);
                defaultValueFunction.FunctionType  = (FunctionTypes)Enum.Parse(typeof(FunctionTypes), subNode.SelectSingleNode("functiontype").InnerText);
                DefaultValueFunctions.Add(defaultValueFunction);
            }
            #endregion

            #region Outputs
            TempOutputs = new ArrayList();
            XmlNode rootFolderNode = doc.SelectSingleNode("ROOT/config/project/rootoutput/rootfolder");

            // Get list of discrete output names
            XmlNodeList outputNamesOfFolders     = doc.SelectNodes("ROOT/config/project/rootoutput//folder");
            XmlNodeList outputNamesOfScriptFiles = doc.SelectNodes("ROOT/config/project/rootoutput//script");
            XmlNodeList outputNamesOfFiles       = doc.SelectNodes("ROOT/config/project/rootoutput//file");
            string[]    outputNames = GetOutputNames(doc);
            this.Outputs = new Output[outputNames.Length];

            for (int outputCounter = 0; outputCounter < outputNames.Length; outputCounter++)
            {
                this.Outputs[outputCounter]            = new Output();
                Outputs[outputCounter].RootFolder      = new Folder();
                Outputs[outputCounter].RootFolder.Name = "Root";
                Outputs[outputCounter].Name            = outputNames[outputCounter];
                ProcessFolderNode(rootFolderNode, Outputs[outputCounter].RootFolder, outputNames[outputCounter]);
            }
            #endregion

            #region Actions
            System.Reflection.Assembly actionAssembly = System.Reflection.Assembly.GetAssembly(typeof(ArchAngel.Actions.ActionSet));
            XmlNodeList actionNodes = doc.SelectNodes("ROOT/config/project/actions/action");

            foreach (XmlNode actionNode in actionNodes)
            {
                string actionTypeName = actionNode.SelectSingleNode("@typename").Value;
                ArchAngel.Actions.BaseAction action = (ArchAngel.Actions.BaseAction)actionAssembly.CreateInstance(actionTypeName);
                action.ReadFromXml(actionNode.InnerXml);
                this.Actions.Add(action);
            }
            #endregion
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="assemblySearchFolders">Folders to search for referenced assemblies.</param>
        public void Init(XmlDocument doc, string[] assemblySearchFolders)
        {
            #region Referenced Assemblies
            AssemblySearchPaths = assemblySearchFolders;
            bool asssemblyFound = false;
            ReferencedAssemblyPaths = doc.SelectSingleNode("ROOT/referencedfiles").InnerText.Split(',');

            for (int i = 0; i < ReferencedAssemblyPaths.Length; i++)
            {
                if (string.IsNullOrEmpty(ReferencedAssemblyPaths[i]))
                {
                    continue;
                }
                ReferencedAssemblyPaths[i] = ReferencedAssemblyPaths[i].Split('|')[0];
                ReferencedAssemblyPaths[i] = ReferencedAssemblyPaths[i].Substring(ReferencedAssemblyPaths[i].LastIndexOf(@"\") + 1);
                asssemblyFound = false;
                string pathsSearched = "";

                foreach (string searchPath in assemblySearchFolders)
                {
                    pathsSearched += pathsSearched.Length > 0 ? ", " + searchPath : searchPath;
                    string filePath = System.IO.Path.Combine(searchPath, ReferencedAssemblyPaths[i]);

                    if (System.IO.File.Exists(filePath))
                    {
                        asssemblyFound = true;
                        ReferencedAssemblyPaths[i] = filePath;
                        break;
                    }
                }
                if (!asssemblyFound)
                {
                    throw new System.IO.FileNotFoundException(string.Format("Referenced assembly not found: {0}\n\nPaths searched: {1}", ReferencedAssemblyPaths[i], pathsSearched));
                }
            }
            #endregion

            this.Name = doc.SelectSingleNode("ROOT/config/project/name").InnerText;
            this.Description = doc.SelectSingleNode("ROOT/config/project/description").InnerText;

            #region User Options
            XmlNodeList nodes = doc.SelectNodes("ROOT/config/project/options/option");
            this.Options = new Option[nodes.Count];

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode subNode = nodes[i];
                this.Options[i] = new Option();
                Options[i].Description = subNode.SelectSingleNode("description").InnerText;
                Options[i].Text = subNode.SelectSingleNode("text").InnerText;
                Options[i].VariableName = subNode.SelectSingleNode("variablename").InnerText;
                Options[i].VarType = GetTypeFromReferencedAssemblies(subNode.SelectSingleNode("type").InnerText, true);
                Options[i].Category = subNode.SelectSingleNode("category").InnerText;
                Options[i].DefaultValue = subNode.SelectSingleNode("defaultvalue") != null ? subNode.SelectSingleNode("defaultvalue").InnerText : "";
                Options[i].DefaultValueIsFunction = subNode.SelectSingleNode("defaultvalueisfunction") != null ? bool.Parse(subNode.SelectSingleNode("defaultvalueisfunction").InnerText) : false;
                Options[i].IteratorName = subNode.SelectSingleNode("iteratorname") != null ? subNode.SelectSingleNode("iteratorname").InnerText : "";
                Options[i].DisplayToUser = subNode.SelectSingleNode("displaytouser").InnerText != null ? subNode.SelectSingleNode("displaytouser").InnerText : "true";
                Options[i].DisplayToUserIsFunction = subNode.SelectSingleNode("displaytouserisfunction").InnerText != null ? bool.Parse(subNode.SelectSingleNode("displaytouserisfunction").InnerText) : false;
                Options[i].ValidatorFunction = subNode.SelectSingleNode("validatorfunction") != null ? subNode.SelectSingleNode("validatorfunction").InnerText : "";

                XmlNodeList valueNodes = subNode.SelectNodes("values/value");
                Options[i].Values = new string[valueNodes.Count];

                for (int x = 0; x < valueNodes.Count; x++)
                {
                    Options[i].Values[x] = valueNodes[x].InnerText;
                }
            }
            #endregion

            #region Default Value Functions
            nodes = doc.SelectNodes("ROOT/config/project/defaultvaluefunctions/defaultvaluefunction");
            this.DefaultValueFunctions = new List<IDefaultValueFunction>();

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode subNode = nodes[i];
                ArchAngel.Providers.Database.Model.DefaultValueFunction defaultValueFunction = new ArchAngel.Providers.Database.Model.DefaultValueFunction();
                defaultValueFunction.ObjectType = GetTypeFromReferencedAssemblies(subNode.SelectSingleNode("objecttype").InnerText, true);
                defaultValueFunction.PropertyName = subNode.SelectSingleNode("propertyname").InnerText;
                defaultValueFunction.UseCustomCode = bool.Parse(subNode.SelectSingleNode("usecustomcode").InnerText);
                defaultValueFunction.FunctionType = (FunctionTypes) Enum.Parse(typeof(FunctionTypes), subNode.SelectSingleNode("functiontype").InnerText);
                DefaultValueFunctions.Add(defaultValueFunction);
            }
            #endregion

            #region Outputs
            TempOutputs = new ArrayList();
            XmlNode rootFolderNode = doc.SelectSingleNode("ROOT/config/project/rootoutput/rootfolder");

            // Get list of discrete output names
            XmlNodeList outputNamesOfFolders = doc.SelectNodes("ROOT/config/project/rootoutput//folder");
            XmlNodeList outputNamesOfScriptFiles = doc.SelectNodes("ROOT/config/project/rootoutput//script");
            XmlNodeList outputNamesOfFiles = doc.SelectNodes("ROOT/config/project/rootoutput//file");
            string[] outputNames = GetOutputNames(doc);
            this.Outputs = new Output[outputNames.Length];

            for (int outputCounter = 0; outputCounter < outputNames.Length; outputCounter++)
            {
                this.Outputs[outputCounter] = new Output();
                Outputs[outputCounter].RootFolder = new Folder();
                Outputs[outputCounter].RootFolder.Name = "Root";
                Outputs[outputCounter].Name = outputNames[outputCounter];
                ProcessFolderNode(rootFolderNode, Outputs[outputCounter].RootFolder, outputNames[outputCounter]);
            }
            #endregion

            #region Actions
            System.Reflection.Assembly actionAssembly = System.Reflection.Assembly.GetAssembly(typeof(ArchAngel.Actions.ActionSet));
            XmlNodeList actionNodes = doc.SelectNodes("ROOT/config/project/actions/action");

            foreach (XmlNode actionNode in actionNodes)
            {
                string actionTypeName = actionNode.SelectSingleNode("@typename").Value;
                ArchAngel.Actions.BaseAction action = (ArchAngel.Actions.BaseAction)actionAssembly.CreateInstance(actionTypeName);
                action.ReadFromXml(actionNode.InnerXml);
                this.Actions.Add(action);
            }
            #endregion
        }