예제 #1
0
        /// <summary>
        /// Implementation of the cmdlet.
        /// </summary>
        protected override void ProcessRecord()
        {
            // The comments are stored in the PrivateData property of the
            // module. This provides an isolated storage area associated
            // with this module and runspace, protecting it from interferance
            // from other aspects of the user's session.
            TransactedComment current = this.MyInvocation.MyCommand.Module.PrivateData as TransactedComment;

            if (current == null)
            {
                current = new TransactedComment();
                this.MyInvocation.MyCommand.Module.PrivateData = current;
            }

            // Check to see if the UseTransaction parameter was specified. If it
            // was not, this.CurrentPSTransaction is null so it can not be in a
            // using statement. Checking this first allows the cmdlet to be used
            // within and outside of a transaction. In principle, a cmdlet could
            // do different things depending on the transactional context, but
            // this cmdlet just does pretty much the same thing in either
            // situation because TransactedComment already handles it differently.
            if (this.TransactionAvailable())
            {
                // Within this using statement, PowerShell exposes the active
                // transaction as Transaction.Current, allowing standard .NET
                // transactional resource managers (such as TransactedComment)
                // to participate.
                using (this.CurrentPSTransaction)
                {
                    foreach (string comment in this.Comment)
                    {
                        current.Append(comment);
                        current.Append(Environment.NewLine);
                    }
                }
            }
            else
            {
                // Otherwise, act on the live version of the TransactedComment.
                foreach (string comment in this.Comment)
                {
                    current.Append(comment);
                    current.Append(Environment.NewLine);
                }
            }
        }
    /// <summary>
    /// Implementation of the cmdlet.
    /// </summary>
    protected override void ProcessRecord()
    {
      // The comments are stored in the PrivateData property of the
      // module. This provides an isolated storage area associated 
      // with this module and runspace, protecting it from interferance 
      // from other aspects of the user's session.
      TransactedComment current = this.MyInvocation.MyCommand.Module.PrivateData as TransactedComment;
      if (current == null)
      {
        current = new TransactedComment();
        this.MyInvocation.MyCommand.Module.PrivateData = current;
      }

      // Check to see if the UseTransaction parameter was specified. If it 
      // was not, this.CurrentPSTransaction is null so it can not be in a 
      // using statement. Checking this first allows the cmdlet to be used 
      // within and outside of a transaction. In principle, a cmdlet could  
      // do different things depending on the transactional context, but
      // this cmdlet just does pretty much the same thing in either
      // situation because TransactedComment already handles it differently.
      if (this.TransactionAvailable())
      {
        // Within this using statement, PowerShell exposes the active
        // transaction as Transaction.Current, allowing standard .NET
        // transactional resource managers (such as TransactedComment)
        // to participate.
        using (this.CurrentPSTransaction)
        {
          foreach (string comment in this.Comment)
          {
            current.Append(comment);
            current.Append(Environment.NewLine);
          }
        }
      }
      else
      {
        // Otherwise, act on the live version of the TransactedComment.
        foreach (string comment in this.Comment)
        {
           current.Append(comment);
           current.Append(Environment.NewLine);
        }
      }
    }