/// <summary>
        /// Processes an HTTP error response
        /// </summary>
        /// <param name="httpWebResponse">The HTTP web response.</param>
        /// <param name="webException">The web exception.</param>
        /// <param name="responseHeadersTraceFlag">The trace flag for response headers.</param>
        /// <param name="responseTraceFlag">The trace flag for responses.</param>
        /// <remarks>
        /// This method doesn't handle 500 ISE errors. This is handled by the caller since
        /// 500 ISE typically indicates that a SOAP fault has occurred and the handling of
        /// a SOAP fault is currently service specific.
        /// </remarks>
        internal void InternalProcessHttpErrorResponse(
            IEwsHttpWebResponse httpWebResponse,
            WebException webException,
            TraceFlags responseHeadersTraceFlag,
            TraceFlags responseTraceFlag)
        {
            EwsUtilities.Assert(
                httpWebResponse.StatusCode != HttpStatusCode.InternalServerError,
                "ExchangeServiceBase.InternalProcessHttpErrorResponse",
                "InternalProcessHttpErrorResponse does not handle 500 ISE errors, the caller is supposed to handle this.");

            this.ProcessHttpResponseHeaders(responseHeadersTraceFlag, httpWebResponse);

            // Deal with new HTTP error code indicating that account is locked.
            // The "unlock" URL is returned as the status description in the response.
            if (httpWebResponse.StatusCode == ExchangeServiceBase.AccountIsLocked)
            {
                string location = httpWebResponse.StatusDescription;

                Uri accountUnlockUrl = null;
                if (Uri.IsWellFormedUriString(location, UriKind.Absolute))
                {
                    accountUnlockUrl = new Uri(location);
                }

                this.TraceMessage(responseTraceFlag, string.Format("Account is locked. Unlock URL is {0}", accountUnlockUrl));

                throw new AccountIsLockedException(
                          string.Format(Strings.AccountIsLocked, accountUnlockUrl),
                          accountUnlockUrl,
                          webException);
            }
        }
Example #2
0
        public static Entity RaycastEntity2(Vector3 pos, Vector3 direction, float distance, params Entity[] toIgnore)
        {
            TraceFlags flags = TraceFlags.IntersectFoliage | TraceFlags.IntersectObjects | TraceFlags.IntersectPeds | TraceFlags.IntersectPedsSimpleCollision | TraceFlags.IntersectVehicles | TraceFlags.IntersectWorld;
            HitResult  ray   = World.TraceLine(pos, pos + direction * distance, flags, toIgnore);

            return(ray.HitEntity);
        }
Example #3
0
        /// <summary>
        /// Save the HTTP response headers.
        /// </summary>
        /// <param name="headers">The response headers</param>
        /// <param name="saveType">Kind of save entry</param>
        private void SaveHttpResponseHeaders(TraceFlags saveType, WebHeaderCollection headers)
        {
            if (this.IsSaveEnabledFor(saveType))
            {
                this.httpResponseHeaders.Clear();

                foreach (string key in headers.AllKeys)
                {
                    string existingValue;

                    if (this.httpResponseHeaders.TryGetValue(key, out existingValue))
                    {
                        this.httpResponseHeaders[key] = existingValue + "," + headers[key];
                    }
                    else
                    {
                        this.httpResponseHeaders.Add(key, headers[key]);
                    }
                }

                if (this.OnResponseHeadersCaptured != null)
                {
                    this.OnResponseHeadersCaptured(headers);
                }
            }
        }
Example #4
0
 public TraceData(
     string name,
     string group,
     string description,
     IClientData clientData,
     string typeName,
     string methodName,
     BindingFlags bindingFlags,
     MethodFlags methodFlags,
     TraceFlags traceFlags,
     IPlugin plugin,
     long token
     )
 {
     this.kind         = IdentifierKind.TraceData;
     this.id           = AttributeOps.GetObjectId(this);
     this.name         = name;
     this.group        = group;
     this.description  = description;
     this.clientData   = clientData;
     this.typeName     = typeName;
     this.methodName   = methodName;
     this.bindingFlags = bindingFlags;
     this.methodFlags  = methodFlags;
     this.traceFlags   = traceFlags;
     this.plugin       = plugin;
     this.token        = token;
 }
