Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise conditional compiles & package dependencies #1346

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public QueryExpression<T> Clone()
ScanIndexForward = ScanIndexForward,
}.SetSelect(base.Select);

#if !NETCORE
#if NETFRAMEWORK
if (ReadWriteTimeoutInternal != null)
q.ReadWriteTimeoutInternal = ReadWriteTimeoutInternal;
if (TimeoutInternal != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ScanExpression<T> Clone()
TotalSegments = TotalSegments,
}.SetSelect(base.Select);

#if !NETCORE
#if NETFRAMEWORK
if (ReadWriteTimeoutInternal != null)
q.ReadWriteTimeoutInternal = ReadWriteTimeoutInternal;
if (TimeoutInternal != null)
Expand Down
2 changes: 1 addition & 1 deletion ServiceStack.Aws/src/ServiceStack.Aws/Sqs/SqsMqWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void Run()
StartPolling();
}
}
#if !NETCORE
#if NETFRAMEWORK
catch(ThreadInterruptedException)
{ // Expected exceptions from Kill()
log.Warn($"Received ThreadInterruptedException in Worker: {QueueName}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETCORE
#if !NETFRAMEWORK

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ServiceStack.Azure.Messaging;
public static class QueueClientExtensions
{

#if NETCORE
#if !NETFRAMEWORK
static readonly PropertyInfo InnerReceiverProperty =
typeof(Microsoft.Azure.ServiceBus.QueueClient).GetProperties(BindingFlags.NonPublic | BindingFlags.Instance).First(x => x.Name == "InnerReceiver");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if NETCORE
#if !NETFRAMEWORK
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.ServiceBus.Core;
#else
Expand Down Expand Up @@ -42,7 +42,7 @@ public void Ack(IMessage? message)
var sbClient = parentFactory.GetOrCreateClient(queueName);
try
{
#if NETCORE
#if !NETFRAMEWORK
sbClient.CompleteAsync(lockToken).GetAwaiter().GetResult();
#else
sbClient.Complete(Guid.Parse(lockToken));
Expand All @@ -59,7 +59,7 @@ public void Ack(IMessage? message)
if (mqResponse is IMessage)
return (IMessage<T>)mqResponse;

#if NETCORE
#if !NETFRAMEWORK
if (mqResponse is not Microsoft.Azure.ServiceBus.Message msg)
return null;
var msgBody = msg.Body.FromMessageBody();
Expand All @@ -85,7 +85,7 @@ public IMessage<T> Get<T>(string queueName, TimeSpan? timeout = default)
var sbClient = parentFactory.GetOrCreateClient(queueName);
string? lockToken = null;

#if NETCORE
#if !NETFRAMEWORK
var msg = Task.Run(() => sbClient.ReceiveAsync(timeout)).GetAwaiter().GetResult();
if (msg != null)
lockToken = msg.SystemProperties.LockToken;
Expand All @@ -110,7 +110,7 @@ public IMessage<T> Get<T>(string queueName, TimeSpan? timeout = default)
return iMessage;
}

#if NETCORE
#if !NETFRAMEWORK
private async Task<Microsoft.Azure.ServiceBus.Message> GetMessageFromReceiver(MessageReceiver messageReceiver, TimeSpan? timeout)
{
var msg = timeout.HasValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Threading;
using ServiceStack.Text;

#if NETCORE
#if !NETFRAMEWORK
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.ServiceBus.Management;
#else
Expand All @@ -20,21 +20,22 @@ namespace ServiceStack.Azure.Messaging;

public class ServiceBusMqMessageFactory : IMessageFactory
{

private long timesStarted;
private long doOperation = WorkerOperation.NoOp;
private long noOfErrors = 0;
private int noOfContinuousErrors = 0;
private string lastExMsg = null;

#if NETCORE
#if !NETFRAMEWORK
public Action<Microsoft.Azure.ServiceBus.Message,IMessage> PublishMessageFilter { get; set; }
#else
public Action<BrokeredMessage,IMessage> PublishMessageFilter { get; set; }
#endif


protected internal readonly string address;
#if !NETCORE
#if NETFRAMEWORK
protected internal readonly NamespaceManager namespaceManager;
#else
protected internal readonly ManagementClient managementClient;
Expand All @@ -52,7 +53,7 @@ public ServiceBusMqMessageFactory(ServiceBusMqServer mqServer, string address)
{
this.MqServer = mqServer;
this.address = address;
#if !NETCORE
#if NETFRAMEWORK
this.namespaceManager = NamespaceManager.CreateFromConnectionString(address);
#else
this.managementClient = new ManagementClient(address);
Expand Down Expand Up @@ -103,7 +104,7 @@ protected internal void StartQueues(Dictionary<Type, IMessageHandlerFactory> han
queueMap.Add(queueName, type);

var mqDesc = new QueueDescription(queueName);
#if !NETCORE
#if NETFRAMEWORK
if (!namespaceManager.QueueExists(queueName))
namespaceManager.CreateQueue(mqDesc);
#else
Expand All @@ -127,7 +128,7 @@ private void AddQueueHandler(Type queueType, string queueName, int threadCount=1
{
queueName = queueName.SafeQueueName()!;

#if NETCORE
#if !NETFRAMEWORK
var sbClient = new QueueClient(address, queueName, ReceiveMode.PeekLock);
var messageHandler = this.GetMessageHandler(queueType);
var sbWorker = new ServiceBusMqWorker(messageHandler, CreateMessageQueueClient(), queueName, sbClient);
Expand Down Expand Up @@ -162,7 +163,7 @@ private void AddQueueHandler(Type queueType, string queueName, int threadCount=1
protected internal void StopQueues()
{
this.status = WorkerStatus.Stopping;
#if NETCORE
#if !NETFRAMEWORK
sbClients.Each(async kvp => await kvp.Value.CloseAsync());
#else
sbClients.Each(kvp => kvp.Value.Close());
Expand All @@ -180,7 +181,7 @@ protected internal QueueClient GetOrCreateClient(string queueName)

var qd = new QueueDescription(queueName);

#if !NETCORE
#if NETFRAMEWORK
// Create queue on ServiceBus namespace if it doesn't exist
if (!namespaceManager.QueueExists(queueName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using ServiceStack.Messaging;
using ServiceStack.Text;
#if NETCORE
#if !NETFRAMEWORK
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.ServiceBus.Core;
#else
Expand All @@ -16,7 +16,7 @@ public class ServiceBusMqMessageProducer : IMessageProducer
private readonly Dictionary<string, MessageReceiver> sbReceivers = new();
protected readonly ServiceBusMqMessageFactory? parentFactory;

#if NETCORE
#if !NETFRAMEWORK
public Action<Microsoft.Azure.ServiceBus.Message,IMessage> PublishMessageFilter { get; set; }
#else
public Action<BrokeredMessage,IMessage> PublishMessageFilter { get; set; }
Expand Down Expand Up @@ -65,7 +65,7 @@ public virtual void Publish(string queueName, IMessage message)
using (JsConfig.With(new Text.Config { IncludeTypeInfo = true }))
{
var msgBody = JsonSerializer.SerializeToString(message, typeof(IMessage));
#if NETCORE
#if !NETFRAMEWORK
var msg = new Microsoft.Azure.ServiceBus.Message
{
Body = msgBody.ToUtf8Bytes(),
Expand All @@ -80,7 +80,7 @@ public virtual void Publish(string queueName, IMessage message)
}
}

#if NETCORE
#if !NETFRAMEWORK
public Microsoft.Azure.ServiceBus.Message ApplyFilter(Microsoft.Azure.ServiceBus.Message azureMessage, IMessage message)
{
PublishMessageFilter?.Invoke(azureMessage, message);
Expand All @@ -94,7 +94,7 @@ public BrokeredMessage ApplyFilter(BrokeredMessage azureMessage, IMessage messag
}
#endif

#if NETCORE
#if !NETFRAMEWORK
protected MessageReceiver GetOrCreateMessageReceiver(string queueName)
{
queueName = queueName.SafeQueueName()!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using ServiceStack.Text;
#if NETCORE
#if !NETFRAMEWORK
using Microsoft.Azure.ServiceBus.Management;
#else
using Microsoft.ServiceBus;
Expand Down Expand Up @@ -51,7 +51,7 @@ public ServiceBusMqServer(string connectionString)
public Func<object, object> ResponseFilter { get; set; }


#if NETCORE
#if !NETFRAMEWORK
/// <summary>
/// Exposes the <see cref="Microsoft.Azure.ServiceBus.Management.ManagementClient"/> which can be used to perform
/// management operations on ServiceBus entities.
Expand Down Expand Up @@ -104,7 +104,7 @@ public bool DisablePublishingToOutq
public bool DisableNotifyMessages { get; set; }


#if NETCORE
#if !NETFRAMEWORK
public Action<Microsoft.Azure.ServiceBus.Message,IMessage> PublishMessageFilter
{
get => messageFactory!.PublishMessageFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
#if NETCORE
#if !NETFRAMEWORK
using Microsoft.Azure.ServiceBus;
#else
using Microsoft.ServiceBus.Messaging;
Expand Down Expand Up @@ -38,7 +38,7 @@ public ServiceBusMqWorker(IMessageHandler messageHandler,

public IMessageHandlerStats GetStats() => MessageHandler.GetStats();

#if NETCORE
#if !NETFRAMEWORK
public Task HandleMessageAsync(Microsoft.Azure.ServiceBus.Message msg, CancellationToken token)
{
var strMessage = msg.Body.FromMessageBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ServiceStack.Azure.Storage;

public static class CloudBlobContainerExtension
{
#if NETCORE
#if !NETFRAMEWORK
public static IEnumerable<IListBlobItem> ListBlobs(this CloudBlobContainer container, string? prefix = null,
bool useFlatBlobListing = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public PostgreSqlDialectProvider()
RegisterConverter<DateOnly>(new PostgreSqlDateOnlyConverter());
#endif

#if NET472
#if NETFRAMEWORK
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using ServiceStack.DataAnnotations;
using ServiceStack.OrmLite.SqlServer.Converters;
using ServiceStack.Text;
#if NETCORE
#if !NETFRAMEWORK
using ApplicationException = System.InvalidOperationException;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public override object FromDbValue(Type fieldType, object value)

if (DateStyle == DateTimeKind.Utc)
{
#if NETCORE
#if !NETFRAMEWORK
//.NET Core returns correct Local time but as Unspecified so change to Local and Convert to UTC
dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Local).ToUniversalTime();
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected SqliteOrmLiteDialectProviderBase()
base.RegisterConverter<Guid>(new SqliteGuidConverter());
base.RegisterConverter<bool>(new SqliteBoolConverter());
base.RegisterConverter<byte[]>(new SqliteByteArrayConverter());
#if NETCORE
#if !NETFRAMEWORK
base.RegisterConverter<char>(new SqliteCharConverter());
#endif
this.Variables = new Dictionary<string, string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Reflection;
using System.Runtime.Serialization;
using ServiceStack.DataAnnotations;
#if NETCORE
#if !NETFRAMEWORK
using System.Globalization;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static void ResetLogFactory(ILogFactory logFactory=null)

public static bool DisableColumnGuessFallback { get; set; }
public static bool StripUpperInLike { get; set; }
#if NETCORE
#if !NETFRAMEWORK
= true;
#endif

Expand Down
10 changes: 5 additions & 5 deletions ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
#if !NETCORE
#if NETFRAMEWORK
using System.Runtime.Remoting.Messaging;
#endif
using System.Threading;
Expand All @@ -23,7 +23,7 @@ public class OrmLiteContext
[ThreadStatic]
public static IDictionary ContextItems;

#if NETCORE
#if !NETFRAMEWORK
AsyncLocal<IDictionary> localContextItems = new();
#endif

Expand All @@ -40,7 +40,7 @@ public virtual IDictionary Items

private IDictionary GetItems()
{
#if NETCORE
#if !NETFRAMEWORK
if (UseThreadStatic)
return ContextItems;

Expand All @@ -63,7 +63,7 @@ private IDictionary GetItems()

private IDictionary CreateItems(IDictionary items = null)
{
#if NETCORE
#if !NETFRAMEWORK
if (UseThreadStatic)
{
ContextItems = items ??= new Dictionary<object, object>();
Expand Down Expand Up @@ -101,7 +101,7 @@ public void ClearItems()
}
else
{
#if NETCORE
#if !NETFRAMEWORK
localContextItems.Value = new ConcurrentDictionary<object, object>();
#else
CallContext.FreeNamedDataSlot(_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Primitives" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Primitives" Version="4.3.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

</Project>
Loading