Ejemplo n.º 1
0
        /// <summary>
        /// Loads the loggerServiceConfiguration Xml section.
        /// </summary>
        /// <param name="sectionNode">The loggerServiceConfiguration root node.</param>
        internal void Load(XmlNode sectionNode)
        {
            if (sectionNode.Attributes["isEnabled"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'isEnabled' attribute on loggerServiceConfiguration section");
            }

            if (sectionNode.Attributes["logSource"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'logSource' attribute on loggerServiceConfiguration section");
            }

            string sIsEnabled = sectionNode.Attributes["isEnabled"].Value;

            if (string.IsNullOrEmpty(sIsEnabled))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'isEnabled' attribute value on loggerServiceConfiguration section");
            }

            string sLogSource = sectionNode.Attributes["logSource"].Value;

            if (string.IsNullOrEmpty(sIsEnabled))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'logSource' attribute value on loggerServiceConfiguration section");
            }

            this.IsEnabled = Convert.ToBoolean(sIsEnabled);
            this.LogSource = sLogSource;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Default constructor.
 /// Uses &lt;smtpServiceConfiguration&gt; section from application configuration file.
 /// </summary>
 public SmtpService()
 {
     if (_config == null)
     {
         ThrowException.ThrowConfigurationErrorsException(
             "Cannot find the smtpServiceConfiguration section from the configuration file");
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Default constructor. Uses &lt;loggerServiceConfiguration&gt; section from application configuration file.
        /// </summary>
        public LoggerService()
        {
            if (_config == null)
            {
                ThrowException.ThrowConfigurationErrorsException("Cannot find the loggerServiceConfiguration section from the configuration file");
            }

            this.LogSource = _config.LogSource;
            this.IsEnabled = _config.IsEnabled;
        }
        /// <summary>
        /// Loads the queueExecutionTracerServiceConfiguration Xml section.
        /// </summary>
        ///
        /// <param name="sectionNode">
        /// The queueExecutionTracerServiceConfiguration root node.
        /// </param>
        internal void Load(XmlNode sectionNode)
        {
            if (sectionNode.Attributes["isEnabled"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'isEnabled' attribute on queueExecutionTracerServiceConfiguration section");
            }

            if (sectionNode.Attributes["withDebugTrace"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'withDebugTrace' attribute on queueExecutionTracerServiceConfiguration section");
            }

            if (sectionNode.Attributes["outputPath"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'outputPath' attribute on queueExecutionTracerServiceConfiguration section");
            }

            string sIsEnabled = sectionNode.Attributes["isEnabled"].Value;

            if (string.IsNullOrEmpty(sIsEnabled))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'isEnabled' attribute value on queueExecutionTracerServiceConfiguration section");
            }

            string sWithDebugTrace = sectionNode.Attributes["withDebugTrace"].Value;

            if (string.IsNullOrEmpty(sIsEnabled))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'withDebugTrace' attribute value on queueExecutionTracerServiceConfiguration section");
            }

            string sOutputPath = sectionNode.Attributes["outputPath"].Value;

            if (string.IsNullOrEmpty(sOutputPath))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'outputPath' attribute value on queueExecutionTracerServiceConfiguration section");
            }

            this.IsEnabled = Convert.ToBoolean(sIsEnabled);

            this.OutputPath = sOutputPath;

#if DEBUG
            this.WithDebugTrace = Convert.ToBoolean(sWithDebugTrace);
#else
            this.WithDebugTrace = false;
#endif
        }
Ejemplo n.º 5
0
        public static T GetValue <T>(string keyName)
        {
            if (string.IsNullOrEmpty(keyName))
            {
                ThrowException.ThrowArgumentNullException("keyName");
            }

            string value = ConfigurationManager.AppSettings[keyName];

            if (value == null)
            {
                ThrowException.ThrowConfigurationErrorsException(string.Format("Cannot find the '{0}' configuration key from the AppSettings section", keyName));
            }

            return(TypeHelper.To <T>(value));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Loads the smtpConfiguration Xml section.
        /// </summary>
        /// <param name="sectionNode">The smtpConfiguration root node.</param>
        internal void Load(XmlNode sectionNode)
        {
            IList <string> attributeNames = new List <string>()
            {
                "hostname", "port", "username", "password", "senderName", "from", "cc", "bcc", "redirection", "enableSsl", "useDefaultCredentials"
            };

            foreach (string attributeName in attributeNames)
            {
                if (sectionNode.Attributes[attributeName] == null)
                {
                    ThrowException.ThrowConfigurationErrorsException(
                        string.Format("Cannot find the '{0}' attribute on 'smtpServiceConfiguration'", attributeName));
                }

                if (attributeName == "hostname")
                {
                    _hostname = sectionNode.Attributes[attributeName].InnerText;
                }
                else if (attributeName == "port")
                {
                    _port = Convert.ToInt32(sectionNode.Attributes[attributeName].InnerText);
                }
                else if (attributeName == "username")
                {
                    _username = sectionNode.Attributes[attributeName].InnerText;
                }
                else if (attributeName == "password")
                {
                    _password = sectionNode.Attributes[attributeName].InnerText;
                }
                else if (attributeName == "senderName")
                {
                    _senderName = sectionNode.Attributes[attributeName].InnerText;
                }
                else if (attributeName == "from")
                {
                    _from = sectionNode.Attributes[attributeName].InnerText;
                }
                else if (attributeName == "cc")
                {
                    _cc = sectionNode.Attributes[attributeName].InnerText;
                }
                else if (attributeName == "bcc")
                {
                    _bcc = sectionNode.Attributes[attributeName].InnerText;
                }
                else if (attributeName == "redirection")
                {
                    _redirection = sectionNode.Attributes[attributeName].InnerText;
                }
                else if (attributeName == "enableSsl")
                {
                    _enableSsl = Convert.ToBoolean(sectionNode.Attributes[attributeName].InnerText);
                }
                else if (attributeName == "useDefaultCredentials")
                {
                    _useDefaultCredentials = Convert.ToBoolean(sectionNode.Attributes[attributeName].InnerText);
                }
            }

            if (_username.Length == 0 || _password.Length == 0)
            {
                _username = null;
                _password = null;
            }

            if (_redirection.Length == 0)
            {
                _redirection = null;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Loads the serviceLocatorConfiguration Xml section.
        /// </summary>
        /// <param name="sectionNode">The serviceLocatorConfiguration root node.</param>
        internal void Load(XmlNode sectionNode)
        {
            try
            {
                int index = 0;
                foreach (XmlNode entryNode in sectionNode.FirstChild.ChildNodes)
                {
                    if (entryNode.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    if (entryNode.Attributes["name"] == null && entryNode.Attributes["interface"] == null)
                    {
                        ThrowException.ThrowConfigurationErrorsException(
                            string.Format("The attribute 'name' or 'interface' is required (block #{0})", index));
                    }

                    if (entryNode.Attributes["implementation"] == null)
                    {
                        ThrowException.ThrowConfigurationErrorsException(
                            string.Format("The attribute 'implementation' is required (block #{0})", index));
                    }

                    if (entryNode.Attributes["instancingMode"] == null)
                    {
                        ThrowException.ThrowConfigurationErrorsException(
                            string.Format("The attribute 'instancingMode' is required (block #{0})", index));
                    }

                    string sName      = null;
                    string sInterface = null;

                    if (entryNode.Attributes["name"] != null)
                    {
                        sName = entryNode.Attributes["name"].Value;
                        if (string.IsNullOrEmpty(sName))
                        {
                            ThrowException.ThrowConfigurationErrorsException(
                                string.Format("The attribute 'name' requires a value (block #{0})", index));
                        }
                    }

                    if (entryNode.Attributes["interface"] != null)
                    {
                        sInterface = entryNode.Attributes["interface"].Value;
                        if (string.IsNullOrEmpty(sInterface))
                        {
                            ThrowException.ThrowConfigurationErrorsException(
                                string.Format("The attribute 'interface' requires a value (block #{0})", index));
                        }
                    }

                    string sImplementation = entryNode.Attributes["implementation"].Value;
                    if (string.IsNullOrEmpty(sImplementation))
                    {
                        ThrowException.ThrowConfigurationErrorsException(
                            string.Format("The attribute 'implementation' requires a value (block #{0})", index));
                    }

                    string sInstancingMode = entryNode.Attributes["instancingMode"].Value;
                    if (string.IsNullOrEmpty(sInstancingMode))
                    {
                        ThrowException.ThrowConfigurationErrorsException(
                            string.Format("The attribute 'instancingMode' requires a value (block #{0})", index));
                    }

                    if (sInstancingMode != "Singleton" && sInstancingMode != "NewInstance")
                    {
                        ThrowException.ThrowConfigurationErrorsException(
                            string.Format("The attribute 'instancingMode' requires a value: 'Singelton' or 'NewInstance' (block #{0})", index));
                    }

                    InstancingMode instancingMode = (sInstancingMode == "Singleton") ?
                                                    InstancingMode.Singleton :
                                                    InstancingMode.NewInstance;

                    if (_instanceEntries.ContainsKey(sName ?? sImplementation))
                    {
                        ThrowException.ThrowConfigurationErrorsException(
                            string.Format("There is already a registered entry for '{0}' (block #{1})", sName ?? sImplementation, index));
                    }

                    _instanceEntries.Add(sName ?? sImplementation, new InstanceEntry
                    {
                        Name           = sName,
                        Interface      = sInterface,
                        Implementation = sImplementation,
                        InstancingMode = instancingMode
                    });

                    index++;
                }
            }
            catch (System.Exception x)
            {
                ThrowException.ThrowConfigurationErrorsException(x.Message);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads the queueExecutionTracerServiceConfiguration Xml section.
        /// </summary>
        ///
        /// <param name="sectionNode">
        /// The queueExecutionTracerServiceConfiguration root node.
        /// </param>
        internal void Load(XmlNode sectionNode)
        {
            if (sectionNode.Attributes["isEnabled"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'isEnabled' attribute on queueExecutionTracerServiceConfiguration section");
            }

            if (sectionNode.Attributes["withDebugTrace"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'withDebugTrace' attribute on queueExecutionTracerServiceConfiguration section");
            }

            if (sectionNode.Attributes["maxItems"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'maxItems' attribute on queueExecutionTracerServiceConfiguration section");
            }

            if (sectionNode.Attributes["rollTimer"] == null)
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'rollTimer' attribute on queueExecutionTracerServiceConfiguration section");
            }

            string sIsEnabled = sectionNode.Attributes["isEnabled"].Value;

            if (string.IsNullOrEmpty(sIsEnabled))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'isEnabled' attribute value on queueExecutionTracerServiceConfiguration section");
            }

            string sWithDebugTrace = sectionNode.Attributes["withDebugTrace"].Value;

            if (string.IsNullOrEmpty(sIsEnabled))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'withDebugTrace' attribute value on queueExecutionTracerServiceConfiguration section");
            }

            string sMaxItems = sectionNode.Attributes["maxItems"].Value;

            if (string.IsNullOrEmpty(sMaxItems))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'maxItems' attribute value on queueExecutionTracerServiceConfiguration section");
            }

            string sRollTimer = sectionNode.Attributes["rollTimer"].Value;

            if (string.IsNullOrEmpty(sRollTimer))
            {
                ThrowException.ThrowConfigurationErrorsException(
                    "Cannot find the 'rollTimer' attribute value on queueExecutionTracerServiceConfiguration section");
            }

            this.IsEnabled = Convert.ToBoolean(sIsEnabled);

            this.MaxItems = Convert.ToInt32(sMaxItems);

            if (this.MaxItems < 1)
            {
                this.MaxItems = 1024;
            }

            this.RollTimer = Convert.ToInt32(sRollTimer);

            if (this.RollTimer < 1)
            {
                this.RollTimer = 1;
            }

#if DEBUG
            this.WithDebugTrace = Convert.ToBoolean(sWithDebugTrace);
#else
            this.WithDebugTrace = false;
#endif
        }