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);
        }
Beispiel #2
0
 public static ActiveSub activate(AMPSAddin.SubscriptionDefinition d, Client client, string messageType, Excel.Workbook workbook)
 {
     if (!_actives.ContainsKey(d))
     {
         _actives[d] = new ActiveSub(client, messageType, d, workbook);
     }
     return(_actives[d]);
 }
Beispiel #3
0
 public static ActiveSub activate(AMPSAddin.SubscriptionDefinition d, Client client, string messageType, Excel.Workbook workbook)
 {
     if (!_actives.ContainsKey(d))
     {
         _actives[d] = new ActiveSub(client, messageType, d, workbook);
     }
     return _actives[d];
 }
        private void deactivate(int index)
        {
            var activeSub = ActiveSub.find(_subs[index]);

            if (activeSub == null)
            {
                return;
            }
            activeSub.close();
        }
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var form = new SubscriptionForm(Globals.AMPSAddin.Application.ActiveWorkbook);
            var sd   = _subs[e.RowIndex];

            form.SubscriptionName = sd.Name;
            // don't let the user modify this name.
            form.txtName.Enabled = false;
            form.ServerName      = sd.ServerName;
            form.Topic           = sd.Topic;
            form.Filter          = sd.Filter;
            form.WorksheetRange  = sd.WorksheetRange;
            bool wasActive = ActiveSub.isActive(sd);

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                sd.Name           = form.SubscriptionName;
                sd.ServerName     = form.ServerName;
                sd.Topic          = form.Topic;
                sd.Filter         = form.Filter;
                sd.WorksheetRange = form.WorksheetRange;
                DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                if (wasActive)
                {
                    row.Cells[0].Value = false;
                    deactivate(e.RowIndex);
                    var wbInfo = Globals.AMPSAddin.getWorkbookInfo(
                        Globals.AMPSAddin.Application.ActiveWorkbook);
                    wbInfo.createOrUpdate(sd);
                    if (activate(e.RowIndex))
                    {
                        row.Cells[0].Value = true;
                    }
                }
                row.Cells[1].Value = sd.Name;
                row.Cells[2].Value = sd.ServerName;
                row.Cells[3].Value = sd.Topic;
                row.Cells[4].Value = sd.Filter;
                row.Cells[5].Value = sd.WorksheetRange;
            }
        }
        private void ManageSubsForm_Load(object sender, EventArgs e)
        {
            // get our current workbook
            var workbook = Globals.AMPSAddin.Application.ActiveWorkbook;

            _subs = new AMPSAddin.SubscriptionDefinition[Globals.AMPSAddin.getWorkbookInfo(workbook).Subscriptions.Count];
            int i = 0;

            foreach (var sub in Globals.AMPSAddin.getWorkbookInfo(workbook).Subscriptions.Values)
            {
                bool active = ActiveSub.isActive(sub);
                this.dataGridView1.Rows.Add(
                    active,
                    sub.Name,
                    sub.ServerName,
                    sub.Topic,
                    sub.Filter,
                    sub.WorksheetRange,
                    "X");
                _subs[i++] = sub;
            }
        }
Beispiel #7
0
        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);
            }
        }