Exemplo n.º 1
0
    public Config(string configFileName, List <string> last_ok_hosts)
    {
        ReadIni ini = new ReadIni(configFileName, true);

        TcpListen = (int)ini["TcpListen"].IntValue;

        SmtpServerName = ini["SmtpServerName"].StrValue;
        SmtpPort       = (int)ini["SmtpPort"].IntValue;
        if (SmtpPort == 0)
        {
            SmtpPort = 25;
        }
        SmtpNumTry = (int)ini["SmtpNumTry"].IntValue;
        if (SmtpNumTry == 0)
        {
            SmtpNumTry = 1;
        }
        SmtpUsername = ini["SmtpUsername"].StrValue;
        SmtpPassword = ini["SmtpPassword"].StrValue;

        SmtpServerName2 = ini["SmtpServerName2"].StrValue;
        SmtpPort2       = (int)ini["SmtpPort2"].IntValue;
        if (SmtpPort2 == 0)
        {
            SmtpPort2 = 25;
        }
        SmtpNumTry2 = (int)ini["SmtpNumTry2"].IntValue;
        if (SmtpNumTry2 == 0)
        {
            SmtpNumTry2 = 1;
        }
        SmtpUsername2 = ini["SmtpUsername2"].StrValue;
        SmtpPassword2 = ini["SmtpPassword2"].StrValue;

        SmtpFrom      = ini["SmtpFrom"].StrValue;
        SmtpFromAlive = ini["SmtpFromAlive"].StrValue;

        SubjectPrefix = ini["SubjectPrefix"].StrValue;

        DnsServer = ini["DnsServer"].StrValue;

        string s = ini["SmtpTo"].StrValue;

        SmtpToList = new StrToken(s).Tokens;

        SaveLog          = ini["SaveLog"].BoolValue;
        SendAliveMessage = ini["SendAliveMessage"].BoolValue;
        TcpSendData      = ini["TcpSendData"].BoolValue;

        Interval  = Math.Max(MinInterval, (int)ini["Interval"].IntValue * 1000);
        Timeout   = Math.Max(MinTimeout, (int)ini["Timeout"].IntValue * 1000);
        NumErrors = Math.Max(1, (int)ini["NumErrors"].IntValue);

        DefaultOptions = ini["DefaultOptions"].StrValue;
        Footer         = ini["Footer"].StrValue;

        string[] keys = ini.GetKeys();

        List <Target> o       = new List <Target>();
        List <Target> last_ok = new List <Target>();
        List <Target> last_ng = new List <Target>();

        foreach (string key in keys)
        {
            if (key.StartsWith("Target", StringComparison.CurrentCultureIgnoreCase))
            {
                string str = ini[key].StrValue;

                Target t = new Target(str);

                o.Add(t);

                bool last_ok_flag = false;

                if (last_ok_hosts != null)
                {
                    if (last_ok_hosts.Contains(t.HostName))
                    {
                        last_ok_flag = true;
                    }
                }

                if (last_ok_flag == false)
                {
                    last_ng.Add(t);
                }
                else
                {
                    last_ok.Add(t);
                }
            }

            if (key.StartsWith("SuffixReplace", StringComparison.CurrentCultureIgnoreCase))
            {
                string str = ini[key].StrValue;

                char[] sps = { ' ', '\t' };

                string[] tokens = str.Split(sps, StringSplitOptions.RemoveEmptyEntries);
                if (tokens.Length == 2)
                {
                    this.SuffixReplaceList.Add(new KeyValuePair <string, string>(tokens[0], tokens[1]));
                }
            }
        }

        TargetList           = o.ToArray();
        TargetListLastOkHost = last_ok.ToArray();
        TargetListLastNgHost = last_ng.ToArray();
    }