Skip to content

Commit 6876497

Browse files
committed
removed dependency on IHttpContextAccessor because HasIso8601FractionBug was always returning true anyway, and it was the only place that used it
1 parent 1bb066a commit 6876497

7 files changed

+26
-40
lines changed

NWebDav.Sample.AzureBlob/AzureBlob/AzureBlobCollectionPropertyManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ internal class AzureBlobCollectionPropertyManager : PropertyManager<AzureBlobCol
1212
{
1313
private static readonly XElement s_xDavCollection = new(WebDavNamespaces.DavNs + "collection");
1414

15-
public AzureBlobCollectionPropertyManager(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) : base(GetProperties(httpContextAccessor, lockingManager))
15+
public AzureBlobCollectionPropertyManager(ILockingManager lockingManager) : base(GetProperties(lockingManager))
1616
{
1717
}
1818

19-
private static DavProperty<AzureBlobCollection>[] GetProperties(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) => new DavProperty<AzureBlobCollection>[]
19+
private static DavProperty<AzureBlobCollection>[] GetProperties(ILockingManager lockingManager) => new DavProperty<AzureBlobCollection>[]
2020
{
2121
// RFC-2518 properties
22-
new DavCreationDate<AzureBlobCollection>(httpContextAccessor)
22+
new DavCreationDate<AzureBlobCollection>()
2323
{
2424
Getter = collection => collection.StoreItemMetadata.CreatedOn,
2525
},

NWebDav.Sample.AzureBlob/AzureBlob/AzureBlobItemPropertyManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ namespace NWebDav.Sample.AzureBlob.AzureBlob;
77

88
internal class AzureBlobItemPropertyManager : PropertyManager<AzureBlobItem>
99
{
10-
public AzureBlobItemPropertyManager(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) : base(GetProperties(httpContextAccessor, lockingManager))
10+
public AzureBlobItemPropertyManager(ILockingManager lockingManager) : base(GetProperties(lockingManager))
1111
{
1212
}
1313

14-
private static DavProperty<AzureBlobItem>[] GetProperties(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) => new DavProperty<AzureBlobItem>[]
14+
private static DavProperty<AzureBlobItem>[] GetProperties(ILockingManager lockingManager) => new DavProperty<AzureBlobItem>[]
1515
{
1616
// RFC-2518 properties
17-
new DavCreationDate<AzureBlobItem>(httpContextAccessor)
17+
new DavCreationDate<AzureBlobItem>()
1818
{
1919
Getter = item => item.StoreItemMetadata.CreatedOn,
2020
},

NWebDav.Sample.AzureBlob/AzureBlob/AzureContainerCollectionPropertyManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ internal class AzureContainerCollectionPropertyManager : PropertyManager<AzureCo
1313
{
1414
private static readonly XElement s_xDavCollection = new(WebDavNamespaces.DavNs + "collection");
1515

16-
public AzureContainerCollectionPropertyManager(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) : base(GetProperties(httpContextAccessor, lockingManager))
16+
public AzureContainerCollectionPropertyManager(ILockingManager lockingManager) : base(GetProperties(lockingManager))
1717
{
1818
}
1919

20-
private static DavProperty<AzureContainerCollection>[] GetProperties(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) => new DavProperty<AzureContainerCollection>[]
20+
private static DavProperty<AzureContainerCollection>[] GetProperties(ILockingManager lockingManager) => new DavProperty<AzureContainerCollection>[]
2121
{
2222
// RFC-2518 properties
23-
new DavCreationDate<AzureContainerCollection>(httpContextAccessor)
23+
new DavCreationDate<AzureContainerCollection>()
2424
{
2525
Getter = _ => DateTime.UnixEpoch,
2626
},

NWebDav.Server/Props/DavTypedProperties.cs

+10-23
Original file line numberDiff line numberDiff line change
@@ -188,47 +188,34 @@ public abstract class DavIso8601Date<TEntry> : DavTypedProperty<TEntry, DateTime
188188
{
189189
private readonly Iso8601DateConverter _converter;
190190

191-
protected DavIso8601Date(IHttpContextAccessor httpContextAccessor)
191+
protected DavIso8601Date()
192192
{
193-
_converter = new Iso8601DateConverter(httpContextAccessor);
193+
_converter = Iso8601DateConverter.Instance;
194194
}
195195

196196
private class Iso8601DateConverter : IConverter
197197
{
198-
private readonly IHttpContextAccessor _httpContextAccessor;
199-
200-
public Iso8601DateConverter(IHttpContextAccessor httpContextAccessor)
198+
internal static readonly Iso8601DateConverter Instance = new();
199+
Iso8601DateConverter()
201200
{
202-
_httpContextAccessor = httpContextAccessor;
203201
}
204202

205203
public object ToXml(DateTime value)
206204
{
207205
// The older built-in Windows WebDAV clients have a problem, so
208206
// they cannot deal with more than 3 digits for the
209207
// milliseconds.
210-
if (HasIso8601FractionBug)
211-
{
212-
// We need to recreate the date again, because the Windows 7
213-
// WebDAV client cannot
214-
var dt = new DateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, value.Millisecond, DateTimeKind.Utc);
215-
return XmlConvert.ToString(dt, XmlDateTimeSerializationMode.Utc);
216-
}
217208

218-
return XmlConvert.ToString(value, XmlDateTimeSerializationMode.Utc);
209+
// P.S. I think the previous comment meant "less than 3 digits".
210+
211+
// We need to recreate the date again, because the Windows 7
212+
// WebDAV client cannot
213+
var dt = new DateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, value.Millisecond, DateTimeKind.Utc);
214+
return XmlConvert.ToString(dt, XmlDateTimeSerializationMode.Utc);
219215
}
220216

221217
public DateTime FromXml(object value) => XmlConvert.ToDateTime((string)value, XmlDateTimeSerializationMode.Utc);
222218

223-
private bool HasIso8601FractionBug
224-
{
225-
get
226-
{
227-
var userAgent = _httpContextAccessor.HttpContext?.Request.Headers.UserAgent.FirstOrDefault();
228-
_ = userAgent; // TODO: Determine if this bug is present based on the user-agent
229-
return true;
230-
}
231-
}
232219
}
233220

234221
/// <summary>

NWebDav.Server/Props/StandardProperties.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Xml.Linq;
2-
using Microsoft.AspNetCore.Http;
32
using NWebDav.Server.Stores;
43

54
namespace NWebDav.Server.Props;
@@ -25,7 +24,7 @@ public class DavCreationDate<TEntry> : DavIso8601Date<TEntry> where TEntry : ISt
2524
// ReSharper disable once StaticMemberInGenericType
2625
public static readonly XName PropertyName = WebDavNamespaces.DavNs + "creationdate";
2726

28-
public DavCreationDate(IHttpContextAccessor httpContextAccessor) : base(httpContextAccessor)
27+
public DavCreationDate() : base()
2928
{}
3029

3130
/// <summary>

NWebDav.Server/Stores/DiskStoreCollectionPropertyManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public class DiskStoreCollectionPropertyManager : PropertyManager<DiskStoreColle
1111
{
1212
private static readonly XElement s_xDavCollection = new(WebDavNamespaces.DavNs + "collection");
1313

14-
public DiskStoreCollectionPropertyManager(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) : base(GetProperties(httpContextAccessor, lockingManager))
14+
public DiskStoreCollectionPropertyManager(ILockingManager lockingManager) : base(GetProperties(lockingManager))
1515
{
1616
}
1717

18-
private static DavProperty<DiskStoreCollection>[] GetProperties(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) => new DavProperty<DiskStoreCollection>[]
18+
private static DavProperty<DiskStoreCollection>[] GetProperties(ILockingManager lockingManager) => new DavProperty<DiskStoreCollection>[]
1919
{
2020
// RFC-2518 properties
21-
new DavCreationDate<DiskStoreCollection>(httpContextAccessor)
21+
new DavCreationDate<DiskStoreCollection>()
2222
{
2323
Getter = collection => collection.DirectoryInfo.CreationTimeUtc,
2424
Setter = (collection, value) =>

NWebDav.Server/Stores/DiskStoreItemPropertyManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ namespace NWebDav.Server.Stores;
1111

1212
public class DiskStoreItemPropertyManager : PropertyManager<DiskStoreItem>
1313
{
14-
public DiskStoreItemPropertyManager(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) : base(GetProperties(httpContextAccessor, lockingManager))
14+
public DiskStoreItemPropertyManager(ILockingManager lockingManager) : base(GetProperties(lockingManager))
1515
{
1616
}
1717

18-
private static DavProperty<DiskStoreItem>[] GetProperties(IHttpContextAccessor httpContextAccessor, ILockingManager lockingManager) => new DavProperty<DiskStoreItem>[]
18+
private static DavProperty<DiskStoreItem>[] GetProperties(ILockingManager lockingManager) => new DavProperty<DiskStoreItem>[]
1919
{
2020
// RFC-2518 properties
21-
new DavCreationDate<DiskStoreItem>(httpContextAccessor)
21+
new DavCreationDate<DiskStoreItem>()
2222
{
2323
Getter = item => item.FileInfo.CreationTimeUtc,
2424
Setter = (item, value) =>

0 commit comments

Comments
 (0)