The description of a value to write.
        /// <summary>
        /// Calls a method on an object.
        /// </summary>
        protected virtual ServiceResult Call(
            ISystemContext context,
            CallMethodRequest methodToCall,
            MethodState method,
            CallMethodResult result)
        {
            ServerSystemContext systemContext = context as ServerSystemContext;
            List<ServiceResult> argumentErrors = new List<ServiceResult>();
            VariantCollection outputArguments = new VariantCollection();

            ServiceResult error = method.Call(
                context,
                methodToCall.ObjectId,
                methodToCall.InputArguments,
                argumentErrors,
                outputArguments);

            if (ServiceResult.IsBad(error))
            {
                return error;
            }

            // check for argument errors.
            bool argumentsValid = true;

            for (int jj = 0; jj < argumentErrors.Count; jj++)
            {
                ServiceResult argumentError = argumentErrors[jj];

                if (argumentError != null)
                {
                    result.InputArgumentResults.Add(argumentError.StatusCode);

                    if (ServiceResult.IsBad(argumentError))
                    {
                        argumentsValid = false;
                    }
                }
                else
                {
                    result.InputArgumentResults.Add(StatusCodes.Good);
                }

                // only fill in diagnostic info if it is requested.
                if (systemContext.OperationContext != null)
                {
                    if ((systemContext.OperationContext.DiagnosticsMask & DiagnosticsMasks.OperationAll) != 0)
                    {
                        if (ServiceResult.IsBad(argumentError))
                        {
                            argumentsValid = false;
                            result.InputArgumentDiagnosticInfos.Add(new DiagnosticInfo(argumentError, systemContext.OperationContext.DiagnosticsMask, false, systemContext.OperationContext.StringTable));
                        }
                        else
                        {
                            result.InputArgumentDiagnosticInfos.Add(null);
                        }
                    }
                }
            }

            // check for validation errors.
            if (!argumentsValid)
            {
                result.StatusCode = StatusCodes.BadInvalidArgument;
                return result.StatusCode;
            }

            // do not return diagnostics if there are no errors.
            result.InputArgumentDiagnosticInfos.Clear();

            // return output arguments.
            result.OutputArguments = outputArguments;

            return ServiceResult.Good;
        }
