Esempio n. 1
0
        public TResult Execute(CommandContext context)
        {
            this.Context = context;
            Stopwatch stopwatch = Stopwatch.StartNew();
            TResult   result;

            try
            {
                this.onBeforeExecute();
                result = this.OnExecute();
            }
            catch (Exception obj)
            {
                this.SetCustomLoggingData("Exception", obj);
                throw;
            }
            finally
            {
                stopwatch.Stop();
                IActivityScope currentActivityScope = ActivityContext.GetCurrentActivityScope();
                if (currentActivityScope != null)
                {
                    currentActivityScope.SetProperty(EntitiesMetadata.CommandName, base.GetType().Name);
                    currentActivityScope.SetProperty(EntitiesMetadata.CoreExecutionLatency, stopwatch.ElapsedMilliseconds.ToString());
                    string customLoggingData = this.GetCustomLoggingData();
                    currentActivityScope.SetProperty(EntitiesMetadata.CustomData, customLoggingData);
                }
            }
            return(result);
        }
Esempio n. 2
0
        // Token: 0x060010D1 RID: 4305 RVA: 0x00062714 File Offset: 0x00060914
        public void SetMetadataValues(object context, RecipientType recipientType, string chunkId)
        {
            this.TraceDebug(context, "Entering SetMetadataValues - TaskName='{0}', RecipientType='{1}', ChunkId='{2}'", new object[]
            {
                this.TaskName,
                recipientType,
                chunkId
            });
            Logger.RegisterMetadata();
            IActivityScope currentActivityScope = ActivityContext.GetCurrentActivityScope();

            if (currentActivityScope != null && currentActivityScope.Status == ActivityContextStatus.ActivityStarted)
            {
                this.TraceDebug(context, "Setting metadata values TaskName='{0}', RecipientType='{1}', ChunkId='{2}', MailboxGuid='{3}', TenantGuid='{4}'", new object[]
                {
                    this.TaskName,
                    recipientType,
                    chunkId,
                    this.RunData.MailboxGuid,
                    this.RunData.TenantGuid
                });
                currentActivityScope.SetProperty(DirectoryProcessorMetadata.TaskName, this.TaskName);
                currentActivityScope.SetProperty(DirectoryProcessorMetadata.RecipientType, recipientType.ToString());
                currentActivityScope.SetProperty(DirectoryProcessorMetadata.ChunkId, chunkId);
                currentActivityScope.SetProperty(DirectoryProcessorMetadata.MailboxGuid, this.RunData.MailboxGuid.ToString());
                currentActivityScope.SetProperty(DirectoryProcessorMetadata.TenantGuid, this.RunData.TenantGuid.ToString());
            }
        }
 internal static void PublishServerInfo(IActivityScope activityScope)
 {
     if (activityScope == null)
     {
         return;
     }
     activityScope.SetProperty(ServiceCommonMetadata.ServerVersionMajor, ServiceCommonMetadataPublisher.VersionMajor);
     activityScope.SetProperty(ServiceCommonMetadata.ServerVersionMinor, ServiceCommonMetadataPublisher.VersionMinor);
     activityScope.SetProperty(ServiceCommonMetadata.ServerVersionBuild, ServiceCommonMetadataPublisher.VersionBuild);
     activityScope.SetProperty(ServiceCommonMetadata.ServerVersionRevision, ServiceCommonMetadataPublisher.VersionRevision);
     activityScope.SetProperty(ServiceCommonMetadata.ServerHostName, ServiceCommonMetadataPublisher.MachineName);
 }
