Exemplo n.º 1
0
        /// <summary>
        /// Seeks to the end of the writer stream in each of the writers in the
        /// content holders.
        /// </summary>
        ///
        /// <param name="contentHolders">
        /// The content holders that contain the writers to be moved.
        /// </param>
        ///
        /// <exception cref="ProviderInvocationException">
        /// If calling Seek on the content writer throws an exception.
        /// </exception>
        ///
        internal override void SeekContentPosition(List <ContentHolder> contentHolders)
        {
            foreach (ContentHolder holder in contentHolders)
            {
                if (holder.Writer != null)
                {
                    try
                    {
                        holder.Writer.Seek(0, System.IO.SeekOrigin.End);
                    }
                    catch (Exception e) // Catch-all OK, 3rd party callout
                    {
                        CommandsCommon.CheckForSevereException(this, e);
                        ProviderInvocationException providerException =
                            new ProviderInvocationException(
                                "ProviderSeekError",
                                SessionStateStrings.ProviderSeekError,
                                holder.PathInfo.Provider,
                                holder.PathInfo.Path,
                                e);


                        // Log a provider health event

                        MshLog.LogProviderHealthEvent(
                            this.Context,
                            holder.PathInfo.Provider.Name,
                            providerException,
                            Severity.Warning);

                        throw providerException;
                    }
                }
            }
        } // SeekContentPosition
Exemplo n.º 2
0
 internal void CloseContent(List <ContentCommandBase.ContentHolder> contentHolders, bool disposing)
 {
     if (contentHolders != null)
     {
         foreach (ContentCommandBase.ContentHolder contentHolder in contentHolders)
         {
             try
             {
                 if (contentHolder.Writer != null)
                 {
                     contentHolder.Writer.Close();
                 }
             }
             catch (Exception exception1)
             {
                 Exception exception = exception1;
                 CommandsCommon.CheckForSevereException(this, exception);
                 ProviderInvocationException providerInvocationException = new ProviderInvocationException("ProviderContentCloseError", SessionStateStrings.ProviderContentCloseError, contentHolder.PathInfo.Provider, contentHolder.PathInfo.Path, exception);
                 MshLog.LogProviderHealthEvent(base.Context, contentHolder.PathInfo.Provider.Name, providerInvocationException, Severity.Warning);
                 if (!disposing)
                 {
                     base.WriteError(new ErrorRecord(providerInvocationException.ErrorRecord, providerInvocationException));
                 }
             }
             try
             {
                 if (contentHolder.Reader != null)
                 {
                     contentHolder.Reader.Close();
                 }
             }
             catch (Exception exception3)
             {
                 Exception exception2 = exception3;
                 CommandsCommon.CheckForSevereException(this, exception2);
                 ProviderInvocationException providerInvocationException1 = new ProviderInvocationException("ProviderContentCloseError", SessionStateStrings.ProviderContentCloseError, contentHolder.PathInfo.Provider, contentHolder.PathInfo.Path, exception2);
                 MshLog.LogProviderHealthEvent(base.Context, contentHolder.PathInfo.Provider.Name, providerInvocationException1, Severity.Warning);
                 if (!disposing)
                 {
                     base.WriteError(new ErrorRecord(providerInvocationException1.ErrorRecord, providerInvocationException1));
                 }
             }
         }
         return;
     }
     else
     {
         throw PSTraceSource.NewArgumentNullException("contentHolders");
     }
 }
Exemplo n.º 3
0
 internal override void SeekContentPosition(List <ContentCommandBase.ContentHolder> contentHolders)
 {
     foreach (ContentCommandBase.ContentHolder contentHolder in contentHolders)
     {
         if (contentHolder.Writer == null)
         {
             continue;
         }
         try
         {
             contentHolder.Writer.Seek((long)0, SeekOrigin.End);
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             CommandsCommon.CheckForSevereException(this, exception);
             ProviderInvocationException providerInvocationException = new ProviderInvocationException("ProviderSeekError", SessionStateStrings.ProviderSeekError, contentHolder.PathInfo.Provider, contentHolder.PathInfo.Path, exception);
             MshLog.LogProviderHealthEvent(base.Context, contentHolder.PathInfo.Provider.Name, providerInvocationException, Severity.Warning);
             throw providerInvocationException;
         }
     }
 }
Exemplo n.º 4
0
 private bool FilterMatch(ManagementObject obj)
 {
     try
     {
         foreach (string desc in Description)
         {
             WildcardPattern wildcardpattern = WildcardPattern.Get(desc, WildcardOptions.IgnoreCase);
             if (wildcardpattern.IsMatch((string)obj["Description"]))
             {
                 return(true);
             }
             if (WildcardPattern.ContainsWildcardCharacters(desc))
             {
                 _inputContainsWildcard = true;
             }
         }
     }
     catch (Exception e)
     {
         CommandsCommon.CheckForSevereException(this, e);
         return(false);
     }
     return(false);
 }
