/*********************************************************************/ /* */ /* AgentService Framework */ /* www.agentservice.it */ /* */ /* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */ /* GNU Lesser General Public License */ /* */ /* This library is free software; you can redistribute it and/or */ /* modify it under the terms of the GNU Lesser General Public */ /* License as published by the Free Software Foundation, */ /* version 2.1 of the License. */ /* */ /* This library is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ /* Lesser General Public License for more details. */ /* */ /* You should have received a copy of the GNU Lesser General Public */ /* License along with this library; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ /* Boston, MA 02111-1307, USA. */ /* */ /*********************************************************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace lido.VSVisioEditor { public partial class ReflectionDialog : Form { System.Object[] obj = null; string[] Dati = null; System.Reflection.Assembly DLL = null; string[] itemS = null; public ReflectionDialog() { InitializeComponent(); } private void cerca_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = null; openFileDialog = new OpenFileDialog(); //string path = Environment.SpecialFolder.MyDocuments + @"\Visual Studio 2008\Projects\"; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); openFileDialog.Filter = "dll files (*.dll)|*.dll"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { if (openFileDialog.FileName != null) { percorsoDll.Text = openFileDialog.FileName; AnalizDLL.Enabled = true; } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } } private void AnalizDLL_Click(object sender, EventArgs e) { DLL = System.Reflection.Assembly.LoadFrom(percorsoDll.Text); System.Type[] moduli = DLL.GetTypes(); string[] item = new string[(moduli.Length)]; int cont = 0; while (cont < moduli.Length) { string nomeClasse = moduli[cont].Name.ToString(); System.Reflection.MemberInfo Info = DLL.GetType(moduli[cont].FullName); string tipoClasse = moduli[cont].BaseType.Name.ToString(); System.Object[] attr = null; string[] nomeRifK = new string[0]; if (tipoClasse == "Behaviour") { attr = Info.GetCustomAttributes(typeof(AgentService.Agent.KnowledgeAttribute), false); foreach (Object attribute in attr) { AgentService.Agent.KnowledgeAttribute Atrr = (AgentService.Agent.KnowledgeAttribute)attribute; System.Type[] Typ = Atrr.Types; nomeRifK = new string[Typ.Length]; int conta = 0; while (conta < Typ.Length) { nomeRifK[conta] = Typ[conta].Name; conta++; } } } string[] nomeRifB = new string[0]; if (tipoClasse == "AgentTemplate") { attr = Info.GetCustomAttributes(typeof(AgentService.Agent.AgentBehavioursAttribute), false); foreach (Object attribute in attr) { AgentService.Agent.AgentBehavioursAttribute Atrr = (AgentService.Agent.AgentBehavioursAttribute)attribute; System.Type[] Typ = Atrr.Types; nomeRifB = new string[Typ.Length]; int conta = 0; while (conta < Typ.Length) { nomeRifB[conta] = Typ[conta].Name; conta++; } } } if (tipoClasse == "AgentTemplate") { attr = Info.GetCustomAttributes(typeof(AgentService.Agent.AgentKnowledgesAttribute), false); foreach (Object attribute in attr) { AgentService.Agent.AgentKnowledgesAttribute Atrr = (AgentService.Agent.AgentKnowledgesAttribute)attribute; System.Type[] Typ = Atrr.Types; nomeRifK = new string[Typ.Length]; int conta = 0; while (conta < Typ.Length) { nomeRifK[conta] = Typ[conta].Name; conta++; } } } int contA = 0; string AttrK = ""; string AttrB = ""; while (contA < nomeRifK.Length) { AttrK = AttrK + " " + nomeRifK[contA]; contA++; } contA = 0; while (contA < nomeRifB.Length) { AttrB = AttrB + " " + nomeRifB[contA]; contA++; } if (tipoClasse == "Knowledge") { item[cont] = tipoClasse + " | " + nomeClasse; // +" - " + a; } else if (tipoClasse == "Behaviour") { item[cont] = tipoClasse + " | " + nomeClasse + " | " + AttrK; //aggiungere attributi K } else if (tipoClasse == "AgentTemplate") { item[cont] = tipoClasse + " | " + nomeClasse + " | " + AttrB + " | " + AttrK; ; // aggiungi attributi B e aggiugi attributi K } if (tipoClasse == "Batch") { item[cont] = tipoClasse + ", " + nomeClasse; } cont++; } int cnt = 0; int cntI = 0; itemS = new string[(item.Length) - 1]; string vuoto = ""; while (cnt < itemS.Length) { if (cntI < item.Length) { vuoto = item[cntI]; if (vuoto == null)//&&) { cntI++; itemS[cnt] = item[cntI]; } itemS[cnt] = item[cntI]; cnt++; cntI++; } } //Risultati.Lines = itemS; obj = itemS; checkedListBox1.Items.Clear(); checkedListBox1.Items.AddRange(obj); } private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { // System.Type sel = sender.GetType(); string sel = checkedListBox1.SelectedItem.ToString(); string[] Separator = new string[] { " | " }; string[] Dati = sel.Split(Separator, StringSplitOptions.None); NomeClasse.Text = Dati[1]; TipoClasse.Text = Dati[0]; if (Dati[0] == "AgentTemplate") { if ((Dati[2] != "") && (Dati[3] != "")) { behaviours.Text = Dati[2]; knowledges.Text = Dati[3]; } else if ((Dati[2] != "") && (Dati[3] == "")) { behaviours.Text = Dati[2]; knowledges.Text = "--"; } else { behaviours.Text = "--"; knowledges.Text = "--"; } } else if (Dati[0] == "Behaviour") { if (Dati[2] != "") knowledges.Text = Dati[2]; else knowledges.Text = "--"; behaviours.Text = "--"; } else { behaviours.Text = "--"; knowledges.Text = "--"; } // string sel = obj[selInd].ToString(); // MessageBox.Show("hai selezionato "+sel); } private void button1_Click(object sender, EventArgs e) { System.Collections.IEnumerator Enum = checkedListBox1.CheckedItems.GetEnumerator(); Enum.MoveNext(); string curr = Enum.Current.ToString(); string[] Separator = new string[] { " | " }; Dati = curr.Split(Separator, StringSplitOptions.None); this.Close(); // return Dati; // MessageBox.Show("gggggg"); } public string[] ListRef { get { return itemS; } } public string[] ParamRef { get { return Dati; } } public System.Reflection.Assembly Dll { get { return DLL; } } void checkedListBox1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { // // // //int cnt = 1; // string sel = checkedListBox1.SelectedItem.ToString(); //if (checkedListBox1.CheckedItems.Count == 1) Ok.Enabled = true; // { // //checkedListBox1.ClearSelected(); // //System.Collections.IEnumerator Enum = checkedListBox1.CheckedItems.GetEnumerator(); // //Enum.MoveNext(); // //string curr = Enum.Current.ToString(); // //if (sel != curr) // //{ // for (int i = 0; i < checkedListBox1.Items.Count; i++) // { // bool CK=checkedListBox1.GetItemChecked(i); // if(CK==true) // checkedListBox1.SetSelected(i, false); // //if (Ck == true) // //{ // // //checkedListBox1.SetItemChecked(i, false); // // checkedListBox1.SetItemCheckState(i, CheckState.Unchecked); // //} // } // //checkedListBox1.ClearSelected(); // } } } }