Exemplo n.º 1
0
 private void processTopic(AMPS.Client.Message message)
 {
     try
     {
         if (message.Data.Length > 0)
         {
             string data = message.Data;
             int idx = data.IndexOf("20066=");
             idx += 6;
             string topicName = data.Substring(idx, data.IndexOf((char)0x01, idx) - idx);
             this.BeginInvoke(new Action(() =>
                 {
                     if (!this.cmbTopic.Items.Contains(topicName))
                     {
                         this.cmbTopic.Items.Add(topicName);
                     }
                 }
             ));
         }
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 2
0
        private void ReceivedMessage(AMPS.Client.Message msg)
        {
            if (!_running) return;
            /*try
            {*/
            string sowKey = msg.getSowKey();
            // if an OOF, remove the row if we know of it
            if (msg.Command == AMPS.Client.Message.Commands.OOF && _rows.ContainsKey(sowKey))
            {
                int theRow = _rows[sowKey];

                vbaInvoke(() =>
                {
                    Excel.Range range = _worksheet.Rows[theRow];
                    range.ClearContents();
                    _worksheet.Cells[theRow, _col] = "(deleted)";
                }
                );
                _rows.Remove(sowKey);
                _empty.Enqueue(theRow);
            }
            else if (msg.Command == AMPS.Client.Message.Commands.Publish || msg.Command == AMPS.Client.Message.Commands.DeltaPublish ||
                    msg.Command == AMPS.Client.Message.Commands.SOW)
            {
                int thisRow = 0;
                // try and find the row
                if (!_rows.TryGetValue(sowKey,out thisRow))
                {
                    string findKey = "|" + sowKey + "|";
                    vbaInvoke(() =>
                    {
                        if (_empty.Count > 0)
                        {
                            thisRow = _empty.Dequeue();

                        }
                        else
                        {
                            thisRow = _lastrow++;
                        }
                        _rows[sowKey] = thisRow;
                        _worksheet.Cells[thisRow, _col].Value = findKey;
                    });
                    if (thisRow == -1) return;
                }
                // row == the row we want
                _shredded.Clear();
                var dataField = msg.getDataRaw();
                _messageType.PopulateDictionary(dataField.buffer, dataField.position, dataField.length, _shredded);
                foreach (var x in _shredded.Keys)
                {
                    int thisCol = 0;
                    if (!_columns.ContainsKey(x))
                    {
                        // find a spot for a new column.  hopefully this happens rarely.
                        for (int i = _col + 1; i < 1024768; i++)
                        {
                            vbaInvoke(() =>
                            {
                                dynamic c = _worksheet.Cells[_row, i];
                                if (c.Text == x)
                                {
                                    thisCol = i;
                                    _columns.Add(x, thisCol);
                                }
                                else if (c.Text == null || c.Text == "")
                                {
                                    c.Value = x;
                                    c.Font.Bold = true;
                                    thisCol = i;
                                    _columns.Add(x, thisCol);
                                }
                            });
                            if (thisCol != 0) break;

                        }
                        if (thisCol == 0) return; // no room
                    }
                    else { thisCol = _columns[x]; }
                    vbaInvoke(() => _worksheet.Cells[thisRow, thisCol].Value = _shredded[x].ToString());
                }
            }
            /*}
            catch (Exception e)
            {
                this.close();
                _running = false;
            }*/
        }