Exemplo n.º 5
0
        private bool FilterMatch(ManagementObject obj)
        {
            bool flag;

            try
            {
                string[] strArrays = this._description;
                int      num       = 0;
                while (num < (int)strArrays.Length)
                {
                    string          str             = strArrays[num];
                    WildcardPattern wildcardPattern = new WildcardPattern(str, WildcardOptions.IgnoreCase);
                    if (!wildcardPattern.IsMatch((string)obj["Description"]))
                    {
                        if (WildcardPattern.ContainsWildcardCharacters(str))
                        {
                            this.inputContainsWildcard = true;
                        }
                        num++;
                    }
                    else
                    {
                        flag = true;
                        return(flag);
                    }
                }
                return(false);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                CommandsCommon.CheckForSevereException(this, exception);
                flag = false;
            }
            return(flag);
        }
        /// <summary>
        /// Appends the content to the specified item.
        /// </summary>
        protected override void ProcessRecord()
        {
            CmdletProviderContext currentContext = GetCurrentContext();

            // Initialize the content

            if (_content == null)
            {
                _content = new object[0];
            }

            if (_pipingPaths)
            {
                // Make sure to clean up the content writers that are already there

                if (contentStreams != null && contentStreams.Count > 0)
                {
                    CloseContent(contentStreams, false);
                    _contentWritersOpen = false;
                    contentStreams      = new List <ContentHolder>();
                }
            }

            if (!_contentWritersOpen)
            {
                // Since the paths are being pipelined in, we have
                // to get new content writers for the new paths
                string[] paths = GetAcceptedPaths(Path, currentContext);

                if (paths.Length > 0)
                {
                    BeforeOpenStreams(paths);
                    contentStreams = GetContentWriters(paths, currentContext);
                    SeekContentPosition(contentStreams);
                }

                _contentWritersOpen = true;
            }

            // Now write the content to the item
            try
            {
                foreach (ContentHolder holder in contentStreams)
                {
                    if (holder.Writer != null)
                    {
                        IList result = null;
                        try
                        {
                            result = holder.Writer.Write(_content);
                        }
                        catch (Exception e) // Catch-all OK. 3rd party callout
                        {
                            CommandsCommon.CheckForSevereException(this, e);
                            ProviderInvocationException providerException =
                                new ProviderInvocationException(
                                    "ProviderContentWriteError",
                                    SessionStateStrings.ProviderContentWriteError,
                                    holder.PathInfo.Provider,
                                    holder.PathInfo.Path,
                                    e);

                            // Log a provider health event

                            MshLog.LogProviderHealthEvent(
                                this.Context,
                                holder.PathInfo.Provider.Name,
                                providerException,
                                Severity.Warning);

                            WriteError(
                                new ErrorRecord(
                                    providerException.ErrorRecord,
                                    providerException));
                            continue;
                        }

                        if (result != null && result.Count > 0 && PassThru)
                        {
                            WriteContentObject(result, result.Count, holder.PathInfo, currentContext);
                        }
                    }
                }
            }
            finally
            {
                // Need to close all the writers if the paths are being pipelined

                if (_pipingPaths)
                {
                    CloseContent(contentStreams, false);
                    _contentWritersOpen = false;
                    contentStreams      = new List <ContentHolder>();
                }
            }
        } // ProcessRecord
