//----------------------------------------------- void itemPollSetup_DropDownOpening(object sender, EventArgs e) { ToolStripMenuItem item = sender as ToolStripMenuItem; if (item != null) { item.DropDownItems.Clear(); } CSnmpPollingSetup setup = item != null ? item.Tag as CSnmpPollingSetup : null; CEntiteSnmp ett = EditedElement as CEntiteSnmp; if (setup != null && ett != null) { CTypeDonneeCumulee tp = new CTypeDonneeCumulee(ett.ContexteDonnee); if (tp.ReadIfExists(setup.IdTypeDonneeCumulee)) { foreach (CChampDonneeCumulee champ in tp.GetChampsRenseignes()) { string strNomChamp = tp.GetNomChamp(champ); if (strNomChamp != null && strNomChamp.Length > 0) { ToolStripMenuItem itemAddToPolledField = new ToolStripMenuItem(strNomChamp); itemAddToPolledField.Tag = new CAddToPollData(setup, champ); itemAddToPolledField.Click += new EventHandler(itemAddToPolledField_Click); item.DropDownItems.Add(itemAddToPolledField); } } } } }
//----------------------------------------------- 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(); } } } }
//----------------------------------------------- void itemAddToPolledField_Click(object sender, EventArgs e) { CEntiteSnmp ett = EditedElement as CEntiteSnmp; if (ett != null) { } }
//------------------------------------------------- public CResultAErreurType <CSnmpHotelPolledData> GetHotelPolledData(CEntiteSnmp entite) { CResultAErreurType <CSnmpHotelPolledData> result = new CResultAErreurType <CSnmpHotelPolledData>(); //trouve le champ CSnmpPollingField field = new CSnmpPollingField(entite.ContexteDonnee); if (!field.ReadIfExistsUniversalId(PollingFieldUID) || field.HotelTableId.Length == 0 || field.HotelColumnId.Length == 0) { result.EmpileErreur(I.T("Incorrect polling field|20256")); return(result); } CSnmpHotelPolledData polledData = new CSnmpHotelPolledData(); polledData.HotelTable = field.HotelTableId; polledData.HotelField = field.HotelColumnId; //calcule l'id de l'entité CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(entite); if (FormuleIdEntite == null) { result.EmpileErreur(I.T("Invalid entity id formula|20257")); return(result); } CResultAErreur resTmp = FormuleIdEntite.Eval(ctx); if (!resTmp || resTmp.Data == null) { result.EmpileErreur(I.T("Invalid entity id formula|20257")); result.EmpileErreur(resTmp.Erreur); return(result); } polledData.EntityId = resTmp.Data.ToString(); CResultAErreurType <C2iExpression> resFormule = GetFormuleFinaleForEntite(entite); if (!resFormule || !(resFormule.Data is C2iExpression)) { result.EmpileErreur(I.T("Error while converting Polling formula|20258")); return(result); } polledData.Formule = resFormule.DataType; result.DataType = polledData; return(result); }
//----------------------------------------------- void m_menuAddToPolled_DropDownOpening(object sender, EventArgs e) { m_menuAddToPolled.DropDownItems.Clear(); CEntiteSnmp ett = EditedElement as CEntiteSnmp; if (ett != null) { foreach (CSnmpPollingSetup p in ett.AgentSnmp.ParametresPolling) { ToolStripMenuItem itemPollSetup = new ToolStripMenuItem(p.Libelle); m_menuAddToPolled.DropDownItems.Add(itemPollSetup); itemPollSetup.Tag = p; itemPollSetup.DropDownItems.Add("DUMMY"); itemPollSetup.DropDownOpening += new EventHandler(itemPollSetup_DropDownOpening); } } }
//------------------------------------------------------------------- public override CResultAErreur TraitementAvantSauvegarde(CContexteDonnee contexte) { CResultAErreur result = base.TraitementAvantSauvegarde(contexte); if (!result) { return(result); } DataTable table = contexte.Tables[GetNomTable()]; if (table == null) { return(result); } HashSet <DataRow> rowsAgent = null; ArrayList lstRows = new ArrayList(table.Rows); HashSet <CEntiteSnmp> entitesARecalculer = new HashSet <CEntiteSnmp>(); foreach (DataRow row in lstRows) { if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added) { if (rowsAgent == null) { rowsAgent = CAgentSnmpServeur.GetTableAgentsAMettreAJourToSnmp(contexte, true); } if (rowsAgent != null) { CRelationEntiteSnmp_ChampCustom rel = new CRelationEntiteSnmp_ChampCustom(row); CEntiteSnmp entite = rel.ElementAChamps as CEntiteSnmp; if (entite != null) { entitesARecalculer.Add(entite); rowsAgent.Add(entite.AgentSnmp.Row.Row); } } } } foreach (CEntiteSnmp entite in entitesARecalculer) { entite.RecalcLibelle(); } return(result); }
internal override void InitFromElementDeSchema(CElementDeSchemaReseau elementDeSchema) { base.InitFromElementDeSchema(elementDeSchema); CEntiteSnmp ettSnmp = elementDeSchema.EntiteSnmp; if (ettSnmp == null) //Ca ne doit jamais arriver { throw new Exception("Bad element for supervision data "); } m_dbKeyEntiteSnmp = ettSnmp.DbKey; m_dicEntitesSnmpConcernant[ettSnmp.DbKey] = true; CDonneeDessinElementDeSchemaReseau donneeDessin = elementDeSchema.DonneeDessin as CDonneeDessinElementDeSchemaReseau; if (donneeDessin != null && donneeDessin.CollectChildsAlarms) { SoitConcernePar(ettSnmp.EntiteSnmpsFilles); } }
//--------------------------------------------- private void AssureMenuSnmp() { if (m_menuAddToPolled != null && m_menuAddToPolled.DropDownItems.Count == 0) { m_menuAddToPolled.DropDownItems.Add("DUMMY"); } if (m_menuSnmp != null) { return; } m_menuSnmp = new ContextMenuStrip(); ToolStripMenuItem item = new ToolStripMenuItem(I.T("Read snmp value|20316")); item.Click += new EventHandler(ReadSnmpValue); m_menuSnmp.Items.Add(item); m_menuEcrireSnmp = new ToolStripMenuItem(I.T("Write snmp value|20352")); m_menuEcrireSnmp.Click += new EventHandler(WriteValue); m_menuSnmp.Items.Add(m_menuEcrireSnmp); item = new ToolStripMenuItem(I.T("Read this entity from SNMP|20318")); item.Click += new EventHandler(ReadSnmpEntity); m_menuSnmp.Items.Add(item); item = new ToolStripMenuItem(I.T("Read all agent from SNMP|20319")); item.Click += new EventHandler(ReadSnmpAgent); m_menuSnmp.Items.Add(item); CEntiteSnmp ett = EditedElement as CEntiteSnmp; if (ett != null && ett.AgentSnmp != null) { m_menuAddToPolled = new ToolStripMenuItem(I.T("Add to polled data|20856")); m_menuAddToPolled.DropDownOpening += new EventHandler(m_menuAddToPolled_DropDownOpening); m_menuSnmp.Items.Add(m_menuAddToPolled); m_menuAddToPolled.DropDownItems.Add("DUMMY"); } m_menuOID = new ToolStripMenuItem(""); m_menuSnmp.Items.Add(m_menuOID); m_menuOID.Click += new EventHandler(m_menuOID_Click); }
//------------------------------------------------- private CResultAErreurType <C2iExpression> GetFormuleFinaleForEntite(CEntiteSnmp entite) { CResultAErreurType <C2iExpression> result = new CResultAErreurType <C2iExpression>(); if (m_formulePolling == null) { result.EmpileErreur(I.T("Can not apply formula to entity @1|20254", entite.Libelle)); return(result); } C2iExpression formule = CCloner2iSerializable.Clone(m_formulePolling) as C2iExpression; ArrayList lst = formule.ExtractExpressionsType(typeof(C2iExpressionChamp)); foreach (C2iExpressionChamp exp in lst) { CDefinitionProprieteDynamiqueChampCustom def = exp.DefinitionPropriete as CDefinitionProprieteDynamiqueChampCustom; string strOID = null; if (def != null) { CChampCustom champ = new CChampCustom(CContexteDonneeSysteme.GetInstance()); if (champ.ReadIfExists(def.DbKeyChamp)) { strOID = entite.GetFieldOID(champ.Id); if (strOID.Trim().Length == 0) { strOID = null; } else { exp.DefinitionPropriete = new CDefinitionProprieteDynamiqueOID(strOID); } } } if (strOID == null) { result.EmpileErreur(I.T("Can not find SNMP field for @1|20255", def.Nom)); return(result); } } result.Data = formule; return(result); }
//------------------------------------------------------------------------ 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(""); }
public void Init(CEntiteSnmp entite) { CWin32Traducteur.Translate(this); m_entiteEditee = entite; int nHeight = 50; foreach (IRelationDefinisseurChamp_Formulaire rel in entite.TypeEntiteSnmp.RelationsFormulaires) { nHeight = Math.Max(rel.Formulaire.Formulaire.Size.Height, nHeight); } nHeight += TitleHeight + 5; nHeight += m_panelElementSupervise.Height; TitleText = entite.Libelle + " (" + entite.Index + ")"; m_bIsInit = false; if (!IsCollapse) { InitControles(); } this.ExtendedSize = nHeight; }
//--------------------------------------------------- void m_imageTools_Click(object sender, EventArgs e) { AssureMenuSnmp(); CEntiteSnmp entiteSnmp = EditedElement as CEntiteSnmp; bool bWriteAutorise = entiteSnmp != null && entiteSnmp.TypeEntiteSnmp != null && !entiteSnmp.TypeEntiteSnmp.ReadOnly; m_menuEcrireSnmp.Visible = bWriteAutorise; if (m_menuAddToPolled != null && entiteSnmp != null && entiteSnmp.AgentSnmp.ParametresPolling.Count() > 0) { m_menuAddToPolled.Visible = !LockEdition; } else { m_menuAddToPolled.Visible = false; } if (m_menuOID != null) { try { string strOID = entiteSnmp.GetFieldOID(WndSnmp.FieldZone.ChampCustom.Id); if (strOID != null) { m_menuOID.Text = I.T("OID @1 (Click to copy)|20857", strOID); m_menuOID.Tag = strOID; m_menuOID.Visible = true; } else { m_menuOID.Visible = false; } } catch { m_menuOID.Visible = false; } } m_menuSnmp.Show(Cursor.Position); }
void ReadSnmpEntity(object sender, EventArgs e) { CEntiteSnmp entite = EditedElement as CEntiteSnmp; if (entite != null) { CResultAErreur result = CResultAErreur.True; using (CWaitCursor waiter = new CWaitCursor()) { result = entite.LireValeursSnmp(); //Trouve le parent IRuntimeFor2iWnd parent = this; while (parent.WndContainer is IRuntimeFor2iWnd) { parent = parent.WndContainer as IRuntimeFor2iWnd; } parent.UpdateValeursCalculees(); } if (!result) { CFormAlerte.Afficher(result.Erreur); } } }
//---------------------------------------------------- /// <summary> /// Remplit ou met à jour l'alarme à partir de données /// issues d'un service de médiation /// </summary> /// <param name="alarme"></param> public void FillFromLocalAlarmeFromMediation(CLocalAlarme alarme) { Libelle = alarme.Libelle; Cle = alarme.GetKey(); AlarmId = alarme.Id; EtatCode = (int)alarme.EtatCode; DateDebut = alarme.DateDebut; DateFin = alarme.DateFin; CTypeAlarme ta = new CTypeAlarme(ContexteDonnee); if (ta.ReadIfExists(Int32.Parse(alarme.TypeAlarme.Id))) { TypeAlarme = ta; } else { throw new Exception(I.T("Alarm type @1 doesn't exists|20104", alarme.TypeAlarme.Libelle)); } Site = null; EquipementLogique = null; LienReseau = null; EntiteSnmp = null; //Site if (alarme.SiteId != null) { /*int? nId = CDbKeyAddOn.GetIdFromUniverselId(typeof(CSite), alarme.SiteId); * if (nId != null) * Row[CSite.c_champId] = nId.Value;*/ CSite site = new CSite(ContexteDonnee); if (site.ReadIfExists(alarme.SiteId)) { Site = site; } } if (alarme.EquipementId != null) { /*int? nId = CDbKeyAddOn.GetIdFromUniverselId(typeof(CEquipementLogique), alarme.EquipementId); * if (nId != null) * Row[CEquipementLogique.c_champId] = nId.Value;*/ CEquipementLogique eqt = new CEquipementLogique(ContexteDonnee); if (eqt.ReadIfExists(alarme.EquipementId)) { EquipementLogique = eqt; } } if (alarme.LienId != null) { /*int? nId = CDbKeyAddOn.GetIdFromUniverselId(typeof(CLienReseau), alarme.LienId); * if (nId != null) * Row[CLienReseau.c_champId] = nId.Value;*/ CLienReseau lien = new CLienReseau(ContexteDonnee); if (lien.ReadIfExists(alarme.LienId)) { LienReseau = lien; } } if (alarme.EntiteSnmpId != null) { /*int? nId = CDbKeyAddOn.GetIdFromUniverselId(typeof(CEntiteSnmp), alarme.EntiteSnmpId); * if (nId != null) * Row[CEntiteSnmp.c_champId] = nId.Value;*/ CEntiteSnmp entite = new CEntiteSnmp(ContexteDonnee); if (entite.ReadIfExists(alarme.EntiteSnmpId)) { EntiteSnmp = entite; } } IsHS = alarme.IsHS; if (alarme.IdSeverite != null) { CSeveriteAlarme severite = new CSeveriteAlarme(ContexteDonnee); if (severite.ReadIfExists(Int32.Parse(alarme.IdSeverite))) { Severite = severite; } } if (alarme.MasquagePropre != null) { CParametrageFiltrageAlarmes parametreFiltre = new CParametrageFiltrageAlarmes(ContexteDonnee); if (parametreFiltre.ReadIfExists(Int32.Parse(alarme.MasquagePropre.Id))) { MasquagePropre = parametreFiltre; } } else { MasquagePropre = null; } foreach (CChampCustom champ in ta.TousLesChampsAssocies) { object val = alarme.GetValeurChamp(champ.Id.ToString()); if (val != null) { SetValeurChamp(champ.Id, val); } } }
public IEnumerable <CEntiteSnmp> GetSupportingSnmpEntitySortedFrom(CEntiteSnmp ett) { return(from e in GetSupportingElementsSortedFrom(ett) where (e is CEntiteSnmp)select(CEntiteSnmp) e); }
//------------------------------------- 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; } } }
//------------------------------------------------------------------------ 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); }