Beispiel #1
0
        /// <summary>
        /// Updates the data in the control from its item.
        /// </summary>
        protected override void UpdateData()
        {
            StringBuilder lsbBuilder = new StringBuilder();

            if (miItem != null)
            {
                // Get setup vars
                UPnPActionTreeItem lavItem   = (UPnPActionTreeItem)miItem;
                Service            lsService = ((Service)(miItem.LinkedObject));
                ServiceDescription ldDesc    = lsService.Description();

                // If description is available
                if (ldDesc != null)
                {
                    // Get the action description for this action
                    ActionDescription laDesc;
                    if (ldDesc.Actions.TryGetValue(lavItem.ActionName, out laDesc))
                    {
                        lsbBuilder.AppendLine(laDesc.ToString());
                    }

                    lsbBuilder.AppendLine();

                    // Lock the inputs
                    dgInputs.BeginUpdate();

                    try
                    {
                        // Lock the outputs
                        dgOutputs.BeginUpdate();

                        try
                        {
                            int liInputIndex  = 0;
                            int liOutputIndex = 0;

                            // For each argument in the action
                            foreach (ArgumentDescription ladDesc in laDesc.Arguments.Values)
                            {
                                // Get the state variable if there is one linked
                                StateVariableDescription lsvDesc = ladDesc.RelatedStateVariableDescription;

                                // Add the input or output argument to the grids
                                AddIOValue(ladDesc, lsvDesc, ref liInputIndex, ref liOutputIndex);

                                // Append a line in the text information for the argument
                                lsbBuilder.AppendLine(
                                    String.Format(
                                        "{0} {1} => {2}",
                                        ladDesc.DirectionValue.ToString(),
                                        ladDesc.Name,
                                        (lsvDesc == null ? "No Related Var" : lsvDesc.ToString())));
                            }

                            // Auto size the input and output grids
                            dgInputs.AutoSizeColumnsMode  = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
                            dgOutputs.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
                        }
                        finally
                        {
                            // Unlock outputs
                            dgOutputs.EndUpdate();
                        }
                    }
                    finally
                    {
                        // Unlock inputs
                        dgInputs.EndUpdate();
                    }
                }
            }

            // Set the info text
            rtbInfo.Text = lsbBuilder.ToString();
        }
Beispiel #2
0
        /// <summary>
        /// Executes the action based on the inputs and outputs data grids.
        /// </summary>
        protected void Execute()
        {
            try
            {
                // Get setup values
                Object[]           loParams  = new Object[dgInputs.Rows.Count];
                UPnPActionTreeItem lavItem   = (UPnPActionTreeItem)miItem;
                Service            lsService = ((Service)(miItem.LinkedObject));
                ServiceDescription ldDesc    = lsService.Description();

                // For each input row
                for (int liCounter = 0; liCounter < dgInputs.Rows.Count; liCounter++)
                {
                    // Get the row info
                    RowInfo liInfo = (RowInfo)(dgInputs.Rows[liCounter].Tag);

                    try
                    {
                        object loValue = dgInputs[clInputValue.Index, liCounter].Value;
                        string lsValue;
                        if (loValue == null)
                        {
                            lsValue = string.Empty;
                        }
                        else
                        {
                            lsValue = loValue.ToString();
                        }
                        loValue = liInfo.StateVarDesc.DataTypeValue.ValueFromString(lsValue);
                        if (loValue == null)
                        {
                            loValue = liInfo.StateVarDesc.DataTypeValue.Default();
                        }

                        // Set the value of the parameter
                        loParams[liInfo.Index] = loValue;
                    }
                    catch (Exception loE)
                    {
                        // Raise exception on conversion error
                        throw new Exception(
                                  String.Format("Error converting input parameter '{0}'.", dgInputs[0, liCounter].Value.ToString()),
                                  loE);
                    }
                }

                // Call the action and get the outputs
                Object[] loOut = lsService.InvokeAction(lavItem.ActionName, loParams);

                // Set the user to the outputs tab
                tcMain.SelectedTab = tpOutputs;

                // For each output parameter
                for (int liCounter = 0; liCounter < dgOutputs.Rows.Count; liCounter++)
                {
                    // Get the row info
                    RowInfo liInfo = (RowInfo)(dgOutputs.Rows[liCounter].Tag);

                    // Set the value in the output grid
                    dgOutputs[clOutputValue.Index, liCounter].Value =
                        liInfo.StateVarDesc.DataTypeValue.StringFromValue(
                            loOut[liInfo.Index]);
                }
            }
            catch (Exception loE)
            {
                // Notify user of any errors
                MessageBox.Show(
                    ExceptionToString(loE),
                    "Error Occured executing action",
                    MessageBoxButtons.OK
                    );
            }
        }