Exemplo n.º 7
0
        } // ProcessRecord

        /// <summary>
        /// Scan forwards to get the tail content
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="currentContext"></param>
        /// <returns>
        /// true if no error occured
        /// false if there was an error
        /// </returns>
        private bool ScanForwardsForTail(ContentHolder holder, CmdletProviderContext currentContext)
        {
            var fsReader = holder.Reader as FileSystemContentReaderWriter;

            Dbg.Diagnostics.Assert(fsReader != null, "Tail is only supported for FileSystemContentReaderWriter");
            var         tailResultQueue = new Queue <object>();
            IList       results         = null;
            ErrorRecord error           = null;

            do
            {
                try
                {
                    results = fsReader.ReadWithoutWaitingChanges(ReadCount);
                }
                catch (Exception e)
                {
                    CommandsCommon.CheckForSevereException(this, e);
                    ProviderInvocationException providerException =
                        new ProviderInvocationException(
                            "ProviderContentReadError",
                            SessionStateStrings.ProviderContentReadError,
                            holder.PathInfo.Provider,
                            holder.PathInfo.Path,
                            e);

                    // Log a provider health event
                    MshLog.LogProviderHealthEvent(
                        this.Context,
                        holder.PathInfo.Provider.Name,
                        providerException,
                        Severity.Warning);

                    // Create and save the error record. The error record
                    // will be written outside the while loop.
                    // This is to make sure the accumulated results get written
                    // out before the error record when the 'scanForwardForTail' is true.
                    error = new ErrorRecord(
                        providerException.ErrorRecord,
                        providerException);

                    break;
                }

                if (results != null && results.Count > 0)
                {
                    foreach (object entry in results)
                    {
                        if (tailResultQueue.Count == Tail)
                        {
                            tailResultQueue.Dequeue();
                        }
                        tailResultQueue.Enqueue(entry);
                    }
                }
            } while (results != null && results.Count > 0);

            if (tailResultQueue.Count > 0)
            {
                // Respect the ReadCount parameter.
                // Output single object when ReadCount == 1; Output array otherwise
                int count = 0;
                if (ReadCount <= 0 || (ReadCount >= tailResultQueue.Count && ReadCount != 1))
                {
                    count = tailResultQueue.Count;
                    ArrayList outputList = new ArrayList();
                    while (tailResultQueue.Count > 0)
                    {
                        outputList.Add(tailResultQueue.Dequeue());
                    }
                    // Write out the content as an array of objects
                    WriteContentObject(outputList.ToArray(), count, holder.PathInfo, currentContext);
                }
                else if (ReadCount == 1)
                {
                    // Write out the content as single object
                    while (tailResultQueue.Count > 0)
                    {
                        WriteContentObject(tailResultQueue.Dequeue(), count++, holder.PathInfo, currentContext);
                    }
                }
                else // ReadCount < Queue.Count
                {
                    while (tailResultQueue.Count >= ReadCount)
                    {
                        ArrayList outputList = new ArrayList();
                        for (int idx = 0; idx < ReadCount; idx++, count++)
                        {
                            outputList.Add(tailResultQueue.Dequeue());
                        }
                        // Write out the content as an array of objects
                        WriteContentObject(outputList.ToArray(), count, holder.PathInfo, currentContext);
                    }

                    int remainder = tailResultQueue.Count;
                    if (remainder > 0)
                    {
                        ArrayList outputList = new ArrayList();
                        for (; remainder > 0; remainder--, count++)
                        {
                            outputList.Add(tailResultQueue.Dequeue());
                        }
                        // Write out the content as an array of objects
                        WriteContentObject(outputList.ToArray(), count, holder.PathInfo, currentContext);
                    }
                }
            }

            if (error != null)
            {
                WriteError(error);
                return(false);
            }

            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the content of an item at the specified path
        /// </summary>
        protected override void ProcessRecord()
        {
            // TotalCount and Tail should not be specified at the same time.
            // Throw out terminating error if this is the case.
            if (_totalCountSpecified && _tailSpecified)
            {
                string      errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, "TotalCount", "Tail");
                ErrorRecord error  = new ErrorRecord(new InvalidOperationException(errMsg), "TailAndHeadCannotCoexist", ErrorCategory.InvalidOperation, null);
                WriteError(error);
                return;
            }

            if (TotalCount == 0)
            {
                // Don't read anything
                return;
            }

            // Get the content readers
            CmdletProviderContext currentContext = CmdletProviderContext;

            contentStreams = this.GetContentReaders(Path, currentContext);

            try
            {
                // Iterate through the content holders reading the content
                foreach (ContentHolder holder in contentStreams)
                {
                    long countRead = 0;

                    Dbg.Diagnostics.Assert(
                        holder.Reader != null,
                        "All holders should have a reader assigned");

                    if (_tailSpecified && !(holder.Reader is FileSystemContentReaderWriter))
                    {
                        string      errMsg = SessionStateStrings.GetContent_TailNotSupported;
                        ErrorRecord error  = new ErrorRecord(new InvalidOperationException(errMsg), "TailNotSupported", ErrorCategory.InvalidOperation, Tail);
                        WriteError(error);
                        continue;
                    }

                    // If Tail is negative, we are supposed to read all content out. This is same
                    // as reading forwards. So we read forwards in this case.
                    // If Tail is positive, we seek the right position. Or, if the seek failed
                    // because of an unsupported encoding, we scan forward to get the tail content.
                    if (Tail >= 0)
                    {
                        bool seekSuccess = false;

                        try
                        {
                            seekSuccess = SeekPositionForTail(holder.Reader);
                        }
                        catch (Exception e)
                        {
                            CommandsCommon.CheckForSevereException(this, e);
                            ProviderInvocationException providerException =
                                new ProviderInvocationException(
                                    "ProviderContentReadError",
                                    SessionStateStrings.ProviderContentReadError,
                                    holder.PathInfo.Provider,
                                    holder.PathInfo.Path,
                                    e);

                            // Log a provider health event
                            MshLog.LogProviderHealthEvent(
                                this.Context,
                                holder.PathInfo.Provider.Name,
                                providerException,
                                Severity.Warning);

                            WriteError(new ErrorRecord(
                                           providerException.ErrorRecord,
                                           providerException));

                            continue;
                        }

                        // If the seek was successful, we start to read forwards from that
                        // point. Otherwise, we need to scan forwards to get the tail content.
                        if (!seekSuccess && !ScanForwardsForTail(holder, currentContext))
                        {
                            continue;
                        }
                    }

                    if (TotalCount != 0)
                    {
                        IList results = null;

                        do
                        {
                            long countToRead = ReadCount;

                            // Make sure we only ask for the amount the user wanted
                            // I am using TotalCount - countToRead so that I don't
                            // have to worry about overflow

                            if ((TotalCount > 0) && (TotalCount - countToRead < countRead))
                            {
                                countToRead = TotalCount - countRead;
                            }

                            try
                            {
                                results = holder.Reader.Read(countToRead);
                            }
                            catch (Exception e) // Catch-all OK. 3rd party callout
                            {
                                CommandsCommon.CheckForSevereException(this, e);
                                ProviderInvocationException providerException =
                                    new ProviderInvocationException(
                                        "ProviderContentReadError",
                                        SessionStateStrings.ProviderContentReadError,
                                        holder.PathInfo.Provider,
                                        holder.PathInfo.Path,
                                        e);

                                // Log a provider health event
                                MshLog.LogProviderHealthEvent(
                                    this.Context,
                                    holder.PathInfo.Provider.Name,
                                    providerException,
                                    Severity.Warning);

                                WriteError(new ErrorRecord(
                                               providerException.ErrorRecord,
                                               providerException));

                                break;
                            }

                            if (results != null && results.Count > 0)
                            {
                                countRead += results.Count;
                                if (ReadCount == 1)
                                {
                                    // Write out the content as a single object
                                    WriteContentObject(results[0], countRead, holder.PathInfo, currentContext);
                                }
                                else
                                {
                                    // Write out the content as an array of objects
                                    WriteContentObject(results, countRead, holder.PathInfo, currentContext);
                                }
                            }
                        } while (results != null && results.Count > 0 && ((TotalCount < 0) || countRead < TotalCount));
                    }
                } // foreach holder in contentStreams
            }
            finally
            {
                // close all the content readers

                CloseContent(contentStreams, false);

                // Empty the content holder array
                contentStreams = new List <ContentHolder>();
            }
        } // ProcessRecord
