public static void FaultIfNull(this WebServiceParameters properties) { if (properties == null) { throw new FaultException(new ArgumentNullException("properties").Message); } }
private static void EnsureNoWriteTaskInGetRequest(PSCommand psCommand, WebServiceParameters parameters) { if (HttpContext.Current.Request.HttpMethod == "GET" && (parameters == null || !parameters.AllowExceuteThruHttpGetRequest)) { string cmdletName = psCommand.GetCmdletName(); if (!cmdletName.StartsWith("Get-", StringComparison.OrdinalIgnoreCase) && !cmdletName.StartsWith("Test-", StringComparison.OrdinalIgnoreCase) && !cmdletName.StartsWith("Export-", StringComparison.OrdinalIgnoreCase) && !cmdletName.StartsWith("Search-", StringComparison.OrdinalIgnoreCase)) { throw new BadRequestException(new InvalidOperationException("HTTP GET request is not allowed to invoke any cmdlet that can make any change to Exchange AD/Store. Cmdlet: " + cmdletName + ".")); } } }
public PowerShellResults ProcessUpload(UploadFileContext context, WebServiceParameters param) { param.FaultIfNull(); UploadUMParameter uploadUMParameter = (UploadUMParameter)param; uploadUMParameter.PromptFileStream = context.FileStream; uploadUMParameter.PromptFileName = Path.GetFileName(context.FileName); if (uploadUMParameter.UMAutoAttendant == null && uploadUMParameter.UMDialPlan == null) { uploadUMParameter.UMAutoAttendant.FaultIfNull(); } return(this.ImportObject(uploadUMParameter)); }
public PowerShellResults ProcessUpload(UploadFileContext context, WebServiceParameters param) { param.FaultIfNull(); SetUserPhotoParameters setUserPhotoParameters = (SetUserPhotoParameters)param; setUserPhotoParameters.PhotoStream = context.FileStream; Identity identity = Identity.ParseIdentity(setUserPhotoParameters.Identity); if (identity == null || string.IsNullOrEmpty(identity.RawIdentity)) { throw new BadQueryParameterException("Identity"); } return(this.SetPhoto(identity, context.FileStream)); }
public PowerShellResults ProcessUpload(UploadFileContext context, WebServiceParameters param) { param.FaultIfNull(); UploadExtensionParameter uploadExtensionParameter = (UploadExtensionParameter)param; uploadExtensionParameter.FileStream = context.FileStream; if (RbacPrincipal.Current.RbacConfiguration.HasRoleOfType(RoleType.MyReadWriteMailboxApps)) { uploadExtensionParameter.AllowReadWriteMailbox = new SwitchParameter(true); } PSCommand pscommand = new PSCommand().AddCommand("New-App"); this.AddParameters(pscommand, param); return(base.Invoke <ExtensionRow>(pscommand)); }
public PowerShellResults ProcessUpload(UploadFileContext context, WebServiceParameters parameters) { parameters.FaultIfNull(); if (parameters is FingerprintUploadParameters) { FingerprintUploadParameters fingerprintUploadParameters = (FingerprintUploadParameters)parameters; byte[] array = new byte[context.FileStream.Length]; context.FileStream.Read(array, 0, array.Length); fingerprintUploadParameters.FileData = array; string description = context.FileName.Substring(context.FileName.LastIndexOf("\\") + 1); fingerprintUploadParameters.Description = description; return(base.NewObject <Fingerprint, FingerprintUploadParameters>("New-Fingerprint", fingerprintUploadParameters)); } return(null); }
public static PSCommand AddParameters(this PSCommand psCommand, WebServiceParameters parameters) { if (parameters != null) { foreach (KeyValuePair <string, object> keyValuePair in parameters) { psCommand.AddParameter(keyValuePair.Key, keyValuePair.Value); } if (parameters.CanSuppressConfirm) { string suppressConfirmParameterName = parameters.SuppressConfirmParameterName; if (parameters.SuppressConfirm) { psCommand.AddParameter(parameters.SuppressConfirmParameterName, new SwitchParameter(true)); } } } return(psCommand); }
public virtual PowerShellResults ProcessUpload(UploadFileContext context, WebServiceParameters parameters) { PowerShellResults result; using (MemoryStream memoryStream = new MemoryStream(Math.Max((int)context.FileStream.Length / 2, 1024))) { using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Compress)) { context.FileStream.CopyTo(gzipStream); } result = new PowerShellResults <EncodedFile> { Output = new EncodedFile[] { new EncodedFile { FileContent = Convert.ToBase64String(memoryStream.ToArray()) } } }; } return(result); }
private static PowerShellResults <O> InvokeCore <O>(PSCommand psCommand, RunspaceMediator runspaceMediator, IEnumerable pipelineInput, WebServiceParameters parameters, CmdletActivity activity, bool isGetListAsync) { Func <WarningRecord, string> func = null; Func <Command, string> func2 = null; PSCommandExtension.EnsureNoWriteTaskInGetRequest(psCommand, parameters); PowerShellResults <O> powerShellResults = new PowerShellResults <O>(); ExTraceGlobals.EventLogTracer.TraceInformation <string, EcpTraceFormatter <PSCommand> >(0, 0L, "{0} tries to invoke {1}. For more details, refer to task trace", RbacPrincipal.Current.NameForEventLog, psCommand.GetTraceFormatter()); using (RunspaceProxy runspaceProxy = new RunspaceProxy(runspaceMediator)) { runspaceProxy.SetVariable("ConfirmPreference", "None"); if (parameters != null) { psCommand.AddParameters(parameters); } using (PowerShell powerShell = runspaceProxy.CreatePowerShell(psCommand)) { List <PSObject> list = null; if (activity != null) { AsyncServiceManager.RegisterPowerShellToActivity(powerShell, activity, pipelineInput, out list, isGetListAsync); } else { AsyncServiceManager.RegisterPowerShell(powerShell); } int requestLatency = 0; DateTime utcNow = DateTime.UtcNow; try { TaskPerformanceRecord taskPerformanceRecord = new TaskPerformanceRecord(psCommand.GetCmdletName(), PSCommandExtension.powerShellLatencyDetectionContextFactory, EcpEventLogConstants.Tuple_EcpPowerShellInvoked, EcpEventLogConstants.Tuple_EcpPowerShellCompleted, EcpEventLogExtensions.EventLog, new IPerformanceDataProvider[] { PerformanceContext.Current, RpcDataProvider.Instance, TaskPerformanceData.CmdletInvoked, TaskPerformanceData.BeginProcessingInvoked, TaskPerformanceData.ProcessRecordInvoked, TaskPerformanceData.EndProcessingInvoked, EcpPerformanceData.PowerShellInvoke }); try { using (EcpPerformanceData.PowerShellInvoke.StartRequestTimer()) { if (list == null) { powerShellResults.Output = powerShell.Invoke <O>(pipelineInput).ToArray <O>(); } else { powerShell.Invoke <PSObject>(pipelineInput, list); powerShellResults.Output = Array <O> .Empty; } } } finally { requestLatency = (int)taskPerformanceRecord.Stop().TotalMilliseconds; IDisposable disposable2 = taskPerformanceRecord; if (disposable2 != null) { disposable2.Dispose(); } } List <ErrorRecord> list2 = new List <ErrorRecord>(); bool flag = false; foreach (ErrorRecord errorRecord in powerShell.Streams.Error) { if (!flag) { flag = PSCommandExtension.TryPatchShouldContinueException(errorRecord, psCommand, parameters); } list2.Add(new ErrorRecord(errorRecord)); } powerShellResults.ErrorRecords = list2.ToArray(); PowerShellResults powerShellResults2 = powerShellResults; IEnumerable <WarningRecord> warning = powerShell.Streams.Warning; if (func == null) { func = ((WarningRecord warningRecord) => warningRecord.Message); } powerShellResults2.Warnings = warning.Select(func).ToArray <string>(); } catch (RuntimeException ex) { PSCommandExtension.TryPatchShouldContinueException(ex.ErrorRecord, psCommand, parameters); ErrorRecord errorRecord2; if (ex.ErrorRecord != null && !(ex is ParameterBindingException)) { errorRecord2 = new ErrorRecord(ex.ErrorRecord); } else { errorRecord2 = new ErrorRecord(ex); } powerShellResults.ErrorRecords = new ErrorRecord[] { errorRecord2 }; } finally { string text = HttpContext.Current.Request.QueryString["reqId"]; ServerLogEvent logEvent = new ServerLogEvent(psCommand, pipelineInput, requestLatency, string.IsNullOrEmpty(text) ? string.Empty : text, (powerShellResults.ErrorRecords != null && powerShellResults.ErrorRecords.Length > 0) ? powerShellResults.ErrorRecords.ToLogString() : string.Empty, (powerShellResults.Output != null) ? powerShellResults.Output.Length : 0); ServerLogger.Instance.LogEvent(logEvent); } PowerShellResults powerShellResults3 = powerShellResults; IEnumerable <Command> commands = psCommand.Commands; if (func2 == null) { func2 = ((Command cmd) => cmd.CommandText); } powerShellResults3.Cmdlets = commands.Select(func2).ToArray <string>(); if (powerShellResults.ErrorRecords.Length > 0) { ExTraceGlobals.EventLogTracer.TraceError <string, EcpTraceFormatter <PSCommand>, EcpTraceFormatter <ErrorRecord[]> >(0, 0L, "{0} invoked {1} and encountered errors: {2}", RbacPrincipal.Current.NameForEventLog, psCommand.GetTraceFormatter(), powerShellResults.ErrorRecords.GetTraceFormatter()); } CmdExecuteInfo cmdExecuteInfo = CmdletLogger.CaculateLogAndSaveToContext(powerShell, utcNow, powerShellResults.ErrorRecords); if (cmdExecuteInfo != null) { powerShellResults.CmdletLogInfo = new CmdExecuteInfo[] { cmdExecuteInfo }; } } } return(powerShellResults); }
private PowerShellResults CoreInvoke(PSCommand psCommand, IEnumerable pipelineInput, Identity translationIdentity, WebServiceParameters parameters) { return(new PowerShellResults(this.CoreInvoke <PSObject>(psCommand, pipelineInput, translationIdentity, parameters))); }
private PowerShellResults <T> CoreInvoke <T>(PSCommand psCommand, IEnumerable pipelineInput, Identity translationIdentity, WebServiceParameters parameters) { PowerShellResults <T> powerShellResults = psCommand.Invoke(this.runspaceMediator, pipelineInput, parameters); powerShellResults.TranslationIdentity = translationIdentity; return(powerShellResults); }
protected PowerShellResults RemoveObjects(string removeCmdlet, Identity[] identities, WebServiceParameters parameters) { return(this.RemoveObjects(new PSCommand().AddCommand(removeCmdlet), identities, parameters)); }
protected PowerShellResults RemoveObjects(PSCommand psCommand, Identity[] identities, WebServiceParameters parameters) { EcpPerfCounters.WebServiceRemoveObject.Increment(); return(this.Invoke(psCommand, identities, parameters)); }
protected PowerShellResults <O> InvokeAndGetObject <O>(PSCommand psCommand, Identity[] identities, WebServiceParameters parameters) where O : BaseRow { PowerShellResults <O> powerShellResults = new PowerShellResults <O>(); powerShellResults.MergeErrors(this.Invoke(psCommand, identities, parameters)); if (powerShellResults.Succeeded && identities.Length <= 5) { IGetObjectForListService <O> getObjectForListService = this as IGetObjectForListService <O>; Func <Identity, PowerShellResults <O> > func; if (getObjectForListService != null) { func = ((Identity x) => getObjectForListService.GetObjectForList(x)); } else { IGetObjectService <O> getObjectService = this as IGetObjectService <O>; if (getObjectService == null) { throw new Exception("Either IGetObjectForListService or IGetObjectService must be implemented for single row refresh."); } func = ((Identity x) => getObjectService.GetObject(x)); } PowerShellResults <O> powerShellResults2 = new PowerShellResults <O>(); try { for (int i = 0; i < identities.Length; i++) { powerShellResults2.MergeAll(func(identities[i])); if (powerShellResults2.Failed) { break; } } } catch (SecurityException) { if (powerShellResults2.HasValue) { throw; } } if (powerShellResults2.SucceededWithValue) { powerShellResults.MergeAll(powerShellResults2); } } return(powerShellResults); }
protected PowerShellResults RemoveObjects(string removeCmdlet, Identity identity, Identity[] identities, string parameterNameForIdentities, WebServiceParameters parameters) { EcpPerfCounters.WebServiceRemoveObject.Increment(); PowerShellResults powerShellResults = new PowerShellResults(); foreach (Identity identity2 in identities) { PSCommand psCommand = new PSCommand().AddCommand(removeCmdlet).AddParameter("Identity", identity).AddParameter(parameterNameForIdentities, identity2.RawIdentity); powerShellResults.MergeErrors(this.Invoke(psCommand, identity, parameters)); } return(powerShellResults); }
protected PowerShellResults Invoke(PSCommand psCommand, Identity translationIdentity, WebServiceParameters parameters) { if (null == translationIdentity) { throw new ArgumentNullException("translationIdentity"); } return(this.CoreInvoke(psCommand, null, translationIdentity, parameters)); }
protected PowerShellResults Invoke(PSCommand psCommand, Identity[] identities, WebServiceParameters parameters) { identities.FaultIfNullOrEmpty(); Identity translationIdentity = (identities.Length == 1) ? identities[0] : null; return(this.CoreInvoke(psCommand, identities.ToIdParameters(), translationIdentity, parameters)); }
protected virtual void AddParameters(PSCommand installCommand, WebServiceParameters param) { installCommand.AddParameters(param); }
protected PowerShellResults ChangePriority <T>(Identity[] identities, int offset, WebServiceParameters parameters) where T : RuleRow { identities.FaultIfNotExactlyOne(); PowerShellResults <T> @object = base.GetObject <T>("Get-" + this.TaskNoun, identities[0]); if (@object.Failed) { return(@object); } int num = @object.Output[0].Priority + offset; if (num < 0) { return(new PowerShellResults()); } PSCommand pscommand = new PSCommand().AddCommand("Set-" + this.TaskNoun); pscommand.AddParameter("Priority", num); PowerShellResults powerShellResults = base.Invoke(pscommand, identities, parameters); if (powerShellResults.ErrorRecords != null && powerShellResults.ErrorRecords.Length == 1 && powerShellResults.ErrorRecords[0].Exception is InvalidPriorityException) { powerShellResults.ErrorRecords = new ErrorRecord[0]; } return(powerShellResults); }
protected override void AddParameters(PSCommand installCommand, WebServiceParameters param) { base.AddParameters(installCommand, param); installCommand.AddParameter("OrganizationApp"); }
public static PowerShellResults <O> Invoke <O>(this PSCommand psCommand, RunspaceMediator runspaceMediator, IEnumerable pipelineInput, WebServiceParameters parameters) { return(PSCommandExtension.InvokeCore <O>(psCommand, runspaceMediator, pipelineInput, parameters, null, false)); }
public static PowerShellResults <O> Invoke <O>(this PSCommand psCommand, RunspaceMediator runspaceMediator, IEnumerable pipelineInput, WebServiceParameters parameters, CmdletActivity activity, bool isGetListAsync) { return(PSCommandExtension.InvokeCore <O>(psCommand, runspaceMediator, pipelineInput, parameters, activity, isGetListAsync)); }
public override PowerShellResults ProcessUpload(UploadFileContext context, WebServiceParameters parameters) { string migrationBatchType = ((MigrationCsvUploadParameters)parameters).MigrationBatchType; string a; if ((a = migrationBatchType) != null) { MigrationBatchCsvSchema migrationBatchCsvSchema; if (!(a == "LocalMove")) { if (!(a == "RemoteMove")) { if (!(a == "Staged")) { if (!(a == "IMAP")) { if (!(a == "Cutover")) { goto IL_7C; } goto IL_7C; } else { migrationBatchCsvSchema = new MigrationBatchCsvSchema(); } } else { migrationBatchCsvSchema = new ExchangeMigrationBatchCsvSchema(); } } else { migrationBatchCsvSchema = new MigrationRemoteMoveCsvSchema(); } } else { migrationBatchCsvSchema = new MigrationLocalMoveCsvSchema(); } migrationBatchCsvSchema.AllowUnknownColumnsInCSV = ((MigrationCsvUploadParameters)parameters).AllowUnknownColumnsInCsv; CsvRow?csvRow = null; int num = 0; using (MemoryStream memoryStream = new MemoryStream((int)context.FileStream.Length)) { context.FileStream.CopyTo(memoryStream); context.FileStream.Position = 0L; memoryStream.Position = 0L; try { foreach (CsvRow csvRow2 in migrationBatchCsvSchema.Read(memoryStream)) { if (csvRow2.Index > 0) { csvRow = new CsvRow?(csvRow ?? csvRow2); num++; } } } catch (CsvUnknownColumnsException ex) { throw new UnknownColumnsInCsvException(ex.Columns); } } if (num == 0) { throw new LocalizedException(Strings.NoMailboxInCsv); } PowerShellResults <EncodedFile> powerShellResults = (PowerShellResults <EncodedFile>)base.ProcessUpload(context, parameters); return(new PowerShellResults <MigrationCsvFile> { Output = new MigrationCsvFile[] { new MigrationCsvFile { FileContent = powerShellResults.Value.FileContent, MailboxCount = num, FirstSmtpAddress = ((csvRow != null) ? csvRow.Value["EmailAddress"] : null) } } }); } IL_7C: throw new Exception(string.Format("Migration type '{0}' doesn't require CSV input.", migrationBatchType)); }
private static bool TryPatchShouldContinueException(ErrorRecord errorRecord, PSCommand psCommand, WebServiceParameters parameters) { if (errorRecord != null && errorRecord.Exception is ShouldContinueException) { ShouldContinueException ex = errorRecord.Exception as ShouldContinueException; ex.Details.CurrentCmdlet = psCommand.GetCmdletName(); ex.Details.SuppressConfirmParameterName = ((parameters != null && parameters.CanSuppressConfirm) ? parameters.SuppressConfirmParameterName : null); return(true); } return(false); }