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); }
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); }