Exemplo n.º 9
0
 protected override void BeginProcessing()
 {
     if (base.ParameterSetName == "Domain")
     {
         if ((this._joinOptions & JoinOptions.PasswordPass) != 0 && (this._joinOptions & JoinOptions.UnsecuredJoin) == 0)
         {
             object[] str = new object[2];
             str[0] = JoinOptions.PasswordPass.ToString();
             str[1] = JoinOptions.UnsecuredJoin.ToString();
             this.WriteErrorHelper(ComputerResources.InvalidJoinOptions, "InvalidJoinOptions", this._joinOptions, ErrorCategory.InvalidArgument, true, str);
         }
         if ((this._joinOptions & JoinOptions.AccountCreate) != 0)
         {
             AddComputerCommand addComputerCommand = this;
             addComputerCommand._joinDomainflags = addComputerCommand._joinDomainflags | 2;
         }
         if ((this._joinOptions & JoinOptions.Win9XUpgrade) != 0)
         {
             AddComputerCommand addComputerCommand1 = this;
             addComputerCommand1._joinDomainflags = addComputerCommand1._joinDomainflags | 16;
         }
         if ((this._joinOptions & JoinOptions.UnsecuredJoin) != 0)
         {
             AddComputerCommand addComputerCommand2 = this;
             addComputerCommand2._joinDomainflags = addComputerCommand2._joinDomainflags | 64;
         }
         if ((this._joinOptions & JoinOptions.PasswordPass) != 0)
         {
             AddComputerCommand addComputerCommand3 = this;
             addComputerCommand3._joinDomainflags = addComputerCommand3._joinDomainflags | 128;
         }
         if ((this._joinOptions & JoinOptions.DeferSPNSet) != 0)
         {
             AddComputerCommand addComputerCommand4 = this;
             addComputerCommand4._joinDomainflags = addComputerCommand4._joinDomainflags | 0x100;
         }
         if ((this._joinOptions & JoinOptions.JoinWithNewName) != 0)
         {
             AddComputerCommand addComputerCommand5 = this;
             addComputerCommand5._joinDomainflags = addComputerCommand5._joinDomainflags | 0x400;
         }
         if ((this._joinOptions & JoinOptions.JoinReadOnly) != 0)
         {
             AddComputerCommand addComputerCommand6 = this;
             addComputerCommand6._joinDomainflags = addComputerCommand6._joinDomainflags | 0x800;
         }
         if ((this._joinOptions & JoinOptions.InstallInvoke) != 0)
         {
             AddComputerCommand addComputerCommand7 = this;
             addComputerCommand7._joinDomainflags = addComputerCommand7._joinDomainflags | 0x40000;
         }
         if (this._unsecure)
         {
             AddComputerCommand addComputerCommand8 = this;
             addComputerCommand8._joinDomainflags = addComputerCommand8._joinDomainflags | 192;
         }
         if (this._server != null)
         {
             try
             {
                 Dns.GetHostEntry(this._server);
             }
             catch (Exception exception1)
             {
                 Exception exception = exception1;
                 CommandsCommon.CheckForSevereException(this, exception);
                 object[] objArray = new object[1];
                 objArray[0] = this._server;
                 this.WriteErrorHelper(ComputerResources.CannotResolveServerName, "AddressResolutionException", this._server, ErrorCategory.InvalidArgument, true, objArray);
             }
             this._domainName = string.Concat(this._domainName, "\\", this._server);
         }
     }
 }
Exemplo n.º 10
0
        protected override void ProcessRecord()
        {
            CmdletProviderContext currentContext = base.GetCurrentContext();

            if (this.content == null)
            {
                this.content = new object[0];
            }
            if (this.pipingPaths && this.contentStreams != null && this.contentStreams.Count > 0)
            {
                base.CloseContent(this.contentStreams, false);
                this.contentWritersOpen = false;
                this.contentStreams     = new List <ContentCommandBase.ContentHolder>();
            }
            if (!this.contentWritersOpen)
            {
                string[] acceptedPaths = this.GetAcceptedPaths(base.Path, currentContext);
                if ((int)acceptedPaths.Length > 0)
                {
                    this.BeforeOpenStreams(acceptedPaths);
                    this.contentStreams = this.GetContentWriters(acceptedPaths, currentContext);
                    this.SeekContentPosition(this.contentStreams);
                }
                this.contentWritersOpen = true;
            }
            try
            {
                foreach (ContentCommandBase.ContentHolder contentStream in this.contentStreams)
                {
                    if (contentStream.Writer == null)
                    {
                        continue;
                    }
                    IList lists = null;
                    try
                    {
                        lists = contentStream.Writer.Write(this.content);
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        CommandsCommon.CheckForSevereException(this, exception);
                        ProviderInvocationException providerInvocationException = new ProviderInvocationException("ProviderContentWriteError", SessionStateStrings.ProviderContentWriteError, contentStream.PathInfo.Provider, contentStream.PathInfo.Path, exception);
                        MshLog.LogProviderHealthEvent(base.Context, contentStream.PathInfo.Provider.Name, providerInvocationException, Severity.Warning);
                        base.WriteError(new ErrorRecord(providerInvocationException.ErrorRecord, providerInvocationException));
                        continue;
                    }
                    if (lists == null || lists.Count <= 0 || !base.PassThru)
                    {
                        continue;
                    }
                    base.WriteContentObject(lists, (long)lists.Count, contentStream.PathInfo, currentContext);
                }
            }
            finally
            {
                if (this.pipingPaths)
                {
                    base.CloseContent(this.contentStreams, false);
                    this.contentWritersOpen = false;
                    this.contentStreams     = new List <ContentCommandBase.ContentHolder>();
                }
            }
        }
