Esempio n. 1
0
        //-----------------------------------------------
        void WriteValue(object sender, EventArgs e)
        {
            CEntiteSnmp entiteSnmp = EditedElement as CEntiteSnmp;

            if (entiteSnmp != null)
            {
                CResultAErreur result = MajChamps(true);
                if (!result)
                {
                    CFormAlerte.Afficher(result.Erreur);
                    return;
                }
                CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(entiteSnmp, ((CChampCustom)WndSnmp.FieldZone.Variable).Id) as CRelationEntiteSnmp_ChampCustom;
                if (rel != null)
                {
                    result = rel.WriteSnmpValue();
                    if (!result)
                    {
                        CFormAlerte.Afficher(result.Erreur);
                    }
                    else
                    {
                        ReadSnmpValue(this, null);
                        MyUpdateValeursCalculees();
                    }
                }
            }
        }
Esempio n. 2
0
        //-------------------------------------------------------------------------------
        //Optimisation : l'entité pour sup n'est créée qu'une seul fois lors d'appels multiples
        public CResultAErreur ReadChampSnmp(int nIdChampCustom, CInterrogateurSnmp dynamicAgent, ref CEntiteSnmpPourSupervision ettPourSup)
        {
            CResultAErreur result = CResultAErreur.True;

            CResultAErreurType <string> resOID = GetFieldOIDWithEntitePourSupervision(nIdChampCustom, ettPourSup);

            if (!resOID)
            {
                result.EmpileErreur(resOID.Erreur);
                return(result);
            }

            string    strOID = resOID.DataType;
            ISnmpData valeur = dynamicAgent.Get(strOID) as ISnmpData;
            CRelationEntiteSnmp_ChampCustom relChamp = CUtilElementAChamps.GetRelationToChamp(this, nIdChampCustom) as CRelationEntiteSnmp_ChampCustom;

            if (relChamp != null)
            {
                if (valeur == null)
                {
                    relChamp.LastSnmpValue = null;
                }
                else
                {
                    relChamp.LastSnmpValue = valeur.ConvertToTypeDotNet();
                }
            }
            result.Data = valeur != null?valeur.ConvertToTypeDotNet() : null;

            return(result);
        }
Esempio n. 3
0
        //-----------------------------------------------------------------------
        public void CopieValeurSnmpDansValeurChamp(int nIdChampCustom)
        {
            CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(this, nIdChampCustom) as CRelationEntiteSnmp_ChampCustom;

            if (rel != null)
            {
                SetValeurFromSnmp(nIdChampCustom, rel.LastSnmpValue);
            }
        }
Esempio n. 4
0
        //----------------------------------------------------
        public CResultAErreur SetValeurFromSnmp(int nIdChampCustom, object valeur)
        {
            CResultAErreur result = SetValeurChamp(nIdChampCustom, valeur);

            if (!result)
            {
                return(result);
            }
            CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(this, nIdChampCustom) as CRelationEntiteSnmp_ChampCustom;

            if (rel != null)
            {
                rel.LastSnmpValue = valeur;
            }

            return(result);
        }
Esempio n. 5
0
        //------------------------------------------------------------------------
        public object GetObjectValueForGrid(object element)
        {
            CEntiteSnmp entite = element as CEntiteSnmp;

            if (entite != null)
            {
                CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(entite, m_wndChampCustom.ChampCustom.Id) as CRelationEntiteSnmp_ChampCustom;
                if (rel != null)
                {
                    string strRetour = rel.Valeur == null ? "" : rel.Valeur.ToString();
                    strRetour += "  (";
                    object val = rel.LastSnmpValue;
                    return(val);
                }
            }
            if (m_wndChampCustom != null)
            {
                return(m_wndChampCustom.GetObjectValueForGrid(element));
            }
            return("");
        }
Esempio n. 6
0
        //--------------------------------------------------------------------
        private void UpdateDateSNMP()
        {
            DateTime?                dtOld   = null;
            CSchemaReseau            schema  = m_stackCheminsReseau.Peek();
            CListeCouplesEntiteChamp couples = schema.GetListeValeursSnmpAffichees();

            foreach (CCoupleEntiteSnmp_Champ couple in couples)
            {
                CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(couple.Entite, couple.ChampCustom.Id) as CRelationEntiteSnmp_ChampCustom;
                if (rel != null && rel.DateSynchroSnmp != null)
                {
                    if (dtOld == null || rel.DateSynchroSnmp.DateTimeValue < dtOld.Value)
                    {
                        dtOld = rel.DateSynchroSnmp.DateTimeValue;
                    }
                }
            }
            m_bHasSnmpEntities  = couples.Count > 0;
            m_panelSNMP.Visible = m_bHasSnmpEntities;
            m_lastSnmpUpdate    = dtOld;
            UpdateLabelSnmpUpdate();
        }
