Exemplo n.º 1
0
        /// <summary>
        /// Handling the remote file open event
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="args">remote file name</param>
        private void HandleRemoteSessionForwardedEvent(object sender, PSEventArgs args)
        {
            if (args.SourceIdentifier.Equals("PSISERemoteSessionOpenFile", StringComparison.OrdinalIgnoreCase))
            {
                string text  = null;
                byte[] array = null;
                try
                {
                    if (args.SourceArgs.Length == 2)
                    {
                        text  = (args.SourceArgs[0] as string);
                        array = (byte[])(args.SourceArgs[1] as PSObject).BaseObject;
                    }
                    if (!string.IsNullOrEmpty(text) && array != null)
                    {
                        string tmpFileName = Path.GetTempFileName();
                        string dirPath     = tmpFileName.Remove(tmpFileName.LastIndexOf('.'));
                        Directory.CreateDirectory(dirPath);
                        string fullFileName = Path.Combine(dirPath, new FileInfo(text).Name);

                        _mapRemoteToLocal[text]         = fullFileName;
                        _mapLocalToRemote[fullFileName] = text;

                        File.WriteAllBytes(fullFileName, array);

                        _callback.OpenRemoteFile(fullFileName);
                    }
                }
                catch (Exception ex)
                {
                    ServiceCommon.Log("Failed to create local copy for downloaded file due to exception: {0}", ex.Message);
                }
            }
        }
Exemplo n.º 2
0
 private void OnRunspacePSEventReceived(object sender, PSEventArgs e)
 {
     if (base.Events != null)
     {
         base.Events.AddForwardedEvent(e);
     }
 }
Exemplo n.º 3
0
        protected override void ProcessRecord()
        {
            bool flag = false;

            lock (base.Events.ReceivedEvents.SyncRoot)
            {
                PSEventArgsCollection receivedEvents = base.Events.ReceivedEvents;
                for (int i = receivedEvents.Count; i > 0; i--)
                {
                    PSEventArgs args = receivedEvents[i - 1];
                    if (((this.sourceIdentifier == null) || this.matchPattern.IsMatch(args.SourceIdentifier)) && ((this.eventIdentifier < 0) || (args.EventIdentifier == this.eventIdentifier)))
                    {
                        flag = true;
                        if (base.ShouldProcess(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.EventResource, new object[] { args.SourceIdentifier }), EventingStrings.Remove))
                        {
                            receivedEvents.RemoveAt(i - 1);
                        }
                    }
                }
            }
            if (((this.sourceIdentifier != null) && !WildcardPattern.ContainsWildcardCharacters(this.sourceIdentifier)) && !flag)
            {
                ErrorRecord errorRecord = new ErrorRecord(new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.SourceIdentifierNotFound, new object[] { this.sourceIdentifier })), "INVALID_SOURCE_IDENTIFIER", ErrorCategory.InvalidArgument, null);
                base.WriteError(errorRecord);
            }
            else if ((this.eventIdentifier >= 0) && !flag)
            {
                ErrorRecord record2 = new ErrorRecord(new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, EventingStrings.EventIdentifierNotFound, new object[] { this.eventIdentifier })), "INVALID_EVENT_IDENTIFIER", ErrorCategory.InvalidArgument, null);
                base.WriteError(record2);
            }
        }