Exemplo n.º 11
0
        } // struct ContentHolder

        /// <summary>
        /// Closes the content readers and writers in the content holder array
        /// </summary>
        internal void CloseContent(List <ContentHolder> contentHolders, bool disposing)
        {
            if (contentHolders == null)
            {
                throw PSTraceSource.NewArgumentNullException("contentHolders");
            }

            foreach (ContentHolder holder in contentHolders)
            {
                try
                {
                    if (holder.Writer != null)
                    {
                        holder.Writer.Close();
                    }
                }
                catch (Exception e) // Catch-all OK. 3rd party callout
                {
                    CommandsCommon.CheckForSevereException(this, e);
                    // Catch all the exceptions caused by closing the writer
                    // and write out an error.

                    ProviderInvocationException providerException =
                        new ProviderInvocationException(
                            "ProviderContentCloseError",
                            SessionStateStrings.ProviderContentCloseError,
                            holder.PathInfo.Provider,
                            holder.PathInfo.Path,
                            e);


                    // Log a provider health event

                    MshLog.LogProviderHealthEvent(
                        this.Context,
                        holder.PathInfo.Provider.Name,
                        providerException,
                        Severity.Warning);

                    if (!disposing)
                    {
                        WriteError(
                            new ErrorRecord(
                                providerException.ErrorRecord,
                                providerException));
                    }
                }

                try
                {
                    if (holder.Reader != null)
                    {
                        holder.Reader.Close();
                    }
                }
                catch (Exception e) // Catch-all OK. 3rd party callout
                {
                    CommandsCommon.CheckForSevereException(this, e);
                    // Catch all the exceptions caused by closing the writer
                    // and write out an error.

                    ProviderInvocationException providerException =
                        new ProviderInvocationException(
                            "ProviderContentCloseError",
                            SessionStateStrings.ProviderContentCloseError,
                            holder.PathInfo.Provider,
                            holder.PathInfo.Path,
                            e);


                    // Log a provider health event

                    MshLog.LogProviderHealthEvent(
                        this.Context,
                        holder.PathInfo.Provider.Name,
                        providerException,
                        Severity.Warning);

                    if (!disposing)
                    {
                        WriteError(
                            new ErrorRecord(
                                providerException.ErrorRecord,
                                providerException));
                    }
                }
            }
        } // CloseContent
Exemplo n.º 12
0
        /// <summary>
        /// Get the List of HotFixes installed on the Local Machine.
        /// </summary>
        protected override void BeginProcessing()
        {
            foreach (string computer in ComputerName)
            {
                bool              foundRecord = false;
                StringBuilder     QueryString = new StringBuilder();
                ConnectionOptions conOptions  = ComputerWMIHelper.GetConnectionOptions(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, this.Credential);
                ManagementScope   scope       = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), conOptions);
                scope.Connect();
                if (Id != null)
                {
                    QueryString.Append("Select * from Win32_QuickFixEngineering where (");
                    for (int i = 0; i <= Id.Length - 1; i++)
                    {
                        QueryString.Append("HotFixID= '");
                        QueryString.Append(Id[i].ToString().Replace("'", "\\'"));
                        QueryString.Append("'");
                        if (i < Id.Length - 1)
                        {
                            QueryString.Append(" Or ");
                        }
                    }
                    QueryString.Append(")");
                }
                else
                {
                    QueryString.Append("Select * from Win32_QuickFixEngineering");
                    foundRecord = true;
                }
                _searchProcess = new ManagementObjectSearcher(scope, new ObjectQuery(QueryString.ToString()));
                foreach (ManagementObject obj in _searchProcess.Get())
                {
                    if (Description != null)
                    {
                        if (!FilterMatch(obj))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        _inputContainsWildcard = true;
                    }

                    // try to translate the SID to a more friendly username
                    // just stick with the SID if anything goes wrong
                    string installed = (string)obj["InstalledBy"];
                    if (!String.IsNullOrEmpty(installed))
                    {
                        try
                        {
                            SecurityIdentifier secObj = new SecurityIdentifier(installed);
                            obj["InstalledBy"] = secObj.Translate(typeof(NTAccount));;
                        }
                        catch (IdentityNotMappedException) // thrown by SecurityIdentifier.Translate
                        {
                        }
                        catch (SystemException e) // thrown by SecurityIdentifier.constr
                        {
                            CommandsCommon.CheckForSevereException(this, e);
                        }
                        //catch (ArgumentException) // thrown (indirectly) by SecurityIdentifier.constr (on XP only?)
                        //{ catch not needed - this is already caught as SystemException
                        //}
                        //catch (PlatformNotSupportedException) // thrown (indirectly) by SecurityIdentifier.Translate (on Win95 only?)
                        //{ catch not needed - this is already caught as SystemException
                        //}
                        //catch (UnauthorizedAccessException) // thrown (indirectly) by SecurityIdentifier.Translate
                        //{ catch not needed - this is already caught as SystemException
                        //}
                    }

                    WriteObject(obj);
                    foundRecord = true;
                }
                if (!foundRecord && !_inputContainsWildcard)
                {
                    Exception Ex = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, computer));
                    WriteError(new ErrorRecord(Ex, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
                }
                if (_searchProcess != null)
                {
                    this.Dispose();
                }
            }
        }//end of BeginProcessing method
