Skip to content

Commit 7920a6d

Browse files
committed
Merge branch 'task/efmigrations' into 1.x
2 parents 7f79bb9 + 76a20f7 commit 7920a6d

230 files changed

Lines changed: 31101 additions & 13610 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ csx
143143
AppPackages/
144144

145145
# Others
146-
sql/
146+
# sql/
147147
*.Cache
148148
ClientBin/
149149
[Ss]tyle[Cc]op.*

SmartStoreNET.Tasks.Targets

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@
9898

9999
<ItemGroup>
100100
<PluginFiles Include="$(WebPluginsFolder)\**\*" />
101-
<MigrationFiles Include="$(WebFolder)\App_Data\Migrations\**\*.sql" />
102-
<MigrationFiles Include="$(WebFolder)\App_Data\Migrations\**\*.txt" />
103101
<UploadedImages Include="$(WebFolder)\Media\uploaded\**\*" />
104102
<SqlCe-Native-Binaries-x86 Include="$(SqlCeFolder)\x86\**\*"/>
105103
<SqlCe-Native-Binaries-amd64 Include="$(SqlCeFolder)\amd64\**\*"/>
@@ -125,9 +123,6 @@
125123

126124
<!-- copy the plugins to the stage directory -->
127125
<Copy SourceFiles="@(PluginFiles)" DestinationFolder="$(StageFolder)\Plugins\%(RecursiveDir)" />
128-
129-
<!-- copy the migration sql scripts to the stage directory -->
130-
<Copy SourceFiles="@(MigrationFiles)" DestinationFolder="$(StageFolder)\App_Data\Migrations\%(RecursiveDir)" />
131126

132127
<!-- publish SmartStore.Admin -->
133128
<MSBuild Projects="$(WebFolder)\Administration\SmartStore.Admin.csproj"