Esempio n. 7
0
        //-------------------------------------
        protected override void  MyUpdateValeursCalculees()
        {
            if (m_controleSnmp == null)
            {
                return;
            }
            CEntiteSnmp entiteSnmp = EditedElement as CEntiteSnmp;

            if (entiteSnmp == null)
            {
                return;
            }

            CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(entiteSnmp, ((CChampCustom)WndSnmp.FieldZone.Variable).Id) as CRelationEntiteSnmp_ChampCustom;

            if (m_createur != null && m_controleSnmp != null)
            {
                m_createur.SetTooltip(m_controleSnmp, "");
            }
            if (rel == null)
            {
                m_controleSnmp.Visible = false;
                m_imageWarning.Visible = false;
            }
            else
            {
                CDateTimeEx dt = rel.DateSynchroSnmp;
                if (dt != null)
                {
                    if (m_createur != null && m_controleSnmp != null)
                    {
                        m_createur.SetTooltip(m_controleSnmp, I.T("Last updated : @1 @2|20317",
                                                                  dt.DateTimeValue.ToShortDateString(),
                                                                  dt.DateTimeValue.ToLongTimeString()));
                    }
                }
                m_controleSnmp.Visible = true;
                object val = rel.LastSnmpValue;
                if (val == null)
                {
                    m_controleSnmp.Text = "";
                }
                else
                {
                    if (WndSnmp.ChampCustom.IsChoixParmis())
                    {
                        m_controleSnmp.Text = WndSnmp.ChampCustom.DisplayFromValue(val);
                    }
                    else if (m_controleSnmp is CheckBox)
                    {
                        ((CheckBox)m_controleSnmp).Checked = (val is bool) ? (bool)val : false;
                    }
                    else
                    {
                        m_controleSnmp.Text = val.ToString();
                    }
                }
                string strVal1 = m_wndChamp.Value != null?m_wndChamp.Value.ToString() : "";

                string strVal2 = val != null?val.ToString() : "";

                if (strVal1 != strVal2 && rel.DateSynchroSnmp != null)
                {
                    m_imageWarning.Visible = true;
                    m_controleSnmp.Width   = m_wndChamp.Control.Width - 16;
                }
                else
                {
                    m_imageWarning.Visible = false;
                    m_controleSnmp.Width   = m_wndChamp.Control.Width;
                }
            }
        }