Exemplo n.º 13
0
        protected override void BeginProcessing()
        {
            bool flag = false;

            string[] strArrays = this._computername;
            for (int i = 0; i < (int)strArrays.Length; i++)
            {
                string            str             = strArrays[i];
                StringBuilder     stringBuilder   = new StringBuilder();
                ConnectionOptions connection      = ComputerWMIHelper.GetConnection(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, this.Credential);
                ManagementScope   managementScope = new ManagementScope(ComputerWMIHelper.GetScopeString(str, "\\root\\cimv2"), connection);
                managementScope.Connect();
                if (this._id == null)
                {
                    stringBuilder.Append("Select * from Win32_QuickFixEngineering");
                    flag = true;
                }
                else
                {
                    stringBuilder.Append("Select * from Win32_QuickFixEngineering where (");
                    for (int j = 0; j <= (int)this._id.Length - 1; j++)
                    {
                        stringBuilder.Append("HotFixID= '");
                        stringBuilder.Append(this._id[j].ToString().Replace("'", "\\'"));
                        stringBuilder.Append("'");
                        if (j < (int)this._id.Length - 1)
                        {
                            stringBuilder.Append(" Or ");
                        }
                    }
                    stringBuilder.Append(")");
                }
                this.searchProcess = new ManagementObjectSearcher(managementScope, new ObjectQuery(stringBuilder.ToString()));
                foreach (ManagementObject managementObject in this.searchProcess.Get())
                {
                    if (this._description == null)
                    {
                        this.inputContainsWildcard = true;
                    }
                    else
                    {
                        if (!this.FilterMatch(managementObject))
                        {
                            continue;
                        }
                    }
                    string item = (string)managementObject["InstalledBy"];
                    if (!string.IsNullOrEmpty(item))
                    {
                        try
                        {
                            SecurityIdentifier securityIdentifier = new SecurityIdentifier(item);
                            managementObject["InstalledBy"] = securityIdentifier.Translate(typeof(NTAccount));
                        }
                        catch (IdentityNotMappedException identityNotMappedException)
                        {
                        }
                        catch (SystemException systemException1)
                        {
                            SystemException systemException = systemException1;
                            CommandsCommon.CheckForSevereException(this, systemException);
                        }
                    }
                    base.WriteObject(managementObject);
                    flag = true;
                }
                if (!flag && !this.inputContainsWildcard)
                {
                    Exception argumentException = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, str));
                    base.WriteError(new ErrorRecord(argumentException, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
                }
                if (this.searchProcess != null)
                {
                    this.Dispose();
                }
            }
        }
Exemplo n.º 14
0
        protected override void ProcessRecord()
        {
            if (!this._totalCountSpecified || !this._tailSpecified)
            {
                if (this.TotalCount != (long)0)
                {
                    CmdletProviderContext cmdletProviderContext = this.CmdletProviderContext;
                    this.contentStreams = base.GetContentReaders(base.Path, cmdletProviderContext);
                    try
                    {
Label0:
                        foreach (ContentCommandBase.ContentHolder contentStream in this.contentStreams)
                        {
                            long count = (long)0;
                            if (!this._tailSpecified || contentStream.Reader as FileSystemContentReaderWriter != null)
                            {
                                if (this.Tail >= 0)
                                {
                                    bool flag = false;
                                    try
                                    {
                                        flag = this.SeekPositionForTail(contentStream.Reader);
                                    }
                                    catch (Exception exception1)
                                    {
                                        Exception exception = exception1;
                                        CommandsCommon.CheckForSevereException(this, exception);
                                        ProviderInvocationException providerInvocationException = new ProviderInvocationException("ProviderContentReadError", SessionStateStrings.ProviderContentReadError, contentStream.PathInfo.Provider, contentStream.PathInfo.Path, exception);
                                        MshLog.LogProviderHealthEvent(base.Context, contentStream.PathInfo.Provider.Name, providerInvocationException, Severity.Warning);
                                        base.WriteError(new ErrorRecord(providerInvocationException.ErrorRecord, providerInvocationException));
                                        continue;
                                    }
                                    if (!flag && !this.ScanForwardsForTail(contentStream, cmdletProviderContext))
                                    {
                                        continue;
                                    }
                                }
                                if (this.TotalCount == (long)0)
                                {
                                    continue;
                                }
                                IList lists = null;
                                do
                                {
                                    long readCount = this.ReadCount;
                                    if (this.TotalCount > (long)0 && this.TotalCount - readCount < count)
                                    {
                                        readCount = this.TotalCount - count;
                                    }
                                    try
                                    {
                                        lists = contentStream.Reader.Read(readCount);
                                    }
                                    catch (Exception exception3)
                                    {
                                        Exception exception2 = exception3;
                                        CommandsCommon.CheckForSevereException(this, exception2);
                                        ProviderInvocationException providerInvocationException1 = new ProviderInvocationException("ProviderContentReadError", SessionStateStrings.ProviderContentReadError, contentStream.PathInfo.Provider, contentStream.PathInfo.Path, exception2);
                                        MshLog.LogProviderHealthEvent(base.Context, contentStream.PathInfo.Provider.Name, providerInvocationException1, Severity.Warning);
                                        base.WriteError(new ErrorRecord(providerInvocationException1.ErrorRecord, providerInvocationException1));
                                        goto Label0;
                                    }
                                    if (lists == null || lists.Count <= 0)
                                    {
                                        continue;
                                    }
                                    count = count + (long)lists.Count;
                                    if (this.ReadCount != (long)1)
                                    {
                                        base.WriteContentObject(lists, count, contentStream.PathInfo, cmdletProviderContext);
                                    }
                                    else
                                    {
                                        base.WriteContentObject(lists[0], count, contentStream.PathInfo, cmdletProviderContext);
                                    }
                                }while (lists != null && lists.Count > 0 && (this.TotalCount < (long)0 || count < this.TotalCount));
                            }
                            else
                            {
                                string      getContentTailNotSupported = SessionStateStrings.GetContent_TailNotSupported;
                                ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(getContentTailNotSupported), "TailNotSupported", ErrorCategory.InvalidOperation, (object)this.Tail);
                                base.WriteError(errorRecord);
                            }
                        }
                    }
                    finally
                    {
                        base.CloseContent(this.contentStreams, false);
                        this.contentStreams = new List <ContentCommandBase.ContentHolder>();
                    }
                    return;
                }
                else
                {
                    return;
                }
            }
            else
            {
                string      str          = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, "TotalCount", "Tail");
                ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(str), "TailAndHeadCannotCoexist", ErrorCategory.InvalidOperation, null);
                base.WriteError(errorRecord1);
                return;
            }
        }
