示例#1
0
        /// <summary>
        /// Creates a new <see cref="SqlTraceListener"/> using the specified settings name
        /// </summary>
        /// <param name="settingsName">the name of the SqlTraceListener settings to use from configuration</param>
        public SqlTraceListener(string settingsName)
            : base(settingsName)
        {
            UkadcDiagnosticsSection ukadcDiagnosticsSection = UkadcDiagnosticsSection.ReadConfigSection();
            SqlTraceListenerElement sqlTraceListenerElement = ukadcDiagnosticsSection.SqlTraceListeners[settingsName];

            if (null == sqlTraceListenerElement)
            {
                throw new ConfigurationErrorsException(
                          string.Format(CultureInfo.CurrentCulture, Resources.SqlTraceListenerConfigError, settingsName));
            }

            string connectionString =
                ConfigurationManager.ConnectionStrings[sqlTraceListenerElement.ConnectionStringName].ConnectionString;

            // use default data adapter
            IDataAccessAdapter adapter = new SqlDataAccessAdapter();

            adapter.Initialize(
                connectionString,
                sqlTraceListenerElement.CommandText,
                sqlTraceListenerElement.CommandType);
            DataAccessAdapter = adapter;

            IPropertyReaderFactory readerFactory = DefaultServiceLocator.GetService <IPropertyReaderFactory>();

            foreach (ParameterElement param in sqlTraceListenerElement.Parameters)
            {
                PropertyReader propertyReader = readerFactory.Create(param);

                this.Parameters.Add(
                    new SqlTraceParameter(param.Name, propertyReader, param.CallToString));
            }
        }
示例#2
0
        private void Init()
        {
            if (!_initialised)
            {
                lock (_initlock)
                {
                    if (!_initialised)
                    {
                        IPropertyReaderFactory readerFactory = DefaultServiceLocator.GetService <IPropertyReaderFactory>();
                        _initialised    = true;
                        _filePathReader = readerFactory.CreateCombinedReader(FilePath);
                        _outputReader   = readerFactory.CreateCombinedReader(Output);
                        _writerCache    = DefaultServiceLocator.GetService <IStreamWriterCache>();

                        try
                        {
                            SafeParseCleanInterval();
                        }
                        // need to start the timer with the default value, even if this throws
                        finally
                        {
                            Timer timer = new Timer(_cleanInterval.TotalMilliseconds);
                            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
                            timer.Start();
                        }
                    }
                }
            }
        }
示例#3
0
 private void InternalConfigure(IPropertyReaderFactory readerFactory, ISmtpService smtpService, string host, int port, string username, string password, string to, string from,
                                string subjectValueToken, string bodyValueToken)
 {
     SmtpService = smtpService;
     SmtpService.Initialize(host, port, username, password);
     From          = from;
     To            = to;
     SubjectReader = readerFactory.CreateCombinedReader(subjectValueToken);
     BodyReader    = readerFactory.CreateCombinedReader(bodyValueToken);
 }
 /// <summary>
 /// Checks to see if the PropertyReaderFactory supports the tokenName. If not, returns a LiteralPropertyReader containing
 /// fullName
 /// </summary>
 private static PropertyReader CreateReaderOrLiteral(IPropertyReaderFactory propertyReaderFactory, Token token)
 {
     if (propertyReaderFactory.ContainsToken(token.TokenName))
     {
         return propertyReaderFactory.Create(token);
     }
     else
     {
         return new LiteralPropertyReader(token.OriginalString);
     }
 }
 /// <summary>
 /// Checks to see if the PropertyReaderFactory supports the tokenName. If not, returns a LiteralPropertyReader containing
 /// fullName
 /// </summary>
 private static PropertyReader CreateReaderOrLiteral(IPropertyReaderFactory propertyReaderFactory, Token token)
 {
     if (propertyReaderFactory.ContainsToken(token.TokenName))
     {
         return(propertyReaderFactory.Create(token));
     }
     else
     {
         return(new LiteralPropertyReader(token.OriginalString));
     }
 }
        /// <summary>
        /// Creates a <see cref="PropertyReader"/> by parsing the combinedToken parameter.
        /// </summary>
        /// <param name="combinedToken">A combined token</param>
        /// <param name="propertyReaderFactory">A factory object used to construct property readers from</param>
        /// <returns>Usually returns a <see cref="CombinedPropertyReader"/> but can optimise to return a specific <see cref="PropertyReader"/>
        /// or <see cref="LiteralPropertyReader"/> if there is no need for a combined version</returns>
        public PropertyReader Create(string combinedToken, IPropertyReaderFactory propertyReaderFactory)
        {
            if (combinedToken == null)
            {
                throw new ArgumentNullException("combinedToken");
            }

            MatchCollection matches = _matchesTokens.Matches(combinedToken);

            // Is the whole format string just a single token? If so, return that single property reader
            if (matches.Count == 1
                && matches[0].Length == combinedToken.Trim().Length)
            {
                Token token = new Token(matches[0].Value);
                return CreateReaderOrLiteral(propertyReaderFactory, token);
            }

            // if no tokens, just return a literalpropertyreader
            if (matches.Count == 0)
            {
                return new LiteralPropertyReader(combinedToken);
            }

            CombinedPropertyReader reader = new CombinedPropertyReader();

            int cursor = 0;

            foreach (Match match in matches)
            {
                if (match.Index > cursor)
                {
                    reader.PropertyReaders.Add(
                        new LiteralPropertyReader(combinedToken.Substring(cursor, match.Index - cursor)));
                }

                Token token = new Token(match.Value);
                reader.PropertyReaders.Add(CreateReaderOrLiteral(propertyReaderFactory, token));
                cursor = match.Index + match.Length;
            }
            if (combinedToken.Length > cursor)
            {
                reader.PropertyReaders.Add(
                    new LiteralPropertyReader(combinedToken.Substring(cursor, combinedToken.Length - cursor)));
            }


            return reader;
        }
        /// <summary>
        /// Creates a <see cref="PropertyReader"/> by parsing the combinedToken parameter.
        /// </summary>
        /// <param name="combinedToken">A combined token</param>
        /// <param name="propertyReaderFactory">A factory object used to construct property readers from</param>
        /// <returns>Usually returns a <see cref="CombinedPropertyReader"/> but can optimise to return a specific <see cref="PropertyReader"/>
        /// or <see cref="LiteralPropertyReader"/> if there is no need for a combined version</returns>
        public PropertyReader Create(string combinedToken, IPropertyReaderFactory propertyReaderFactory)
        {
            if (combinedToken == null)
            {
                throw new ArgumentNullException("combinedToken");
            }

            MatchCollection matches = _matchesTokens.Matches(combinedToken);

            // Is the whole format string just a single token? If so, return that single property reader
            if (matches.Count == 1 &&
                matches[0].Length == combinedToken.Trim().Length)
            {
                Token token = new Token(matches[0].Value);
                return(CreateReaderOrLiteral(propertyReaderFactory, token));
            }

            // if no tokens, just return a literalpropertyreader
            if (matches.Count == 0)
            {
                return(new LiteralPropertyReader(combinedToken));
            }

            CombinedPropertyReader reader = new CombinedPropertyReader();

            int cursor = 0;

            foreach (Match match in matches)
            {
                if (match.Index > cursor)
                {
                    reader.PropertyReaders.Add(
                        new LiteralPropertyReader(combinedToken.Substring(cursor, match.Index - cursor)));
                }

                Token token = new Token(match.Value);
                reader.PropertyReaders.Add(CreateReaderOrLiteral(propertyReaderFactory, token));
                cursor = match.Index + match.Length;
            }
            if (combinedToken.Length > cursor)
            {
                reader.PropertyReaders.Add(
                    new LiteralPropertyReader(combinedToken.Substring(cursor, combinedToken.Length - cursor)));
            }


            return(reader);
        }