src/Libraries/SmartStore.Core/Caching/NullCache.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ namespace SmartStore.Core.Caching
77
public partial class NullCache : ICacheManager
88
{
99

10+
private readonly static ICacheManager s_instance = new NullCache();
11+
12+
public static ICacheManager Instance
13+
{
14+
get { return s_instance; }
15+
}
16+
1017
public T Get<T>(string key, Func<T> acquirer, int? cacheTime = 60)
1118
{
1219
return acquirer();

src/Libraries/SmartStore.Core/Data/BaseDataProviderManager.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
namespace SmartStore.Core.Data
4+
{
5+
public abstract class DataProviderFactory
6+
{
7+
protected DataProviderFactory(DataSettings settings)
8+
{
9+
Guard.ArgumentNotNull(() => settings);
10+
this.Settings = settings;
11+
}
12+
13+
protected DataSettings Settings
14+
{
15+
get;
16+
private set;
17+
}
18+
19+
public abstract IDataProvider LoadDataProvider();
20+
}
21+
}
Lines changed: 246 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,258 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using System.Web.Hosting;
8+
using SmartStore.Utilities;
9+
using SmartStore.Utilities.Threading;
310

411
namespace SmartStore.Core.Data
512
{
6-
public partial class DataSettings
13+
14+
public partial class DataSettings
715
{
8-
public DataSettings()
16+
private static readonly ReaderWriterLockSlim s_rwLock = new ReaderWriterLockSlim();
17+
private static DataSettings s_current = null;
18+
private static Func<DataSettings> s_settingsFactory = new Func<DataSettings>(() => new DataSettings());
19+
private static bool? s_installed = null;
20+
21+
protected const char SEPARATOR = ':';
22+
protected const string FILENAME = "Settings.txt";
23+
24+
private DataSettings()
925
{
10-
RawDataSettings=new Dictionary<string, string>();
26+
RawDataSettings = new Dictionary<string, string>();
1127
}
12-
public string DataProvider { get; set; }
13-
public string DataConnectionString { get; set; }
14-
public IDictionary<string, string> RawDataSettings { get; private set; }
28+
29+
#region Static members
30+
31+
public static void SetDefaultFactory(Func<DataSettings> factory)
32+
{
33+
Guard.ArgumentNotNull(() => factory);
34+
35+
lock (s_rwLock.GetWriteLock())
36+
{
37+
s_settingsFactory = factory;
38+
}
39+
}
40+
41+
public static DataSettings Current
42+
{
43+
get
44+
{
45+
using (s_rwLock.GetUpgradeableReadLock())
46+
{
47+
if (s_current == null)
48+
{
49+
using (s_rwLock.GetWriteLock())
50+
{
51+
if (s_current == null)
52+
{
53+
s_current = s_settingsFactory();
54+
s_current.Load();
55+
}
56+
}
57+
}
58+
}
59+
60+
return s_current;
61+
}
62+
}
63+
64+
public static bool DatabaseIsInstalled()
65+
{
66+
if (!s_installed.HasValue)
67+
{
68+
s_installed = Current.IsValid();
69+
}
70+
71+
return s_installed.Value;
72+
}
73+
74+
public static void Reload()
75+
{
76+
using (s_rwLock.GetWriteLock())
77+
{
78+
s_current = null;
79+
s_installed = null;
80+
}
81+
}
82+
83+
public static void Delete()
84+
{
85+
using (s_rwLock.GetWriteLock())
86+
{
87+
string filePath = Path.Combine(CommonHelper.MapPath("~/App_Data/"), FILENAME);
88+
File.Delete(filePath);
89+
s_current = null;
90+
s_installed = null;
91+
}
92+
}
93+
94+
#endregion
95+
96+
#region Instance members
97+
98+
public string DataProvider
99+
{
100+
get;
101+
set;
102+
}
103+
104+
public string ProviderInvariantName
105+
{
106+
get
107+
{
108+
if (this.DataProvider.HasValue() && this.DataProvider.IsCaseInsensitiveEqual("sqlserver"))
109+
return "System.Data.SqlClient";
110+
111+
// SqlCe should always be the default provider
112+
return "System.Data.SqlServerCe.4.0";
113+
}
114+
}
115+
116+
public bool IsSqlServer
117+
{
118+
get
119+
{
120+
return this.DataProvider.HasValue() && this.DataProvider.IsCaseInsensitiveEqual("sqlserver");
121+
}
122+
}
123+
124+
public string DataConnectionString
125+
{
126+
get;
127+
set;
128+
}
129+
130+
public IDictionary<string, string> RawDataSettings
131+
{
132+
get;
133+
private set;
134+
}
15135

16136
public bool IsValid()
17137
{
18-
return !String.IsNullOrEmpty(this.DataProvider) && !String.IsNullOrEmpty(this.DataConnectionString);
19-
}
20-
}
138+
return this.DataProvider.HasValue() && this.DataConnectionString.HasValue();
139+
}
140+
141+
public virtual bool Load()
142+
{
143+
using (s_rwLock.GetWriteLock())
144+
{
145+
string filePath = Path.Combine(CommonHelper.MapPath("~/App_Data/"), FILENAME);
146+
147+
this.Reset();
148+
149+
if (File.Exists(filePath))
150+
{
151+
string text = File.ReadAllText(filePath);
152+
var settings = ParseSettings(text);
153+
if (settings.Any())
154+
{
155+
this.RawDataSettings.AddRange(settings);
156+
if (settings.ContainsKey("DataProvider"))
157+
{
158+
this.DataProvider = settings["DataProvider"];
159+
}
160+
if (settings.ContainsKey("DataConnectionString"))
161+
{
162+
this.DataConnectionString = settings["DataConnectionString"];
163+
}
164+
165+
return this.IsValid();
166+
}
167+
}
168+
169+
return false;
170+
}
171+
}
172+
173+
public void Reset()
174+
{
175+
using (s_rwLock.GetWriteLock())
176+
{
177+
this.RawDataSettings.Clear();
178+
this.DataProvider = null;
179+
this.DataConnectionString = null;
180+
s_installed = null;
181+
}
182+
}
183+
184+
public virtual bool Save()
185+
{
186+
if (!this.IsValid())
187+
return false;
188+
189+
using (s_rwLock.GetWriteLock())
190+
{
191+
string filePath = Path.Combine(CommonHelper.MapPath("~/App_Data/"), FILENAME);
192+
if (!File.Exists(filePath))
193+
{
194+
using (File.Create(filePath))
195+
{
196+
// we use 'using' to close the file after it's created
197+
}
198+
}
199+
200+
var text = SerializeSettings();
201+
File.WriteAllText(filePath, text);
202+
203+
return true;
204+
}
205+
}
206+
207+
#endregion
208+
209+
#region Instance helpers
210+
211+
protected virtual IDictionary<string, string> ParseSettings(string text)
212+
{
213+
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
214+
215+
if (text.IsEmpty())
216+
return result;
217+
218+
var settings = new List<string>();
219+
using (var reader = new StringReader(text))
220+
{
221+
string str;
222+
while ((str = reader.ReadLine()) != null)
223+
settings.Add(str);
224+
}
225+
226+
foreach (var setting in settings)
227+
{
228+
var separatorIndex = setting.IndexOf(SEPARATOR);
229+
if (separatorIndex == -1)
230+
{
231+
continue;
232+
}
233+
string key = setting.Substring(0, separatorIndex).Trim();
234+
string value = setting.Substring(separatorIndex + 1).Trim();
235+
236+
if (key.HasValue() && value.HasValue())
237+
{
238+
result.Add(key, value);
239+
}
240+
}
241+
242+
return result;
243+
}
244+
245+
protected virtual string SerializeSettings()
246+
{
247+
return string.Format("DataProvider: {0}{2}DataConnectionString: {1}{2}",
248+
this.DataProvider,
249+
this.DataConnectionString,
250+
Environment.NewLine
251+
);
252+
}
253+
254+
#endregion
255+
256+
}
257+
21258
}

src/Libraries/SmartStore.Core/Data/DataSettingsHelper.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)