Exemplo n.º 4
0
 private void OnRunspaceForwardEvent(object sender, PSEventArgs e)
 {
     if (e.ForwardEvent)
     {
         this.OnForwardEvent(e);
     }
 }
        internal void ProcessReceivedData(RemoteDataObject <PSObject> receivedData)
        {
            if (receivedData.RunspacePoolId != this.clientRunspacePoolId)
            {
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.RunspaceIdsDoNotMatch, new object[] { receivedData.RunspacePoolId, this.clientRunspacePoolId });
            }
            switch (receivedData.DataType)
            {
            case RemotingDataType.RunspacePoolOperationResponse:
                this.SetMaxMinRunspacesResponseRecieved.SafeInvoke <RemoteDataEventArgs <PSObject> >(this, new RemoteDataEventArgs <PSObject>(receivedData.Data));
                return;

            case RemotingDataType.RunspacePoolStateInfo:
            {
                RunspacePoolStateInfo runspacePoolStateInfo = RemotingDecoder.GetRunspacePoolStateInfo(receivedData.Data);
                this.StateInfoReceived.SafeInvoke <RemoteDataEventArgs <RunspacePoolStateInfo> >(this, new RemoteDataEventArgs <RunspacePoolStateInfo>(runspacePoolStateInfo));
                this.NotifyAssociatedPowerShells(runspacePoolStateInfo);
                return;
            }

            case RemotingDataType.CreatePowerShell:
            case RemotingDataType.AvailableRunspaces:
            case RemotingDataType.GetCommandMetadata:
                break;

            case RemotingDataType.PSEventArgs:
            {
                PSEventArgs pSEventArgs = RemotingDecoder.GetPSEventArgs(receivedData.Data);
                this.PSEventArgsReceived.SafeInvoke <RemoteDataEventArgs <PSEventArgs> >(this, new RemoteDataEventArgs <PSEventArgs>(pSEventArgs));
                break;
            }

            case RemotingDataType.ApplicationPrivateData:
            {
                PSPrimitiveDictionary applicationPrivateData = RemotingDecoder.GetApplicationPrivateData(receivedData.Data);
                this.ApplicationPrivateDataReceived.SafeInvoke <RemoteDataEventArgs <PSPrimitiveDictionary> >(this, new RemoteDataEventArgs <PSPrimitiveDictionary>(applicationPrivateData));
                return;
            }

            case RemotingDataType.RunspacePoolInitData:
            {
                RunspacePoolInitInfo runspacePoolInitInfo = RemotingDecoder.GetRunspacePoolInitInfo(receivedData.Data);
                this.RSPoolInitInfoReceived.SafeInvoke <RemoteDataEventArgs <RunspacePoolInitInfo> >(this, new RemoteDataEventArgs <RunspacePoolInitInfo>(runspacePoolInitInfo));
                return;
            }

            case RemotingDataType.RemoteHostCallUsingRunspaceHost:
            {
                RemoteHostCall data = RemoteHostCall.Decode(receivedData.Data);
                this.RemoteHostCallReceived.SafeInvoke <RemoteDataEventArgs <RemoteHostCall> >(this, new RemoteDataEventArgs <RemoteHostCall>(data));
                return;
            }

            default:
                return;
            }
        }