示例#8
0
 /// <summary>
 /// Construct the trace listener
 /// </summary>
 /// <param name="combinedFactory">A property reader factory</param>
 /// <param name="smtpService">The SMTP service</param>
 /// <param name="host">The host name</param>
 /// <param name="port">The host port number</param>
 /// <param name="username">The username used when sending an email</param>
 /// <param name="password">The password used when sending an email</param>
 /// <param name="to">The address of the user who will receive diagnostic traces</param>
 /// <param name="from">The senders address</param>
 /// <param name="subjectValueToken">A token defining the subject</param>
 /// <param name="bodyValueToken">A token defining the body</param>
 public SmtpTraceListener(IPropertyReaderFactory combinedFactory, ISmtpService smtpService, string host, int port, string username, string password, string to, string from,
                          string subjectValueToken, string bodyValueToken)
     : base("SmtpTraceListener")
 {
     InternalConfigure(combinedFactory, smtpService, host, port, username, password, to, from, subjectValueToken, bodyValueToken);
 }
示例#9
0
 /// <summary>
 /// Construct the trace listener
 /// </summary>
 /// <param name="combinedFactory">A property reader factory</param>
 /// <param name="smtpService">The SMTP service</param>
 /// <param name="host">The host name</param>
 /// <param name="port">The host port number</param>
 /// <param name="username">The username used when sending an email</param>
 /// <param name="password">The password used when sending an email</param>
 /// <param name="to">The address of the user who will receive diagnostic traces</param>
 /// <param name="from">The senders address</param>
 /// <param name="subjectValueToken">A token defining the subject</param>
 /// <param name="bodyValueToken">A token defining the body</param>
 public SmtpTraceListener(IPropertyReaderFactory combinedFactory, ISmtpService smtpService, string host, int port, string username, string password, string to, string from,
                          string subjectValueToken, string bodyValueToken)
     : base("SmtpTraceListener")
 {
     InternalConfigure(combinedFactory, smtpService, host, port, username, password, to, from, subjectValueToken, bodyValueToken);
 }
示例#10
0
 private void InternalConfigure(IPropertyReaderFactory readerFactory, ISmtpService smtpService, string host, int port, string username, string password, string to, string from,
                                string subjectValueToken, string bodyValueToken)
 {
     SmtpService = smtpService;
     SmtpService.Initialize(host, port, username, password);
     From = from;
     To = to;
     SubjectReader = readerFactory.CreateCombinedReader(subjectValueToken);
     BodyReader = readerFactory.CreateCombinedReader(bodyValueToken);
 }