Example #5
0
        ///////////////////////////////////////////////////////////////////////

        #region Private Methods
        private void AddRange(
            IClientData clientData,
            TraceFlags traceFlags,
            IPlugin plugin,
            IEnumerable <TraceCallback> collection
            )
        {
            foreach (TraceCallback item in collection)
            {
                if (item != null)
                {
                    Result error = null;

                    ITrace trace = ScriptOps.NewCoreTrace(
                        item, clientData, traceFlags, plugin, ref error);

                    if (trace != null)
                    {
                        this.Add(trace);
                    }
                    else
                    {
                        DebugOps.Complain(ReturnCode.Error, error);
                    }
                }
            }
        }
        private void RunTest(TraceFlags traceFlags, bool traceEnabled, HttpRequestMessage httpRequestMessage, HttpResponseMessage responseMessage, Action <string, string> assertation, bool skipHttpRequestContext = false)
        {
            if (!skipHttpRequestContext)
            {
                ITraceListener traceListener = new MockTraceListener()
                {
                    InlineAssertation = assertation
                };

                HttpRequestContext requestContext = new HttpRequestContext(
                    new TraceContext(
                        traceEnabled,
                        traceFlags,
                        traceListener),
                    new SimpleAuthorizationTokenProvider("abc"));

                httpRequestMessage.Properties.Add(
                    nameof(HttpRequestContext),
                    requestContext);
            }

            TraceListenerHttpHandler traceListenerHttpHandler = new TraceListenerHttpHandler();

            traceListenerHttpHandler.InnerHandler = new MockHttpMessageHandler(responseMessage);

            using (HttpClient httpClient = new HttpClient(traceListenerHttpHandler)) // not production code so disposing it as soon as test finish
            {
                HttpResponseMessage response = httpClient.SendAsync(httpRequestMessage).Result;
            }
        }
 /// <summary>
 /// Logs the specified string to the TraceListener if tracing is enabled.
 /// </summary>
 /// <param name="traceType">Kind of trace entry.</param>
 /// <param name="logEntry">The entry to log.</param>
 internal void TraceMessage(TraceFlags traceType, string logEntry)
 {
     if (this.IsTraceEnabledFor(traceType))
     {
         string traceTypeStr = traceType.ToString();
         string logMessage   = EwsUtilities.FormatLogMessage(traceTypeStr, logEntry);
         this.TraceListener.Trace(traceTypeStr, logMessage);
     }
 }
 /// <summary>
 /// Logs the specified XML to the TraceListener if tracing is enabled.
 /// </summary>
 /// <param name="traceType">Kind of trace entry.</param>
 /// <param name="stream">The stream containing XML.</param>
 internal void TraceXml(TraceFlags traceType, MemoryStream stream)
 {
     if (this.IsTraceEnabledFor(traceType))
     {
         string traceTypeStr = traceType.ToString();
         string logMessage   = EwsUtilities.FormatLogMessageWithXmlContent(traceTypeStr, stream);
         this.TraceListener.Trace(traceTypeStr, logMessage);
     }
 }
Example #9
0
        ///////////////////////////////////////////////////////////////////////

        public TraceList(
            IClientData clientData,
            TraceFlags traceFlags,
            IPlugin plugin,
            IEnumerable <TraceCallback> collection
            )
        {
            AddRange(clientData, traceFlags, plugin, collection);
        }
 /// <summary>
 /// Traces the HTTP response headers.
 /// </summary>
 /// <param name="traceType">Kind of trace entry.</param>
 /// <param name="response">The response.</param>
 private void TraceHttpResponseHeaders(TraceFlags traceType, IEwsHttpWebResponse response)
 {
     if (this.IsTraceEnabledFor(traceType))
     {
         string traceTypeStr    = traceType.ToString();
         string headersAsString = EwsUtilities.FormatHttpResponseHeaders(response);
         string logMessage      = EwsUtilities.FormatLogMessage(traceTypeStr, headersAsString);
         this.TraceListener.Trace(traceTypeStr, logMessage);
     }
 }
Example #11
0
 static partial void TraceDetail(TraceFlags traceFlags, bool newLine, string description)
 {
     if (EnabledFags.HasFlag(traceFlags))
     {
         if (newLine)
         {
             Debug.WriteLine("");
         }
         Debug.WriteLine(description);
     }
 }