Exemplo n.º 15
0
        private bool ScanForwardsForTail(ContentCommandBase.ContentHolder holder, CmdletProviderContext currentContext)
        {
            FileSystemContentReaderWriter reader = holder.Reader as FileSystemContentReaderWriter;
            Queue <object> objs        = new Queue <object>();
            IList          lists       = null;
            ErrorRecord    errorRecord = null;

            do
            {
                try
                {
                    lists = reader.ReadWithoutWaitingChanges(this.ReadCount);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    CommandsCommon.CheckForSevereException(this, exception);
                    ProviderInvocationException providerInvocationException = new ProviderInvocationException("ProviderContentReadError", SessionStateStrings.ProviderContentReadError, holder.PathInfo.Provider, holder.PathInfo.Path, exception);
                    MshLog.LogProviderHealthEvent(base.Context, holder.PathInfo.Provider.Name, providerInvocationException, Severity.Warning);
                    errorRecord = new ErrorRecord(providerInvocationException.ErrorRecord, providerInvocationException);
                    break;
                }
                if (lists == null || lists.Count <= 0)
                {
                    continue;
                }
                foreach (object obj in lists)
                {
                    if (objs.Count == this.Tail)
                    {
                        objs.Dequeue();
                    }
                    objs.Enqueue(obj);
                }
            }while (lists != null && lists.Count > 0);
            if (objs.Count > 0)
            {
                int count = 0;
                if (this.ReadCount <= (long)0 || this.ReadCount >= (long)objs.Count && this.ReadCount != (long)1)
                {
                    count = objs.Count;
                    ArrayList arrayLists = new ArrayList();
                    while (objs.Count > 0)
                    {
                        arrayLists.Add(objs.Dequeue());
                    }
                    base.WriteContentObject(arrayLists.ToArray(), (long)count, holder.PathInfo, currentContext);
                }
                else
                {
                    if (this.ReadCount != (long)1)
                    {
                        while ((long)objs.Count >= this.ReadCount)
                        {
                            ArrayList arrayLists1 = new ArrayList();
                            int       num         = 0;
                            while ((long)num < this.ReadCount)
                            {
                                arrayLists1.Add(objs.Dequeue());
                                num++;
                                count++;
                            }
                            base.WriteContentObject(arrayLists1.ToArray(), (long)count, holder.PathInfo, currentContext);
                        }
                        int count1 = objs.Count;
                        if (count1 > 0)
                        {
                            ArrayList arrayLists2 = new ArrayList();
                            while (count1 > 0)
                            {
                                arrayLists2.Add(objs.Dequeue());
                                count1--;
                                count++;
                            }
                            base.WriteContentObject(arrayLists2.ToArray(), (long)count, holder.PathInfo, currentContext);
                        }
                    }
                    else
                    {
                        while (objs.Count > 0)
                        {
                            int num1 = count;
                            count = num1 + 1;
                            base.WriteContentObject(objs.Dequeue(), (long)num1, holder.PathInfo, currentContext);
                        }
                    }
                }
            }
            if (errorRecord == null)
            {
                return(true);
            }
            else
            {
                base.WriteError(errorRecord);
                return(false);
            }
        }