Example #2
0
        /// <summary>
        /// Handles the Click event of the Conditions_RefreshMI control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Conditions_RefreshMI_Click(object sender, EventArgs e)
        {
            try
            {
                CallMethodRequest request = new CallMethodRequest();

                request.ObjectId = ObjectTypeIds.ConditionType;
                request.MethodId = MethodIds.ConditionType_ConditionRefresh;
                request.InputArguments.Add(new Variant(m_subscription.Id));
                
                CallMethodRequestCollection methodsToCall = new CallMethodRequestCollection();
                methodsToCall.Add(request);

                CallMethodResultCollection results = null;
                DiagnosticInfoCollection diagnosticInfos = null;

                m_session.Call(
                    null,
                    methodsToCall,
                    out results,
                    out diagnosticInfos);

                ClientBase.ValidateResponse(results, methodsToCall);
                ClientBase.ValidateDiagnosticInfos(diagnosticInfos, methodsToCall);

                if (StatusCode.IsBad(results[0].StatusCode))
                {
                    throw ServiceResultException.Create((uint)results[0].StatusCode, "Unexpected error calling RefreshConditions.");
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
Example #3
0
        /// <summary>
        /// Adds a comment to the selected conditions.
        /// </summary>
        /// <param name="methodId">The NodeId for the method to call.</param>
        /// <param name="comment">The comment to pass as an argument.</param>
        private void CallMethod(NodeId methodId, string comment)
        {
            // build list of methods to call.
            CallMethodRequestCollection methodsToCall = new CallMethodRequestCollection();

            for (int ii = 0; ii < ConditionsLV.SelectedItems.Count; ii++)
            {
                ConditionState condition = (ConditionState)ConditionsLV.SelectedItems[ii].Tag;

                CallMethodRequest request = new CallMethodRequest();

                request.ObjectId = condition.NodeId;
                request.MethodId = methodId;
                request.Handle = ConditionsLV.SelectedItems[ii];

                if (comment != null)
                {
                    request.InputArguments.Add(new Variant(condition.EventId.Value));
                    request.InputArguments.Add(new Variant((LocalizedText)comment));
                }

                methodsToCall.Add(request);
            }

            if (methodsToCall.Count == 0)
            {
                return;
            }

            // call the methods.
            CallMethodResultCollection results = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            m_session.Call(
                null,
                methodsToCall,
                out results,
                out diagnosticInfos);

            ClientBase.ValidateResponse(results, methodsToCall);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, methodsToCall);

            for (int ii = 0; ii < results.Count; ii++)
            {
                if (StatusCode.IsBad(results[ii].StatusCode))
                {
                    ListViewItem item = (ListViewItem)methodsToCall[ii].Handle;
                    item.SubItems[8].Text = Utils.Format("{0}", results[ii].StatusCode);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Responds to the dialog.
        /// </summary>
        private void Respond(int selectedResponse)
        {
            // build list of dialogs to respond to (caller should always make sure that only one is selected).
            CallMethodRequestCollection methodsToCall = new CallMethodRequestCollection();

            for (int ii = 0; ii < ConditionsLV.SelectedItems.Count; ii++)
            {
                DialogConditionState dialog = ConditionsLV.SelectedItems[ii].Tag as DialogConditionState;

                if (dialog == null)
                {
                    continue;
                }

                CallMethodRequest request = new CallMethodRequest();

                request.ObjectId = dialog.NodeId;
                request.MethodId = MethodIds.DialogConditionType_Respond;
                request.InputArguments.Add(new Variant(selectedResponse));
                request.Handle = ConditionsLV.SelectedItems[ii];

                methodsToCall.Add(request);
            }

            if (methodsToCall.Count == 0)
            {
                return;
            }

            // call the methods.
            CallMethodResultCollection results = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            m_session.Call(
                null,
                methodsToCall,
                out results,
                out diagnosticInfos);

            ClientBase.ValidateResponse(results, methodsToCall);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, methodsToCall);

            for (int ii = 0; ii < results.Count; ii++)
            {
                if (StatusCode.IsBad(results[ii].StatusCode))
                {
                    ListViewItem item = (ListViewItem)methodsToCall[ii].Handle;
                    item.SubItems[8].Text = Utils.Format("{0}", results[ii].StatusCode);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Confirms the selected conditions.
        /// </summary>
        private void Shelve(bool shelving, bool oneShot, double shelvingTime)
        {
            // build list of methods to call.
            CallMethodRequestCollection methodsToCall = new CallMethodRequestCollection();

            for (int ii = 0; ii < ConditionsLV.SelectedItems.Count; ii++)
            {
                ConditionState condition = (ConditionState)ConditionsLV.SelectedItems[ii].Tag;

                // check if the node supports shelving.
                BaseObjectState shelvingState = condition.FindChild(m_session.SystemContext, BrowseNames.ShelvingState) as BaseObjectState;

                if (shelvingState == null)
                {
                    continue;
                }

                CallMethodRequest request = new CallMethodRequest();

                request.ObjectId = shelvingState.NodeId;
                request.Handle = ConditionsLV.SelectedItems[ii];

                // select the method to call.
                if (!shelving)
                {
                    request.MethodId = MethodIds.ShelvedStateMachineType_Unshelve;
                }
                else
                {
                    if (oneShot)
                    {
                        request.MethodId = MethodIds.ShelvedStateMachineType_OneShotShelve;
                    }
                    else
                    {
                        request.MethodId = MethodIds.ShelvedStateMachineType_TimedShelve;
                        request.InputArguments.Add(new Variant(shelvingTime));
                    }
                }

                methodsToCall.Add(request);
            }

            if (methodsToCall.Count == 0)
            {
                return;
            }

            // call the methods.
            CallMethodResultCollection results = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            m_session.Call(
                null,
                methodsToCall,
                out results,
                out diagnosticInfos);

            ClientBase.ValidateResponse(results, methodsToCall);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, methodsToCall);

            for (int ii = 0; ii < results.Count; ii++)
            {
                if (StatusCode.IsBad(results[ii].StatusCode))
                {
                    ListViewItem item = (ListViewItem)methodsToCall[ii].Handle;
                    item.SubItems[8].Text = Utils.Format("{0}", results[ii].StatusCode);
                }
            }
        }
        /// <summary>
        /// Calls the method.
        /// </summary>
        public void Call()
        {
            // build list of methods to call.
            CallMethodRequestCollection methodsToCall = new CallMethodRequestCollection();

            CallMethodRequest methodToCall = new CallMethodRequest();

            methodToCall.ObjectId = m_objectId;
            methodToCall.MethodId = m_methodId;

            foreach (DataRow row in m_dataset.Tables[0].Rows)
            {
                Argument argument = (Argument)row[0];
                Variant value = (Variant)row[4];
                argument.Value = value.Value;
                methodToCall.InputArguments.Add(value);
            }

            methodsToCall.Add(methodToCall);

            // call the method.
            CallMethodResultCollection results = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            ResponseHeader responseHeader = m_session.Call(
                null,
                methodsToCall,
                out results,
                out diagnosticInfos);

            ClientBase.ValidateResponse(results, methodsToCall);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, methodsToCall);
            
            for (int ii = 0; ii < results.Count; ii++)
            {
                // display any input argument errors.
                if (results[ii].InputArgumentResults != null)
                {
                    for (int jj = 0; jj < results[ii].InputArgumentResults.Count; jj++)
                    {
                        if (StatusCode.IsBad(results[ii].InputArgumentResults[jj]))
                        {
                            DataRow row = m_dataset.Tables[0].Rows[jj];
                            row[5] = results[ii].InputArgumentResults[jj].ToString();
                            ResultCH.Visible = true;
                        }
                    }
                }

                // throw an exception on error.
                if (StatusCode.IsBad(results[ii].StatusCode))
                {
                    throw ServiceResultException.Create(results[ii].StatusCode, ii, diagnosticInfos, responseHeader.StringTable);
                }

                // display the output arguments
                ResultCH.Visible = false;
                NoArgumentsLB.Visible = m_outputArguments == null || m_outputArguments.Length == 0;
                NoArgumentsLB.Text = "Method invoked successfully.\r\nNo output arguments to display.";
                m_dataset.Tables[0].Rows.Clear();

                if (m_outputArguments != null)
                {
                    for (int jj = 0; jj < m_outputArguments.Length; jj++)
                    {
                        DataRow row = m_dataset.Tables[0].NewRow();

                        if (results[ii].OutputArguments.Count > jj)
                        {
                            UpdateRow(row, m_outputArguments[jj], results[ii].OutputArguments[jj], true);
                        }
                        else
                        {
                            UpdateRow(row, m_outputArguments[jj], Variant.Null, true);
                        }
                        
                        m_dataset.Tables[0].Rows.Add(row);
                    }
                }
            }
        }