public static DiagCategory GetCustomGroup()

in DiagManager/DiagClasses/DiagFactory.cs [329:449]


        public static DiagCategory GetCustomGroup (string CustomGroupName, string filename)
        {

            //AS currently doesn't support public release
            if (!string.IsNullOrEmpty(CustomGroupName)  &&  (DiagRuntime.IsPublicVersion  == true  && CustomGroupName.ToUpper().Contains("ANALYSIS")))
            {
                return null;

            }
            DiagCategory cat;
            if (CustomGroupName != null)

            { 
                cat = new DiagCategory("CustomGroup", CustomGroupName);
            }
            else
            {
                cat = new DiagCategory("CustomGroup", "PlaceHolder"); //will change later
            }

            //we need to fake a custom xml file for TSQL Scripts to make it easier to develop



            XPathDocument doc;

            string CustomGroupDir = Path.GetDirectoryName(filename);
            string[] sqlfiles = Directory.GetFiles(CustomGroupDir, "*.sql");


            if (File.Exists (filename))
            { 
                
              doc = new XPathDocument(filename);
            }
            else if (sqlfiles.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<?xml version=\"1.0\" standalone=\"yes\"?>\n\r");
                sb.Append("<CustomTasks>\n\r");

                foreach (string file in sqlfiles)
                {
                    string fileNameOnly = Path.GetFileName(file);
                    string format = "<CustomTask enabled = \"true\" groupname = \"{0}\" taskname = \"{1}\" type = \"TSQL_Script\" point = \"Startup\" wait = \"No\" cmd = \"{2}\" pollinginterval = \"0\" />";
                    sb.AppendFormat(format, cat.Name, fileNameOnly, fileNameOnly);


                }
                sb.Append("</CustomTasks>");

                StringReader stream = new StringReader(sb.ToString());

                doc = new XPathDocument(stream);
            }
            else
            {
                throw new ArgumentException("Invalid custom group: " + ((CustomGroupName == null)? "NULL": CustomGroupName));
            }



            XPathNavigator rootnav = doc.CreateNavigator();

            XPathNodeIterator iter = rootnav.Select("CustomTasks/CustomTask ");


            while (iter.MoveNext())
            {
                string groupname = iter.Current.GetAttribute("groupname", "");
                
                //reading it from the file
                if (CustomGroupName == null)
                {
                    cat.Name = groupname;
                }

                string taskname = iter.Current.GetAttribute("taskname", "");
                string type = iter.Current.GetAttribute("type", "");
                string point = iter.Current.GetAttribute("point", "");
                string wait = iter.Current.GetAttribute("wait", "");
                string cmd = iter.Current.GetAttribute("cmd", "");
                string strpollinginterval = iter.Current.GetAttribute("pollinginterval", "");

                Int32 pollinginterval = 0;
                if (!string.IsNullOrEmpty(strpollinginterval))
                {
                    pollinginterval = Convert.ToInt32(iter.Current.GetAttribute("pollinginterval", ""));
                }

                /*
                if (groupname != cat.Name)
                {
                    throw new ArgumentException(string.Format("The custom diagnotics group name supplied from file directory doesn't match the xml definition.  file directory is {0} and the xml group name is {1}", cat.Name, groupname));
                }*/


                CustomTask task = new CustomTask(cat, "CustomTask", taskname, type, point, wait, cmd, pollinginterval);
                cat.DiagEventList.Add(task);


                //merge file system and config xml files
                XPathDocument doc2 = new XPathDocument(@"Templates\CustomDiagnostics_Template.xml");
                XPathNavigator rootnav2 = doc2.CreateNavigator();
                XPathNodeIterator iter2 = rootnav2.Select(string.Format("CustomDiagnostics/CustomGroup[@name=\"{0}\"]/Scenarios/Scenario", cat.Name));

                task.EnabledTemplate = GetLocalScenarioList(iter2);

                XPathNodeIterator iterVersion = rootnav2.Select(string.Format("CustomDiagnostics/CustomGroup[@name=\"{0}\"]/Versions/Version", cat.Name));

                task.EnabledVersions = GetLocalVersionList(iterVersion);  // GlobalVersionList;

                XPathNodeIterator iterFeature = rootnav2.Select(string.Format("CustomDiagnostics/CustomGroup[@name=\"{0}\"]/Features/Feature", cat.Name));
                task.EnabledFeatures = GetLocalFeatureList (iterFeature);// GlobalFeatureList;


            }
            return cat;


        }