Наследование: Microsoft.OData.Client.HttpWebRequestMessage
Пример #1
0
        public override void InitializeContext(IConnectionInfo connectionInfo, object context, QueryExecutionManager executionManager)
        {
            var dsContext = (DataServiceContext)context;

            var properties = connectionInfo.GetConnectionProperties();

            dsContext.Credentials = properties.GetCredentials();

            dsContext.Configurations.RequestPipeline.OnMessageCreating += args =>
            {
                var message = new CustomizedRequestMessage(args, properties.GetWebProxy());
                return(message);
            };

            dsContext.SendingRequest2 += (s, e) =>
            {
                executionManager.SqlTranslationWriter.WriteLine($"URL:\t\t{e.RequestMessage.Url}");

                if (properties.LogMethod)
                {
                    executionManager.SqlTranslationWriter.WriteLine($"Method:\t{e.RequestMessage.Method}");
                }

                if (properties.LogHeaders)
                {
                    executionManager.SqlTranslationWriter.WriteLine("Headers:");
                    var headers = string.Join("\r\n", e.RequestMessage.Headers.Select(o => $"\t{o.Key}:{o.Value}"));
                    executionManager.SqlTranslationWriter.WriteLine(headers);
                }
            };
        }
        public override void InitializeContext(IConnectionInfo connectionInfo, object context, QueryExecutionManager executionManager)
        {
            var dsContext = (DataServiceContext)context;

            var properties = connectionInfo.GetConnectionProperties();
            dsContext.Credentials = properties.GetCredentials();

            dsContext.Configurations.RequestPipeline.OnMessageCreating += args =>
            {
                var message = new CustomizedRequestMessage(args, properties);
                return message;
            };

            dsContext.SendingRequest2 += (s, e) =>
            {
                executionManager.SqlTranslationWriter.WriteLine($"URL:\t\t{e.RequestMessage.Url}");

                if (properties.LogMethod)
                    executionManager.SqlTranslationWriter.WriteLine($"Method:\t{e.RequestMessage.Method}");

                if (properties.LogHeaders)
                {
                    executionManager.SqlTranslationWriter.WriteLine("Headers:");
                    var headers = string.Join("\r\n", e.RequestMessage.Headers.Select(o => $"\t{o.Key}:{o.Value}"));
                    executionManager.SqlTranslationWriter.WriteLine(headers);
                }
            };
        }