Example #12
0
 static partial void LogTimeDetail(TraceFlags traceFlags, bool newLine, string description)
 {
     if (EnabledFags.HasFlag(traceFlags))
     {
         if (newLine)
         {
             Debug.WriteLine("");
         }
         Debug.Write("{0} - ", GetTimeString());
         Trace(traceFlags, false, description);
     }
 }
Example #13
0
        ///////////////////////////////////////////////////////////////////////

        public static bool HasFlags(
            TraceFlags flags,
            TraceFlags hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != TraceFlags.None);
            }
        }
Example #14
0
        internal TraceParent(string?traceparent)
        {
            if (traceparent is null)
            {
                this.Version = 0;
                this.Flags   = TraceFlags.None;
                return;
            }

            ReadOnlySpan <char> traceparentChars = traceparent.AsSpan();

            // Decode version
            ReadOnlySpan <char> slice = Consume(ref traceparentChars, VersionByteCount * 2);

            fixed(byte *pVersion = &this.Version)
            {
                Hex.Decode(slice, new Span <byte>(pVersion, 1));
            }

            ConsumeHyphen(ref traceparentChars);

            // Decode traceid
            slice = Consume(ref traceparentChars, TraceIdByteCount * 2);
            fixed(byte *pTraceId = this.TraceId)
            {
                Hex.Decode(slice, new Span <byte>(pTraceId, TraceIdByteCount));
            }

            ConsumeHyphen(ref traceparentChars);

            // Decode parentid
            slice = Consume(ref traceparentChars, ParentIdByteCount * 2);
            fixed(byte *pParentId = this.ParentId)
            {
                Hex.Decode(slice, new Span <byte>(pParentId, ParentIdByteCount));
            }

            ConsumeHyphen(ref traceparentChars);

            // Decode flags
            slice = Consume(ref traceparentChars, FlagsByteCount * 2);
            fixed(TraceFlags *pFlags = &this.Flags)
            {
                Hex.Decode(slice, new Span <byte>(pFlags, 1));
            }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExchangeServiceBase"/> class.
 /// </summary>
 /// <param name="service">The other service.</param>
 /// <param name="requestedServerVersion">The requested server version.</param>
 internal ExchangeServiceBase(ExchangeServiceBase service, ExchangeVersion requestedServerVersion)
     : this(requestedServerVersion)
 {
     this.useDefaultCredentials = service.useDefaultCredentials;
     this.credentials           = service.credentials;
     this.traceEnabled          = service.traceEnabled;
     this.traceListener         = service.traceListener;
     this.traceFlags            = service.traceFlags;
     this.timeout                  = service.timeout;
     this.preAuthenticate          = service.preAuthenticate;
     this.userAgent                = service.userAgent;
     this.acceptGzipEncoding       = service.acceptGzipEncoding;
     this.keepAlive                = service.keepAlive;
     this.connectionGroupName      = service.connectionGroupName;
     this.timeZone                 = service.timeZone;
     this.httpHeaders              = service.httpHeaders;
     this.ewsHttpWebRequestFactory = service.ewsHttpWebRequestFactory;
 }
Example #16
0
        private void Write(TraceFlags flags, uint id, TraceSeverity level, string exeName, string area, string category, string message)
        {
            Payload payload = new Payload();

            payload.Size       = (ushort)Marshal.SizeOf(typeof(Payload));
            payload.dwVersion  = TRACE_VERSION_CURRENT;
            payload.Id         = id;
            payload.TimeStamp  = DateTime.Now.ToFileTime();
            payload.wzExeName  = exeName;
            payload.wzProduct  = area;
            payload.wzCategory = category;

            // If the message is smaller than 800 characters, no need to break it up.
            if (message == null || message.Length <= 800)
            {
                payload.wzMessage = message;
                payload.dwFlags   = flags;
                WriteImpl(level, payload);
                return;
            }

            // For larger messages, break it into 800 character chunks.
            for (int i = 0; i < message.Length; i += 800)
            {
                int cchRemaining = Math.Min(800, message.Length - i);
                payload.wzMessage = message.Substring(i, cchRemaining);

                if (i == 0)
                {
                    payload.dwFlags = TraceFlags.TRACE_FLAG_START | flags;
                }
                else if (i + 800 < message.Length)
                {
                    payload.dwFlags = TraceFlags.TRACE_FLAG_MIDDLE | flags;
                }
                else
                {
                    payload.dwFlags = TraceFlags.TRACE_FLAG_END | flags;
                }

                WriteImpl(level, payload);
            }
        }
Example #17
0
 /// <summary>
 /// Determines whether saving is enabled for specified save flag(s).
 /// </summary>
 /// <param name="saveFlags">The save flags.</param>
 /// <returns>True if saving is enabled for specified save flag(s).
 /// </returns>
 internal bool IsSaveEnabledFor(TraceFlags saveFlags)
 {
     return((this.SaveFlags & saveFlags) != 0);
 }
Example #18
0
 public static void LogTime(this TraceFlags @this, bool newLine, string description)
 {
 }
 /// <summary>
 /// Create new instance of <see cref="TraceContext"/>
 /// </summary>
 /// <param name="traceEnabled"></param>
 /// <param name="traceFlags"></param>
 /// <param name="traceListener"></param>
 public TraceContext(bool traceEnabled, TraceFlags traceFlags, ITraceListener traceListener)
 {
     this.TraceEnabled  = traceEnabled;
     this.TraceFlags    = traceFlags;
     this.TraceListener = traceListener;
 }
        /// <summary>
        /// Traces the HTTP response headers.
        /// </summary>
        /// <param name="traceType">Kind of trace entry.</param>
        /// <param name="response">The response.</param>
        internal void ProcessHttpResponseHeaders(TraceFlags traceType, IEwsHttpWebResponse response)
        {
            this.TraceHttpResponseHeaders(traceType, response);

            this.SaveHttpResponseHeaders(response.Headers);
        }
Example #21
0
 public static void LogTime(TraceFlags traceFlags, bool newLine, string description)
 {
     LogTimeDetail(traceFlags, newLine, description);
 }
Example #22
0
 static partial void LogTimeDetail(TraceFlags traceFlags, bool newLine, string description);
 /// <summary>
 /// Initializes a new instance of the <see cref="ExchangeServiceBase"/> class.
 /// </summary>
 /// <param name="service">The other service.</param>
 /// <param name="requestedServerVersion">The requested server version.</param>
 internal ExchangeServiceBase(ExchangeServiceBase service, ExchangeVersion requestedServerVersion)
     : this(requestedServerVersion)
 {
     this.useDefaultCredentials = service.useDefaultCredentials;
     this.credentials = service.credentials;
     this.traceEnabled = service.traceEnabled;
     this.traceListener = service.traceListener;
     this.traceFlags = service.traceFlags;
     this.timeout = service.timeout;
     this.preAuthenticate = service.preAuthenticate;
     this.userAgent = service.userAgent;
     this.acceptGzipEncoding = service.acceptGzipEncoding;
     this.keepAlive = service.keepAlive;
     this.connectionGroupName = service.connectionGroupName;
     this.timeZone = service.timeZone;
     this.httpHeaders = service.httpHeaders;
     this.ewsHttpWebRequestFactory = service.ewsHttpWebRequestFactory;
 }
 /// <summary>
 /// Traces the HTTP response headers.
 /// </summary>
 /// <param name="traceType">Kind of trace entry.</param>
 /// <param name="response">The response.</param>
 private void TraceHttpResponseHeaders(TraceFlags traceType, IEwsHttpWebResponse response)
 {
     if (this.IsTraceEnabledFor(traceType))
     {
         string traceTypeStr = traceType.ToString();
         string headersAsString = EwsUtilities.FormatHttpResponseHeaders(response);
         string logMessage = EwsUtilities.FormatLogMessage(traceTypeStr, headersAsString);
         this.TraceListener.Trace(traceTypeStr, logMessage);
     }
 }
Example #25
0
 public static void Trace(this TraceFlags @this, string format, params object[] args)
 {
 }
 /// <summary>
 /// Logs the specified XML to the TraceListener if tracing is enabled.
 /// </summary>
 /// <param name="traceType">Kind of trace entry.</param>
 /// <param name="stream">The stream containing XML.</param>
 internal void TraceXml(TraceFlags traceType, MemoryStream stream)
 {
     if (this.IsTraceEnabledFor(traceType))
     {
         string traceTypeStr = traceType.ToString();
         string logMessage = EwsUtilities.FormatLogMessageWithXmlContent(traceTypeStr, stream);
         this.TraceListener.Trace(traceTypeStr, logMessage);
     }
 }
 /// <summary>
 /// Logs the specified string to the TraceListener if tracing is enabled.
 /// </summary>
 /// <param name="traceType">Kind of trace entry.</param>
 /// <param name="logEntry">The entry to log.</param>
 internal void TraceMessage(TraceFlags traceType, string logEntry)
 {
     if (this.IsTraceEnabledFor(traceType))
     {
         string traceTypeStr = traceType.ToString();
         string logMessage = EwsUtilities.FormatLogMessage(traceTypeStr, logEntry);
         this.TraceListener.Trace(traceTypeStr, logMessage);
     }
 }
 /// <summary>
 /// Determines whether tracing is enabled for specified trace flag(s).
 /// </summary>
 /// <param name="traceFlags">The trace flags.</param>
 /// <returns>True if tracing is enabled for specified trace flag(s).
 /// </returns>
 internal bool IsTraceEnabledFor(TraceFlags traceFlags)
 {
     return this.TraceEnabled && ((this.TraceFlags & traceFlags) != 0);
 }
        /// <summary>
        /// Processes an HTTP error response
        /// </summary>
        /// <param name="httpWebResponse">The HTTP web response.</param>
        /// <param name="webException">The web exception.</param>
        /// <param name="responseHeadersTraceFlag">The trace flag for response headers.</param>
        /// <param name="responseTraceFlag">The trace flag for responses.</param>
        /// <remarks>
        /// This method doesn't handle 500 ISE errors. This is handled by the caller since
        /// 500 ISE typically indicates that a SOAP fault has occurred and the handling of
        /// a SOAP fault is currently service specific.
        /// </remarks>
        internal void InternalProcessHttpErrorResponse(
                            IEwsHttpWebResponse httpWebResponse,
                            WebException webException,
                            TraceFlags responseHeadersTraceFlag,
                            TraceFlags responseTraceFlag)
        {
            EwsUtilities.Assert(
                httpWebResponse.StatusCode != HttpStatusCode.InternalServerError,
                "ExchangeServiceBase.InternalProcessHttpErrorResponse",
                "InternalProcessHttpErrorResponse does not handle 500 ISE errors, the caller is supposed to handle this.");

            this.ProcessHttpResponseHeaders(responseHeadersTraceFlag, httpWebResponse);

            // Deal with new HTTP error code indicating that account is locked.
            // The "unlock" URL is returned as the status description in the response.
            if (httpWebResponse.StatusCode == ExchangeServiceBase.AccountIsLocked)
            {
                string location = httpWebResponse.StatusDescription;

                Uri accountUnlockUrl = null;
                if (Uri.IsWellFormedUriString(location, UriKind.Absolute))
                {
                    accountUnlockUrl = new Uri(location);
                }

                this.TraceMessage(responseTraceFlag, string.Format("Account is locked. Unlock URL is {0}", accountUnlockUrl));

                throw new AccountIsLockedException(
                    string.Format(Strings.AccountIsLocked, accountUnlockUrl),
                    accountUnlockUrl,
                    webException);
            }
        }
Example #30
0
 public static void Trace(this TraceFlags @this, string format, params object[] args)
 {
     DebugTracing.Trace(@this, format, args);
 }
Example #31
0
 public static void LogTime(this TraceFlags @this, bool newLine, string description)
 {
     DebugTracing.LogTime(@this, newLine, description);
 }
Example #32
0
 public static void LogTime(this TraceFlags @this, bool newLine, string format, params object[] args)
 {
     DebugTracing.LogTime(@this, newLine, format, args);
 }
 /// <summary>
 /// Determines whether tracing is enabled for specified trace flag(s).
 /// </summary>
 /// <param name="traceFlags">The trace flags.</param>
 /// <returns>True if tracing is enabled for specified trace flag(s).
 /// </returns>
 internal bool IsTraceEnabledFor(TraceFlags traceFlags)
 {
     return(this.TraceEnabled && ((this.TraceFlags & traceFlags) != 0));
 }
        private void Write(TraceFlags flags, uint id, TraceSeverity level, string exeName, string area, string category, string message)
        {
            Payload payload = new Payload();
            payload.Size = (ushort)Marshal.SizeOf(typeof(Payload));
            payload.dwVersion = TRACE_VERSION_CURRENT;
            payload.Id = id;
            payload.TimeStamp = DateTime.Now.ToFileTime();
            payload.wzExeName = exeName;
            payload.wzProduct = area;
            payload.wzCategory = category;

            // If the message is smaller than 800 characters, no need to break it up.
            if (message == null || message.Length <= 800)
            {
                payload.wzMessage = message;
                payload.dwFlags = flags;
                WriteImpl(level, payload);
                return;
            }

            // For larger messages, break it into 800 character chunks.
            for (int i = 0; i < message.Length; i += 800)
            {
                int cchRemaining = Math.Min(800, message.Length - i);
                payload.wzMessage = message.Substring(i, cchRemaining);

                if (i == 0)
                    payload.dwFlags = TraceFlags.TRACE_FLAG_START | flags;
                else if (i + 800 < message.Length)
                    payload.dwFlags = TraceFlags.TRACE_FLAG_MIDDLE | flags;
                else
                    payload.dwFlags = TraceFlags.TRACE_FLAG_END | flags;

                WriteImpl(level, payload);
            }
        }
Example #35
0
 public static void LogTime(TraceFlags traceFlags, string description)
 {
     LogTime(traceFlags, false, description);
 }
Example #36
0
 /// <summary>
 /// Method for setting $EwsSession session context variable.
 /// </summary>
 /// <param name="userName">Connecting username.</param>
 /// <param name="password">Connecting password.</param>
 /// <param name="ewsUrl">Ews endpoint.</param>
 /// <param name="impersonateEmail">Email address of the impersonated user.</param>
 /// <param name="traceEnabled">Enable ews tracing.</param>
 /// <param name="traceFolder">Location where trace items will be saved.</param>
 /// <param name="traceFlags">Options what to trace.</param>
 internal void SetSessionVariable(string userName, SecureString password, Uri ewsUrl, string autodicoverEmail, string impersonateEmail, bool traceEnabled, string traceFolder, TraceFlags traceFlags, ExchangeVersion exchangeVersion)
 {
     this.SetSessionVariable(userName, password, ewsUrl, autodicoverEmail, exchangeVersion);
     this.SetSessionVariable(impersonateEmail, traceEnabled, traceFolder, traceFlags);
 }
Example #37
0
 public static void LogTime(TraceFlags traceFlags, bool newLine, string format, params object[] args)
 {
     LogTime(traceFlags, newLine, string.Format(format, args));
 }
Example #38
0
        /// <summary>
        /// Helper method for setting already imported session. 
        /// </summary>
        /// <param name="impersonateEmail">Email address of the impersonated user.</param>
        /// <param name="traceEnabled">Enable ews tracing.</param>
        /// <param name="traceFolder">Location where trace items will be saved.</param>
        /// <param name="traceFlags">Options what to trace.</param>
        internal void SetSessionVariable(string impersonateEmail, bool traceEnabled, string traceFolder, TraceFlags traceFlags)
        {
            if (!String.IsNullOrEmpty(impersonateEmail))
                this.SetSessionImpersonation(impersonateEmail);
            else
                this.SetSessionImpersonation(null);

            if (traceEnabled)
            {
                ExchangeService ewsService = this.GetSessionVariable();
                ewsService.TraceListener = new TraceListener(traceFolder);
                ewsService.TraceEnabled = traceEnabled;
                ewsService.TraceFlags = traceFlags;

                this.SessionState.PSVariable.Set("EwsSession", ewsService);
            }
        }
        /// <summary>
        /// Traces the HTTP response headers.
        /// </summary>
        /// <param name="traceType">Kind of trace entry.</param>
        /// <param name="response">The response.</param>
        internal void ProcessHttpResponseHeaders(TraceFlags traceType, IEwsHttpWebResponse response)
        {
            this.TraceHttpResponseHeaders(traceType, response);

            this.SaveHttpResponseHeaders(response.Headers);
        }
Example #40
0
 public static void LogTime(this TraceFlags @this, bool newLine, string format, params object[] args)
 {
 }