Esempio n. 4
0
        protected override ICollection <KeyValuePair <string, object> > GetComponentSpecificData(IActivityScope activityScope, string eventId)
        {
            Dictionary <string, object> dictionary = null;

            if (activityScope != null)
            {
                HttpContext httpContext = HttpContext.Current;
                if (httpContext != null)
                {
                    string sourceCafeServer = CafeHelper.GetSourceCafeServer(httpContext.Request);
                    if (!string.IsNullOrEmpty(sourceCafeServer))
                    {
                        activityScope.SetProperty(ActivityContextLoggerMetaData.FrontEndServer, sourceCafeServer);
                    }
                    string requestUrlForLog = httpContext.GetRequestUrlForLog();
                    activityScope.SetProperty(ActivityContextLoggerMetaData.Url, requestUrlForLog);
                }
                RbacPrincipal current = RbacPrincipal.GetCurrent(false);
                if (current != null)
                {
                    string value;
                    if (current.RbacConfiguration.DelegatedPrincipal != null)
                    {
                        value = current.RbacConfiguration.DelegatedPrincipal.UserId;
                    }
                    else
                    {
                        SmtpAddress executingUserPrimarySmtpAddress = current.RbacConfiguration.ExecutingUserPrimarySmtpAddress;
                        value = (executingUserPrimarySmtpAddress.IsValidAddress ? executingUserPrimarySmtpAddress.ToString() : current.RbacConfiguration.ExecutingUserPrincipalName);
                    }
                    if (!string.IsNullOrEmpty(value))
                    {
                        activityScope.SetProperty(ActivityContextLoggerMetaData.PrimarySmtpAddress, value);
                    }
                    OrganizationId organizationId = current.RbacConfiguration.OrganizationId;
                    if (organizationId != null && organizationId.OrganizationalUnit != null)
                    {
                        string name = organizationId.OrganizationalUnit.Name;
                        activityScope.SetProperty(ActivityContextLoggerMetaData.Organization, name);
                    }
                }
                dictionary = new Dictionary <string, object>(ActivityContextLogger.EnumToShortKeyMapping.Count);
                ExtensibleLogger.CopyPIIProperty(activityScope, dictionary, ActivityContextLoggerMetaData.PrimarySmtpAddress, ActivityContextLogger.PrimarySmtpAddressKey);
                ExtensibleLogger.CopyProperties(activityScope, dictionary, ActivityContextLogger.EnumToShortKeyMapping);
            }
            return(dictionary);
        }
Esempio n. 5
0
 private static void SetBudgetSnapshotResourceInfo(string budgetResourcesString, IActivityScope activityScope)
 {
     if (!string.IsNullOrEmpty(budgetResourcesString))
     {
         foreach (string text in budgetResourcesString.Split(new string[]
         {
             "),"
         }, StringSplitOptions.RemoveEmptyEntries))
         {
             string[] array2 = text.Split(new char[]
             {
                 '('
             });
             if (array2.Length > 1)
             {
                 string[] array3 = array2[1].Split(new char[]
                 {
                     ')'
                 });
                 string   text2  = array3[0].ToLower();
                 string   value  = array3[1];
                 string[] array4 = array2[2].Split(new char[]
                 {
                     ','
                 });
                 string value2 = array4[0].Split(new char[]
                 {
                     ':'
                 })[1];
                 string value3 = array4[1].Split(new char[]
                 {
                     ':'
                 })[1];
                 string a;
                 if ((a = text2) != null && a == "mdb")
                 {
                     activityScope.SetProperty(BudgetMetadata.MDBResource, value);
                     activityScope.SetProperty(BudgetMetadata.MDBHealth, value2);
                     activityScope.SetProperty(BudgetMetadata.MDBHistoricalLoad, value3);
                 }
             }
         }
     }
 }
        private static void PublishGeneric(HttpContextBase context)
        {
            IActivityScope currentActivityScope = ServiceCommonMetadataPublisher.GetCurrentActivityScope(context);

            if (currentActivityScope == null)
            {
                return;
            }
            ServiceCommonMetadataPublisher.PublishServerInfo(currentActivityScope);
            if (context == null)
            {
                return;
            }
            HttpRequestBase  request  = context.Request;
            HttpResponseBase response = context.Response;
            string           value    = request.GetRequestHeader("X-Forwarded-For");

            if (string.IsNullOrEmpty(value))
            {
                value = request.UserHostAddress;
            }
            currentActivityScope.SetProperty(ServiceCommonMetadata.ClientIpAddress, value);
            currentActivityScope.SetProperty(ActivityStandardMetadata.ClientInfo, request.UserAgent);
            currentActivityScope.SetProperty(ServiceCommonMetadata.RequestSize, request.ContentLength.ToString());
            if (currentActivityScope.GetProperty(ServiceCommonMetadata.HttpStatus) == null)
            {
                currentActivityScope.SetProperty(ServiceCommonMetadata.HttpStatus, response.StatusCode.ToString());
            }
            if (request.Cookies.Count > 0)
            {
                for (int i = 0; i < request.Cookies.Count; i++)
                {
                    if (string.Equals(request.Cookies[i].Name, "exchangecookie", StringComparison.OrdinalIgnoreCase))
                    {
                        currentActivityScope.SetProperty(ServiceCommonMetadata.Cookie, request.Cookies[i].Value);
                        return;
                    }
                }
            }
        }
        private static void PublishAuthData(HttpContextBase context)
        {
            if (context == null)
            {
                return;
            }
            IActivityScope currentActivityScope = ServiceCommonMetadataPublisher.GetCurrentActivityScope(context);

            if (currentActivityScope == null)
            {
                return;
            }
            Dictionary <Enum, string> authValues = context.GetAuthValues();

            foreach (KeyValuePair <Enum, string> keyValuePair in authValues)
            {
                currentActivityScope.SetProperty(keyValuePair.Key, keyValuePair.Value);
            }
        }
