Skip to content

Commit 71a75da

Browse files
committed
Fixes how the file paths can be set dynamically on startup, bumps version
1 parent 4483b55 commit 71a75da

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

ClientDependency.Core/CompositeFiles/Providers/BaseCompositeFileProcessingProvider.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,32 @@ namespace ClientDependency.Core.CompositeFiles.Providers
1414
{
1515
public abstract class BaseCompositeFileProcessingProvider : ProviderBase, IHttpProvider
1616
{
17+
18+
private static bool _dynamicallyConfiguredPath = false;
19+
private static string _compositeFilePathDefaultFolder = "~/App_Data/ClientDependency";
20+
1721
/// <summary>
18-
/// The default path for storing composite files
22+
/// The default path for storing composite files, either absolute or virtual
1923
/// </summary>
2024
/// <remarks>
2125
/// Can be set dynamically during startup
2226
/// </remarks>
23-
public static string CompositeFilePathVirtualFolderDefault = "~/App_Data/ClientDependency";
27+
public static string CompositeFilePathDefaultFolder
28+
{
29+
get { return _compositeFilePathDefaultFolder; }
30+
set
31+
{
32+
_compositeFilePathDefaultFolder = value;
33+
_dynamicallyConfiguredPath = true;
34+
}
35+
}
2436

2537
/// <summary>
2638
/// Defines the UrlType default value, this can be set at startup
2739
/// </summary>
2840
public static CompositeUrlType UrlTypeDefault = CompositeUrlType.MappedId;
29-
30-
public string CompositeFilePathVirtualFolder { get; private set; } = CompositeFilePathVirtualFolderDefault;
41+
42+
public string CompositeFilePathFolder { get; private set; }
3143

3244
/// <summary>
3345
/// constructor sets defaults
@@ -40,6 +52,7 @@ protected BaseCompositeFileProcessingProvider()
4052
UrlType = UrlTypeDefault;
4153
PathBasedUrlFormat = "{dependencyId}/{version}/{type}";
4254
BundleDomains = new List<string>();
55+
CompositeFilePathFolder = CompositeFilePathDefaultFolder;
4356
}
4457

4558
#region Public Properties
@@ -89,7 +102,9 @@ protected BaseCompositeFileProcessingProvider()
89102

90103
public void Initialize(HttpContextBase http)
91104
{
92-
CompositeFilePath = new DirectoryInfo(http.Server.MapPath(CompositeFilePathVirtualFolder));
105+
CompositeFilePath = CompositeFilePathFolder.StartsWith("~/")
106+
? new DirectoryInfo(http.Server.MapPath(CompositeFilePathFolder))
107+
: new DirectoryInfo(CompositeFilePathFolder);
93108
}
94109

95110
#endregion
@@ -550,12 +565,10 @@ public override void Initialize(string name, System.Collections.Specialized.Name
550565

551566
if (config["compositeFilePath"] != null)
552567
{
553-
//use the config setting if it has not been dynamically set OR
554-
//when the config section doesn't equal the default
555-
if (CompositeFilePathVirtualFolder == CompositeFilePathVirtualFolderDefault
556-
|| config["compositeFilePath"] != CompositeFilePathVirtualFolderDefault)
568+
//use the config setting if it has not been dynamically set
569+
if (!_dynamicallyConfiguredPath)
557570
{
558-
CompositeFilePathVirtualFolder = config["compositeFilePath"];
571+
CompositeFilePathFolder = config["compositeFilePath"];
559572
}
560573
}
561574

ClientDependency.Core/CompositeFiles/Providers/XmlFileMapper.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Linq;
45
using System.Text;
56
using System.Web;
@@ -31,24 +32,50 @@ public class XmlFileMapper : BaseFileMapProvider
3132
private FileInfo _xmlFile;
3233

3334
private static readonly object Locker = new object();
35+
private static string _fileMapFolder = "~/App_Data/ClientDependency";
36+
private static bool _dynamicallyConfiguredPath = false;
37+
38+
[Obsolete("Use FileMapDefaultFolder instead")]
39+
[EditorBrowsable(EditorBrowsableState.Never)]
40+
public static string FileMapVirtualFolder
41+
{
42+
get { return FileMapDefaultFolder; }
43+
set { FileMapDefaultFolder = value; }
44+
}
3445

3546
/// <summary>
36-
/// Specifies the default folder to store the file map in
47+
/// Specifies the default folder to store the file map in, either absolute or virtual
3748
/// </summary>
3849
/// <remarks>
3950
/// allows for dynamically changing the folder on startup
4051
/// </remarks>
41-
public static string FileMapVirtualFolder = "~/App_Data/ClientDependency";
52+
public static string FileMapDefaultFolder
53+
{
54+
get { return _fileMapFolder; }
55+
set
56+
{
57+
_fileMapFolder = value;
58+
_dynamicallyConfiguredPath = true;
59+
}
60+
}
4261

43-
public string FileMapFolder { get; private set; } = FileMapVirtualFolder;
62+
public string FileMapFolder { get; private set; }
4463

4564
private DirectoryInfo _xmlMapFolder;
4665

66+
public XmlFileMapper()
67+
{
68+
FileMapFolder = FileMapDefaultFolder;
69+
}
70+
4771
public override void Initialize(HttpContextBase http)
4872
{
4973
if (http == null) throw new ArgumentNullException("http");
5074

51-
_xmlMapFolder = new DirectoryInfo(http.Server.MapPath(FileMapFolder));
75+
//check for a virtual path before MapPath
76+
_xmlMapFolder = FileMapFolder.StartsWith("~/")
77+
? new DirectoryInfo(http.Server.MapPath(FileMapFolder))
78+
: new DirectoryInfo(FileMapFolder);
5279

5380
//Name the map file according to the machine name
5481
_xmlFile = new FileInfo(GetXmlMapPath());
@@ -82,10 +109,8 @@ public override void Initialize(string name, System.Collections.Specialized.Name
82109

83110
if (config["mapPath"] != null)
84111
{
85-
//use the config setting if it has not been dynamically set OR
86-
//when the config section doesn't equal the default
87-
if (FileMapFolder == FileMapVirtualFolder
88-
|| config["mapPath"] != FileMapVirtualFolder)
112+
//use the config setting if it has not been dynamically set
113+
if (!_dynamicallyConfiguredPath)
89114
{
90115
FileMapFolder = config["mapPath"];
91116
}

ClientDependency.UnitTests/ClientDependencySettingsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public void Settings_Legacy_Pre_13()
6767
Assert.AreEqual(1, settings.ConfigSection.CompositeFileElement.MimeTypeCompression.Count);
6868
Assert.AreEqual(0, settings.ConfigSection.CompositeFileElement.RogueFileCompression.Count);
6969

70-
Assert.AreEqual(settings.DefaultCompositeFileProcessingProvider.CompositeFilePathVirtualFolder, "~/App_Data/TEMP/ClientDependency");
71-
Assert.AreEqual(settings.DefaultCompositeFileProcessingProvider.CompositeFilePathVirtualFolder, XmlFileMapper.FileMapVirtualFolder);
70+
Assert.AreEqual(settings.DefaultCompositeFileProcessingProvider.CompositeFilePathFolder, "~/App_Data/TEMP/ClientDependency");
71+
Assert.AreEqual(settings.DefaultCompositeFileProcessingProvider.CompositeFilePathFolder, XmlFileMapper.FileMapVirtualFolder);
7272
Assert.AreEqual(CompositeUrlType.Base64QueryStrings, settings.DefaultCompositeFileProcessingProvider.UrlType);
7373
}
7474

SolutionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
[assembly: AssemblyVersion("1.9.4")]
1111
[assembly: AssemblyFileVersion("1.9.4")]
12-
[assembly: AssemblyInformationalVersion("1.9.4-beta")]
12+
[assembly: AssemblyInformationalVersion("1.9.4-beta02")]

0 commit comments

Comments
 (0)