コード例 #1
0
        //
        // BeginProcessing() is invoked once per pipeline
        //
        protected override void BeginProcessing()
        {
#if CORECLR
            if (Platform.IsIoT)
            {
                // IoT does not have the '$env:windir\System32\pdh.dll' assembly which is required by this cmdlet.
                throw new PlatformNotSupportedException();
            }

            // PowerShell Core requires at least Windows 7,
            // so no version test is needed
            _pdhHelper = new PdhHelper(false);
#else
            _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6);
#endif
            _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();

            uint res = _pdhHelper.ConnectToDataSource();
            if (res != 0)
            {
                ReportPdhError(res, true);
                return;
            }

            if (Continuous.IsPresent && _maxSamplesSpecified)
            {
                Exception exc = new Exception(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples")));
                ThrowTerminatingError(new ErrorRecord(exc, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null));
            }
        }
コード例 #2
0
        //
        // BeginProcessing() is invoked once per pipeline
        //
        protected override void BeginProcessing()
        {
            if (Platform.IsIoT)
            {
                // IoT does not have the '$env:windir\System32\pdh.dll' assembly which is required by this cmdlet.
                throw new PlatformNotSupportedException();
            }

            _pdhHelper   = new PdhHelper();
            _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();

            uint res = _pdhHelper.ConnectToDataSource();

            if (res != PdhResults.PDH_CSTATUS_VALID_DATA)
            {
                ReportPdhError(res, true);
                return;
            }

            if (Continuous.IsPresent && _maxSamplesSpecified)
            {
                Exception exc = new Exception(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples")));
                ThrowTerminatingError(new ErrorRecord(exc, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null));
            }
        }
コード例 #3
0
        //
        // BeginProcessing() is invoked once per pipeline
        //
        protected override void BeginProcessing()
        {
#if CORECLR
            if (Platform.IsIoT)
            {
                // IoT does not have the '$env:windir\System32\pdh.dll' assembly which is required by this cmdlet.
                throw new PlatformNotSupportedException();
            }

            // PowerShell Core requires at least Windows 7,
            // so no version test is needed
            _pdhHelper = new PdhHelper(false);
#else
            //
            // Determine the OS version: this cmdlet requires Windows 7
            // because it uses new Pdh functionality.
            //
            Version osVersion = System.Environment.OSVersion.Version;
            if (osVersion.Major < 6 ||
                (osVersion.Major == 6 && osVersion.Minor < 1))
            {
                string    msg = _resourceMgr.GetString("ExportCtrWin7Required");
                Exception exc = new Exception(msg);
                ThrowTerminatingError(new ErrorRecord(exc, "ExportCtrWin7Required", ErrorCategory.NotImplemented, null));
            }

            _pdhHelper = new PdhHelper(osVersion.Major < 6);
#endif
            _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();

            //
            // Validate the Format and CounterSamples arguments
            //
            ValidateFormat();

            if (Circular.IsPresent && _maxSize == 0)
            {
                string    msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterCircularNoMaxSize"));
                Exception exc = new Exception(msg);
                WriteError(new ErrorRecord(exc, "CounterCircularNoMaxSize", ErrorCategory.InvalidResult, null));
            }

            uint res = _pdhHelper.ConnectToDataSource();
            if (res != 0)
            {
                ReportPdhError(res, true);
            }

            res = _pdhHelper.OpenQuery();
            if (res != 0)
            {
                ReportPdhError(res, true);
            }
        }
コード例 #4
0
        //
        // ProcessSummary().
        // Does the work to process Summary parameter set.
        //
        private void ProcessSummary()
        {
            uint res = _pdhHelper.ConnectToDataSource(_resolvedPaths);

            if (res != 0)
            {
                ReportPdhError(res, true);
                return;
            }

            CounterFileInfo summaryObj;

            res = _pdhHelper.GetFilesSummary(out summaryObj);

            if (res != 0)
            {
                ReportPdhError(res, true);
                return;
            }

            WriteObject(summaryObj);
        }
コード例 #5
0
        //
        // BeginProcessing() is invoked once per pipeline
        //
        protected override void BeginProcessing()
        {
            _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();

            //
            // Determine the OS version: this cmdlet requires Windows 7
            // because it uses new Pdh functionality.
            //
            if (System.Environment.OSVersion.Version.Major < 6 ||
                (System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor < 1))
            {
                string    msg = _resourceMgr.GetString("ExportCtrWin7Required");
                Exception exc = new Exception(msg);
                ThrowTerminatingError(new ErrorRecord(exc, "ExportCtrWin7Required", ErrorCategory.NotImplemented, null));
            }

            _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6);

            //
            // Validate the Format and CounterSamples arguments
            //
            ValidateFormat();

            if (Circular.IsPresent && _maxSize == 0)
            {
                string    msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterCircularNoMaxSize"));
                Exception exc = new Exception(msg);
                WriteError(new ErrorRecord(exc, "CounterCircularNoMaxSize", ErrorCategory.InvalidResult, null));
            }

            uint res = _pdhHelper.ConnectToDataSource();

            if (res != 0)
            {
                ReportPdhError(res, true);
            }

            res = _pdhHelper.OpenQuery();
            if (res != 0)
            {
                ReportPdhError(res, true);
            }
        }
コード例 #6
0
        //
        // BeginProcessing() is invoked once per pipeline
        //
        protected override void BeginProcessing()
        {
            _resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();

            _pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6);
            uint res = _pdhHelper.ConnectToDataSource();

            if (res != 0)
            {
                ReportPdhError(res, true);
                return;
            }


            if (Continuous.IsPresent && _maxSamplesSpecified)
            {
                Exception exc = new Exception(string.Format(CultureInfo.CurrentCulture, _resourceMgr.GetString("CounterContinuousOrMaxSamples")));
                ThrowTerminatingError(new ErrorRecord(exc, "CounterContinuousOrMaxSamples", ErrorCategory.InvalidArgument, null));
            }
        }