PageRenderTime 27ms CodeModel.GetById 23ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/DotNetSlave.BusinessLogic/Web/InstallUtil.cs

#
C# | 73 lines | 48 code | 9 blank | 16 comment | 7 complexity | 62016f7c3e67323f156d04d05d85c1d0 MD5 | raw file
 1// Written by: Roman D. Clarkson
 2// http://www.romanclarkson.com  mailto:inspirit@romanclarkson.com
 3
 4using System;
 5using System.Web.Configuration;
 6
 7namespace BlogEngine.Core.Web
 8{
 9    /// <summary>
10    /// 
11    /// </summary>
12    public class InstallUtil
13    {
14        private const string beversion = "BEVersion";
15        private const string installdate = "InstallDate";
16        private const string lastupdated = "LastUpdated";
17
18        /// <summary>
19        /// 
20        /// </summary>
21        public static void CheckInstallation()
22        {
23            CheckIfInstalling();
24            CheckIfUpgrading();
25        }
26
27        private static void UpdateTheLastUpdatedAppKey()
28        {
29            string currentDateTime = DateTime.Now.ToString();
30
31            if (WebConfigurationManager.AppSettings[lastupdated] == null)
32            {
33                AppConfig.Instance().SetValue(lastupdated, currentDateTime);
34            }
35            else
36            {
37                AppConfig.Instance().SetValue(lastupdated, currentDateTime);
38            }
39        }
40
41        /// <summary>
42        /// 
43        /// </summary>
44        /// Todo:  Need to expand this to check the web.config assembly version and compare it with the current assembly in the bin.
45        private static void CheckIfUpgrading()
46        {
47            string currentAssemblyVersion = WebConfigurationManager.AppSettings[beversion];
48            string assemblyVersion = BlogSettings.Instance.Version();
49
50            if (WebConfigurationManager.AppSettings[beversion] == null)
51            {
52                AppConfig.Instance().SetValue(beversion, BlogSettings.Instance.Version());
53                UpdateTheLastUpdatedAppKey();
54            }
55        }
56
57        /// <summary>
58        /// 
59        /// </summary>
60        /// Todo:  This can be expanded using install scripts.
61        private static void CheckIfInstalling()
62        {
63            string currentDateTime = DateTime.Now.ToString();
64
65            if (WebConfigurationManager.AppSettings[installdate] == string.Empty ||
66                WebConfigurationManager.AppSettings[installdate] == null)
67            {
68                AppConfig.Instance().SetValue(installdate, currentDateTime);
69                UpdateTheLastUpdatedAppKey();
70            }
71        }
72    }
73}