private void SaveSettings()
        {
            Interfaces.IChannel[] channels = new Interfaces.IChannel[grid.RowsCount - 1];
            for (int i = 1; i < grid.RowsCount; i++)
            {
                channels[i - 1] = (Interfaces.IChannel)grid[i, gridColName].Tag;
            }
            plugin.Channels = channels;

            SNMPAgent[] agents = new SNMPAgent[agentGrid.RowsCount - 1];
            for (int i = 1; i < agentGrid.RowsCount; i++)
            {
                agents[i - 1]             = (SNMPAgent)agentGrid[i, agentGridColName].Tag;
                agents[i - 1].AgentActive = (bool)agentGrid[i, agentGridColActive].Value;
            }
            plugin.Agents = agents;

            foreach (SNMPAgent stat in agents)
            {
                stat.ClearChannels();
                foreach (SNMPChannelImp chan in channels)
                {
                    if (chan.AgentName == stat.Name)
                    {
                        stat.AddChannel(chan);
                        chan.MyAgent = (SNMPAgent)stat;
                    }
                }
            }

            plugin.SaveSettings();
        }
        private void OnAddAgent(object sender, EventArgs e)
        {
            int         row          = agentGrid.RowsCount;
            VersionCode version      = VersionCode.V1;
            IPEndPoint  agentIP      = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 161);
            string      getCommunity = "public";
            string      setCommunity = "private";
            string      name         = GetUniqueAgentName();

            SNMPAgent     agent          = new SNMPAgent(version, agentIP, getCommunity, setCommunity, name);
            List <string> forbiddenNames = new List <string>();

            for (int i = 1; i < agentGrid.RowsCount; i++)
            {
                forbiddenNames.Add(agentGrid[i, agentGridColName].DisplayText);
            }
            FormProfile fpr = new FormProfile(agent, forbiddenNames);

            if (fpr.ShowDialog() == DialogResult.OK)
            {
                AddAgent(agent);
                agentGrid.Selection.ResetSelection(true);
                agentGrid.Selection.SelectRow(row, true);
            }
        }
Exemplo n.º 3
0
        public static SNMPAgent CreateAgent(XmlElement node, Plugin plugin)
        {
            SNMPAgent apf          = null;
            string    name         = node.Attributes["name"].Value;
            int       cycleTimeout = 100;

            try { cycleTimeout = int.Parse(node.Attributes["cycleTimeout"].Value); }    // Backward compatibility
            catch { };
            int retryTimeout = 1000;

            try { retryTimeout = int.Parse(node.Attributes["retryTimeout"].Value); }
            catch { };
            int retryCount = 3;

            try { retryCount = int.Parse(node.Attributes["retryCount"].Value); }
            catch { };
            int failedCount = 20;

            try { failedCount = int.Parse(node.Attributes["failedCount"].Value); }
            catch { };
            int loggingLevel = 0;

            try { loggingLevel = int.Parse(node.Attributes["loggingLevel"].Value); }
            catch { };
            bool stationActive = true;

            try { stationActive = bool.Parse(node.Attributes["agentActive"].Value); }
            catch { };
            string      ipAddress = node.Attributes["ipAddress"].Value;
            int         udpPort   = int.Parse(node.Attributes["udpPort"].Value);
            string      vCode     = node.Attributes["versionCode"].Value;
            VersionCode version;

            switch (vCode)
            {
            case "V1":
                version = VersionCode.V1;
                break;

            case "V2":
                version = VersionCode.V2;
                break;

            case "V3":
                version = VersionCode.V3;
                break;

            default:
                version = VersionCode.V1;
                break;
            }
            string getCommunity = node.Attributes["getCommunity"].Value;
            string setCommunity = node.Attributes["setCommunity"].Value;

            apf = CreateAgent(name, plugin, ipAddress, udpPort, version, getCommunity, setCommunity, cycleTimeout, retryTimeout, retryCount, failedCount);
            apf.LoggingLevel = loggingLevel;
            apf.AgentActive  = stationActive;
            return(apf);
        }
