private bool activate(int index) { this.Cursor = Cursors.WaitCursor; string subName = dataGridView1.Rows[index].Cells[1].Value.ToString(); Globals.AMPSAddin.Application.StatusBar = "Activating subscription " + subName + "..."; // activate try { var workbook = Globals.AMPSAddin.Application.ActiveWorkbook; var ampsWBInfo = Globals.AMPSAddin.getWorkbookInfo(workbook); Client c = new Client(Guid.NewGuid().ToString()); AMPSAddin.ServerDefinition serverDef = ampsWBInfo.Servers[_subs[index].ServerName]; c.connect(serverDef.URL); c.logon(); ActiveSub.activate(_subs[index], c, serverDef.MessageType, workbook); } catch (Exception ex) { this.Cursor = Cursors.Default; MessageBox.Show(string.Format("Error activating: {0}", ex.Message), "Error activating subscription " + subName, MessageBoxButtons.OK, MessageBoxIcon.Error); Globals.AMPSAddin.Application.StatusBar = false; return(false); } Globals.AMPSAddin.Application.StatusBar = false; this.Cursor = Cursors.Default; return(true); }
private void button1_Click(object sender, RibbonControlEventArgs e) { //var topicStore = Globals.AMPSAddin.GetTopicStoreForActiveWorkbook(); Excel.Range activeCell = Globals.AMPSAddin.Application.ActiveWindow.ActiveCell; try { Excel.Workbook activeWorkbook = Globals.AMPSAddin.Application.ActiveWorkbook; var form = new SubscriptionForm(activeWorkbook); form.WorksheetRange = Globals.AMPSAddin.Application.ActiveWindow.ActiveSheet.Name + "!" + activeCell.Address; if (form.ShowDialog() == DialogResult.OK) { AMPSAddin.ServerDefinition serverDef = Globals.AMPSAddin.getWorkbookInfo(activeWorkbook).Servers[form.ServerName]; Client c = new Client(Guid.NewGuid().ToString()); c.connect(serverDef.URL); c.logon(); string[] worksheetNames = form.WorksheetRange.Split('!'); AMPSAddin.SubscriptionDefinition def = new AMPSAddin.SubscriptionDefinition { Name = form.SubscriptionName, ServerName = form.ServerName, Topic = form.Topic, WorksheetRange = form.WorksheetRange, Filter = form.Filter }; Globals.AMPSAddin.getWorkbookInfo(activeWorkbook).createOrUpdate(def); ActiveSub.activate(def, c, serverDef.MessageType, Globals.AMPSAddin.Application.ActiveWorkbook); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void cmbServer_SelectedIndexChanged(object sender, EventArgs e) { if (cmbServer.Text == NEW_SERVER) { // go create a new server ServerForm f = new ServerForm(); if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var sd = new AMPSAddin.ServerDefinition { Name = f.ServerName, URL = f.getURL(), MessageType = f.MessageType }; Globals.AMPSAddin.getWorkbookInfo(_workbook).createOrUpdate(sd); Globals.AMPSAddin.getWorkbookInfo(_workbook).Servers[f.ServerName] = sd; cmbServer.Items.Add(f.ServerName); cmbServer.Text = f.ServerName; } else { cmbServer.SelectedItem = null; cmbServer.Text = null; } } // all topics are gone -- reset them. cmbTopic.Items.Clear(); if (!string.IsNullOrEmpty(cmbServer.Text)) { string url = Globals.AMPSAddin.getWorkbookInfo(_workbook).Servers[cmbServer.Text].URL; beginNewTopicSubscription(url); } updateControls(); }