예제 #1
0
        private void BindVariableToEvent(PSVariable variable, string eventName)
        {
            Debug.Assert(variable != null, "variable != null");
            Debug.Assert(variable.Value != null, "variable.Value != null");

            object target = PSVariableHelper.GetBaseObject(variable);

            Type type = target.GetType();

            WriteVerbose("Target is a " + type.Name);

            try
            {
                EventInfo eventInfo = PSEventHelper.GetEventInfo(type, eventName, CaseSensitive.IsPresent);
                if (eventInfo == null)
                {
                    WriteWarning("Event '" + eventName + "' cannot be found on instance of " + type.Name);
                }
                else
                {
                    // bind the event source
                    m_manager.AddBinding(variable, eventInfo, (this.QueueName ?? PSQueueHelper.DEFAULT_QUEUE));

                    WriteVerbose("Now listening for '" + eventName + "' events from $" + VariableName);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, "BindVariableToEvent Error");
                ThrowTerminatingError(new ErrorRecord(ex, "BindFailure", ErrorCategory.NotSpecified, type));
            }
        }
예제 #2
0
 protected override void BeginProcessing()
 {
     m_manager        = new PSBindingManager(this);
     m_variableHelper = new PSVariableHelper(this);
 }
예제 #3
0
 protected EventCommandBase()
 {
     m_variableHelper = new PSVariableHelper(this);
 }