Esempio n. 8
0
        private object InternalAfterReceiveRequest(ref Message request, RequestDetailsLogger logger)
        {
            try
            {
                Globals.UpdateErrorTracingConfiguration();
                IActivityScope             activityScope = OwaApplication.GetRequestDetailsLogger.ActivityScope;
                HttpRequestMessageProperty httpRequestMessageProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
                string value = httpRequestMessageProperty.Headers[OWADispatchOperationSelector.Action];
                activityScope.SetProperty(ExtensibleLoggerMetadata.EventId, value);
                string value2 = httpRequestMessageProperty.Headers["X-OWA-ClientBuildVersion"];
                if (!string.IsNullOrEmpty(value2))
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.ClientBuildVersion, value2);
                }
                else
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.ClientBuildVersion, "NA");
                }
                string value3 = httpRequestMessageProperty.Headers["X-EWS-TargetVersion"];
                if (!string.IsNullOrEmpty(value3))
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.RequestVersion, value3);
                }
                else
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.RequestVersion, "NA");
                }
                JsonMessageHeaderProcessor jsonMessageHeaderProcessor = new JsonMessageHeaderProcessor();
                string methodName = OWAMessageInspector.GetMethodName(request);
                bool   flag       = OWAMessageInspector.RequestNeedsHeaderProcessing(methodName);
                bool   flag2      = OWAMessageInspector.RequestNeedsQueryStringProcessing(methodName);
                bool   flag3      = OWAMessageInspector.RequestNeedsHttpHeaderProcessing(methodName);
                if (flag || flag2 || flag3)
                {
                    using (MessageBuffer messageBuffer = request.CreateBufferedCopy(int.MaxValue))
                    {
                        Message request2 = messageBuffer.CreateMessage();
                        if (flag)
                        {
                            jsonMessageHeaderProcessor.ProcessMessageHeaders(request2);
                            jsonMessageHeaderProcessor.ProcessEwsVersionFromHttpHeaders(request);
                        }
                        else if (flag2)
                        {
                            jsonMessageHeaderProcessor.ProcessMessageHeadersFromQueryString(request2);
                        }
                        else if (flag3)
                        {
                            jsonMessageHeaderProcessor.ProcessHttpHeaders(request, ExchangeVersion.Exchange2013);
                        }
                        request = messageBuffer.CreateMessage();
                    }
                }
                request.Properties["MessageHeaderProcessor"] = jsonMessageHeaderProcessor;
                request.Properties["ConnectionCostType"]     = 0;
                WebMethodEntry jsonWebMethodEntry;
                if (!OWAMessageInspector.MethodNameToWebMethodEntryMap.Member.TryGetValue(methodName, out jsonWebMethodEntry))
                {
                    jsonWebMethodEntry = WebMethodEntry.JsonWebMethodEntry;
                }
                request.Properties["WebMethodEntry"] = jsonWebMethodEntry;
                MessageHeaderProcessor messageHeaderProcessor = (MessageHeaderProcessor)request.Properties["MessageHeaderProcessor"];
                messageHeaderProcessor.MarkMessageHeaderAsUnderstoodIfExists(request, "RequestServerVersion", "http://schemas.microsoft.com/exchange/services/2006/types");
                RequestDetailsLogger.LogEvent(logger, OwaServerLogger.LoggerData.CallContextInitBegin);
                Message     requestRef  = request;
                CallContext callContext = OwaApplication.GetRequestDetailsLogger.TrackLatency <CallContext>(ServiceLatencyMetadata.CallContextInitLatency, () => CallContextUtilities.CreateCallContext(requestRef, messageHeaderProcessor, true, ""));
                RequestDetailsLogger.LogEvent(logger, OwaServerLogger.LoggerData.CallContextInitEnd);
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsMowaClient, OfflineClientRequestUtilities.IsRequestFromMOWAClient(callContext.HttpContext.Request, callContext.HttpContext.Request.UserAgent) ? 1 : 0);
                bool?flag4 = new bool?(OfflineClientRequestUtilities.IsRequestFromOfflineClient(callContext.HttpContext.Request));
                if (flag4 != null)
                {
                    callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsOfflineEnabled, flag4.Value ? 1 : 0);
                }
                callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current);
                if (string.IsNullOrEmpty(callContext.OwaExplicitLogonUser))
                {
                    OWAMessageInspector.CheckThatUserProvisionedDevice(methodName, callContext);
                    OWAMessageInspector.CheckMowaRemoteWipe(methodName, callContext);
                    OWAMessageInspector.CheckClientVersion(callContext);
                    OWAMessageInspector.CheckMowaDisabled(callContext);
                    OWAMessageInspector.CheckMobileDevicePolicyIsCorrect(methodName, callContext);
                }
                OWAMessageInspector.MarkResponseNonCacheable(methodName);
                callContext.WorkloadType       = WorkloadType.Owa;
                callContext.UsingWcfDispatcher = true;
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.UsingWcfHttpHandler, 1);
                if (ExchangeVersion.Current == ExchangeVersion.Exchange2007)
                {
                    ExchangeVersion.Current = ExchangeVersion.Exchange2013;
                }
                if (OWAMessageInspector.ShouldCreateUserContext(callContext))
                {
                    UserContext userContext = UserContextManager.GetMailboxContext(callContext.HttpContext, callContext.EffectiveCaller, true) as UserContext;
                    if (userContext != null)
                    {
                        callContext.OwaCulture = userContext.UserCulture;
                        if (userContext.FeaturesManager != null)
                        {
                            callContext.FeaturesManager = userContext.FeaturesManager;
                            if (userContext.FeaturesManager.ServerSettings.OwaMailboxSessionCloning.Enabled)
                            {
                                callContext.OwaUserContextKey = userContext.Key.ToString();
                            }
                        }
                    }
                }
            }
            catch (LocalizedException ex)
            {
                Microsoft.Exchange.Diagnostics.Components.Services.ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, string>((long)this.GetHashCode(), "[OWAMessageInspector::AfterReceiveRequest] Caught localized exception trying to create callcontext.  Class: {0}, Message: {1}", ex.GetType().FullName, ex.Message);
                OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OWAMessageInspector", null, "InternalAfterReceiveRequest", string.Format("OwaServiceFaultException_InnerException - {0}", ex)));
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex, "OwaServiceFaultException_InnerException");

                throw OwaFaultExceptionUtilities.CreateFault(ex);
            }
            return(null);
        }
