void IErrorHandler.ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            ServiceDiagnostics.ReportUnhandledException(error, HttpContext.Current);
            string text  = HttpContext.Current.Request.QueryString["$format"];
            string text2 = HttpContext.Current.Request.Headers["Accept"];
            XmlObjectSerializer          serializer;
            WebBodyFormatMessageProperty property;

            if ((text != null && text.Equals("json", StringComparison.InvariantCultureIgnoreCase)) || (text2 != null && text2.Equals("application/json", StringComparison.InvariantCultureIgnoreCase)))
            {
                serializer = new DataContractJsonSerializer(typeof(ServiceFault));
                property   = new WebBodyFormatMessageProperty(WebContentFormat.Json);
            }
            else
            {
                serializer = new DataContractSerializer(typeof(ServiceFault));
                property   = new WebBodyFormatMessageProperty(WebContentFormat.Xml);
            }
            fault = Message.CreateMessage(version, string.Empty, new ServiceFault(string.Empty, error), serializer);
            fault.Properties.Add("WebBodyFormatMessageProperty", property);
            HttpResponseMessageProperty httpResponseMessageProperty = new HttpResponseMessageProperty();
            DataServiceException        ex = error as DataServiceException;

            if (ex != null)
            {
                httpResponseMessageProperty.StatusCode = (HttpStatusCode)ex.StatusCode;
            }
            else
            {
                httpResponseMessageProperty.StatusCode = HttpStatusCode.InternalServerError;
            }
            fault.Properties.Add(HttpResponseMessageProperty.Name, httpResponseMessageProperty);
        }
Пример #2
0
        private void LoadConfigFile(string configPath)
        {
            SafeXmlDocument safeXmlDocument = new SafeXmlDocument();

            if (!File.Exists(configPath))
            {
                ReportingWebServiceEventLogConstants.Tuple_LoadReportingschemaFailed.LogEvent(new object[]
                {
                    Strings.ErrorSchemaConfigurationFileMissing(configPath)
                });
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorSchemaInitializationFail, Strings.ErrorSchemaInitializationFail);
            }
            safeXmlDocument.Load(configPath);
            try
            {
                Dictionary <string, ReportingSchema.ReportPropertyCmdletParamMapping[]> reportPropertyCmdletParamMapping = this.LoadRbacMapping(safeXmlDocument);
                this.LoadEntityNodes(safeXmlDocument, reportPropertyCmdletParamMapping);
            }
            catch (ReportingSchema.SchemaLoadException ex)
            {
                ReportingWebServiceEventLogConstants.Tuple_LoadReportingschemaFailed.LogEvent(new object[]
                {
                    ex.Message
                });
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorSchemaInitializationFail, Strings.ErrorSchemaInitializationFail, ex);
            }
        }
Пример #3
0
        private void ThrowError(ErrorRecord errorRecord)
        {
            Exception exception = errorRecord.Exception;

            if (exception is OverBudgetException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorOverBudget, Strings.ErrorOverBudget, exception);
                return;
            }
            if (exception is ConnectionFailedException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ConnectionFailedException, Strings.ConnectionFailedException, exception);
                return;
            }
            if (exception is ADTransientException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ADTransientError, Strings.ADTransientError, exception);
                return;
            }
            if (exception is InvalidExpressionException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.InvalidQueryException, Strings.InvalidQueryException, exception);
                return;
            }
            if (exception is DataMartTimeoutException)
            {
                ServiceDiagnostics.ThrowError(ReportingErrorCode.DataMartTimeoutException, Strings.DataMartTimeoutException, exception);
                return;
            }
            ServiceDiagnostics.ThrowError(ReportingErrorCode.UnknownError, Strings.UnknownError, exception);
        }
 public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
 {
     if (request.Properties.ContainsKey("UriTemplateMatchResults"))
     {
         HttpRequestMessageProperty httpRequestMessageProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
         UriTemplateMatch           uriTemplateMatch           = (UriTemplateMatch)request.Properties["UriTemplateMatchResults"];
         string text = uriTemplateMatch.QueryParameters["$orderby"];
         if (!string.IsNullOrEmpty(text) && text.IndexOf('\'') >= 0)
         {
             ServiceDiagnostics.ThrowError(ReportingErrorCode.InvalidQueryException, "Single quotation marks is not supported in $orderby.");
         }
     }
     return(null);
 }
        private string GetTenantDomain(HttpRequest httpRequest)
        {
            string text = null;

            if (httpRequest.Url.Segments.Any((string segment) => segment.Equals("partner/", StringComparison.OrdinalIgnoreCase)))
            {
                text = httpRequest.QueryString["tenantDomain"];
                if (string.IsNullOrEmpty(text))
                {
                    ExTraceGlobals.ReportingWebServiceTracer.TraceError(0L, "[RbacPrincipalManager::GetTenantDomain] Get tenant domain from query string failed.");
                    ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorMissingTenantDomainInRequest, Strings.ErrorMissingTenantDomainInRequest);
                }
            }
            return(text);
        }
