Esempio n. 1
0
        internal static ErrorRecord InitializeErrorRecordCore(InvocationContext context, Exception exception, string errorId, ErrorCategory errorCategory, CimResultContext cimResultContext)
        {
            object errorSource = null;

            if (cimResultContext != null)
            {
                errorSource = cimResultContext.ErrorSource;
            }
            if (errorSource == null && context != null && context.TargetCimInstance != null)
            {
                errorSource = context.TargetCimInstance;
            }
            ErrorRecord errorRecord = new ErrorRecord(exception, errorId, errorCategory, errorSource);

            if (context != null)
            {
                OriginInfo  originInfo          = new OriginInfo(context.ComputerName, Guid.Empty);
                ErrorRecord remotingErrorRecord = new RemotingErrorRecord(errorRecord, originInfo);
                DebugHelper.WriteLogEx("Created RemotingErrorRecord.", 0);
                return(remotingErrorRecord);
            }
            else
            {
                return(errorRecord);
            }
        }
Esempio n. 2
0
        public static IComponent?DependencyToComponent(Dependency dependency)
        {
            if (string.IsNullOrEmpty(dependency.Name) || string.IsNullOrEmpty(dependency.Destination))
            {
                return(null);
            }
            var component = new Component
            {
                Name        = dependency.Name,
                Destination = GetRealDependencyDestination(dependency)
            };

            if (!string.IsNullOrEmpty(dependency.Origin))
            {
                var newVersion = dependency.GetVersion();
                var hash       = dependency.Sha2;
                var size       = dependency.Size;

                ValidationContext?validationContext = null;
                if (hash != null)
                {
                    validationContext = new ValidationContext {
                        Hash = hash, HashType = HashType.Sha256
                    }
                }
                ;
                var originInfo = new OriginInfo(new Uri(dependency.Origin, UriKind.Absolute), newVersion, size, validationContext);
                component.OriginInfo = originInfo;
            }

            return(component);
        }
 /// <summary>
 /// Constructor taking WarningRecord to wrap and OriginInfo.
 /// </summary>
 /// <param name="warningRecord">WarningRecord to wrap</param>
 /// <param name="originInfo">OriginInfo</param>
 internal RemotingWarningRecord(
     WarningRecord warningRecord,
     OriginInfo originInfo)
     : base(warningRecord.FullyQualifiedWarningId, warningRecord.Message)
 {
     _originInfo = originInfo;
 }
