Esempio n. 1
0
        //---------------------------------------------------
        public void InitDialog(IDefinition definition, IObjectTree mibTree)
        {
            m_definition   = definition;
            m_trap         = m_definition.Entity as TrapType;
            m_notification = m_definition.Entity as NotificationType;


            InitComboVersions();
            InitComboGenericCode();

            m_cmbGenericCode.Text = GenericCode.EnterpriseSpecific.ToString();
            m_cmbTrapVersion.Text = VersionCode.V1.ToString();

            string strOID = ObjectIdentifier.Convert(m_definition.GetNumericalForm());

            if (strOID.IndexOf('.') >= 0)
            {
                string strGeneric = strOID.Substring(strOID.LastIndexOf('.') + 1);
                strOID = strOID.Substring(0, strOID.LastIndexOf('.'));
                m_txtSpecificCode.Text = strGeneric;
            }
            m_txtEntreprise.Text = strOID;
            m_txtCommunity.Text  = "public";

            m_panelVariables.SuspendDrawing();
            m_panelVariables.ClearAndDisposeControls();
            List <string> lstVariables = new List <string>();

            if (m_trap != null)
            {
                lstVariables.AddRange(m_trap.Variables);
            }
            else if (m_notification != null)
            {
                lstVariables.AddRange(m_notification.Objects);
            }
            foreach (string strVariable in lstVariables)
            {
                IDefinition defVar = mibTree.Find(strVariable);
                if (defVar != null)
                {
                    CControlTrapVariable ctrl = new CControlTrapVariable();
                    m_panelVariables.Controls.Add(ctrl);
                    ctrl.Dock = DockStyle.Top;
                    ctrl.BringToFront();
                    ctrl.Init(defVar);
                }
            }
            m_panelVariables.ResumeDrawing();
        }
Esempio n. 2
0
        //----------------------------------------------------------------
        private CResultAErreurType <CSnmpTrap> CreateTrap()
        {
            CResultAErreurType <CSnmpTrap> result = new CResultAErreurType <CSnmpTrap>();
            CSnmpTrap trap = new CSnmpTrap();

            trap.AgentIpString = m_txtIP.Text;
            trap.Communaute    = m_txtCommunity.Text;

            try
            {
                GenericCode code = (GenericCode)Enum.Parse(typeof(GenericCode), m_cmbGenericCode.Text);
                trap.GenericCode = code;
            }
            catch
            {
                result.EmpileErreur(I.T("Invalid generic code|20115"));
            }
            try
            {
                VersionCode code = (VersionCode)Enum.Parse(typeof(VersionCode), m_cmbTrapVersion.Text);
                trap.VersionCode = code;
            }
            catch
            {
                result.EmpileErreur(I.T("Invalide version code|20116"));
            }
            if (trap.GenericCode == GenericCode.EnterpriseSpecific)
            {
                try
                {
                    trap.EntrepriseOID = new ObjectIdentifier(m_txtEntreprise.Text);
                }
                catch
                {
                    result.EmpileErreur(I.T("Invalid entreprise value|20117"));
                }
                if (m_txtSpecificCode.IntValue == null)
                {
                    result.EmpileErreur(I.T("Invalide specific code[20118"));
                }
                else
                {
                    trap.SpecificCode = m_txtSpecificCode.IntValue.Value;
                }
            }
            trap.TrapDateTime = DateTime.Now;
            foreach (Control ctrl in m_panelVariables.Controls)
            {
                CControlTrapVariable trapV = ctrl as CControlTrapVariable;
                if (trapV != null)
                {
                    CResultAErreurType <ISnmpData> resData = trapV.GetValue();
                    if (!resData)
                    {
                        result.EmpileErreur(resData.Erreur);
                    }
                    else if (resData.DataType != null)
                    {
                        IDefinition def = trapV.Definition;
                        trap.SetVariableValue(ObjectIdentifier.Convert(def.GetNumericalForm()), resData.DataType);
                    }
                }
            }
            if (result)
            {
                result.DataType = trap;
            }
            return(result);
        }