Пример #1
0
        public static UniversalStreamRecord FromVariablePlain(VariablePlain variable)
        {
            UniversalStreamRecord usr = new UniversalStreamRecord();

            usr.Message = "$" + variable.Name + ": " + ObjectToString(variable.Value);
            return(usr);
        }
Пример #2
0
        public static UniversalStreamRecord FromObject(Object obj)
        {
            UniversalStreamRecord usr = new UniversalStreamRecord();

            usr.Message = ObjectToString(obj);
            return(usr);
        }
Пример #3
0
        public static Collection <UniversalStreamRecord> FromPSObjectPSCollection(PSDataCollection <PSObject> collection)
        {
            Collection <UniversalStreamRecord> collectionUniversalStreamRecord = new Collection <UniversalStreamRecord>();

            if (collection != null && collection.Count > 0)
            {
                foreach (PSObject psobj in collection)
                {
                    UniversalStreamRecord record = UniversalStreamRecord.FromPSObject(psobj);
                    collectionUniversalStreamRecord.Add(record);
                }
            }

            return(collectionUniversalStreamRecord);
        }
Пример #4
0
        public static Collection <UniversalStreamRecord> FromErrorRecordPSCollection(PSDataCollection <ErrorRecord> collection)
        {
            Collection <UniversalStreamRecord> collectionUniversalStreamRecord = new Collection <UniversalStreamRecord>();

            if (collection != null && collection.Count > 0)
            {
                foreach (ErrorRecord er in collection)
                {
                    UniversalStreamRecord record = UniversalStreamRecord.FromErrorRecord(er);
                    collectionUniversalStreamRecord.Add(record);
                }
            }

            return(collectionUniversalStreamRecord);
        }
Пример #5
0
        public static Collection <UniversalStreamRecord> FromInformationalRecordPSCollection <T>(PSDataCollection <T> collection) where T : InformationalRecord
        {
            Collection <UniversalStreamRecord> collectionUniversalStreamRecord = new Collection <UniversalStreamRecord>();

            if (collection != null && collection.Count > 0)
            {
                foreach (InformationalRecord ir in collection)
                {
                    UniversalStreamRecord record = UniversalStreamRecord.FromInformationalRecord(ir);
                    collectionUniversalStreamRecord.Add(record);
                }
            }

            return(collectionUniversalStreamRecord);
        }
Пример #6
0
        public static Collection <UniversalStreamRecord> FromVariablePlainHashSet(HashSet <VariablePlain> collection, bool includeReadOnly = true)
        {
            Collection <UniversalStreamRecord> collectionUniversalStreamRecord = new Collection <UniversalStreamRecord>();

            if (collection != null && collection.Count > 0)
            {
                foreach (VariablePlain var in collection)
                {
                    if (var.ReadOnly & includeReadOnly == false)
                    {
                        //Do nothing as ReadOnly entries should be ignored
                    }
                    else
                    {
                        UniversalStreamRecord record = UniversalStreamRecord.FromVariablePlain(var);
                        collectionUniversalStreamRecord.Add(record);
                    }
                }
            }

            return(collectionUniversalStreamRecord);
        }
Пример #7
0
        public override string ToString()
        {
            StringBuilder sbuilder = new StringBuilder();

            sbuilder.Append("Script status: ");
            if (Successful)
            {
                sbuilder.Append("Executed successfully");

                //IF SuccessfulNoError is FALSE, we need to report this
                if (SuccessfulNoError == false)
                {
                    sbuilder.Append(", but errors were reported");
                }

                sbuilder.AppendLine();
            }
            else
            {
                sbuilder.Append("Failed");
                //If _pipelineState is FAILED, we ignore this. Else the result is "Failed [Pipeline state FAILED]"
                if (_pipelineState != PSInvocationState.Failed)
                {
                    sbuilder.Append(string.Format(" [Pipeline state {0}]", _pipelineState));
                }
                sbuilder.AppendLine();

                sbuilder.AppendLine("-EXCEPTION------------------------");
                if (FailedException != null)
                {
                    sbuilder.AppendLine(FailedException.ToString());
                }
                else
                {
                    sbuilder.AppendLine("No exception found");
                }
                sbuilder.AppendLine("----------------------------------");
            }
            sbuilder.AppendLine();

            Collection <UniversalStreamRecord> universalRecordCollection;

            //MTH: We are moving down the streams in this order: Output(1), Error(2), Warning(3), Verbose(4), Debug(5) and finally the Variables
            //See [Understanding Streams, Redirection, and Write-Host in PowerShell](blogs.technet.com/b/heyscriptingguy/archive/2014/03/30/understanding-streams-redirection-and-write-host-in-powershell.aspx)
            universalRecordCollection = UniversalStreamRecord.FromPSObjectPSCollection(StreamOutput);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Output));

            //MTH: This will list all non-terminating errors. In fact, these ARE real errors but normally $ErrorActionPreference is set to "Continue" - which is the default.
            //If set to $ErrorActionPreference = "Stop", any error will become terminating.
            //See: [Managing non-terminating errors](http://blogs.msdn.com/b/powershell/archive/2006/04/25/583241.aspx)
            universalRecordCollection = UniversalStreamRecord.FromErrorRecordPSCollection(StreamError);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Error));

            //Only contains entires when $WarningPreference = 'Continue' - this is the default in PowerShell
            universalRecordCollection = UniversalStreamRecord.FromInformationalRecordPSCollection(StreamWarning);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Warning));

            //Only contains entries when $VerbosePreference = 'Continue'
            universalRecordCollection = UniversalStreamRecord.FromInformationalRecordPSCollection(StreamVerbose);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Verbose));

            //Only contains entries when $DebugPreference = 'Continue'
            universalRecordCollection = UniversalStreamRecord.FromInformationalRecordPSCollection(StreamDebug);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Debug));

            //Add the variables but only if read/write variables were passed in (second paramter FALSE)
            universalRecordCollection = UniversalStreamRecord.FromVariablePlainHashSet(Variables, false);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, "Writeable variables:", "No writeable variable exist"));

            return(sbuilder.ToString());
        }
Пример #8
0
 public static UniversalStreamRecord FromPSObject(PSObject psObj)
 {
     return(UniversalStreamRecord.FromObject(psObj.BaseObject));
 }