Пример #1
0
 public static void FaultIfNull(this WebServiceParameters properties)
 {
     if (properties == null)
     {
         throw new FaultException(new ArgumentNullException("properties").Message);
     }
 }
Пример #2
0
 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 + "."));
         }
     }
 }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }
Пример #6
0
 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);
 }
Пример #7
0
 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);
 }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
0
 private PowerShellResults CoreInvoke(PSCommand psCommand, IEnumerable pipelineInput, Identity translationIdentity, WebServiceParameters parameters)
 {
     return(new PowerShellResults(this.CoreInvoke <PSObject>(psCommand, pipelineInput, translationIdentity, parameters)));
 }
Пример #11
0
        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);
        }
Пример #12
0
 protected PowerShellResults RemoveObjects(string removeCmdlet, Identity[] identities, WebServiceParameters parameters)
 {
     return(this.RemoveObjects(new PSCommand().AddCommand(removeCmdlet), identities, parameters));
 }
Пример #13
0
 protected PowerShellResults RemoveObjects(PSCommand psCommand, Identity[] identities, WebServiceParameters parameters)
 {
     EcpPerfCounters.WebServiceRemoveObject.Increment();
     return(this.Invoke(psCommand, identities, parameters));
 }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }
Пример #16
0
 protected PowerShellResults Invoke(PSCommand psCommand, Identity translationIdentity, WebServiceParameters parameters)
 {
     if (null == translationIdentity)
     {
         throw new ArgumentNullException("translationIdentity");
     }
     return(this.CoreInvoke(psCommand, null, translationIdentity, parameters));
 }
Пример #17
0
        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));
        }
Пример #18
0
 protected virtual void AddParameters(PSCommand installCommand, WebServiceParameters param)
 {
     installCommand.AddParameters(param);
 }
Пример #19
0
        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);
        }
Пример #20
0
 protected override void AddParameters(PSCommand installCommand, WebServiceParameters param)
 {
     base.AddParameters(installCommand, param);
     installCommand.AddParameter("OrganizationApp");
 }
Пример #21
0
 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));
 }
Пример #22
0
 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));
        }
Пример #24
0
 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);
 }