public override string ToString() { StringBuilder stringBuilder = new StringBuilder(this.CommandText); foreach (object obj in this.Parameters) { MonadParameter monadParameter = (MonadParameter)obj; if (monadParameter.IsSwitch) { stringBuilder.Append(" -" + monadParameter.ParameterName); } else { string text = MonadCommand.FormatParameterValue(monadParameter.Value); if (!string.IsNullOrEmpty(text)) { stringBuilder.Append(" -" + monadParameter.ParameterName + " " + text.ToString()); } else { stringBuilder.Append(" -" + monadParameter.ParameterName + " ''"); } } } return(stringBuilder.ToString()); }
internal static string FormatParameterValue(object value) { if (value != null && value is IList) { StringBuilder stringBuilder = new StringBuilder(); if (value is byte[]) { stringBuilder.AppendFormat("'{0}'", Strings.BinaryDataStakeHodler); } else { IList list = (IList)value; for (int i = 0; i < list.Count - 1; i++) { stringBuilder.Append(MonadCommand.FormatNonListParameterValue(list[i]) + ","); } if (list.Count > 0) { stringBuilder.Append(MonadCommand.FormatNonListParameterValue(list[list.Count - 1])); } else { stringBuilder.Append("@()"); } } return(stringBuilder.ToString()); } return(MonadCommand.FormatNonListParameterValue(value)); }
internal static PSDataCollection <object> Serialize(IEnumerable collection) { PSDataCollection <object> psdataCollection = new PSDataCollection <object>(); if (collection != null) { foreach (object obj in collection) { if (MonadCommand.CanSerialize(obj)) { psdataCollection.Add(MonadCommand.Serialize(obj)); } else if (obj is Enum) { psdataCollection.Add(obj.ToString()); } else { psdataCollection.Add(obj); } } } psdataCollection.Complete(); return(psdataCollection); }
public object[] EndExecute(MonadAsyncResult asyncResult) { ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.EndExecute()"); if (asyncResult.RunningCommand != this) { throw new ArgumentException("Parameter does not correspond to this command.", "asyncResult"); } List <object> list = null; try { Collection <PSObject> collection = this.pipelineProxy.EndInvoke(asyncResult); bool flag = false; if (this.Connection.IsRemote && collection.Count > 0 && collection[0] != null && collection[0].BaseObject != null && collection[0].BaseObject is PSCustomObject) { flag = MonadCommand.CanDeserialize(collection[0]); } list = new List <object>(collection.Count); ExTraceGlobals.IntegrationTracer.Information <int>((long)this.GetHashCode(), "\tPipeline contains {0} results", collection.Count); for (int i = 0; i < collection.Count; i++) { if (collection[i] == null) { ExTraceGlobals.VerboseTracer.Information <int>((long)this.GetHashCode(), "\tPipeline contains a null result at position {0}", i); } else { if (collection[i].BaseObject == null) { throw new InvalidOperationException("Pure PSObjects are not supported."); } if (!this.Connection.IsRemote) { list.Add(collection[i].BaseObject); } else if (flag) { list.Add(MonadCommand.Deserialize(collection[i])); } else { list.Add(collection[i]); } } } } finally { this.Connection.NotifyExecutionFinished(); if (this.EndExecution != null) { this.EndExecution(this, new RunGuidEventArgs(this.guid)); } this.Connection.CurrentCommand = null; this.pipelineProxy = null; } ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.EndExecute()"); return(list.ToArray()); }
// Token: 0x06001087 RID: 4231 RVA: 0x00032A73 File Offset: 0x00030C73 private object UnWrappPSObject(PSObject element) { if (this.isRemote && element.BaseObject != null && element.BaseObject is PSCustomObject && MonadCommand.CanDeserialize(element)) { return(MonadCommand.Deserialize(element)); } return(element.BaseObject); }
// Token: 0x060010CA RID: 4298 RVA: 0x00033B8C File Offset: 0x00031D8C private ErrorRecord ResolveErrorRecord(ErrorRecord errorRecord) { RemoteException ex = errorRecord.Exception as RemoteException; if (ex != null) { return(new ErrorRecord(MonadCommand.DeserializeException(ex), errorRecord.FullyQualifiedErrorId, errorRecord.CategoryInfo.Category, errorRecord.TargetObject)); } return(errorRecord); }
internal static Exception DeserializeException(Exception ex) { RemoteException ex2 = ex as RemoteException; if (ex2 != null && MonadCommand.CanDeserialize(ex2.SerializedRemoteException)) { return((MonadCommand.Deserialize(ex2.SerializedRemoteException) as Exception) ?? ex); } return(ex); }
internal static bool CanDeserialize(PSObject psObject) { if (psObject == null || psObject.Members["SerializationData"] == null || psObject.Members["SerializationData"].Value == null) { return(false); } Type destinationType = MonadCommand.ResolveType(psObject); return(MonadCommand.TypeConverter.CanConvertFrom(psObject, destinationType)); }
// Token: 0x06000F1E RID: 3870 RVA: 0x0002BA80 File Offset: 0x00029C80 internal MonadAsyncResult(MonadCommand runningCommand, AsyncCallback callback, object stateObject, IAsyncResult psAsyncResult, PSDataCollection <PSObject> output) { ExTraceGlobals.IntegrationTracer.Information <string>((long)this.GetHashCode(), "new MonadAsyncResult({0})", runningCommand.CommandText); this.runningCommand = runningCommand; this.asyncState = stateObject; this.callback = callback; this.completionEvent = new ManualResetEvent(false); runningCommand.ActivePipeline.InvocationStateChanged += this.PipelineStateChanged; this.SetIsCompleted(runningCommand.ActivePipeline.InvocationStateInfo.State); this.psAsyncResult = psAsyncResult; this.output = output; }
public ProgressReportEventArgs(ProgressRecord progressRecord, MonadCommand command) { if (progressRecord == null) { throw new ArgumentNullException("progressRecord"); } if (command == null) { throw new ArgumentNullException("command"); } this.progressRecord = progressRecord; this.command = command; }
private PSCommand GetPipelineCommand(out IEnumerable pipelineInputFromScript) { ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.GetPipelineCommand()"); if (this.CommandText.Contains(" ") && this.CommandType == CommandType.StoredProcedure) { throw new InvalidOperationException("CommandType.StoredProcedure cannot be used to run scripts. Add any parameters to the Parameters collection."); } ExTraceGlobals.IntegrationTracer.Information <string>((long)this.GetHashCode(), "\tCreating command {0}", this.CommandText); bool flag = this.CommandType == CommandType.Text; PSCommand pscommand = null; pipelineInputFromScript = null; if (this.Connection != null && this.Connection.IsRemote && this.CommandType == CommandType.Text && MonadCommand.scriptRegex.IsMatch(this.CommandText)) { this.ConvertScriptToStoreProcedure(this.CommandText, out pscommand, out pipelineInputFromScript); } else { pscommand = new PSCommand().AddCommand(new Command(this.CommandText, flag, !flag)); foreach (object obj in this.Parameters) { MonadParameter monadParameter = (MonadParameter)obj; if (ParameterDirection.Input != monadParameter.Direction) { throw new InvalidOperationException("ParameterDirection.Input is the only supported parameter type."); } ExTraceGlobals.IntegrationTracer.Information <string, object>((long)this.GetHashCode(), "\tAdding parameter {0} = {1}", monadParameter.ParameterName, monadParameter.Value); if (this.connection.IsRemote && MonadCommand.CanSerialize(monadParameter.Value)) { if (monadParameter.Value is ICollection) { pscommand.AddParameter(monadParameter.ParameterName, MonadCommand.Serialize(monadParameter.Value as IEnumerable)); } else { pscommand.AddParameter(monadParameter.ParameterName, MonadCommand.Serialize(monadParameter.Value)); } } else if (monadParameter.IsSwitch) { pscommand.AddParameter(monadParameter.ParameterName, true); } else { pscommand.AddParameter(monadParameter.ParameterName, monadParameter.Value); } } } ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.GetPipelineCommand()"); return(pscommand); }
// Token: 0x06001005 RID: 4101 RVA: 0x000309AC File Offset: 0x0002EBAC protected override void FillProperties(Type type, PSObject psObject, object dummyObject, IList <string> properties) { MoveRequestStatisticsPresentationObject moveRequestStatisticsPresentationObject = dummyObject as MoveRequestStatisticsPresentationObject; foreach (PSMemberInfo psmemberInfo in psObject.Members) { if (properties.Contains(psmemberInfo.Name)) { if (psmemberInfo.Name == "Report") { PSObject psobject = psObject.Members[psmemberInfo.Name].Value as PSObject; if (psobject != null) { Type type2 = MonadCommand.ResolveType(psobject); BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; ConstructorInfo constructor = type2.GetConstructor(bindingAttr, null, new Type[] { typeof(Guid) }, null); object obj = constructor.Invoke(new object[] { Guid.Empty }); object value = psobject.Members["Entries"].Value; if (value is PSObject && ((PSObject)value).BaseObject is IList) { IList list = ((PSObject)value).BaseObject as IList; foreach (object obj2 in list) { type2.GetMethod("Append", bindingAttr, null, new Type[] { typeof(LocalizedString) }, null).Invoke(obj, new object[] { new LocalizedString(obj2.ToString()) }); } } PropertyInfo property = moveRequestStatisticsPresentationObject.GetType().GetProperty(psmemberInfo.Name); property.SetValue(moveRequestStatisticsPresentationObject, obj, null); } } else { PropertyInfo property2 = moveRequestStatisticsPresentationObject.GetType().GetProperty(psmemberInfo.Name); property2.SetValue(moveRequestStatisticsPresentationObject, MockObjectCreator.GetSingleProperty(psObject.Members[psmemberInfo.Name].Value, property2.PropertyType), null); } } } }
protected override void InitializeRunspace(Runspace runspace) { PSCommand pscommand = new PSCommand(); pscommand.AddCommand("ConsoleInitialize.ps1"); this.ExecuteCommand(pscommand, runspace); if (this.serverSettings != null) { pscommand = new PSCommand(); pscommand.AddCommand("Set-ADServerSettingsForLogonUser"); pscommand.AddParameter("RunspaceServerSettings", MonadCommand.Serialize(this.serverSettings)); this.ExecuteCommand(pscommand, runspace); } }
public WarningReportEventArgs(Guid guid, string warning, int objectIndex, MonadCommand command) : base(guid) { if (warning == null) { throw new ArgumentNullException("warning"); } if (command == null) { throw new ArgumentNullException("command"); } this.SetWarningMessageHelpUrl(warning); this.objectIndex = objectIndex; this.command = command; }
private MonadCommand(MonadCommand from) { this.commandText = from.commandText; this.commandType = from.commandType; this.commandTimeout = from.commandTimeout; this.connection = from.connection; MonadParameterCollection parameters = this.Parameters; foreach (object obj in from.Parameters) { ICloneable cloneable = (ICloneable)obj; parameters.Add(cloneable.Clone()); } this.ErrorReport += from.ErrorReport; this.WarningReport += from.WarningReport; this.StartExecution += from.StartExecution; this.EndExecution += from.EndExecution; }
internal static object Deserialize(PSObject psObject) { if (psObject == null) { throw new ArgumentNullException("psObject"); } if (psObject.Members["SerializationData"] != null && psObject.Members["SerializationData"].Value == null) { throw new ArgumentException("Cannot deserialize PSObject, SerializationData is missing."); } Type type = MonadCommand.ResolveType(psObject); if (psObject.Members["EMCMockEngineEnabled"] != null) { return(MockObjectInformation.TranslateToMockObject(type, psObject)); } return(MonadCommand.TypeConverter.ConvertFrom(psObject, type, null, true)); }
internal static Type ResolveType(PSObject psObject) { if (psObject == null) { throw new ArgumentNullException("psObject"); } lock (MonadCommand.syncInstance) { if (MonadCommand.typeDictionary.ContainsKey(psObject.TypeNames[0])) { return(MonadCommand.typeDictionary[psObject.TypeNames[0]]); } } string text = psObject.TypeNames[0].Substring("Deserialized.".Length); Type type = null; try { type = (Type)LanguagePrimitives.ConvertTo(text, typeof(Type)); } catch (PSInvalidCastException) { type = MonadCommand.ResolvePSType(psObject, text); if (type == null) { throw; } } lock (MonadCommand.syncInstance) { if (!MonadCommand.typeDictionary.ContainsKey(psObject.TypeNames[0])) { MonadCommand.typeDictionary.Add(psObject.TypeNames[0], type); } } return(type); }
// Token: 0x0600105A RID: 4186 RVA: 0x00031C54 File Offset: 0x0002FE54 internal MonadDataReader(MonadCommand command, CommandBehavior behavior, MonadAsyncResult asyncResult) { ExTraceGlobals.IntegrationTracer.Information <string, CommandBehavior>((long)this.GetHashCode(), "--> new MonadDataReader({0}, {1})", command.CommandText, behavior); this.command = command; this.commandBehavior = behavior; this.connection = command.Connection; this.isRemote = command.Connection.IsRemote; this.asyncResult = asyncResult; PSDataCollection <PSObject> output = asyncResult.Output; this.command.ActivePipeline.InvocationStateChanged += this.PipelineStateChanged; output.DataAdded += this.PipelineDataAdded; if (this.WaitOne(output)) { ExTraceGlobals.VerboseTracer.Information((long)this.GetHashCode(), "\tFirst result ready."); PSObject psobject = output[0]; PagedPositionInfo pagedPositionInfo = this.UnWrappPSObject(psobject) as PagedPositionInfo; if (pagedPositionInfo != null) { ExTraceGlobals.VerboseTracer.Information((long)this.GetHashCode(), "\tPagedPositionInfo object found."); output.RemoveAt(0); this.positionInfo = pagedPositionInfo; psobject = null; if (this.WaitOne(output)) { psobject = output[0]; } } if (psobject != null) { ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "\tFirst object returned, generating schema."); this.GenerateSchema(psobject); this.firstResult = this.UnWrappPSObject(psobject); } } ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<-- new MonadDataReader()"); }
private void CreatePipeline(IEnumerable pipelineInput, PSCommand commands, IEnumerable pipelineInputFromScript) { ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.CreatePipeline(input)"); if (this.pipelineProxy != null) { throw new InvalidOperationException("The command is already executing."); } if (this.Connection == null || (this.Connection.State & ConnectionState.Open) == ConnectionState.Closed) { throw new InvalidOperationException("The command requires an open connection."); } if (pipelineInputFromScript != null) { this.pipelineProxy = new MonadPipelineProxy(this.Connection.RunspaceProxy, pipelineInputFromScript, commands); } else if (pipelineInput != null) { if (this.connection.IsRemote) { this.pipelineProxy = new MonadPipelineProxy(this.Connection.RunspaceProxy, MonadCommand.Serialize(pipelineInput), commands); } else { this.pipelineProxy = new MonadPipelineProxy(this.Connection.RunspaceProxy, pipelineInput, commands); } } else { this.pipelineProxy = new MonadPipelineProxy(this.Connection.RunspaceProxy, commands); } this.InitializePipelineProxy(); ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.CreatePipeline(input)"); }
private void CreatePipeline(WorkUnit[] workUnits, PSCommand commands) { ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.CreatePipeline(workUnits)"); if (this.pipelineProxy != null) { throw new InvalidOperationException("The command is already executing."); } if (this.Connection == null || (this.Connection.State & ConnectionState.Open) == ConnectionState.Closed) { throw new InvalidOperationException("The command requires an open connection."); } if (this.connection.IsRemote) { using (PSDataCollection <object> powerShellInput = WorkUnitBase.GetPowerShellInput <object>(workUnits)) { this.pipelineProxy = new MonadPipelineProxy(this.Connection.RunspaceProxy, MonadCommand.Serialize(powerShellInput), commands, workUnits); goto IL_A7; } } this.pipelineProxy = new MonadPipelineProxy(this.Connection.RunspaceProxy, WorkUnitBase.GetPowerShellInput <object>(workUnits), commands, workUnits); IL_A7: this.InitializePipelineProxy(); ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.CreatePipeline(workUnits)"); }
public ErrorReportEventArgs(Guid guid, ErrorRecord errorRecord, int objectIndex, MonadCommand command) : base(guid) { if (errorRecord == null) { throw new ArgumentNullException("errorRecord"); } if (command == null) { throw new ArgumentNullException("command"); } this.errorRecord = errorRecord; this.objectIndex = objectIndex; this.command = command; }
public MonadDataAdapter(MonadCommand selectCommand) : this() { this.SelectCommand = selectCommand; }
// Token: 0x06001059 RID: 4185 RVA: 0x00031C3F File Offset: 0x0002FE3F internal MonadDataReader(MonadCommand command, CommandBehavior behavior, MonadAsyncResult asyncResult, string preservedObjectProperty) : this(command, behavior, asyncResult) { this.preservedObjectProperty = preservedObjectProperty; }
// Token: 0x060010C7 RID: 4295 RVA: 0x000337D4 File Offset: 0x000319D4 private Collection <PSObject> ClosePipeline(MonadAsyncResult asyncResult) { ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "-->MonadCommand.ClosePipeline()"); if (base.PowerShell == null) { throw new InvalidOperationException("The command is not currently executing."); } Exception ex = null; Collection <PSObject> result = new Collection <PSObject>(); ExTraceGlobals.VerboseTracer.Information((long)this.GetHashCode(), "\tWaiting for the pipeline to finish."); try { base.PowerShell.EndInvoke(asyncResult.PowerShellIAsyncResult); } catch (Exception) { ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "\tPipeline End Invoke Fired an Exception."); if (base.PowerShell.InvocationStateInfo.Reason == null) { throw; } } ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "\tPipeline finished."); if (base.PowerShell.InvocationStateInfo.State == PSInvocationState.Completed && base.PowerShell.Streams.Error.Count == 0) { result = asyncResult.Output.ReadAll(); } else if (base.PowerShell.InvocationStateInfo.State == PSInvocationState.Stopped || base.PowerShell.InvocationStateInfo.State == PSInvocationState.Failed || base.PowerShell.Streams.Error.Count > 0) { ex = MonadCommand.DeserializeException(base.PowerShell.InvocationStateInfo.Reason); if (ex != null && (this.IsHandledException(ex) || base.PowerShell.InvocationStateInfo.State == PSInvocationState.Stopped)) { ThrowTerminatingErrorException ex2 = ex as ThrowTerminatingErrorException; ErrorRecord errorRecord; if (ex2 != null) { errorRecord = ex2.ErrorRecord; } else { errorRecord = new ErrorRecord(ex, LocalizedException.GenerateErrorCode(ex).ToString("X"), ErrorCategory.InvalidOperation, null); } if (base.WorkUnits != null) { for (int i = 0; i < base.WorkUnits.Length; i++) { if (base.WorkUnits[i].CurrentStatus == 2) { if (base.PowerShell.InvocationStateInfo.State != PSInvocationState.Stopped) { this.lastUnhandledError = errorRecord; break; } } else { base.ReportError(errorRecord, i); base.WorkUnits[i].CurrentStatus = 3; } } } else { base.ReportError(errorRecord, -1); } ex = null; } if (ex == null) { result = asyncResult.Output.ReadAll(); base.DrainErrorStream(-1); } asyncResult.Output.Complete(); base.PowerShell.Streams.Error.Complete(); } this.pipelineStateAtClose = base.PowerShell.InvocationStateInfo.State; if (ex != null && !(ex is PipelineStoppedException)) { ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), ex.ToString()); if (!(ex is CmdletInvocationException)) { int innerErrorCode = LocalizedException.GenerateErrorCode(ex); ex = new CommandExecutionException(innerErrorCode, this.Command.ToString(), ex); } this.InteractionHandler.ReportException(ex); throw ex; } if (this.LastUnhandledError != null) { throw new MonadDataAdapterInvocationException(this.LastUnhandledError, this.Command.ToString()); } ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "<--MonadCommand.ClosePipeline()"); return(result); }