Esempio n. 9
0
        internal static void AsyncCommit(Guid cmdletUniqueId, bool forceSync)
        {
            if (!LoggerSettings.LogEnabled)
            {
                return;
            }
            if (!LoggerHelper.IsPswsNormalRequest)
            {
                IActivityScope currentActivityScope = ActivityContext.GetCurrentActivityScope();
                if (currentActivityScope == null)
                {
                    throw new ArgumentException("activityScope is null.");
                }
                RequestDetailsLoggerBase <RpsCmdletLogger> .InitializeRequestLogger(currentActivityScope);

                RpsCmdletLogger rpsCmdletLogger = RequestDetailsLoggerBase <RpsCmdletLogger> .Current;
                if (rpsCmdletLogger == null)
                {
                    return;
                }
                rpsCmdletLogger.EndActivityContext = false;
                RpsCmdletLoggerBuffer rpsCmdletLoggerBuffer = RpsCmdletLoggerBuffer.Get(cmdletUniqueId);
                foreach (KeyValuePair <Enum, object> keyValuePair in rpsCmdletLoggerBuffer.MetadataLogCache)
                {
                    RequestDetailsLoggerBase <RpsCmdletLogger> .SafeSetLogger(rpsCmdletLogger, keyValuePair.Key, keyValuePair.Value);
                }
                foreach (KeyValuePair <string, string> keyValuePair2 in rpsCmdletLoggerBuffer.GenericInfoLogCache)
                {
                    RequestDetailsLoggerBase <RpsCmdletLogger> .SafeAppendColumn(rpsCmdletLogger, RpsCmdletMetadata.GenericInfo, keyValuePair2.Key, keyValuePair2.Value);
                }
                foreach (KeyValuePair <string, string> keyValuePair3 in rpsCmdletLoggerBuffer.GenericErrorLogCache)
                {
                    RequestDetailsLoggerBase <RpsCmdletLogger> .SafeAppendColumn(rpsCmdletLogger, RpsCmdletMetadata.GenericErrors, keyValuePair3.Key, keyValuePair3.Value);
                }
                foreach (KeyValuePair <Enum, Dictionary <string, string> > keyValuePair4 in rpsCmdletLoggerBuffer.GenericColumnLogCache)
                {
                    foreach (KeyValuePair <string, string> keyValuePair5 in keyValuePair4.Value)
                    {
                        RequestDetailsLoggerBase <RpsCmdletLogger> .SafeAppendColumn(rpsCmdletLogger, keyValuePair4.Key, keyValuePair5.Key, keyValuePair5.Value);
                    }
                }
                foreach (KeyValuePair <Enum, double> keyValuePair6 in rpsCmdletLoggerBuffer.LatencyLogCache)
                {
                    rpsCmdletLogger.UpdateLatency(keyValuePair6.Key, keyValuePair6.Value);
                }
                rpsCmdletLogger.AsyncCommit(forceSync);
                foreach (KeyValuePair <Enum, object> keyValuePair7 in rpsCmdletLoggerBuffer.MetadataLogCache)
                {
                    currentActivityScope.SetProperty(keyValuePair7.Key, null);
                }
                foreach (KeyValuePair <Enum, double> keyValuePair8 in rpsCmdletLoggerBuffer.LatencyLogCache)
                {
                    currentActivityScope.SetProperty(keyValuePair8.Key, null);
                }
                foreach (KeyValuePair <Enum, Dictionary <string, string> > keyValuePair9 in rpsCmdletLoggerBuffer.GenericColumnLogCache)
                {
                    currentActivityScope.SetProperty(keyValuePair9.Key, null);
                }
                currentActivityScope.SetProperty(RpsCmdletMetadata.GenericInfo, null);
                currentActivityScope.SetProperty(RpsCmdletMetadata.GenericErrors, null);
                rpsCmdletLoggerBuffer.Reset();
                CmdletStaticDataWithUniqueId <RpsCmdletLoggerBuffer> .Remove(cmdletUniqueId);
            }
        }
