Esempio n. 1
0
        /// <summary>
        /// Begin loading the configuration.
        /// </summary>
        private void StartConfigurationLoad()
        {
            DisplayProgressMessage("Loading configuration, please wait...", 0);
            myStopwatch.Reset();
            myStopwatch.Start();
            var loader = new DefaultConfigurationFileLoader(this);
            myBodyEl = validationResults.Document.Body;
            myBodyEl.InnerHtml = string.Empty;
            this.configurationHierarchy.Initialise(myFileName);

            // Initialise the display
            DisplayConfig();
            ClearProcessed();

            try
            {
                // Attempt to load the configuration
                loader.Load(new FileInfo(myFileName));
            }
            catch (ConfigurationException error)
            {
                // There is an error with the configuration
                myBodyEl.AppendChild(
                    GenerateElement("div",
                    new HtmlAttribute("class", "error"),
                    GenerateElement("div", "Unable to load configuration:")));
                var errors = GenerateElement("ul");
                myBodyEl.AppendChild(errors);

                // Generate the error details
                Exception errorDetails = error;
                while (errorDetails != null)
                {
                    errors.AppendChild(
                        GenerateElement("li", errorDetails.Message));
                    errorDetails = errorDetails.InnerException;
                }

                // Log the base error
                LogMessage(error.Message);
                isConfigValid = false;
            }
            catch (PreprocessorException error)
            {
                // There was an error with pre-processing
                var message = "Preprocessing failed loading the XML: " + error.Message;
                myBodyEl.AppendChild(
                    GenerateElement("div",
                    new HtmlAttribute("class", "error"),
                    GenerateElement("div", message)));
                LogMessage(message);
                isConfigValid = false;
            }
            catch (Exception error)
            {
                // Catch-all exception block
                StringBuilder message = new StringBuilder();
                message.Append("An unexpected error has occurred while loading the configuration!" +
                    Environment.NewLine +
                    "Please report this error to the CCNet user group (http://groups.google.com/group/ccnet-user). This will help us to improve this application.");
                Exception currentError = error;
                while (currentError != null)
                {
                    message.AppendFormat("{0}{1} [{2}]", Environment.NewLine, currentError.Message, currentError.GetType().Name);
                    message.AppendFormat("{0}{1}", Environment.NewLine, currentError.StackTrace);
                    currentError = currentError.InnerException;
                    if (currentError != null)
                    {
                        message.AppendFormat("{0}{1} Inner Exception {1}", Environment.NewLine, new string('=', 10));
                    }
                }
                MessageBox.Show(this, message.ToString(), "Unexpected error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                isConfigValid = false;
            }
        }
Esempio n. 2
0
        private object ValidateElement(HtmlElement tableEl, XmlNode node, int row, Configuration configuration)
        {
            HtmlAttribute rowClass = new HtmlAttribute("class", (row % 2) == 1 ? "even" : "odd");
            object loadedItem = null;
            try
            {
                loadedItem = myConfigReader.Read(node);
                this.configurationHierarchy.Add(loadedItem);
                if (loadedItem is IProject)
                {
                    IProject project = loadedItem as IProject;
                    configuration.AddProject(project);
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", project.Name),
                            GenerateElement("td", "Project"),
                            GenerateElement("td", "Yes")));
                    LogMessage(string.Format("Loaded project '{0}'", project.Name));
                }
                else if (loadedItem is IQueueConfiguration)
                {
                    IQueueConfiguration queueConfig = loadedItem as IQueueConfiguration;
                    configuration.QueueConfigurations.Add(queueConfig);
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", queueConfig.Name),
                            GenerateElement("td", "Queue"),
                            GenerateElement("td", "Yes")));
                    LogMessage(string.Format("Loaded queue '{0}'", queueConfig.Name));
                }
                else if (loadedItem is ISecurityManager)
                {
                    ISecurityManager securityManager = loadedItem as ISecurityManager;
                    configuration.SecurityManager = securityManager as ISecurityManager;
                    LogMessage("Loaded security manager");
                }
                else
                {
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td", (node as XmlElement).GetAttribute("name")),
                            GenerateElement("td", node.Name),
                            GenerateElement("td", "No")));
                    var message = "Unknown configuration type: " + loadedItem.GetType().Name;
                    tableEl.AppendChild(
                        GenerateElement("tr",
                            rowClass,
                            GenerateElement("td",
                                new HtmlAttribute("colspan", "3"),
                                GenerateElement("div",
                                    new HtmlAttribute("class", "error"),
                                    message))));
                    LogMessage(message);
                    isConfigValid = false;
                }
            }
            catch (Exception error)
            {
                string errorMsg = error.Message;
                int index = errorMsg.IndexOf("Xml Source");
                if (index >= 0) errorMsg = errorMsg.Substring(0, index - 1);
                tableEl.AppendChild(
                    GenerateElement("tr",
                        rowClass,
                        GenerateElement("td", (node as XmlElement).GetAttribute("name")),
                        GenerateElement("td", node.Name),
                        GenerateElement("td", "No")));
                tableEl.AppendChild(
                    GenerateElement("tr",
                        rowClass,
                        GenerateElement("td",
                            new HtmlAttribute("colspan", "3"),
                            GenerateElement("div",
                                new HtmlAttribute("class", "error"),
                                errorMsg))));
                isConfigValid = false;
                LogMessage(error.Message);
            }

            return loadedItem;
        }
Esempio n. 3
0
 private void attachScript(HtmlElement parentElement, String scriptText)
 {
     HtmlElement newScript = browser.Document.CreateElement("script");
     mshtml.IHTMLScriptElement script = (mshtml.IHTMLScriptElement)newScript.DomElement;
     script.text = scriptText;
     parentElement.AppendChild(newScript);
 }