Exemplo n.º 1
0
        /// <summary>
        /// Deploy the update
        /// </summary>
        public void DeployUpdate(IDataUpdate update, string connectionStringName, XmlDocument configurationDom)
        {
            string connectionString = configurationDom.SelectSingleNode(String.Format("//connectionStrings/add[@name='{0}']/@connectionString", connectionStringName)).Value;

            using (NpgsqlConnection conn = new NpgsqlConnection(connectionString))
            {
                conn.Open();
                var checkSql = update.GetCheckSql(this.InvariantName);
                if (!String.IsNullOrEmpty(checkSql))
                {
                    using (NpgsqlCommand cmd = new NpgsqlCommand(checkSql, conn))
                        if (!(bool)cmd.ExecuteScalar())
                        {
                            return;
                        }
                }

                var deplSql = update.GetDeploySql(this.InvariantName);
                if (!String.IsNullOrEmpty(deplSql))
                {
                    using (NpgsqlCommand cmd = new NpgsqlCommand(deplSql, conn))
                        cmd.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the form. (1) Positions the form; (2) displays the watch variable and current value; (3) displays the flag state
        /// corresponding to the current value of the watch variable.
        /// </summary>
        /// <param name="bitmaskControl">Reference to the bit mask control that called this form.</param>
        public FormShowFlags(VariableControl bitmaskControl)
        {
            InitializeComponent();

            m_VariableControl = bitmaskControl;

            // Add this form to the list of opened dialog forms associated with the client form.
            m_ClientAsFormPTU = m_VariableControl.ClientForm as FormPTU;
            if (m_ClientAsFormPTU != null)
            {
                m_ClientAsFormPTU.OpenedDialogBoxList.Add(this);
            }

            // Register the event handler for the data update event.
            m_ClientAsIDataUpdate = m_VariableControl.ClientForm as IDataUpdate;
            if (m_ClientAsIDataUpdate != null)
            {
                m_ClientAsIDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_OldIdentifier = (short)m_VariableControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            m_WatchVariableName = m_VariableControl.VariableNameFieldText;

            // Get a list of the current state of each flag and keep a record to determine if there is a change in state.
            List <FlagState_t> flagStateList = Lookup.WatchVariableTableByOldIdentifier.GetFlagStateList(m_OldIdentifier, m_PreviousValue = GetValue());

            m_TableLayoutPanel = ConstructLayoutPanel();
            m_PanelFlagList.Controls.Add(m_TableLayoutPanel);
            ConfigureTableLayoutPanel(m_TableLayoutPanel, flagStateList);

            UpdateTitle(m_WatchVariableName, GetValue());
            UpdateFlagStates(m_TableLayoutPanel.Controls, flagStateList);
            CheckHeight();
            PositionTheForm(m_VariableControl);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="watchControl">The watch control derived user control that called this form.</param>
        /// <exception cref="Exception">Thrown if the old Identifier associated with the control that called this form is not defined in the current data dictionary.</exception>
        public FormChangeWatch(WatchControl watchControl)
        {
            InitializeComponent();

            m_WatchControl = watchControl;

            // Use the communication interface associated with the client form.
            m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface <ICommunicationWatch>;
            Debug.Assert(m_ICommunicationInterface != null);

            // Register the event handler for the data update event.
            m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate;
            if (m_IDataUpdate != null)
            {
                m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_IPollTarget = m_WatchControl.ClientForm as IPollTarget;
            Debug.Assert(m_IPollTarget != null);

            m_OldIdentifier = (short)m_WatchControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            m_WatchVariableName = m_WatchControl.VariableNameFieldText;
            Text = m_WatchVariableName;

            #region - [Units] -
            string units = m_WatchVariable.Units;
            m_LabelCurrentValueUnits.Text   = units;
            m_LabelAllowableRangeUnits.Text = units;
            m_LabelNewValueUnits.Text       = units;
            #endregion - [Units] -

            // Update the display by calling the DataUpdate event handler.
            DataUpdate(this, new EventArgs());
        }
        private void OnSubscriptionDataUpdated(IDataUpdate update)
        {
            // In this sample for clarity we assume that the realtime update contains at most a single point.
            // Robust real-world apps should iterate on update.Records.
            IData record = update.Records.FirstOrDefault();

            if (record != null)
            {
                if (update.UpdateType == UpdateType.ExistingPoint && this.Records.Count > 0)
                {
                    // In this inter-day context, receiving an update of type "ExistingPoint" means that
                    // the last received record, ie the record of the current day, is to be overriden.
                    // Here we simply remove / add the record.
                    this.Records.RemoveAt(0);
                }

                this.Records.Insert(0, record.ToBarRecord());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the form. (1) Positions the form; (2) displays the watch variable and current value; (3) displays the flag state 
        /// corresponding to the current value of the watch variable.
        /// </summary>
        /// <param name="bitmaskControl">Reference to the bit mask control that called this form.</param>
        public FormShowFlags(VariableControl bitmaskControl)
        {
            InitializeComponent();

            m_VariableControl = bitmaskControl;

            // Add this form to the list of opened dialog forms associated with the client form.
            m_ClientAsFormPTU = m_VariableControl.ClientForm as FormPTU;
            if (m_ClientAsFormPTU != null)
            {
                m_ClientAsFormPTU.OpenedDialogBoxList.Add(this);
            }

            // Register the event handler for the data update event.
            m_ClientAsIDataUpdate = m_VariableControl.ClientForm as IDataUpdate;
            if (m_ClientAsIDataUpdate != null)
            {
                m_ClientAsIDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_OldIdentifier = (short)m_VariableControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            m_WatchVariableName = m_VariableControl.VariableNameFieldText;
            
            // Get a list of the current state of each flag and keep a record to determine if there is a change in state.
            List<FlagState_t> flagStateList = Lookup.WatchVariableTableByOldIdentifier.GetFlagStateList(m_OldIdentifier, m_PreviousValue = GetValue());

            m_TableLayoutPanel = ConstructLayoutPanel();
            m_PanelFlagList.Controls.Add(m_TableLayoutPanel);
            ConfigureTableLayoutPanel(m_TableLayoutPanel, flagStateList);

            UpdateTitle(m_WatchVariableName, GetValue());
            UpdateFlagStates(m_TableLayoutPanel.Controls, flagStateList);
            CheckHeight();
            PositionTheForm(m_VariableControl);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="bitmaskControl">The <c>WatchControl</c> derived user control that called this form.</param>
        public FormChangeBitmask(WatchBitmaskControl bitmaskControl)
        {
            InitializeComponent();

            m_WatchControl = bitmaskControl;

            // Use the communication interface associated with the client form.
            m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface<ICommunicationWatch>;
            Debug.Assert(m_ICommunicationInterface != null);

            // Register the event handler for the data update event.
            m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate;
            if (m_IDataUpdate != null)
            {
                m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_IPollTarget = m_WatchControl.ClientForm as IPollTarget;
            Debug.Assert(m_IPollTarget != null);

            m_OldIdentifier = (short)m_WatchControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch(Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            Debug.Assert(m_WatchVariable.VariableType == VariableType.Bitmask, "FormChangeBitmask.Ctor() - [m_WatchVariable.VariableType == VariableType.Bitmask]");

            Text = m_WatchVariable.Name;

            #region - [Units] -
            string units = m_WatchVariable.Units;
            m_LabelCurrentValueUnits.Text = units;
            m_LabelNewValueUnits.Text = units;
            #endregion - [Units] -

            #region - [NumericUpDown] -
            m_NumericUpDownNewValue.Hexadecimal = m_RadioButtonHex.Checked;
            m_NumericUpDownNewValue.DecimalPlaces = 0;
            m_NumericUpDownNewValue.Increment = 1;

            m_NumericUpDownNewValue.Maximum = (decimal)m_WatchVariable.MaxModifyValue;
            m_NumericUpDownNewValue.Minimum = (decimal)m_WatchVariable.MinModifyValue;
            
            // Initialize the NumericUpDown control Value property.
            try
            {
                m_NumericUpDownNewValue.Value = (decimal)m_WatchControl.Value;
            }
            catch (Exception)
            {
                // The specified initial value is outside of the limits, set to the minimum value.
                m_NumericUpDownNewValue.Value = m_NumericUpDownNewValue.Minimum;
            }
            #endregion - [NumericUpDown] -

            #region - [ICheckBoxUInt32] -
            m_ICheckBoxUInt32 = new CheckBoxUInt32();
            CheckBox[] checkBoxes;
            ConfigureCheckBoxes(out checkBoxes);
            m_ICheckBoxUInt32.CheckBoxes = checkBoxes;
            m_ICheckBoxUInt32.SetText(m_OldIdentifier);
            m_ICheckBoxUInt32.SetChecked((uint)m_WatchControl.Value);
            #endregion - [ICheckBoxUInt32] -

            // Update the display by calling the DataUpdate event handler.
            DataUpdate(this, new EventArgs());

            // Now that the display has been initialized, disable the apply button. This will only be re-enabled when the user has specified a new watch value.
            m_ButtonApply.Enabled = false;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="watchControl">The watch control derived user control that called this form.</param>
        /// <exception cref="Exception">Thrown if the old Identifier associated with the control that called this form is not defined in the current data dictionary.</exception>
        public FormChangeWatch(WatchControl watchControl)
        {
            InitializeComponent();

            m_WatchControl = watchControl;

            // Use the communication interface associated with the client form.
            m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface<ICommunicationWatch>;
            Debug.Assert(m_ICommunicationInterface != null);

            // Register the event handler for the data update event.
            m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate;
            if (m_IDataUpdate != null)
            {
                m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_IPollTarget = m_WatchControl.ClientForm as IPollTarget;
            Debug.Assert(m_IPollTarget != null);

            m_OldIdentifier = (short)m_WatchControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            m_WatchVariableName = m_WatchControl.VariableNameFieldText;
            Text = m_WatchVariableName;

            #region - [Units] -
            string units = m_WatchVariable.Units;
            m_LabelCurrentValueUnits.Text = units;
            m_LabelAllowableRangeUnits.Text = units;
            m_LabelNewValueUnits.Text = units;
            #endregion - [Units] -

            // Update the display by calling the DataUpdate event handler.
            DataUpdate(this, new EventArgs());
        }
 public void SetListener(IDataUpdate listener)
 {
     this.listener = listener;
 }
        /// <summary>
        /// Initialize a new instance of the class.
        /// </summary>
        /// <param name="bitmaskControl">The <c>WatchControl</c> derived user control that called this form.</param>
        public FormChangeBitmask(WatchBitmaskControl bitmaskControl)
        {
            InitializeComponent();

            m_WatchControl = bitmaskControl;

            // Use the communication interface associated with the client form.
            m_ICommunicationInterface = m_WatchControl.ClientForm as ICommunicationInterface <ICommunicationWatch>;
            Debug.Assert(m_ICommunicationInterface != null);

            // Register the event handler for the data update event.
            m_IDataUpdate = m_WatchControl.ClientForm as IDataUpdate;
            if (m_IDataUpdate != null)
            {
                m_IDataUpdate.DataUpdate += new EventHandler(DataUpdate);
            }

            m_IPollTarget = m_WatchControl.ClientForm as IPollTarget;
            Debug.Assert(m_IPollTarget != null);

            m_OldIdentifier = (short)m_WatchControl.Identifier;
            try
            {
                m_WatchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[m_OldIdentifier];
                if (m_WatchVariable == null)
                {
                    throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
                }
            }
            catch (Exception)
            {
                throw new ArgumentException(Resources.MBTWatchVariableNotDefined);
            }

            Debug.Assert(m_WatchVariable.VariableType == VariableType.Bitmask, "FormChangeBitmask.Ctor() - [m_WatchVariable.VariableType == VariableType.Bitmask]");

            Text = m_WatchVariable.Name;

            #region - [Units] -
            string units = m_WatchVariable.Units;
            m_LabelCurrentValueUnits.Text = units;
            m_LabelNewValueUnits.Text     = units;
            #endregion - [Units] -

            #region - [NumericUpDown] -
            m_NumericUpDownNewValue.Hexadecimal   = m_RadioButtonHex.Checked;
            m_NumericUpDownNewValue.DecimalPlaces = 0;
            m_NumericUpDownNewValue.Increment     = 1;

            m_NumericUpDownNewValue.Maximum = (decimal)m_WatchVariable.MaxModifyValue;
            m_NumericUpDownNewValue.Minimum = (decimal)m_WatchVariable.MinModifyValue;

            // Initialize the NumericUpDown control Value property.
            try
            {
                m_NumericUpDownNewValue.Value = (decimal)m_WatchControl.Value;
            }
            catch (Exception)
            {
                // The specified initial value is outside of the limits, set to the minimum value.
                m_NumericUpDownNewValue.Value = m_NumericUpDownNewValue.Minimum;
            }
            #endregion - [NumericUpDown] -

            #region - [ICheckBoxUInt32] -
            m_ICheckBoxUInt32 = new CheckBoxUInt32();
            CheckBox[] checkBoxes;
            ConfigureCheckBoxes(out checkBoxes);
            m_ICheckBoxUInt32.CheckBoxes = checkBoxes;
            m_ICheckBoxUInt32.SetText(m_OldIdentifier);
            m_ICheckBoxUInt32.SetChecked((uint)m_WatchControl.Value);
            #endregion - [ICheckBoxUInt32] -

            // Update the display by calling the DataUpdate event handler.
            DataUpdate(this, new EventArgs());

            // Now that the display has been initialized, disable the apply button. This will only be re-enabled when the user has specified a new watch value.
            m_ButtonApply.Enabled = false;
        }