Inheritance: System.Configuration.ConfigurationSection
示例#1
0
        /// <summary>
        /// Sends mail through SMTP server.
        /// </summary>
        /// <param name="Config"> ReviewNotifierConfiguration. </param>
        /// <param name="smtpItems"> Mail to send. </param>
        /// <returns> true if successful. </returns>
        private static bool SendSmtpMail(ReviewNotifierConfiguration Config, List<MailMessage> smtpItems)
        {
            SmtpClient client = new SmtpClient(Config.SmtpServer);
            if (Config.Password == null)
                client.UseDefaultCredentials = true;
            else
                client.Credentials = new NetworkCredential(Config.User, Config.Password, Config.Domain);

            if (Config.UseSsl)
                client.EnableSsl = true;

            foreach (MailMessage email in smtpItems)
                client.Send(email);

            return true;
        }
示例#2
0
        /// <summary>
        /// Sends mail through the exchange server.
        /// </summary>
        /// <param name="Config"> ReviewNotifierConfiguration. </param>
        /// <param name="exchangeItems"> Mail to send. </param>
        /// <returns> true if successful. </returns>
        private static bool SendExchangeMail(ReviewNotifierConfiguration Config, List<MessageType> exchangeItems)
        {
            int maxQuotaNum = int.MaxValue;
            var binding = (ExchangeServicePortType)new ExchangeServicePortTypeClient(
                new BasicHttpBinding("ExchangeServiceBinding")
                {
                    MaxReceivedMessageSize = maxQuotaNum,
                    MaxBufferSize = maxQuotaNum,
                    ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
                    {
                        MaxArrayLength = maxQuotaNum,
                        MaxStringContentLength = maxQuotaNum,
                        MaxNameTableCharCount = maxQuotaNum
                    }
                },
                new EndpointAddress(Config.EmailService));

            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
            folder.Id = DistinguishedFolderIdNameType.sentitems;

            TargetFolderIdType targetFolder = new TargetFolderIdType();
            targetFolder.Item = folder;

            CreateItemType createItem = new CreateItemType();
            createItem.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
            createItem.MessageDispositionSpecified = true;
            createItem.SavedItemFolderId = targetFolder;

            createItem.Items = new NonEmptyArrayOfAllItemsType();
            createItem.Items.Items = exchangeItems.ToArray();

            var createReq = new CreateItemRequest() { CreateItem = createItem };

            var response = binding.CreateItem(createReq);

            bool result = true;
            foreach (ResponseMessageType r in response.CreateItemResponse1.ResponseMessages.Items)
            {
                if (r.ResponseClass != ResponseClassType.Success)
                {
                    logger.Log("Failed to send the message. ");
                    logger.Log(r.MessageText);

                    result = false;
                }
            }

            return result;
        }
示例#3
0
        /// <summary>
        /// Returns the user's friendly name, if LDAP is enabled; otherwise returns userName.
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="userName"></param>
        /// <returns>User's friendly (given) name.</returns>
        private static string ResolveFriendlyName(ReviewNotifierConfiguration Config, string userName)
        {
            if (!Config.UseLdap)
                return userName;

            string givenname;
            if (givennameDictionary.TryGetValue(userName, out givenname))
                return givenname;

            givenname = RetrieveLdapProperty("givenname", userName);
            if (givenname != null)
            {
                givennameDictionary[userName] = givenname;
            }
            else
            {
                givenname = userName;
                Console.Error.WriteLine("Failed ldap lookup for {0}. Using {1}.", userName, givenname);
            }

            return givenname;
        }
示例#4
0
        /// <summary>
        /// Resolves the email address from the user name, performing LDAP query if necessary.
        /// </summary>
        /// <param name="Config"></param>
        /// <param name="userName"></param>
        /// <returns>User's email address.</returns>
        private static string ResolveUser(ReviewNotifierConfiguration Config, string userName)
        {
            if (!Config.UseLdap)
                return userName + "@" + Config.EmailDomain;

            string email;
            if (emailDictionary.TryGetValue(userName, out email))
                return email;

            email = RetrieveLdapProperty("mail", userName);
            if (email != null)
            {
                emailDictionary[userName] = email;
            }
            else
            {
                email = userName + "@" + Config.EmailDomain;
                Console.Error.WriteLine("Failed ldap lookup for {0}. Using {1}.", userName, email);
            }

            return email;
        }
示例#5
0
        public static bool Load()
        {
            if (_section == null)
            {
                lock (_lock)
                {
                    if (_section == null)
                    {
                        //Configuration exeConfig = ConfigurationManager.OpenExeConfiguration(Environment.GetCommandLineArgs()[0]);
                        Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                        var section = (ReviewNotifierConfiguration)config.GetSection(_sectionName);
                        if (section == null)
                        {
                            section = new ReviewNotifierConfiguration();
                            section.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToApplication;
                            section.SectionInformation.AllowLocation = false;
                        }
                        _config = config;
                        _section = section;
                    }
                }
            }
            return _section != null;
        }