Exemplo n.º 4
0
        private void txtIP_Validating(object sender, CancelEventArgs e)
        {
            IPAddress ip;

            if (!SNMPAgent.IsValidIPAddress(txtIP.Text, out ip))
            {
                e.Cancel = true;
                txtIP.SelectAll();
                errorProvider1.SetError(txtIP, "IP address is not valid");
            }
        }
        private void AddAgent(SNMPAgent agent)
        {
            int row = agentGrid.RowsCount;

            agentGrid.RowsCount++;
            agentGrid[row, agentGridColName]        = new SourceGrid.Cells.Cell(agent.Name);
            agentGrid[row, agentGridColName].Tag    = agent;
            agentGrid[row, agentGridColActive]      = new SourceGrid.Cells.CheckBox("", agent.AgentActive);
            agentGrid[row, agentGridColAddr]        = new SourceGrid.Cells.Cell("IP: " + agent.AgentIP.ToString(), typeof(string));
            agentGrid[row, agentGridColPara]        = new SourceGrid.Cells.Cell("Version = " + agent.VersionCode.ToString() + ", GetCommunity = " + agent.GetCommunity + ", SetCommunity = " + agent.SetCommunity, typeof(string));
            agentGrid[row, agentGridColName].Editor = null;
            agentGrid[row, agentGridColAddr].Editor = null;
            agentGrid[row, agentGridColPara].Editor = null;
        }
Exemplo n.º 6
0
 public static void SaveAgent(XmlElement node, SNMPAgent agent)
 {
     node.SetAttribute("name", agent.Name);
     node.SetAttribute("ipAddress", agent.AgentIP.Address.ToString());                 //Address.ToString());
     node.SetAttribute("udpPort", agent.AgentIP.Port.ToString());
     node.SetAttribute("versionCode", agent.VersionCode.ToString());
     node.SetAttribute("getCommunity", agent.GetCommunity);
     node.SetAttribute("setCommunity", agent.SetCommunity);
     node.SetAttribute("cycleTimeout", agent.CycleTimeout.ToString());
     node.SetAttribute("retryTimeout", agent.RetryTimeout.ToString());
     node.SetAttribute("retryCount", agent.RetryCount.ToString());
     node.SetAttribute("failedCount", agent.FailedCount.ToString());
     node.SetAttribute("loggingLevel", agent.LoggingLevel.ToString());
     node.SetAttribute("agentActive", agent.AgentActive.ToString());
 }
        void agentGrid_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            SourceGrid.Grid agentGrid      = (SourceGrid.Grid)sender;
            int []          rows           = agentGrid.Selection.GetSelectionRegion().GetRowsIndex();
            SNMPAgent       agent          = (SNMPAgent)agentGrid[rows[0], agentGridColName].Tag;
            string          oldname        = agent.Name;
            List <string>   forbiddenNames = new List <string>();

            for (int i = 1; i < agentGrid.RowsCount; i++)
            {
                if (i != rows[0])
                {
                    forbiddenNames.Add(agentGrid[i, agentGridColName].DisplayText);
                }
            }
            FormProfile fpr = new FormProfile(agent, forbiddenNames);

            if (fpr.ShowDialog() == DialogResult.OK)
            {
                agentGrid[rows[0], agentGridColName].Value   = agent.Name;
                agentGrid[rows[0], agentGridColActive].Value = agent.AgentActive;
                agentGrid[rows[0], agentGridColAddr].Value   = "IP: " + agent.AgentIP.ToString();
                agentGrid[rows[0], agentGridColPara].Value   = "Version = " + agent.VersionCode.ToString() + ", GetCommunity = " + agent.GetCommunity + ", SetCommunity = " + agent.SetCommunity;
                agentGrid.Invalidate();
            }
            else
            {
                return;
            }
            if (oldname != agent.Name)
            {
                for (int i = 1; i < grid.RowsCount; i++)
                {
                    if (grid[i, gridColAgent].DisplayText == oldname)
                    {
                        (grid[i, gridColName].Tag as SNMPAgent).Name = agent.Name;
                        grid[i, gridColAgent].Value = agent.Name;
                        grid.Invalidate();
                    }
                }
            }
        }
Exemplo n.º 8
0
 public FormProfile(SNMPAgent agent, List <string> forbiddenNames)
 {
     InitializeComponent();
     _agent          = agent;
     _forbiddenNames = forbiddenNames;
 }
Exemplo n.º 9
0
 public FormProfile(SNMPAgent agent)
 {
     InitializeComponent();
     _agent = agent;
 }