Exemplo n.º 6
0
        private void OnEventForwarded(PSEventArgs e)
        {
            EventHandler <PSEventArgs> internalForwardEvent = this.InternalForwardEvent;

            if (internalForwardEvent != null)
            {
                internalForwardEvent(this, e);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Raises the ForwardEvent event.
        /// </summary>
        private void OnEventForwarded(PSEventArgs e)
        {
            EventHandler <PSEventArgs> eh = InternalForwardEvent;

            if (eh != null)
            {
                eh(this, e);
            }
        }
Exemplo n.º 8
0
        protected virtual void OnForwardEvent(PSEventArgs e)
        {
            EventHandler <PSEventArgs> forwardEvent = this.ForwardEvent;

            if (forwardEvent != null)
            {
                forwardEvent(this, e);
            }
        }
Exemplo n.º 9
0
        private void OnEventForwarded(PSEventArgs e)
        {
            EventHandler <PSEventArgs> internalForwardEvent = this.InternalForwardEvent;

            if (internalForwardEvent == null)
            {
                return;
            }
            internalForwardEvent((object)this, e);
        }
Exemplo n.º 10
0
 private void ReceivedEvents_PSEventReceived(object sender, PSEventArgs e)
 {
     if (this.sourceIdentifier == null)
     {
         this.NotifyEvent(e);
     }
     else
     {
         this.ScanEventQueue();
     }
 }
Exemplo n.º 11
0
 private void OpenItem(object sender, IBizItem it)
 {
     if (BizItemHandlerEvent.Instance.D_OpenItem != null)
     {
         PSEventArgs args = new PSEventArgs
         {
             PSOption = ClientData.UserGlobalOption
         };
         PLMOperationArgs e = new PLMOperationArgs(FrmLogon.PLMProduct.ToString(), PLMLocation.ItemList.ToString(), it);
         BizItemHandlerEvent.Instance.D_OpenItem(sender, e);
     }
 }
Exemplo n.º 12
0
 private void ReceivedEvents_PSEventReceived(object sender, PSEventArgs e)
 {
     // If they want to wait on just any event
     if (_sourceIdentifier == null)
     {
         NotifyEvent(e);
     }
     // They are waiting on a specific one
     else
     {
         ScanEventQueue();
     }
 }
        private void HandlePSEventReceived(object sender, PSEventArgs args)
        {
            if (string.Equals(RemoteSessionOpenFile, args.SourceIdentifier, StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    if (args.SourceArgs.Length >= 1)
                    {
                        string localFilePath  = string.Empty;
                        string remoteFilePath = args.SourceArgs[0] as string;

                        // Is this a local process runspace?  Treat as a local file
                        if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Local)
                        {
                            localFilePath = remoteFilePath;
                        }
                        else
                        {
                            byte[] fileContent = null;

                            if (args.SourceArgs.Length == 2)
                            {
                                PSObject sourceObj = args.SourceArgs[1] as PSObject;
                                if (sourceObj != null)
                                {
                                    fileContent = sourceObj.BaseObject as byte[];
                                }
                            }

                            // If fileContent is still null after trying to
                            // unpack the contents, just return an empty byte
                            // array.
                            fileContent = fileContent ?? new byte[0];

                            localFilePath =
                                this.StoreRemoteFile(
                                    remoteFilePath,
                                    fileContent,
                                    this.powerShellContext.CurrentRunspace);
                        }

                        // Open the file in the editor
                        this.editorOperations?.OpenFile(localFilePath);
                    }
                }
                catch (NullReferenceException e)
                {
                    this.logger.WriteException("Could not store null remote file content", e);
                }
            }
        }
Exemplo n.º 14
0
 private void NotifyEvent(PSEventArgs e)
 {
     if (this.receivedEvent == null)
     {
         lock (this.receivedEventLock)
         {
             if (this.receivedEvent == null)
             {
                 this.receivedEvent = e;
                 this.eventArrived.Set();
             }
         }
     }
 }
Exemplo n.º 15
0
 // Notify that an event has arrived
 private void NotifyEvent(PSEventArgs e)
 {
     if (_receivedEvent == null)
     {
         lock (_receivedEventLock)
         {
             if (_receivedEvent == null)
             {
                 _receivedEvent = e;
                 _eventArrived.Set();
             }
         }
     }
 }
Exemplo n.º 16
0
        private void HandleRemoteSessionForwardedEvent(object sender, PSEventArgs args)
        {
            if ((Runspace == null) || (Runspace.Events == null))
            {
                return;
            }

            // Forward events from nested pushed session to parent session.
            try
            {
                Runspace.Events.GenerateEvent(
                    sourceIdentifier: args.SourceIdentifier,
                    sender: null,
                    args: args.SourceArgs,
                    extraData: null);
            }
            catch (Exception)
            {
            }
        }
        private void HandlePSEventReceived(object sender, PSEventArgs args)
        {
            if (string.Equals(RemoteSessionOpenFile, args.SourceIdentifier, StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    if (args.SourceArgs.Length >= 1)
                    {
                        string localFilePath  = string.Empty;
                        string remoteFilePath = args.SourceArgs[0] as string;

                        // Is this a local process runspace?  Treat as a local file
                        if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Local ||
                            this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.LocalProcess)
                        {
                            localFilePath = remoteFilePath;
                        }
                        else
                        {
                            byte[] fileContent =
                                args.SourceArgs.Length == 2
                                ? (byte[])((args.SourceArgs[1] as PSObject).BaseObject)
                                : new byte[0];

                            localFilePath =
                                this.StoreRemoteFile(
                                    remoteFilePath,
                                    fileContent,
                                    this.powerShellContext.CurrentRunspace);
                        }

                        // Open the file in the editor
                        this.editorOperations.OpenFile(localFilePath);
                    }
                }
                catch (NullReferenceException e)
                {
                    Logger.WriteException("Could not store null remote file content", e);
                }
            }
        }
        /// <summary>
        /// Handles the start pipeline event, this is called by the event manager.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void HandleStartEvent(object sender, PSEventArgs args)
        {
            ServerSteppablePipelineDriverEventArg driverArg = (object)args.SourceEventArgs as ServerSteppablePipelineDriverEventArg;
            ServerSteppablePipelineDriver         driver    = driverArg.SteppableDriver;

            Exception exceptionOccurred = null;

            try
            {
                using (ExecutionContextForStepping ctxt =
                           ExecutionContextForStepping.PrepareExecutionContext(
                               driver.LocalPowerShell.GetContextFromTLS(),
                               driver.LocalPowerShell.InformationalBuffers,
                               driver.RemoteHost))
                {
                    driver.SteppablePipeline = driver.LocalPowerShell.GetSteppablePipeline();
                    driver.SteppablePipeline.Begin(!driver.NoInput);
                }

                if (driver.NoInput)
                {
                    driver.HandleInputEndReceived(this, EventArgs.Empty);
                }
            }
            catch (Exception e)
            {
                // We need to catch this so that we can set the pipeline execution;
                // state to "failed" and send the exception as an error to the user.
                // Otherwise, the event manager will swallow this exception and
                // cause the client to not respond.
                exceptionOccurred = e;
            }

            if (exceptionOccurred != null)
            {
                driver.SetState(PSInvocationState.Failed, exceptionOccurred);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Handler for the PSEventReceived event; note that this method will be invoked when the remote
        /// computer generates a Windows PowerShell event.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private static void OnPSEventReceived(object sender, PSEventArgs e)
        {
            // The information about the original event (in this case FileSystemWatcher.Created) is stored
            // in the SourceArgs property of the PSEventArgs argument of this method.
            //
            // PSEventArgs[0] will be the original event sender (in this case the remote instance of
            // System.IO.FileSystemWatcher) and PSEventArgs[1] will be the original arguments to the event
            // (in this case an instance of System.IO.FileSystemEventArgs). Note that these two
            // objects originated on the remote computer and the local computer receives deserialized
            // representations of the objects. The deserialized objects are of type PSObject.
            PSObject fileSystemEventArgs = (PSObject)e.SourceArgs[1];

            // For the purposes of this sample, we only output a message indicating that a file was created
            // on the remote machine, and the time it was created. Since the PSObject is only an instance
            // of a deserialized FileSystemEventArgs object, we need to use the Properties collection to
            // access the name of the file (i.e. FileSystemEventArgs.Name).
            string fileName = (string)fileSystemEventArgs.Properties["Name"].Value;

            Console.WriteLine("File '{0}' was created on computer '{1}' at {2}", fileName, e.ComputerName, e.TimeGenerated);

            // Increment the count of events received.
            Events02.eventsReceived++;
        }
 /// <summary>
 /// Unused at the moment. Will be used for remote debugging scripts.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void HandleRemoteSessionForwardedEvent(object sender, PSEventArgs args)
 {
     if (args.SourceIdentifier.Equals("PSISERemoteSessionOpenFile", StringComparison.OrdinalIgnoreCase))
     {
         string text  = null;
         byte[] array = null;
         try
         {
             if (args.SourceArgs.Length == 2)
             {
                 text  = (args.SourceArgs[0] as string);
                 array = (byte[])(args.SourceArgs[1] as PSObject).BaseObject;
             }
             if (!string.IsNullOrEmpty(text) && array != null)
             {
                 // bool flag;
                 // this.LoadFile(text, array, out flag);
             }
         }
         catch
         {
         }
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Remove the event from the queue
        /// </summary>
        protected override void ProcessRecord()
        {
            // Go through all the received events and write them to the output
            // pipeline
            bool foundMatch = false;

            lock (Events.ReceivedEvents.SyncRoot)
            {
                PSEventArgsCollection currentEvents = Events.ReceivedEvents;

                for (int eventCounter = currentEvents.Count; eventCounter > 0; eventCounter--)
                {
                    PSEventArgs currentEvent = currentEvents[eventCounter - 1];

                    // If they specified a event identifier and we don't match, continue
                    if ((_sourceIdentifier != null) &&
                        (!_matchPattern.IsMatch(currentEvent.SourceIdentifier)))
                    {
                        continue;
                    }

                    // If they specified a TimeGenerated and we don't match, continue
                    if ((_eventIdentifier >= 0) &&
                        (currentEvent.EventIdentifier != _eventIdentifier))
                    {
                        continue;
                    }

                    foundMatch = true;
                    if (ShouldProcess(
                            String.Format(
                                System.Globalization.CultureInfo.CurrentCulture,
                                EventingStrings.EventResource,
                                currentEvent.SourceIdentifier),
                            EventingStrings.Remove))
                    {
                        currentEvents.RemoveAt(eventCounter - 1);
                    }
                }
            }

            // Generate an error if we couldn't find the subscription identifier,
            // and no globbing was done.
            if ((_sourceIdentifier != null) &&
                (!WildcardPattern.ContainsWildcardCharacters(_sourceIdentifier)) &&
                (!foundMatch))
            {
                ErrorRecord errorRecord = new ErrorRecord(
                    new ArgumentException(
                        String.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            EventingStrings.SourceIdentifierNotFound, _sourceIdentifier)),
                    "INVALID_SOURCE_IDENTIFIER",
                    ErrorCategory.InvalidArgument,
                    null);

                WriteError(errorRecord);
            }
            else if ((_eventIdentifier >= 0) && (!foundMatch))
            {
                ErrorRecord errorRecord = new ErrorRecord(
                    new ArgumentException(
                        String.Format(
                            System.Globalization.CultureInfo.CurrentCulture,
                            EventingStrings.EventIdentifierNotFound, _eventIdentifier)),
                    "INVALID_EVENT_IDENTIFIER",
                    ErrorCategory.InvalidArgument,
                    null);

                WriteError(errorRecord);
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Pass thru of the ForwardEvent event from the internal pool
 /// </summary>
 private void OnInternalPoolForwardEvent(object sender, PSEventArgs e)
 {
     OnEventForwarded(e);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Raises the ForwardEvent event
        /// </summary>
        private void OnEventForwarded(PSEventArgs e)
        {
            EventHandler<PSEventArgs> eh = InternalForwardEvent;

            if (eh != null)
            {
                eh(this, e);
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// Pass thru of the ForwardEvent event from the internal pool.
 /// </summary>
 private void OnInternalPoolForwardEvent(object sender, PSEventArgs e)
 {
     OnEventForwarded(e);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Raises the ForwardEvent event.
 /// </summary>
 private void OnEventForwarded(PSEventArgs e)
 {
     InternalForwardEvent?.Invoke(this, e);
 }
Exemplo n.º 26
0
        private void HandleRemoteSessionForwardedEvent(object sender, PSEventArgs args)
        {
            if ((Runspace == null) || (Runspace.Events == null)) { return; }

            // Forward events from nested pushed session to parent session.
            try
            {
                Runspace.Events.GenerateEvent(
                    sourceIdentifier: args.SourceIdentifier,
                    sender: null,
                    args: args.SourceArgs,
                    extraData: null);
            }
            catch (Exception e)
            {
                CommandProcessorBase.CheckForSevereException(e);
            }
        }
Exemplo n.º 27
0
 private void lvwSentLst_DoubleClick(object sender, EventArgs e)
 {
     if (this.lvwSentLst.SelectedItems.Count != 0)
     {
         ListViewItem item = this.lvwSentLst.SelectedItems[0];
         if (PLGrantPerm.CanDoClassOperation(ClientData.LogonUser.Oid, "DQDOSSIRSENT", Guid.Empty, "ClaRel_BROWSE") == 1)
         {
             DEBusinessItem tag = item.Tag as DEBusinessItem;
             if (BizItemHandlerEvent.Instance.D_OpenItem != null)
             {
                 PSEventArgs args = new PSEventArgs {
                     PSOption = ClientData.UserGlobalOption
                 };
                 PLMOperationArgs args2 = new PLMOperationArgs(FrmLogon.PLMProduct.ToString(), PLMLocation.ItemList.ToString(), tag);
                 BizItemHandlerEvent.Instance.D_OpenItem(sender, args2);
             }
         }
     }
 }
        private async void HandlePSEventReceivedAsync(object sender, PSEventArgs args)
        {
            if (string.Equals(RemoteSessionOpenFile, args.SourceIdentifier, StringComparison.CurrentCultureIgnoreCase))
            {
                try
                {
                    if (args.SourceArgs.Length >= 1)
                    {
                        string localFilePath  = string.Empty;
                        string remoteFilePath = args.SourceArgs[0] as string;

                        // Is this a local process runspace?  Treat as a local file
                        if (this.powerShellContext.CurrentRunspace.Location == RunspaceLocation.Local)
                        {
                            localFilePath = remoteFilePath;
                        }
                        else
                        {
                            byte[] fileContent = null;

                            if (args.SourceArgs.Length >= 2)
                            {
                                // Try to cast as a PSObject to get the BaseObject, if not, then try to case as a byte[]
                                PSObject sourceObj = args.SourceArgs[1] as PSObject;
                                if (sourceObj != null)
                                {
                                    fileContent = sourceObj.BaseObject as byte[];
                                }
                                else
                                {
                                    fileContent = args.SourceArgs[1] as byte[];
                                }
                            }

                            // If fileContent is still null after trying to
                            // unpack the contents, just return an empty byte
                            // array.
                            fileContent = fileContent ?? Array.Empty <byte>();

                            if (remoteFilePath != null)
                            {
                                localFilePath =
                                    this.StoreRemoteFile(
                                        remoteFilePath,
                                        fileContent,
                                        this.powerShellContext.CurrentRunspace);
                            }
                            else
                            {
                                await(this.editorOperations?.NewFileAsync()).ConfigureAwait(false);
                                EditorContext context = await(editorOperations?.GetEditorContextAsync()).ConfigureAwait(false);
                                context?.CurrentFile.InsertText(Encoding.UTF8.GetString(fileContent, 0, fileContent.Length));
                            }
                        }

                        bool preview = true;
                        if (args.SourceArgs.Length >= 3)
                        {
                            bool?previewCheck = args.SourceArgs[2] as bool?;
                            preview = previewCheck ?? true;
                        }

                        // Open the file in the editor
                        this.editorOperations?.OpenFileAsync(localFilePath, preview);
                    }
                }
                catch (NullReferenceException e)
                {
                    this.logger.LogException("Could not store null remote file content", e);
                }
            }
        }
Exemplo n.º 29
0
 public EventAction(PSEventSubscriber sender, PSEventArgs args)
 {
     this.sender = sender;
     this.args   = args;
 }
        /// <summary>
        /// Handles process record event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void HandleProcessRecord(object sender, PSEventArgs args)
        {
            ServerSteppablePipelineDriverEventArg driverArg = (object)args.SourceEventArgs as ServerSteppablePipelineDriverEventArg;
            ServerSteppablePipelineDriver         driver    = driverArg.SteppableDriver;

            lock (driver.SyncObject)
            {
                // Make sure start event handler was called
                if (driver.SteppablePipeline == null)
                {
                    return;
                }

                // make sure only one thread does the processing
                if (driver.ProcessingInput)
                {
                    return;
                }

                driver.ProcessingInput = true;
                driver.Pulsed          = false;
            }

            bool      shouldDoComplete  = false;
            Exception exceptionOccurred = null;

            try
            {
                using (ExecutionContextForStepping ctxt =
                           ExecutionContextForStepping.PrepareExecutionContext(
                               driver.LocalPowerShell.GetContextFromTLS(),
                               driver.LocalPowerShell.InformationalBuffers,
                               driver.RemoteHost))
                {
                    bool isProcessCalled = false;
                    while (true)
                    {
                        if (driver.PipelineState != PSInvocationState.Running)
                        {
                            driver.SetState(driver.PipelineState, null);
                            return;
                        }

                        if (!driver.InputEnumerator.MoveNext())
                        {
                            shouldDoComplete = true;
                            if (!driver.NoInput || isProcessCalled)
                            {
                                // if there is noInput then we
                                // need to call process atleast once
                                break;
                            }
                        }

                        isProcessCalled = true;
                        Array output;
                        if (driver.NoInput)
                        {
                            output = driver.SteppablePipeline.Process();
                        }
                        else
                        {
                            output = driver.SteppablePipeline.Process(driver.InputEnumerator.Current);
                        }

                        foreach (object o in output)
                        {
                            if (driver.PipelineState != PSInvocationState.Running)
                            {
                                driver.SetState(driver.PipelineState, null);
                                return;
                            }

                            // send the output data to the client
                            driver.DataStructureHandler.SendOutputDataToClient(PSObject.AsPSObject(o));
                        }

                        lock (driver.SyncObject)
                        {
                            driver.TotalObjectsProcessed++;
                            if (driver.TotalObjectsProcessed >= driver.Input.Count)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                exceptionOccurred = e;
            }
            finally
            {
                lock (driver.SyncObject)
                {
                    driver.ProcessingInput = false;
                    driver.CheckAndPulseForProcessing(false);
                }
                // Check if should perform stop
                if (driver.PipelineState == PSInvocationState.Stopping)
                {
                    driver.PerformStop();
                }
            }

            if (shouldDoComplete)
            {
                try
                {
                    using (ExecutionContextForStepping ctxt =
                               ExecutionContextForStepping.PrepareExecutionContext(
                                   driver.LocalPowerShell.GetContextFromTLS(),
                                   driver.LocalPowerShell.InformationalBuffers,
                                   driver.RemoteHost))
                    {
                        Array output = driver.SteppablePipeline.End();
                        foreach (object o in output)
                        {
                            if (driver.PipelineState != PSInvocationState.Running)
                            {
                                driver.SetState(driver.PipelineState, null);
                                return;
                            }

                            // send the output data to the client
                            driver.DataStructureHandler.SendOutputDataToClient(PSObject.AsPSObject(o));
                        }

                        driver.SetState(PSInvocationState.Completed, null);
                        return;
                    }
                }
                catch (Exception e)
                {
                    exceptionOccurred = e;
                }
                finally
                {
                    // Check if should perform stop
                    if (driver.PipelineState == PSInvocationState.Stopping)
                    {
                        driver.PerformStop();
                    }
                }
            }

            if (exceptionOccurred != null)
            {
                driver.SetState(PSInvocationState.Failed, exceptionOccurred);
            }
        }
Exemplo n.º 31
0
 private void OpenItem(object sender, IBizItem it)
 {
     if (BizItemHandlerEvent.Instance.D_OpenItem != null)
     {
         PSEventArgs args = new PSEventArgs
         {
             PSOption = ClientData.UserGlobalOption
         };
         PLMOperationArgs e = new PLMOperationArgs(FrmLogon.PLMProduct.ToString(), PLMLocation.ItemList.ToString(), it);
         BizItemHandlerEvent.Instance.D_OpenItem(sender, e);
     }
 }
Exemplo n.º 32
0
 /// <summary>
 /// Forward runspace events to the pool's event queue
 /// </summary>
 private void OnRunspaceForwardEvent(object sender, PSEventArgs e)
 {
     if (e.ForwardEvent)
     {
         OnForwardEvent(e);
     }
 }
Exemplo n.º 33
0
        } // AssertIfStateIsBeforeOpen

        /// <summary>
        /// Raises the ForwardEvent event
        /// </summary>
        protected virtual void OnForwardEvent(PSEventArgs e)
        {
            EventHandler<PSEventArgs> eh = this.ForwardEvent;

            if (eh != null)
            {
                eh(this, e);
            }
        }