Exemplo n.º 16
0
 protected override void ProcessRecord()
 {
     if ((int)this.ComputerName.Length > 0 && (this._fileversioninfo.IsPresent || this._module.IsPresent))
     {
         Exception   invalidOperationException = new InvalidOperationException(ProcessResources.NoComputerNameWithFileVersion);
         ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, "InvalidOperationException", ErrorCategory.InvalidOperation, this.ComputerName);
         base.ThrowTerminatingError(errorRecord);
     }
     foreach (Process process in base.MatchingProcesses())
     {
         if (!this._module.IsPresent || !this._fileversioninfo.IsPresent)
         {
             if (!this._module.IsPresent)
             {
                 if (!this._fileversioninfo.IsPresent)
                 {
                     base.WriteObject(process);
                 }
                 else
                 {
                     try
                     {
                         base.WriteObject(PsUtils.GetMainModule(process).FileVersionInfo, true);
                     }
                     catch (InvalidOperationException invalidOperationException2)
                     {
                         InvalidOperationException invalidOperationException1 = invalidOperationException2;
                         base.WriteNonTerminatingError(process, invalidOperationException1, ProcessResources.CouldnotEnumerateFileVer, "CouldnotEnumerateFileVer", ErrorCategory.PermissionDenied);
                     }
                     catch (ArgumentException argumentException1)
                     {
                         ArgumentException argumentException = argumentException1;
                         base.WriteNonTerminatingError(process, argumentException, ProcessResources.CouldnotEnumerateFileVer, "CouldnotEnumerateFileVer", ErrorCategory.PermissionDenied);
                     }
                     catch (Win32Exception win32Exception3)
                     {
                         Win32Exception win32Exception = win32Exception3;
                         try
                         {
                             if (win32Exception.ErrorCode != 0x12b)
                             {
                                 base.WriteNonTerminatingError(process, win32Exception, ProcessResources.CouldnotEnumerateFileVer, "CouldnotEnumerateFileVer", ErrorCategory.PermissionDenied);
                             }
                             else
                             {
                                 base.WriteObject(PsUtils.GetMainModule(process).FileVersionInfo, true);
                             }
                         }
                         catch (Win32Exception win32Exception2)
                         {
                             Win32Exception win32Exception1 = win32Exception2;
                             base.WriteNonTerminatingError(process, win32Exception1, ProcessResources.CouldnotEnumerateFileVer, "CouldnotEnumerateFileVer", ErrorCategory.PermissionDenied);
                         }
                     }
                     catch (Exception exception1)
                     {
                         Exception exception = exception1;
                         CommandsCommon.CheckForSevereException(this, exception);
                         base.WriteNonTerminatingError(process, exception, ProcessResources.CouldnotEnumerateFileVer, "CouldnotEnumerateFileVer", ErrorCategory.PermissionDenied);
                     }
                 }
             }
             else
             {
                 try
                 {
                     base.WriteObject(process.Modules, true);
                 }
                 catch (Win32Exception win32Exception7)
                 {
                     Win32Exception win32Exception4 = win32Exception7;
                     try
                     {
                         if (win32Exception4.ErrorCode != 0x12b)
                         {
                             base.WriteNonTerminatingError(process, win32Exception4, ProcessResources.CouldnotEnumerateModules, "CouldnotEnumerateModules", ErrorCategory.PermissionDenied);
                         }
                         else
                         {
                             base.WriteObject(process.Modules, true);
                         }
                     }
                     catch (Win32Exception win32Exception6)
                     {
                         Win32Exception win32Exception5 = win32Exception6;
                         base.WriteNonTerminatingError(process, win32Exception5, ProcessResources.CouldnotEnumerateModules, "CouldnotEnumerateModules", ErrorCategory.PermissionDenied);
                     }
                 }
                 catch (Exception exception3)
                 {
                     Exception exception2 = exception3;
                     CommandsCommon.CheckForSevereException(this, exception2);
                     base.WriteNonTerminatingError(process, exception2, ProcessResources.CouldnotEnumerateModules, "CouldnotEnumerateModules", ErrorCategory.PermissionDenied);
                 }
             }
         }
         else
         {
             ProcessModule processModule = null;
             try
             {
                 ProcessModuleCollection modules = process.Modules;
                 foreach (ProcessModule module in modules)
                 {
                     processModule = module;
                     base.WriteObject(module.FileVersionInfo, true);
                 }
             }
             catch (InvalidOperationException invalidOperationException4)
             {
                 InvalidOperationException invalidOperationException3 = invalidOperationException4;
                 base.WriteNonTerminatingError(process, invalidOperationException3, ProcessResources.CouldnotEnumerateModuleFileVer, "CouldnotEnumerateModuleFileVer", ErrorCategory.PermissionDenied);
             }
             catch (ArgumentException argumentException3)
             {
                 ArgumentException argumentException2 = argumentException3;
                 base.WriteNonTerminatingError(process, argumentException2, ProcessResources.CouldnotEnumerateModuleFileVer, "CouldnotEnumerateModuleFileVer", ErrorCategory.PermissionDenied);
             }
             catch (Win32Exception win32Exception11)
             {
                 Win32Exception win32Exception8 = win32Exception11;
                 try
                 {
                     if (win32Exception8.ErrorCode != 0x12b)
                     {
                         base.WriteNonTerminatingError(process, win32Exception8, ProcessResources.CouldnotEnumerateModuleFileVer, "CouldnotEnumerateModuleFileVer", ErrorCategory.PermissionDenied);
                     }
                     else
                     {
                         base.WriteObject(processModule.FileVersionInfo, true);
                     }
                 }
                 catch (Win32Exception win32Exception10)
                 {
                     Win32Exception win32Exception9 = win32Exception10;
                     base.WriteNonTerminatingError(process, win32Exception9, ProcessResources.CouldnotEnumerateModuleFileVer, "CouldnotEnumerateModuleFileVer", ErrorCategory.PermissionDenied);
                 }
             }
             catch (Exception exception5)
             {
                 Exception exception4 = exception5;
                 CommandsCommon.CheckForSevereException(this, exception4);
                 base.WriteNonTerminatingError(process, exception4, ProcessResources.CouldnotEnumerateModuleFileVer, "CouldnotEnumerateModuleFileVer", ErrorCategory.PermissionDenied);
             }
         }
     }
 }