Esempio n. 4
0
        private void InitializeErrorRecordCore(CimJobContext jobContext, Exception exception, string errorId, ErrorCategory errorCategory)
        {
            object        targetObject;
            Exception     exception1     = exception;
            string        str            = errorId;
            ErrorCategory errorCategory1 = errorCategory;

            if (jobContext != null)
            {
                targetObject = jobContext.TargetObject;
            }
            else
            {
                targetObject = null;
            }
            ErrorRecord errorRecord = new ErrorRecord(exception1, str, errorCategory1, targetObject);

            if (jobContext == null)
            {
                this.errorRecord = errorRecord;
                return;
            }
            else
            {
                OriginInfo originInfo = new OriginInfo(jobContext.Session.ComputerName, Guid.Empty);
                this.errorRecord = new RemotingErrorRecord(errorRecord, originInfo);
                this.errorRecord.SetInvocationInfo(jobContext.CmdletInvocationInfo);
                this.errorRecord.PreserveInvocationInfoOnce = true;
                return;
            }
        }
 public RemotingErrorRecord(ErrorRecord errorRecord, OriginInfo originInfo)
     : base(errorRecord, (Exception)null)
 {
     if (errorRecord != null)
     {
         this.SetInvocationInfo(errorRecord.InvocationInfo);
     }
     this.originInfo = originInfo;
 }
        /// <summary>
        /// constructor that is used to wrap an error record
        /// </summary>
        /// <param name="errorRecord"></param>
        /// <param name="originInfo"></param>
        /// <param name="replaceParentContainsErrorRecordException"></param>
        private RemotingErrorRecord(ErrorRecord errorRecord, OriginInfo originInfo, Exception replaceParentContainsErrorRecordException) :
            base(errorRecord, replaceParentContainsErrorRecordException)
        {
            if (null != errorRecord)
            {
                base.SetInvocationInfo(errorRecord.InvocationInfo);
            }

            _originInfo = originInfo;
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="progressRecord">the progress record that is wrapped</param>
 /// <param name="originInfo">origin information</param>
 public RemotingProgressRecord(ProgressRecord progressRecord, OriginInfo originInfo) :
     base(Validate(progressRecord).ActivityId, Validate(progressRecord).Activity, Validate(progressRecord).StatusDescription)
 {
     _originInfo = originInfo;
     if (progressRecord != null)
     {
         this.PercentComplete  = progressRecord.PercentComplete;
         this.ParentActivityId = progressRecord.ParentActivityId;
         this.RecordType       = progressRecord.RecordType;
         this.SecondsRemaining = progressRecord.SecondsRemaining;
         if (!string.IsNullOrEmpty(progressRecord.CurrentOperation))
         {
             this.CurrentOperation = progressRecord.CurrentOperation;
         }
     }
 }
Esempio n. 8
0
    public void SubCharacter(CharacterInfo characterInfo)
    {
        IsSubCharacter = true;

        if (characterDataSheet.TryGetCharacterTribe(characterInfo.id, out var tribe))
        {
            TribeInfo tribeInfo = new TribeInfo(tribe, characterInfo.id);

            if (deployedTribes.ContainsKey(tribeInfo))
            {
                --deployedTribes[tribeInfo];

                if (deployedTribes[tribeInfo] == 0)
                {
                    deployedTribes.Remove(tribeInfo);
                    SubAppliedTribe(tribeInfo.tribe);
                }
            }
            else
            {
                Debug.Log("Error No Tribes");
            }
        }

        if (characterDataSheet.TryGetCharacterOrigin(characterInfo.id, out var origin))
        {
            OriginInfo originInfo = new OriginInfo(origin, characterInfo.id);

            if (deployedOrigins.ContainsKey(originInfo))
            {
                --deployedOrigins[originInfo];

                if (deployedOrigins[originInfo] == 0)
                {
                    deployedOrigins.Remove(originInfo);
                    SubAppliedOrigin(originInfo.origin);
                }
            }
            else
            {
                Debug.Log("Error No Origins");
            }
        }

        UpdateApplySynergy();
    }
Esempio n. 9
0
        private void HandleErrorReady(object sender, EventArgs eventArgs)
        {
            PSDataCollectionPipelineReader <ErrorRecord, object> reader = sender as PSDataCollectionPipelineReader <ErrorRecord, object>;

            foreach (object obj2 in reader.NonBlockingRead())
            {
                ErrorRecord errorRecord = obj2 as ErrorRecord;
                if (errorRecord != null)
                {
                    OriginInfo          originInfo = new OriginInfo(reader.ComputerName, reader.RunspaceId);
                    RemotingErrorRecord record2    = new RemotingErrorRecord(errorRecord, originInfo)
                    {
                        PreserveInvocationInfoOnce = true
                    };
                    this.WriteError(record2);
                }
            }
        }
Esempio n. 10
0
    public void AddCharacter(CharacterInfo characterInfo)
    {
        IsSubCharacter = false;

        if (characterDataSheet.TryGetCharacterTribe(characterInfo.id, out var tribe))
        {
            TribeInfo tribeInfo = new TribeInfo(tribe, characterInfo.id);
            currentAddTribe = tribe;

            if (deployedTribes.ContainsKey(tribeInfo))
            {
                ++deployedTribes[tribeInfo];
            }
            else
            {
                deployedTribes.Add(tribeInfo, 1);
                AddAppliedTribe(tribeInfo.tribe);
            }
        }

        if (characterDataSheet.TryGetCharacterOrigin(characterInfo.id, out var origin))
        {
            OriginInfo originInfo = new OriginInfo(origin, characterInfo.id);
            currentAddOrigin = origin;

            if (deployedOrigins.ContainsKey(originInfo))
            {
                ++deployedOrigins[originInfo];
            }
            else
            {
                deployedOrigins.Add(originInfo, 1);
                AddAppliedOrigin(originInfo.origin);
            }
        }

        UpdateApplySynergy();
    }
Esempio n. 11
0
 /// <summary>
 /// Deserializer constructor.
 /// </summary>
 /// <param name="info">Serializer information</param>
 /// <param name="context">Streaming context</param>
 protected RemotingErrorRecord(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     _originInfo = (OriginInfo)info.GetValue("RemoteErrorRecord_OriginInfo", typeof(OriginInfo));
 }
Esempio n. 12
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="errorRecord">the error record that is wrapped</param>
 /// <param name="originInfo">origin information</param>
 public RemotingErrorRecord(ErrorRecord errorRecord, OriginInfo originInfo) : this(errorRecord, originInfo, null)
 {
 }
Esempio n. 13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="record">The Information message that is wrapped</param>
 /// <param name="originInfo">The origin information</param>
 public RemotingInformationRecord(InformationRecord record, OriginInfo originInfo)
     : base(record)
 {
     _originInfo = originInfo;
 }
Esempio n. 14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="message">The verbose message that is wrapped</param>
 /// <param name="originInfo">The origin information</param>
 public RemotingVerboseRecord(string message, OriginInfo originInfo) : base(message)
 {
     _originInfo = originInfo;
 }
Esempio n. 15
0
    public override bool Equals(object obj)
    {
        OriginInfo originInfo = obj as OriginInfo;

        return((originInfo.origin == origin && originInfo.id == id) ? true : false);
    }
Esempio n. 16
0
        protected void ProcessJobFailure(ExecutionCmdletHelper helper, out Exception failureException, out ErrorRecord failureErrorRecord)
        {
            RemotePipeline pipeline = helper.Pipeline as RemotePipeline;
            RemoteRunspace runspace = pipeline.GetRunspace() as RemoteRunspace;

            failureException   = null;
            failureErrorRecord = null;
            if (helper.InternalException != null)
            {
                string errorId = "RemotePipelineExecutionFailed";
                failureException = helper.InternalException;
                if ((failureException is InvalidRunspaceStateException) || (failureException is InvalidRunspacePoolStateException))
                {
                    errorId = "InvalidSessionState";
                    if (!string.IsNullOrEmpty(failureException.Source))
                    {
                        errorId = string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { errorId, failureException.Source });
                    }
                }
                failureErrorRecord = new ErrorRecord(helper.InternalException, errorId, ErrorCategory.OperationStopped, helper);
            }
            else if (runspace.RunspaceStateInfo.State == RunspaceState.Broken)
            {
                failureException = runspace.RunspaceStateInfo.Reason;
                object computerName = runspace.ConnectionInfo.ComputerName;
                string str2         = null;
                PSRemotingTransportException exception = failureException as PSRemotingTransportException;
                string fQEIDFromTransportError         = WSManTransportManagerUtils.GetFQEIDFromTransportError((exception != null) ? exception.ErrorCode : 0, "PSSessionStateBroken");
                if (exception != null)
                {
                    str2 = "[" + runspace.ConnectionInfo.ComputerName + "] ";
                    if (exception.ErrorCode == -2144108135)
                    {
                        string str4 = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.URIRedirectionReported, new object[] { exception.Message, "MaximumConnectionRedirectionCount", "PSSessionOption", "AllowRedirection" });
                        str2 = str2 + str4;
                    }
                    else if (!string.IsNullOrEmpty(exception.Message))
                    {
                        str2 = str2 + exception.Message;
                    }
                    else if (!string.IsNullOrEmpty(exception.TransportMessage))
                    {
                        str2 = str2 + exception.TransportMessage;
                    }
                }
                if (failureException == null)
                {
                    failureException = new RuntimeException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.RemoteRunspaceOpenUnknownState, new object[] { runspace.RunspaceStateInfo.State }));
                }
                failureErrorRecord = new ErrorRecord(failureException, computerName, fQEIDFromTransportError, ErrorCategory.OpenError, null, null, null, null, null, str2, null);
            }
            else if (pipeline.PipelineStateInfo.State == PipelineState.Failed)
            {
                object targetObject = runspace.ConnectionInfo.ComputerName;
                failureException = pipeline.PipelineStateInfo.Reason;
                if (failureException != null)
                {
                    RemoteException exception2  = failureException as RemoteException;
                    ErrorRecord     errorRecord = null;
                    if (exception2 != null)
                    {
                        errorRecord = exception2.ErrorRecord;
                    }
                    else
                    {
                        errorRecord = new ErrorRecord(pipeline.PipelineStateInfo.Reason, "JobFailure", ErrorCategory.OperationStopped, targetObject);
                    }
                    string     str5       = ((RemoteRunspace)pipeline.GetRunspace()).ConnectionInfo.ComputerName;
                    Guid       instanceId = pipeline.GetRunspace().InstanceId;
                    OriginInfo originInfo = new OriginInfo(str5, instanceId);
                    failureErrorRecord = new RemotingErrorRecord(errorRecord, originInfo);
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Handle the object obtained from an ObjectStream's reader
        /// based on its type.
        /// </summary>
        /// <param name="cmdlet">Cmdlet to use for outputting the object.</param>
        /// <param name="instanceId"></param>
        /// <param name="overrideInquire">Suppresses prompt on messages with Inquire preference.
        /// Needed for Receive-Job</param>
        internal void WriteStreamObject(Cmdlet cmdlet, Guid instanceId, bool overrideInquire = false)
        {
            switch (ObjectType)
            {
            case PSStreamObjectType.Output:
            {
                if (instanceId != Guid.Empty)
                {
                    PSObject o = Value as PSObject;
                    if (o != null)
                    {
                        AddSourceJobNoteProperty(o, instanceId);
                    }
                }

                cmdlet.WriteObject(Value);
            }

            break;

            case PSStreamObjectType.Error:
            {
                ErrorRecord         errorRecord       = (ErrorRecord)this.Value;
                RemotingErrorRecord remoteErrorRecord = errorRecord as RemotingErrorRecord;

                if (remoteErrorRecord == null)
                {
                    // if we get a base ErrorRecord object, check if the computerName is
                    // populated in the RecommendedAction field
                    if (errorRecord.ErrorDetails != null && !string.IsNullOrEmpty(errorRecord.ErrorDetails.RecommendedAction))
                    {
                        string computerName;
                        Guid   jobInstanceId;
                        GetIdentifierInfo(errorRecord.ErrorDetails.RecommendedAction,
                                          out jobInstanceId, out computerName);

                        errorRecord = new RemotingErrorRecord(errorRecord,
                                                              new OriginInfo(computerName, Guid.Empty,
                                                                             jobInstanceId));
                    }
                }
                else
                {
                    errorRecord = remoteErrorRecord;
                }

                errorRecord.PreserveInvocationInfoOnce = true;
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteError(errorRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Warning:
            {
                string            warning           = (string)Value;
                WarningRecord     warningRecord     = new WarningRecord(warning);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteWarning(warningRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Verbose:
            {
                string            verbose           = (string)Value;
                VerboseRecord     verboseRecord     = new VerboseRecord(verbose);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteVerbose(verboseRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Progress:
            {
                ProgressRecord progressRecord = (ProgressRecord)Value;

                RemotingProgressRecord remotingProgressRecord = progressRecord as RemotingProgressRecord;
                if (remotingProgressRecord == null)
                {
                    Guid   jobInstanceId;
                    string computerName;
                    GetIdentifierInfo(progressRecord.CurrentOperation, out jobInstanceId,
                                      out computerName);
                    OriginInfo info = new OriginInfo(computerName, Guid.Empty, jobInstanceId);
                    progressRecord = new RemotingProgressRecord(progressRecord, info);
                }
                else
                {
                    progressRecord = remotingProgressRecord;
                }

                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteProgress(progressRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Debug:
            {
                string            debug             = (string)Value;
                DebugRecord       debugRecord       = new DebugRecord(debug);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteDebug(debugRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Information:
            {
                InformationRecord         informationRecord       = (InformationRecord)this.Value;
                RemotingInformationRecord remoteInformationRecord = informationRecord as RemotingInformationRecord;

                if (remoteInformationRecord == null)
                {
                    // if we get a base InformationRecord object, check if the computerName is
                    // populated in the Source field
                    if (!string.IsNullOrEmpty(informationRecord.Source))
                    {
                        string computerName;
                        Guid   jobInstanceId;
                        GetIdentifierInfo(informationRecord.Source, out jobInstanceId, out computerName);
                        informationRecord = new RemotingInformationRecord(informationRecord,
                                                                          new OriginInfo(computerName, Guid.Empty,
                                                                                         jobInstanceId));
                    }
                }
                else
                {
                    informationRecord = remoteInformationRecord;
                }

                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteInformation(informationRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.WarningRecord:
            case PSStreamObjectType.MethodExecutor:
            case PSStreamObjectType.BlockingError:
            case PSStreamObjectType.ShouldMethod:
            {
                WriteStreamObject(cmdlet, overrideInquire);
            }

            break;
            }
        }
Esempio n. 18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="message">The debug message that is wrapped</param>
 /// <param name="originInfo">The origin information</param>
 public RemotingDebugRecord(string message, OriginInfo originInfo) : base(message)
 {
     _originInfo = originInfo;
 }