Esempio n. 8
0
        //------------------------------------------------------------------------
        public bool Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, object element)
        {
            CEntiteSnmp entite = element as CEntiteSnmp;

            if (entite != null)
            {
                CRelationEntiteSnmp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(entite, m_wndChampCustom.ChampCustom.Id) as CRelationEntiteSnmp_ChampCustom;
                if (rel != null)
                {
                    int       nWidthChampCustom = Math.Max((cellBounds.Width * m_wndChampCustom.Size.Width) / Math.Max(Size.Width, 1), 10);
                    object    val     = rel.Valeur;
                    object    valSnmp = rel.LastSnmpValue;
                    Rectangle rct     = new Rectangle(new Point(0, 0), new Size(nWidthChampCustom, cellBounds.Height));
                    rct.Offset(cellBounds.Location);
                    Pen   pen = new Pen(Color.Black, 1);
                    Brush br  = new SolidBrush(m_wndChampCustom.BackColor);
                    graphics.FillRectangle(br, rct);
                    graphics.DrawRectangle(pen, rct);

                    br.Dispose();

                    StringFormat format = new StringFormat();
                    format.LineAlignment = StringAlignment.Center;
                    format.Alignment     = StringAlignment.Near;
                    br = new SolidBrush(m_wndChampCustom.ForeColor);
                    graphics.DrawString(val == null ? "" : val.ToString(), m_wndChampCustom.Font, br, rct, format);
                    br.Dispose();
                    string strVal1 = val != null?val.ToString() : "";

                    string strVal2 = valSnmp != null?valSnmp.ToString() : "";

                    bool bHasDif = strVal1 != strVal2 && rel.DateSynchroSnmp != null;
                    rct = cellBounds;
                    rct.Offset(nWidthChampCustom, 0);
                    rct.Size = new Size(rct.Size.Width - nWidthChampCustom, rct.Size.Height);
                    if (bHasDif)
                    {
                        rct.Size = new Size(rct.Size.Width - 16, rct.Size.Height);
                    }
                    br = new SolidBrush(m_wndValeurAutre.BackColor);
                    graphics.FillRectangle(br, rct);
                    graphics.DrawRectangle(pen, rct);
                    br.Dispose();
                    pen.Dispose();
                    br = new SolidBrush(m_wndValeurAutre.ForeColor);
                    graphics.DrawString(valSnmp == null ? "" : valSnmp.ToString(), m_wndValeurAutre.Font, br, rct, format);
                    format.Dispose();
                    br.Dispose();
                    if (bHasDif)
                    {
                        rct = new Rectangle(cellBounds.Right - 16, cellBounds.Top, 16, cellBounds.Height);
                        br  = new SolidBrush(BackColor);
                        graphics.FillRectangle(br, rct);
                        br.Dispose();
                        rct.Location = new Point(rct.Left, rct.Top + rct.Height / 2 - 8);
                        rct.Height   = 16;
                        graphics.DrawImage(Resource.alerte, rct);
                    }
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 9
0
        //-----------------------------------------------------------------------
        //Si idsChampsAMettreAJour est vide, il faut tout mettre à jour
        public CResultAErreur SendToSnmp(bool bOnlyModifiés, params int[] idsChampsAMettreAJour)
        {
            CResultAErreur result = CResultAErreur.True;

            if (TypeEntiteSnmp == null)
            {
                return(result);
            }
            if (TypeEntiteSnmp.ReadOnly)
            {
                result.EmpileErreur(I.T("This is a readonly entity|20127"));
                return(result);
            }
            IEnumerable <CChampEntiteFromQueryToChampCustom> lstChamps = TypeEntiteSnmp.ChampsFromQuery;
            Dictionary <string, object>            lstValeurs          = new Dictionary <string, object>();
            CResultAErreurType <IObjetDeEasyQuery> resObj = TypeEntiteSnmp.FindSourceObjetInQuery( );

            if (!resObj || resObj.DataType == null)
            {
                result.EmpileErreur(resObj.Erreur);
                return(result);
            }

            IObjetDeEasyQuery objetSource = resObj.DataType;
            CEasyQuery        query       = objetSource.Query;

            Dictionary <string, string> dicOIDStringToChamp = new Dictionary <string, string>();
            CEntiteSnmpPourSupervision  ettPourSup          = null;

            foreach (CChampEntiteFromQueryToChampCustom champ in lstChamps)
            {
                if (champ.IdChampCustom != null && (idsChampsAMettreAJour.Length == 0 ||
                                                    idsChampsAMettreAJour.Contains(champ.IdChampCustom.Value)))
                {
                    CRelationElementAChamp_ChampCustom rel = CUtilElementAChamps.GetRelationToChamp(this, champ.IdChampCustom.Value);
                    if (rel != null && (bOnlyModifiés && (rel.Row.RowState == DataRowState.Added || rel.Row.RowState == DataRowState.Modified) ||
                                        !bOnlyModifiés))
                    {
                        object valeur = rel.Valeur;

                        ITableDefinition  table = null;
                        IColumnDefinition col   = null;
                        if (query.FindSource(champ.Champ.ColonneSource, objetSource,
                                             out table,
                                             out col))
                        {
                            CColumnDefinitionSNMP colSnmp = col as CColumnDefinitionSNMP;

                            if (colSnmp != null && !champ.Champ.IsReadOnly)
                            {
                                ISnmpData snmpVal = AbstractTypeAssignment.GetSnmpFromDotNet(colSnmp.SnmpType, valeur);
                                if (snmpVal == null && valeur != null)
                                {
                                    snmpVal = new OctetString(valeur.ToString());
                                }
                                if (snmpVal != null)
                                {
                                    string strIndex = Index;
                                    if (champ.Champ.FormuleIndex != null)
                                    {
                                        if (ettPourSup == null)
                                        {
                                            ettPourSup = GetEntitePourSupervision(TypeEntiteSnmp.GetTypeEntitePourSupervision(null, false));
                                        }
                                        CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(ettPourSup);
                                        CResultAErreur restTmp            = champ.Champ.FormuleIndex.Eval(ctx);
                                        if (restTmp && restTmp.Data != null)
                                        {
                                            strIndex = restTmp.Data.ToString();
                                        }
                                    }
                                    if (!strIndex.StartsWith("."))
                                    {
                                        strIndex = "." + strIndex;
                                    }
                                    lstValeurs[colSnmp.OIDString + strIndex]          = snmpVal;
                                    dicOIDStringToChamp[colSnmp.OIDString + strIndex] = champ.ChampCustom.Nom;
                                }
                            }
                        }
                    }
                }
            }
            if (lstValeurs.Count > 0)
            {
                CInterrogateurSnmp agent = new CInterrogateurSnmp();
                agent.Connexion.Version  = AgentSnmp.SnmpVersion;
                agent.ConnexionIp        = AgentSnmp.SnmpIp;
                agent.ConnexionPort      = AgentSnmp.SnmpPort;
                agent.ConnexionCommunity = AgentSnmp.SnmpCommunaute;
                foreach (KeyValuePair <string, object> kv in lstValeurs)
                {
                    try
                    {
                        CResultAErreur resTmp = agent.Set(kv.Key, kv.Value);

                        if (!resTmp)
                        {
                            string strChamp = null;
                            if (dicOIDStringToChamp.TryGetValue(kv.Key, out strChamp))
                            {
                                result.EmpileErreur(new CErreurValidation(I.T("Entity @1 (@2), Field @3 : |20105", Libelle, Index, strChamp) + resTmp.Erreur.ToString(), resTmp.IsAvertissement));
                            }
                            else
                            {
                                result.EmpileErreur(resTmp.Erreur);
                            }
                            if (!result.IsAvertissement)
                            {
                                return(result);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        result.EmpileErreur(new CErreurException(e));
                    }
                }
            }
            return(result);
        }