Пример #6
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);
            }
        }
Пример #7
0
        public static string GetCurrentReportingVersion(HttpContext httpContext)
        {
            string text = (string)httpContext.Items["Exchange_RWS_Version"];

            if (string.IsNullOrEmpty(text))
            {
                bool flag  = httpContext.Request.QueryString.AllKeys.Contains(ReportingVersion.QueryStringParameterName);
                bool flag2 = httpContext.Request.Headers.AllKeys.Contains(ReportingVersion.HttpHeaderName);
                if (flag && flag2)
                {
                    ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorVersionAmbiguous, Strings.ErrorVersionAmbiguous);
                }
                else if (flag || flag2)
                {
                    string version;
                    if (flag)
                    {
                        version = httpContext.Request.QueryString[ReportingVersion.QueryStringParameterName];
                        ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string>(0L, "[ReportingVersion::GetVersion] Version in query string: {0}", text);
                    }
                    else
                    {
                        version = httpContext.Request.Headers[ReportingVersion.HttpHeaderName];
                        ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string>(0L, "[ReportingVersion::GetVersion] Version in header: {0}", text);
                    }
                    if (!ReportingVersion.IsVersionSupported(version, out text))
                    {
                        ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorInvalidVersion, Strings.ErrorInvalidVersion);
                    }
                }
                else
                {
                    ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string>(0L, "[ReportingVersion::GetVersion] Use the latest version: {0}", ReportingVersion.LatestVersion);
                    text = ReportingVersion.LatestVersion;
                }
            }
            ExTraceGlobals.ReportingWebServiceTracer.Information <string>(0L, "[ReportingVersion::GetVersion] Version: {0}", text);
            httpContext.Items["Exchange_RWS_Version"] = text;
            return(text);
        }
 public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
 {
     if (request.Properties.ContainsKey("UriTemplateMatchResults"))
     {
         HttpRequestMessageProperty httpRequestMessageProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
         UriTemplateMatch           uriTemplateMatch           = (UriTemplateMatch)request.Properties["UriTemplateMatchResults"];
         string value = uriTemplateMatch.QueryParameters["$format"];
         if ("json".Equals(value, StringComparison.OrdinalIgnoreCase))
         {
             uriTemplateMatch.QueryParameters.Remove("$format");
             httpRequestMessageProperty.Headers["Accept"] = "application/json;odata=verbose";
         }
         else if ("Atom".Equals(value, StringComparison.OrdinalIgnoreCase))
         {
             uriTemplateMatch.QueryParameters.Remove("$format");
             httpRequestMessageProperty.Headers["Accept"] = "application/atom+xml";
         }
         else if (!string.IsNullOrEmpty(value))
         {
             ServiceDiagnostics.ThrowError(ReportingErrorCode.InvalidFormatQuery, Strings.InvalidFormatQuery);
         }
     }
     return(null);
 }
        private RbacPrincipal CreateRbacPrincipal(IIdentity identity, string tenantDomain, string cacheKey, HttpContext httpContext)
        {
            ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] Create RbacPrincipal. Identity: {0}; tenantDomain: {1}; cacheKey: '{2}'", identity.GetSafeName(true), tenantDomain ?? string.Empty, cacheKey);
            ExchangeRunspaceConfigurationSettings rbacSettings = null;

            ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewExchangeRunspaceConfigurationSettingsLatency, delegate
            {
                rbacSettings = new ExchangeRunspaceConfigurationSettings(ExchangeRunspaceConfigurationSettings.ExchangeApplication.ReportingWebService, tenantDomain, ExchangeRunspaceConfigurationSettings.SerializationLevel.None);
            });
            ReportingSchema schema = ReportingSchema.GetCurrentReportingSchema(httpContext);

            try
            {
                RequestStatistics requestStatistics = HttpContext.Current.Items[RequestStatistics.RequestStatsKey] as RequestStatistics;
                if (requestStatistics != null)
                {
                    requestStatistics.AddExtendedStatisticsDataPoint("AuthType", identity.AuthenticationType);
                }
                using (new AverageTimePerfCounter(RwsPerfCounters.AverageRbacPrincipalCreation, RwsPerfCounters.AverageRbacPrincipalCreationBase, true))
                {
                    RwsExchangeRunspaceConfiguration rbacConfiguration = null;
                    ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewRwsExchangeRunspaceConfigurationLatency, delegate
                    {
                        rbacConfiguration = RwsExchangeRunspaceConfiguration.NewInstance(identity, rbacSettings, schema.CmdletFilter, this.GetSnapinSet());
                    });
                    RbacPrincipal rbacPrincipal = null;
                    ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewRbacPrincipalLatency, delegate
                    {
                        rbacPrincipal = new RbacPrincipal(rbacConfiguration, cacheKey);
                    });
                    return(rbacPrincipal);
                }
            }
            catch (CmdletAccessDeniedException ex)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <CmdletAccessDeniedException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] CmdletAccessDeniedException: {0}", ex);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorTenantNotInOrgScope, Strings.ErrorTenantNotInOrgScope(tenantDomain), ex);
            }
            catch (CannotResolveTenantNameException ex2)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <CannotResolveTenantNameException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] CannotResolveTenantNameException: {0}", ex2);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorTenantNotResolved, Strings.ErrorTenantNotResolved(tenantDomain), ex2);
            }
            catch (ADTransientException ex3)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <ADTransientException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] ADTransientException: {0}", ex3);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ADTransientError, Strings.ADTransientError, ex3);
            }
            catch (DataSourceOperationException ex4)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <DataSourceOperationException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] DataSourceOperationException: {0}", ex4);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ADOperationError, Strings.ADOperationError, ex4);
            }
            catch (TimeoutException ex5)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <TimeoutException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] TimeoutException: {0}", ex5);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.CreateRunspaceConfigTimeoutError, Strings.CreateRunspaceConfigTimeoutError, ex5);
            }
            catch (Exception ex6)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <Exception>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] Exception: {0}", ex6);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.UnknownError, Strings.UnknownError, ex6);
            }
            return(null);
        }
Пример #10
0
 internal static void ThrowError(ReportingErrorCode errorCode, string message)
 {
     ServiceDiagnostics.ThrowError(errorCode, message, null);
 }
Пример #11
0
 protected override void HandleException(HandleExceptionArgs args)
 {
     base.HandleException(args);
     ServiceDiagnostics.ReportUnhandledException(args.Exception, HttpContext.Current);
 }
Пример #12
0
        private void InitializeWatsonReporting()
        {
            bool appSettingAsBool = Global.GetAppSettingAsBool("WatsonEnabled", true);

            ServiceDiagnostics.InitializeWatsonReporting(appSettingAsBool);
        }