Esempio n. 10
0
        public static void PublishMetadata()
        {
            if (!BudgetMetadataPublisher.isBudgetMetadataRegistered)
            {
                ActivityContext.RegisterMetadata(typeof(BudgetMetadata));
                BudgetMetadataPublisher.isBudgetMetadataRegistered = true;
            }
            HttpContext httpContext = HttpContext.Current;

            if (httpContext == null)
            {
                return;
            }
            IActivityScope currentActivityScope = ActivityContext.GetCurrentActivityScope();

            if (currentActivityScope == null)
            {
                return;
            }
            string contextItem = httpContext.GetContextItem("StartBudget");

            if (contextItem != null)
            {
                string[] budgetElements = contextItem.Split(new char[]
                {
                    ','
                });
                currentActivityScope.SetProperty(BudgetMetadata.BeginBudgetConnections, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 1));
                currentActivityScope.SetProperty(BudgetMetadata.MaxConn, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 2));
                currentActivityScope.SetProperty(BudgetMetadata.MaxBurst, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 3));
                currentActivityScope.SetProperty(BudgetMetadata.BeginBalance, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 4));
                currentActivityScope.SetProperty(BudgetMetadata.Cutoff, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 5));
                currentActivityScope.SetProperty(BudgetMetadata.RechargeRate, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 6));
                currentActivityScope.SetProperty(BudgetMetadata.ThrottlingPolicy, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 7));
                currentActivityScope.SetProperty(BudgetMetadata.IsServiceAct, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 8));
                currentActivityScope.SetProperty(BudgetMetadata.LiveTime, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 9));
                currentActivityScope.SetProperty(BudgetMetadata.BeginBudgetHangingConnections, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements, 10));
                currentActivityScope.SetProperty(BudgetMetadata.BeginBudgetSubscriptions, BudgetMetadataPublisher.GetBugdetSnapshotSubscriptions(contextItem));
            }
            currentActivityScope.SetProperty(BudgetMetadata.TotalDCRequestCount, httpContext.GetContextItem("TotalLdapRequestCount"));
            currentActivityScope.SetProperty(BudgetMetadata.TotalDCRequestLatency, httpContext.GetContextItem("TotalLdapRequestLatency"));
            currentActivityScope.SetProperty(BudgetMetadata.TotalMBXRequestCount, httpContext.GetContextItem("TotalRpcRequestCount"));
            currentActivityScope.SetProperty(BudgetMetadata.TotalMBXRequestLatency, httpContext.GetContextItem("TotalRpcRequestLatency"));
            string contextItem2 = httpContext.GetContextItem("EndBudget");

            if (contextItem2 != null)
            {
                string[] budgetElements2 = contextItem2.Split(new char[]
                {
                    ','
                });
                currentActivityScope.SetProperty(BudgetMetadata.EndBudgetConnections, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements2, 1));
                currentActivityScope.SetProperty(BudgetMetadata.EndBalance, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements2, 4));
                currentActivityScope.SetProperty(BudgetMetadata.EndBudgetHangingConnections, BudgetMetadataPublisher.GetBudgetSnapshotValueAtIndex(budgetElements2, 10));
                string bugdetSnapshotResources = BudgetMetadataPublisher.GetBugdetSnapshotResources(contextItem2);
                BudgetMetadataPublisher.SetBudgetSnapshotResourceInfo(bugdetSnapshotResources, currentActivityScope);
                currentActivityScope.SetProperty(BudgetMetadata.EndBudgetSubscriptions, BudgetMetadataPublisher.GetBugdetSnapshotSubscriptions(contextItem2));
            }
        }