void MainForm_Load(object sender, EventArgs e) { log.InfoFormat("Manager is starting..."); var name = GetType().Name; var client = new RabbitBroker(); client.Open(); Client = client; log.InfoFormat("Manager is started!"); var id = client.Id; client.Subscribe <HelloMessage>(id.Broad, OnResponse); foreach (var pair in AddinExtensions.GetFiltered <ResponseDescAttribute, IResponse>()) { var resp = pair.Value; var rType = resp.GetType(); var subName = nameof(client.Subscribe); var subMeth = client.GetType().GenericMe(subName, rType); var hndlMeth = GetType().GenericMe(nameof(OnResponse), rType); var act = typeof(Action <,>).MakeGenericType(typeof(IIdentity), rType); var dlgt = Delegate.CreateDelegate(act, this, hndlMeth); Invoke(client, subMeth, id.Uni, dlgt, rType); Invoke(client, subMeth, id.Multi, dlgt, rType); } }
public MainForm() { InitializeComponent(); // Bindings contactList = new BindingList <Contact>(); var contactSource = new BindingSource(contactList, null); dataGridView1.AllowUserToAddRows = false; dataGridView1.DataSource = contactSource; // Logging BasicConfigurator.Configure(); // Events Load += MainForm_Load; FormClosing += MainForm_FormClosing; dataGridView1.RowsAdded += DataGridView1_RowsAdded; Icon = Icons.Logo.ToIcon(); // Extensions handlers = AddinExtensions.GetFiltered <CustomExtensionAttribute, IResponseHandler>().Select(v => v.Value).ToArray(); }
void DataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { var grid = (DataGridView)sender; var row = grid.Rows[e.RowIndex]; var msg = (Contact)row.DataBoundItem; var menu = new ContextMenuStrip(); var reqs = AddinExtensions.GetFiltered <RequestDescAttribute, IRequest>().ToArray(); foreach (var pair in reqs) { var req = pair.Value; var name = req.GetType().Name.Replace(typeof(IRequest) .Name.Substring(1), string.Empty); var icon = (Image)Icons.ResourceManager.GetObject(name); EventHandler onclick = (s, a) => { var userReq = (IMessage)Activator.CreateInstance(req.GetType()); using (var dialog = new RequestDialog(req, icon)) if (dialog.ShowDialog(this) == DialogResult.OK) { Client.Publish(msg.Id, req); } }; var item = new ToolStripMenuItem(name, icon, onclick); var category = pair.Key?.Category; if (string.IsNullOrWhiteSpace(category)) { menu.Items.Add(item); } else { var subMenu = menu.Items.OfType <ToolStripDropDownItem>().FirstOrDefault(i => i.Text == category); if (subMenu == null) { menu.Items.Add(subMenu = new ToolStripMenuItem(category, Icons.Category)); } subMenu.DropDownItems.Add(item); } } row.ContextMenuStrip = menu; }
public void Start() { Handlers = new Dictionary <Type, IRequestHandler>(); log.InfoFormat("Service is starting..."); var name = GetType().Name; var client = new RabbitBroker(); client.Open(); Client = client; log.InfoFormat("Service is started!"); var id = client.Id; client.Publish(id.Broad, new HelloMessage { Machine = Environment.MachineName, User = Environment.UserName, Local = client.LocalEndpoint.ToShortString(), Remote = client.RemoteEndpoint.ToShortString() }); foreach (var pair in AddinExtensions.GetFiltered <ReqHandlerFilterAttribute, IRequestHandler>()) { var handler = pair.Value; var intfName = typeof(IRequestHandler <>).Name; foreach (var intf in handler.GetType().GetInterfaces()) { if (!(intf.Name.Equals(intfName))) { continue; } var reqType = intf.GetGenericArguments()[0]; GetType().GenericMe(nameof(Subscribe), reqType).Invoke(this, null); log.InfoFormat("Found '{0}' for '{1}'.", handler, reqType); Handlers[reqType] = handler; } } }