Exemplo n.º 1
0
        public IList GetData(IEntity entity, Expression expression)
        {
            IPSCommandWrapper ipscommandWrapper = DependencyFactory.CreatePSCommandWrapper();

            ipscommandWrapper.AddCommand(entity.TaskInvocationInfo.CmdletName);
            if (entity.TaskInvocationInfo.Parameters != null)
            {
                foreach (KeyValuePair <string, string> keyValuePair in entity.TaskInvocationInfo.Parameters)
                {
                    ipscommandWrapper.AddParameter(keyValuePair.Key, keyValuePair.Value);
                }
            }
            if (!this.principal.IsInRole(string.Format("{0}\\{1}?{2}", entity.TaskInvocationInfo.SnapinName, entity.TaskInvocationInfo.CmdletName, "Expression")))
            {
                throw new InvalidOperationException(string.Format("Expression parameter is not avaible for the cmdlet {0}\\{1}. Add an entry in Microsoft.Exchange.Configuration.Authorization.ClientRoleEntries.TenantReportingRequiredParameters for your cmdlet.", entity.TaskInvocationInfo.SnapinName, entity.TaskInvocationInfo.CmdletName));
            }
            ipscommandWrapper.AddParameter("Expression", expression);
            IList data = null;

            using (new AverageTimePerfCounter(RwsPerfCounters.AverageReportCmdletResponseTime, RwsPerfCounters.AverageReportCmdletResponseTimeBase, true))
            {
                PowerShellResults result = ipscommandWrapper.Invoke(ReportingDataSource.RunspaceMediator);
                if (result.Succeeded)
                {
                    ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.CreateGenericTypeListForResults, delegate
                    {
                        data = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[]
                        {
                            entity.ClrType
                        }), new object[]
                        {
                            result.Output.Count
                        });
                    });
                    foreach (PSObject psobject in result.Output)
                    {
                        data.Add(psobject.BaseObject);
                    }
                    ReportingDataSource.reportRowCounter.AddSample((long)data.Count);
                }
                else
                {
                    ReportingWebServiceEventLogConstants.Tuple_InvokeCmdletFailed.LogEvent(new object[]
                    {
                        EventLogExtension.GetUserNameToLog(),
                        ipscommandWrapper.Commands[0].CommandText,
                        result.Errors[0].Exception
                    });
                    RwsPerfCounters.ReportCmdletErrors.Increment();
                    this.ThrowError(result.Errors[0]);
                }
            }
            return(data);
        }
Exemplo n.º 2
0
        internal static void ReportUnhandledException(Exception exception, HttpContext httpContext)
        {
            Exception ex = exception;

            if (exception is DataServiceException && exception.InnerException != null)
            {
                ex = exception.InnerException;
            }
            if (HttpContext.Current != null && HttpContext.Current.Response != null)
            {
                HttpContext.Current.Response.AddHeader("X-RWS-Error", (ex != null) ? ex.GetType().ToString() : string.Empty);
            }
            bool   flag = !(exception is DataServiceException) || (exception is DataServiceException && ((DataServiceException)exception).ErrorCode.Equals(ReportingErrorCode.UnknownError.ToString(), StringComparison.InvariantCultureIgnoreCase));
            string text;
            int    num;

            if (flag)
            {
                text = string.Format("UnknownError&ExceptionType={0}&ExceptionMessage={1}", (ex != null) ? ex.GetType().ToString() : string.Empty, (ex != null) ? ex.Message : string.Empty);
                num  = 500;
            }
            else
            {
                text = ((DataServiceException)exception).ErrorCode;
                num  = ((DataServiceException)exception).StatusCode;
            }
            RwsPerfCounters.RequestErrors.Increment();
            string text2 = (httpContext != null && httpContext.Request != null) ? httpContext.Request.Url.ToString() : string.Empty;

            ReportingWebServiceEventLogConstants.Tuple_RequestFailed.LogPeriodicEvent(EventLogExtension.GetPeriodicKeyPerUser(), new object[]
            {
                EventLogExtension.GetUserNameToLog(),
                text2,
                num.ToString(),
                text,
                ex,
                (ActivityContext.ActivityId != null) ? ActivityContext.ActivityId.Value.ToString() : "NoActivityId"
            });
            if (ServiceDiagnostics.sendWatsonReportsEnabled && ServiceDiagnostics.IsRWSException(exception) && !(exception is DataServiceException))
            {
                RwsPerfCounters.SendWatson.Increment();
                ExWatson.AddExtraData(text2);
                ExWatson.SendReport(exception);
            }
        }