diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 8d67c53..47c57f6 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -1973 \ No newline at end of file +1981 \ No newline at end of file diff --git a/Builder/IISMainHandler/product.wxs b/Builder/IISMainHandler/product.wxs index dc4afb1..986e293 100644 --- a/Builder/IISMainHandler/product.wxs +++ b/Builder/IISMainHandler/product.wxs @@ -87,6 +87,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -99,28 +123,22 @@ - - - + + + + + - - - - + + + + - - - + + + - - - - - - - - @@ -129,6 +147,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FLocal.Common/Config.cs b/FLocal.Common/Config.cs index 14b06d6..4055cb3 100644 --- a/FLocal.Common/Config.cs +++ b/FLocal.Common/Config.cs @@ -10,6 +10,8 @@ namespace FLocal.Common { public class Config : Config { + public readonly string AppInfo; + public readonly string InitTime; public readonly Web.Core.DB.IDBConnection mainConnection; @@ -52,8 +54,9 @@ namespace FLocal.Common { public readonly ILogger Logger; - protected Config(NameValueCollection data) : base(data) { + protected Config(NameValueCollection data) : base() { this.InitTime = DateTime.Now.ToLongTimeString(); + this.AppInfo = data["AppInfo"]; this.dataDir = data["DataDir"]; this.DirSeparator = System.IO.Path.DirectorySeparatorChar.ToString(); this.SaltMigration = data["SaltMigration"]; diff --git a/FLocal.IISHandler/FLocal.IISHandler.csproj b/FLocal.IISHandler/FLocal.IISHandler.csproj index f1f7388..43636a5 100644 --- a/FLocal.IISHandler/FLocal.IISHandler.csproj +++ b/FLocal.IISHandler/FLocal.IISHandler.csproj @@ -132,6 +132,14 @@ {CE888859-9E46-41F7-91CE-8EC106F3A625} Common + + {AD931A4B-F62A-4095-B185-BAA9C991FBFF} + FLocal.Patcher.Common + + + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED} + Patcher.Web + {6F532626-E9F8-498E-9683-1538E7CD62CB} Core diff --git a/FLocal.IISHandler/Initializer.cs b/FLocal.IISHandler/Initializer.cs index fa8b730..ad78d61 100644 --- a/FLocal.IISHandler/Initializer.cs +++ b/FLocal.IISHandler/Initializer.cs @@ -9,6 +9,7 @@ using FLocal.Common; using FLocal.Common.dataobjects; using System.IO; using System.Threading; +using FLocal.Patcher.Common; namespace FLocal.IISHandler { class Initializer { @@ -39,6 +40,7 @@ namespace FLocal.IISHandler { private void DoInitialize() { Config.Init(ConfigurationManager.AppSettings); + PatcherConfiguration.Init(ConfigurationManager.AppSettings); string dir = FLocal.Common.Config.instance.dataDir + "Logs\\"; using(StreamWriter writer = new StreamWriter(dir + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".INITIALIZE.txt")) { diff --git a/FLocal.IISHandler/MainHandler.cs b/FLocal.IISHandler/MainHandler.cs index f3a53fe..f66a931 100644 --- a/FLocal.IISHandler/MainHandler.cs +++ b/FLocal.IISHandler/MainHandler.cs @@ -6,6 +6,7 @@ using System.Web; using System.Configuration; using Web.Core; using FLocal.Common; +using FLocal.Patcher.Common; namespace FLocal.IISHandler { public class MainHandler : IHttpHandler { @@ -18,12 +19,16 @@ namespace FLocal.IISHandler { private void doProcessRequest(HttpContext httpcontext) { + if(PatcherInfo.instance.IsNeedsPatching) { + throw new FLocalException("DB is outdated"); + } + Uri current = httpcontext.Request.Url; if(!current.Host.EndsWith(Config.instance.BaseHost)) { - throw new Web.Core.FLocalException("Wrong host: " + current.Host + " (expected *" + Config.instance.BaseHost + ")"); + throw new FLocalException("Wrong host: " + current.Host + " (expected *" + Config.instance.BaseHost + ")"); } if(Config.instance.forceHttps && !httpcontext.Request.IsSecureConnection) { - throw new Web.Core.FLocalException("Only HTTPS connections are allowed"); + throw new FLocalException("Only HTTPS connections are allowed"); } Uri referer = httpcontext.Request.UrlReferrer; diff --git a/FLocal.Migration.Console/Program.cs b/FLocal.Migration.Console/Program.cs index 1763658..66982e9 100644 --- a/FLocal.Migration.Console/Program.cs +++ b/FLocal.Migration.Console/Program.cs @@ -12,10 +12,12 @@ namespace FLocal.Migration.Console { Consolery.Run(typeof(Program), args); } + private static bool isConfigInitialized = false; + private static object initializeConfig_locker = new object(); private static void initializeConfig() { - if(!Config.isInitialized) { - lock(typeof(Config)) { - if(!Config.isInitialized) { + if(!isConfigInitialized) { + lock(initializeConfig_locker) { + if(!isConfigInitialized) { Config.Init(ConfigurationManager.AppSettings); } } diff --git a/FLocal.Patcher.Common/FLocal.Patcher.Common.csproj b/FLocal.Patcher.Common/FLocal.Patcher.Common.csproj new file mode 100644 index 0000000..a29b38d --- /dev/null +++ b/FLocal.Patcher.Common/FLocal.Patcher.Common.csproj @@ -0,0 +1,76 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {AD931A4B-F62A-4095-B185-BAA9C991FBFF} + Library + Properties + FLocal.Patcher.Common + FLocal.Patcher.Common + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + + + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED} + Patcher.Web + + + {78F407CF-416D-4D1F-971C-9A51FEA69B3A} + Patcher + + + {6F532626-E9F8-498E-9683-1538E7CD62CB} + Web.Core + + + + + \ No newline at end of file diff --git a/FLocal.Patcher.Common/PatcherConfiguration.cs b/FLocal.Patcher.Common/PatcherConfiguration.cs new file mode 100644 index 0000000..5e5dd7c --- /dev/null +++ b/FLocal.Patcher.Common/PatcherConfiguration.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Collections.Specialized; +using System.IO; +using Patcher.Data.Patch; +using Web.Core; +using Patcher.Web; + +namespace FLocal.Patcher.Common { + public class PatcherConfiguration : Config, IPatcherConfiguration { + + private readonly string _DbDriverName; + public string DbDriverName { + get { throw new NotImplementedException(); } + } + + private readonly string _GuestConnectionString; + public string GuestConnectionString { + get { throw new NotImplementedException(); } + } + + private readonly string _PatchesTable; + public string PatchesTable { + get { throw new NotImplementedException(); } + } + + private readonly string _EnvironmentName; + public string EnvironmentName { + get { throw new NotImplementedException(); } + } + + public IEnumerable getPatchesList() { + return PatchesLoader.getPatchesList(); + } + + public Stream loadPatch(PatchId patchId) { + return PatchesLoader.loadPatch(patchId); + } + + protected PatcherConfiguration(NameValueCollection data) : base() { + this._DbDriverName = data["Patcher.DbDriver"]; + this._EnvironmentName = data["Patcher.EnvironmentName"]; + this._GuestConnectionString = data["ConnectionString"]; + this._PatchesTable = data["Patcher.PatchesTable"]; + } + + public static void Init(NameValueCollection data) { + doInit(() => new PatcherConfiguration(data)); + } + + } +} diff --git a/FLocal.Patcher.Common/PatcherInfo.cs b/FLocal.Patcher.Common/PatcherInfo.cs new file mode 100644 index 0000000..1918cf1 --- /dev/null +++ b/FLocal.Patcher.Common/PatcherInfo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FLocal.Patcher.Common { + public class PatcherInfo : Patcher.Web.PatcherInfo { + + public static readonly PatcherInfo instance = new PatcherInfo(); + + private PatcherInfo() : base(PatcherConfiguration.instance) { + } + + } +} diff --git a/FLocal.Patcher.Common/PatchesLoader.cs b/FLocal.Patcher.Common/PatchesLoader.cs new file mode 100644 index 0000000..d813333 --- /dev/null +++ b/FLocal.Patcher.Common/PatchesLoader.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.IO; +using Patcher.Data.Patch; + +namespace FLocal.Patcher.Common { + static class PatchesLoader { + + private static readonly Regex PatchName = new Regex("^Patch_(?[01-9]+)_(?[a-z]+)\\.xml$", RegexOptions.Compiled | RegexOptions.ExplicitCapture); + + public static IEnumerable getPatchesList() { + return + from resourceName in Resources.ResourcesManager.GetResourcesList() + where PatchName.IsMatch(resourceName) + let match = PatchName.Match(resourceName) + select new PatchId(int.Parse(match.Groups["version"].Value), match.Groups["name"].Value); + } + + public static Stream loadPatch(PatchId patchId) { + return Resources.ResourcesManager.GetResource(String.Format("Patch_{0:D5}_{1}.xml", patchId.version, patchId.name)); + } + + //public static + + } +} diff --git a/FLocal.Patcher.Common/Properties/AssemblyInfo.cs b/FLocal.Patcher.Common/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..07f60f6 --- /dev/null +++ b/FLocal.Patcher.Common/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FLocal.Patcher.Common")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FLocal.Patcher.Common")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ecdf2812-7787-443b-bbf1-00be83dbc3ca")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FLocal.Patcher.Common/Resources/ResourcesManager.cs b/FLocal.Patcher.Common/Resources/ResourcesManager.cs new file mode 100644 index 0000000..b3dd1e7 --- /dev/null +++ b/FLocal.Patcher.Common/Resources/ResourcesManager.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using Patcher; + +namespace FLocal.Patcher.Common.Resources { + static class ResourcesManager { + + public class XmlUrlResolver : System.Xml.XmlUrlResolver { + public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) { + //Assembly assembly = Assembly.GetExecutingAssembly(); + //return assembly.GetManifestResourceStream(this.GetType(),Path.GetFileName(absoluteUri.AbsolutePath)); + // throw new ApplicationException(Path.GetFileName(absoluteUri.AbsolutePath)); + try { + return GetResource(Path.GetFileName(absoluteUri.AbsolutePath)); //note that we ignore all folders structure + } catch(ResourceNotFoundException) { + throw new XmlResourceNotFoundException(absoluteUri); + } + } + } + + public static Stream GetResource(string name) { + var result = Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(ResourcesManager), name); + if(result == null) { + throw new ResourceNotFoundException(name); + } + return result; + } + + private static readonly string Namespace = typeof(ResourcesManager).Namespace + "."; + + public static IEnumerable GetResourcesList() { + return + from rawName in Assembly.GetExecutingAssembly().GetManifestResourceNames() + where rawName.StartsWith(Namespace) + select rawName.Substring(Namespace.Length); + } + + } +} diff --git a/FLocal.Patcher.IISHandler/FLocal.Patcher.IISHandler.csproj b/FLocal.Patcher.IISHandler/FLocal.Patcher.IISHandler.csproj new file mode 100644 index 0000000..2f23b0b --- /dev/null +++ b/FLocal.Patcher.IISHandler/FLocal.Patcher.IISHandler.csproj @@ -0,0 +1,75 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D} + Library + Properties + FLocal.Patcher.IISHandler + FLocal.Patcher.IISHandler + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + 3.5 + + + + 3.5 + + + 3.5 + + + + + + + + + + + {AD931A4B-F62A-4095-B185-BAA9C991FBFF} + FLocal.Patcher.Common + + + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED} + Patcher.Web + + + {6F532626-E9F8-498E-9683-1538E7CD62CB} + Web.Core + + + + + \ No newline at end of file diff --git a/FLocal.Patcher.IISHandler/MainHandler.cs b/FLocal.Patcher.IISHandler/MainHandler.cs new file mode 100644 index 0000000..38ae00b --- /dev/null +++ b/FLocal.Patcher.IISHandler/MainHandler.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; +using FLocal.Patcher.Common; + +namespace FLocal.Patcher.IISHandler { + public class MainHandler : Patcher.Web.MainHandler { + + protected override Patcher.Web.PatcherInfo patcherInfo { + get { + return PatcherInfo.instance; + } + } + + protected override string GetAdminConnectionString(HttpContext context) { + throw new NotImplementedException(); + } + + } +} diff --git a/FLocal.Patcher.IISHandler/Properties/AssemblyInfo.cs b/FLocal.Patcher.IISHandler/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1623ca6 --- /dev/null +++ b/FLocal.Patcher.IISHandler/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FLocal.Patcher.IISHandler")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FLocal.Patcher.IISHandler")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7a43a64d-9908-4ffa-ae00-29343eecf31e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FLocal.sln b/FLocal.sln index b26dccb..d2e3de0 100644 --- a/FLocal.sln +++ b/FLocal.sln @@ -23,6 +23,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TexCompiler", "TexCompiler\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Patcher", "Patcher\Patcher.csproj", "{78F407CF-416D-4D1F-971C-9A51FEA69B3A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FLocal.Patcher.IISHandler", "FLocal.Patcher.IISHandler\FLocal.Patcher.IISHandler.csproj", "{5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Patcher.Web", "Patcher.Web\Patcher.Web.csproj", "{FB3DDF5A-E31D-4763-9633-5EEC6462DAED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FLocal.Patcher.Common", "FLocal.Patcher.Common\FLocal.Patcher.Common.csproj", "{AD931A4B-F62A-4095-B185-BAA9C991FBFF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -133,16 +139,46 @@ Global {7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Release|Mixed Platforms.Build.0 = Release|Any CPU {7D2A38F8-C42D-4F9F-AF64-1DDD5842C7EC}.Release|x86.ActiveCfg = Release|Any CPU - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|Any CPU.ActiveCfg = Debug|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|Mixed Platforms.Build.0 = Debug|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|x86.ActiveCfg = Debug|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|x86.Build.0 = Debug|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|Any CPU.ActiveCfg = Release|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|Mixed Platforms.Build.0 = Release|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|x86.ActiveCfg = Release|x86 - {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|x86.Build.0 = Release|x86 + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|x86.ActiveCfg = Debug|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Debug|x86.Build.0 = Debug|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|x86.ActiveCfg = Release|Any CPU + {78F407CF-416D-4D1F-971C-9A51FEA69B3A}.Release|x86.Build.0 = Release|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Debug|x86.ActiveCfg = Debug|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Release|Any CPU.Build.0 = Release|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {5CCEDD35-6D7A-4F0F-87B8-290EFCF8EF2D}.Release|x86.ActiveCfg = Release|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Debug|x86.ActiveCfg = Debug|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Release|Any CPU.Build.0 = Release|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED}.Release|x86.ActiveCfg = Release|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Debug|x86.ActiveCfg = Debug|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Release|Any CPU.Build.0 = Release|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {AD931A4B-F62A-4095-B185-BAA9C991FBFF}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Patcher.Web/CheckParams.cs b/Patcher.Web/CheckParams.cs new file mode 100644 index 0000000..5086e24 --- /dev/null +++ b/Patcher.Web/CheckParams.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Patcher.Data.Patch; + +namespace Patcher.Web { + class CheckParams : ICheckParams { + + private readonly IPatcherConfiguration configuration; + + public CheckParams(IPatcherConfiguration configuration) { + this.configuration = configuration; + } + + public string DbDriverName { + get { + return this.configuration.DbDriverName; + } + } + + public string ConnectionString { + get { + return this.configuration.GuestConnectionString; + } + } + + public string PatchesTable { + get { + return this.configuration.PatchesTable; + } + } + + public IEnumerable getPatchesList() { + return this.configuration.getPatchesList(); + } + + } +} diff --git a/Patcher.Web/IPatcherConfiguration.cs b/Patcher.Web/IPatcherConfiguration.cs new file mode 100644 index 0000000..fe29759 --- /dev/null +++ b/Patcher.Web/IPatcherConfiguration.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Patcher.Data.Patch; +using System.IO; + +namespace Patcher.Web { + public interface IPatcherConfiguration { + + string DbDriverName { + get; + } + + string GuestConnectionString { + get; + } + + string PatchesTable { + get; + } + + string EnvironmentName { + get; + } + + IEnumerable getPatchesList(); + + Stream loadPatch(PatchId patchId); + + } +} diff --git a/Patcher.Web/MainHandler.cs b/Patcher.Web/MainHandler.cs new file mode 100644 index 0000000..a2218b7 --- /dev/null +++ b/Patcher.Web/MainHandler.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Web; + +namespace Patcher.Web { + abstract public class MainHandler : IHttpHandler { + + abstract protected PatcherInfo patcherInfo { + get; + } + + abstract protected string GetAdminConnectionString(HttpContext context); + + public bool IsReusable { + get { return true; } + } + + private void Install(HttpContext context) { + var writer = context.Response.Output; + writer.WriteLine("

Installing...

"); + System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2)); + this.patcherInfo.AreNewPatchesInstalled = true; + writer.WriteLine("

Installed

"); + } + + private void ShowInfo(HttpContext context) { + var writer = context.Response.Output; + writer.WriteLine("
"); + } + + public void ProcessRequest(HttpContext context) { + if(context.Request.Form["install"] == "install") { + this.Install(context); + } else { + this.ShowInfo(context); + } + } + + } +} diff --git a/Patcher.Web/Patcher.Web.csproj b/Patcher.Web/Patcher.Web.csproj new file mode 100644 index 0000000..a92adf9 --- /dev/null +++ b/Patcher.Web/Patcher.Web.csproj @@ -0,0 +1,73 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {FB3DDF5A-E31D-4763-9633-5EEC6462DAED} + Library + Properties + Patcher.Web + Patcher.Web + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + + 3.5 + + + 3.5 + + + + + + + + + + + + + + {78F407CF-416D-4D1F-971C-9A51FEA69B3A} + Patcher + + + {6F532626-E9F8-498E-9683-1538E7CD62CB} + Web.Core + + + + + \ No newline at end of file diff --git a/Patcher.Web/PatcherInfo.cs b/Patcher.Web/PatcherInfo.cs new file mode 100644 index 0000000..3fdd4b6 --- /dev/null +++ b/Patcher.Web/PatcherInfo.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Patcher.Web { + abstract public class PatcherInfo { + + internal readonly IPatcherConfiguration configuration; + + public readonly bool IsContainsNewPatches; + + public bool AreNewPatchesInstalled { + get; + internal set; + } + + public bool IsNeedsPatching { + get { + return this.IsContainsNewPatches && !this.AreNewPatchesInstalled; + } + } + + protected PatcherInfo(IPatcherConfiguration configuration) { + this.configuration = configuration; + this.IsContainsNewPatches = (new Checker(new CheckParams(configuration))).IsNeedsPatching(); + } + + } +} diff --git a/Patcher.Web/Properties/AssemblyInfo.cs b/Patcher.Web/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..96e7ba0 --- /dev/null +++ b/Patcher.Web/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Patcher.Web")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Patcher.Web")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ef9cd949-c853-4a5c-b4f6-8195fb785378")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Patcher/Checker.cs b/Patcher/Checker.cs new file mode 100644 index 0000000..c59c799 --- /dev/null +++ b/Patcher/Checker.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Web.Core; +using Patcher.Data.Patch; +using Patcher.DB; + +namespace Patcher { + public class Checker { + + private const string STATUS_INSTALLING = "installing"; + private const string STATUS_INSTALLED = "installed"; + + private readonly ICheckParams checkParams; + + public Checker(ICheckParams checkParams) { + this.checkParams = checkParams; + } + + public IEnumerable GetPatchesToInstall() { + List inputPatches = this.checkParams.getPatchesList().OrderBy(patchId => patchId).ToList(); + using(Transaction transaction = TransactionFactory.Create(this.checkParams.DbDriverName, this.checkParams.ConnectionString)) { + return Util.RemoveExtra( + from patchId in this.checkParams.getPatchesList() + orderby patchId ascending + select patchId, + from row in transaction.ExecuteReader( + string.Format( + "select {1}, {2} from {0} where {3} = {4}", + transaction.EscapeName(this.checkParams.PatchesTable), + transaction.EscapeName("VERSION"), + transaction.EscapeName("NAME"), + transaction.EscapeName("STATUS"), + transaction.MarkParam("pstatus") + ), + new Dictionary { + { "pstatus", STATUS_INSTALLED }, + } + ) + let patch = new PatchId(int.Parse(row["VERSION"]), row["NAME"]) + orderby patch ascending + select patch + ); + } + } + + public bool IsNeedsPatching() { + System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2)); + return true; + //return this.GetPatchesToInstall().Any(); + } + + } +} diff --git a/Patcher/Context.cs b/Patcher/Context.cs index c39ffd8..b0d413d 100644 --- a/Patcher/Context.cs +++ b/Patcher/Context.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Web.Core; using Patcher.Data.Patch; using Patcher.DB; using System.IO; @@ -11,25 +12,40 @@ namespace Patcher class Context { - public readonly IConfig config; + private readonly IUpdateParams updateParams; - public readonly Func> getPatchesList; - - public readonly Func loadPatch; + public List getPatchesList() { + return (from patchId in this.updateParams.getPatchesList() orderby patchId ascending select patchId).ToList(); + } public readonly IDBTraits DbDriver; - private static readonly Dictionary DB_DRIVERS = new Dictionary - { - { "oracle", OracleDBTraits.instance }, - { "oracle-faketransactional", OracleFakeTransactionalDBTraits.instance }, - }; - - public Context(IConfig config, Func> getPatchesListUnsorted, Func loadPatch) { - this.config = config; - this.getPatchesList = () => (from patchId in getPatchesListUnsorted() orderby patchId ascending select patchId).ToList(); - this.loadPatch = loadPatch; - this.DbDriver = DB_DRIVERS[config.DbDriverName]; + public readonly IInteractiveConsole console; + + public string EnvironmentName { + get { + return this.updateParams.EnvironmentName; + } + } + + public string PatchesTable { + get { + return this.updateParams.PatchesTable; + } + } + + public Stream loadPatch(PatchId patchId) { + return this.updateParams.loadPatch(patchId); + } + + public Transaction CreateTransaction() { + return TransactionFactory.Create(this.updateParams.DbDriverName, this.updateParams.ConnectionString); + } + + public Context(IUpdateParams updateParams, IInteractiveConsole console) { + this.updateParams = updateParams; + this.DbDriver = DBTraitsFactory.GetTraits(updateParams.DbDriverName); + this.console = console; } } diff --git a/Patcher/DB/DBTraitsFactory.cs b/Patcher/DB/DBTraitsFactory.cs new file mode 100644 index 0000000..58d951b --- /dev/null +++ b/Patcher/DB/DBTraitsFactory.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Patcher.DB { + static class DBTraitsFactory { + + public static IDBTraits GetTraits(string DbDriverName) { + switch(DbDriverName.ToLower()) { + case "oracle": + return OracleDBTraits.instance; + case "oracle-faketransactional": + return OracleFakeTransactionalDBTraits.instance; + default: + throw new NotImplementedException(); + } + } + + } +} diff --git a/Patcher/DB/TransactionFactory.cs b/Patcher/DB/TransactionFactory.cs index f6c916a..7767071 100644 --- a/Patcher/DB/TransactionFactory.cs +++ b/Patcher/DB/TransactionFactory.cs @@ -9,15 +9,10 @@ namespace Patcher.DB { - private static Transaction Create(IDBTraits DbDriver, string ConnectionString) + public static Transaction Create(string DbDriverName, string ConnectionString) { - return new Transaction(DbDriver, ConnectionString); + return new Transaction(DBTraitsFactory.GetTraits(DbDriverName), ConnectionString); } - public static Transaction Create(Context context) - { - return Create(context.DbDriver, context.config.ConnectionString); - } - } } diff --git a/Patcher/Data/Patch/AbstractPatch.cs b/Patcher/Data/Patch/AbstractPatch.cs index 136ecb2..6c1b01b 100644 --- a/Patcher/Data/Patch/AbstractPatch.cs +++ b/Patcher/Data/Patch/AbstractPatch.cs @@ -6,6 +6,7 @@ using System.Text; using System.Xml; using System.Xml.Linq; using System.Xml.Schema; +using Web.Core; using Patcher.Data.Command; using Patcher.DB; @@ -41,7 +42,7 @@ namespace Patcher.Data.Patch public static AbstractPatch LoadById(PatchId id, Context context) { - return Cache, AbstractPatch>.instance.GetValue(new KeyValuePair(id, context), () => _LoadById(id, context)); + return Cache.instance.get(new KeyValuePair(id, context), () => _LoadById(id, context)); } private static AbstractPatch _LoadById(PatchId id, Context context) @@ -58,9 +59,9 @@ namespace Patcher.Data.Patch XElement version = data.Root.Element("version"); string number = version.Element("number").Value; string author = version.Element("author").Value; - if((number != id.version.ToString()) || (author != id.author)) + if((number != id.version.ToString()) || (author != id.name)) { - throw new ApplicationException(string.Format("Versions mismatch on patch #{0} from {1} (got #{2} from {3})", id.version, id.author, number, author)); + throw new ApplicationException(string.Format("Versions mismatch on patch #{0} from {1} (got #{2} from {3})", id.version, id.name, number, author)); } HashSet restrictToEnvironments; diff --git a/Patcher/Data/Patch/PatchId.cs b/Patcher/Data/Patch/PatchId.cs index f2212e8..fcb2f46 100644 --- a/Patcher/Data/Patch/PatchId.cs +++ b/Patcher/Data/Patch/PatchId.cs @@ -9,12 +9,12 @@ namespace Patcher.Data.Patch { public readonly int version; - public readonly string author; + public readonly string name; - public PatchId(int version, string author) + public PatchId(int version, string name) { this.version = version; - this.author = author; + this.name = name; } private int _CompareTo(PatchId other) @@ -22,7 +22,7 @@ namespace Patcher.Data.Patch int result = this.version.CompareTo(other.version); if(result == 0) { - result = this.author.CompareTo(other.author); + result = this.name.CompareTo(other.name); } return result; } @@ -50,8 +50,8 @@ namespace Patcher.Data.Patch { case "version": return this.version.ToString(formatProvider); - case "author": - return this.author.ToString(formatProvider); + case "name": + return this.name.ToString(formatProvider); default: throw new ApplicationException(String.Format("Unknown format {0}", format)); } diff --git a/Patcher/IConfig.cs b/Patcher/ICheckParams.cs similarity index 72% rename from Patcher/IConfig.cs rename to Patcher/ICheckParams.cs index 9db673b..288d68e 100644 --- a/Patcher/IConfig.cs +++ b/Patcher/ICheckParams.cs @@ -6,14 +6,9 @@ using Patcher.Data.Patch; namespace Patcher { - public interface IConfig + public interface ICheckParams { - string EnvironmentName - { - get; - } - string DbDriverName { get; @@ -29,5 +24,7 @@ namespace Patcher get; } + IEnumerable getPatchesList(); + } } diff --git a/Patcher/IUpdateParams.cs b/Patcher/IUpdateParams.cs new file mode 100644 index 0000000..8edd31c --- /dev/null +++ b/Patcher/IUpdateParams.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using Patcher.Data.Patch; + +namespace Patcher { + public interface IUpdateParams : ICheckParams { + + string EnvironmentName { + get; + } + + Stream loadPatch(PatchId patchId); + + } +} diff --git a/Patcher/Patcher.csproj b/Patcher/Patcher.csproj index 9e19f3f..114e88b 100644 --- a/Patcher/Patcher.csproj +++ b/Patcher/Patcher.csproj @@ -1,8 +1,8 @@  - + Debug - x86 + AnyCPU 9.0.30729 2.0 {78F407CF-416D-4D1F-971C-9A51FEA69B3A} @@ -13,8 +13,7 @@ v3.5 512 - - x86 + true full false @@ -23,8 +22,7 @@ prompt 4 - - x86 + pdbonly true bin\Release\ @@ -32,19 +30,21 @@ prompt 4 - - - - + + 3.5 + - + + 3.5 + + @@ -75,6 +75,7 @@ + @@ -89,12 +90,12 @@ - - + + + - @@ -150,6 +151,12 @@ + + + {6F532626-E9F8-498E-9683-1538E7CD62CB} + Web.Core + +