NewLife/X

增加数据库管理,支持列出数据库,备份、下载数据库
Stone authored at 2016-07-12 18:35:46
8d21733
Tree
1 Parent(s) d4a74ae
Summary: 9 changed files with 442 additions and 3 deletions.
Added +67 -0
Added +25 -0
Modified +1 -1
Modified +1 -1
Added +30 -0
Added +43 -0
Added +257 -0
Modified +15 -1
Modified +3 -0
Added +67 -0
diff --git a/NewLife.Cube/Areas/Admin/Controllers/DbController.cs b/NewLife.Cube/Areas/Admin/Controllers/DbController.cs
new file mode 100644
index 0000000..9845129
--- /dev/null
+++ b/NewLife.Cube/Areas/Admin/Controllers/DbController.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Configuration;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using NewLife.Security;
+using XCode.DataAccessLayer;
+using XCode.Membership;
+
+namespace NewLife.Cube.Admin.Controllers
+{
+    /// <summary>数据库管理</summary>
+    [DisplayName("数据库管理")]
+    [EntityAuthorize(PermissionFlags.Detail)]
+    public class DbController : ControllerBaseX
+    {
+        /// <summary>数据库列表</summary>
+        /// <returns></returns>
+        public ActionResult Index()
+        {
+            var list = new List<DbItem>();
+
+            // 读取配置文件
+            var css = new HashSet<String>(StringComparer.OrdinalIgnoreCase);
+            foreach (ConnectionStringSettings set in ConfigurationManager.ConnectionStrings)
+            {
+                if (!css.Contains(set.Name)) css.Add(set.Name);
+            }
+
+            foreach (var item in DAL.ConnStrs)
+            {
+                var di = new DbItem();
+                di.Name = item.Key;
+                di.ConnStr = item.Value.ConnectionString;
+
+                //var type = DbFactory.GetProviderType(item.Value.ConnectionString, item.Value.ProviderName);
+                //if (type != null)
+                //{
+                //    var db = Activator.CreateInstance(type) as IDatabase;
+                //    if (db != null)
+                //    {
+                //        di.Type = db.DbType;
+                //        if (!di.ConnStr.IsNullOrEmpty()) di.Version = db.ServerVersion;
+                //    }
+                //}
+                var dal = DAL.Create(item.Key);
+                di.Type = dal.DbType;
+                try
+                {
+                    di.Version = dal.Db.ServerVersion;
+                }
+                catch { }
+
+                if (!css.Contains(di.Name)) di.Dynamic = true;
+
+                di.Backups = Rand.Next(5);
+
+                list.Add(di);
+            }
+
+            return View(list);
+        }
+
+    }
+}
Added +25 -0
diff --git a/NewLife.Cube/Areas/Admin/Controllers/FileController.cs b/NewLife.Cube/Areas/Admin/Controllers/FileController.cs
new file mode 100644
index 0000000..d6d234b
--- /dev/null
+++ b/NewLife.Cube/Areas/Admin/Controllers/FileController.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using XCode.Membership;
+
+namespace NewLife.Cube.Admin.Controllers
+{
+    /// <summary>文件管理</summary>
+    [DisplayName("文件管理")]
+    [EntityAuthorize(PermissionFlags.Detail)]
+    public class FileController : ControllerBaseX
+    {
+        //
+        // GET: /Admin/File/
+
+        public ActionResult Index()
+        {
+            return View();
+        }
+
+    }
+}
Modified +1 -1
diff --git a/NewLife.Cube/Areas/Admin/Controllers/SysController.cs b/NewLife.Cube/Areas/Admin/Controllers/SysController.cs
index 188bae1..f89224a 100644
--- a/NewLife.Cube/Areas/Admin/Controllers/SysController.cs
+++ b/NewLife.Cube/Areas/Admin/Controllers/SysController.cs
@@ -4,6 +4,6 @@ using NewLife.Common;
 namespace NewLife.Cube.Admin.Controllers
 {
     /// <summary>系统设置控制器</summary>
-    [DisplayName("高级设置")]
+    [DisplayName("系统设置")]
     public class SysController : ConfigController<SysConfig> { }
 }
\ No newline at end of file
Modified +1 -1
diff --git a/NewLife.Cube/Areas/Admin/Controllers/XCodeController.cs b/NewLife.Cube/Areas/Admin/Controllers/XCodeController.cs
index 0f943cc..5dd8120 100644
--- a/NewLife.Cube/Areas/Admin/Controllers/XCodeController.cs
+++ b/NewLife.Cube/Areas/Admin/Controllers/XCodeController.cs
@@ -3,7 +3,7 @@
 namespace NewLife.Cube.Admin.Controllers
 {
     /// <summary>设置控制器</summary>
-    [DisplayName("数据库设置")]
+    [DisplayName("数据映射设置")]
     public class XCodeController : ConfigController<XCode.Setting>
     {
     }
Added +30 -0
diff --git a/NewLife.Cube/Areas/Admin/Models/DbItem.cs b/NewLife.Cube/Areas/Admin/Models/DbItem.cs
new file mode 100644
index 0000000..70f13a3
--- /dev/null
+++ b/NewLife.Cube/Areas/Admin/Models/DbItem.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using XCode.DataAccessLayer;
+
+namespace NewLife.Cube.Admin
+{
+    /// <summary>数据项</summary>
+    public class DbItem
+    {
+        /// <summary>连接名</summary>
+        public String Name { get; set; }
+
+        /// <summary>数据库类型</summary>
+        public DatabaseType Type { get; set; }
+
+        /// <summary>连接字符串</summary>
+        public String ConnStr { get; set; }
+
+        /// <summary>数据驱动版本</summary>
+        public String Version { get; set; }
+
+        /// <summary>是否动态</summary>
+        public Boolean Dynamic { get; set; }
+
+        /// <summary>备份数</summary>
+        public Int32 Backups { get; set; }
+    }
+}
\ No newline at end of file
Added +43 -0
diff --git a/NewLife.Cube/Areas/Admin/Views/Db/Index.cshtml b/NewLife.Cube/Areas/Admin/Views/Db/Index.cshtml
new file mode 100644
index 0000000..6035d76
--- /dev/null
+++ b/NewLife.Cube/Areas/Admin/Views/Db/Index.cshtml
@@ -0,0 +1,43 @@
+@using System.Diagnostics;
+@using NewLife.Common;
+@using NewLife.Cube.Admin;
+@{
+    //ViewBag.Title = "服务器信息";
+    var dbs = Model as IList<DbItem>;
+}
+<table class="table table-bordered table-hover table-striped table-condensed">
+    <thead>
+        <tr>
+            <th class="text-center">名称</th>
+            <th class="text-center">类型</th>
+            <th class="text-center">连接字符串</th>
+            <th class="text-center">版本</th>
+            <th class="text-center">动态</th>
+            <th class="text-center">备份</th>
+            <th class="text-center">下载</th>
+        </tr>
+    </thead>
+    <tbody>
+        @foreach (var item in dbs)
+        {
+            <tr>
+                <td>@item.Name</td>
+                <td>@item.Type</td>
+                <td>@item.ConnStr</td>
+                <td>@item.Version</td>
+                <td>
+                    @if (item.Dynamic)
+                    {
+                        <text>是,</text>@Html.ActionLink("静态化", "SetStatic", new { Name = item.Name })
+                    }
+                    else
+                    {
+                        <text>否</text>
+                    }
+                </td>
+                <td>@Html.ActionLink("备份", "Backup", new { Name = item.Name }),共 @item.Backups.ToString("n0")个</td>
+                <td class="text-center">@Html.ActionLink("下载", "Download", new { Name = item.Name })</td>
+            </tr>
+        }
+    </tbody>
+</table>
\ No newline at end of file
Added +257 -0
diff --git a/NewLife.Cube/Areas/Admin/Views/Db/Index.generated.cs b/NewLife.Cube/Areas/Admin/Views/Db/Index.generated.cs
new file mode 100644
index 0000000..3f65920
--- /dev/null
+++ b/NewLife.Cube/Areas/Admin/Views/Db/Index.generated.cs
@@ -0,0 +1,257 @@
+#pragma warning disable 1591
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     此代码由工具生成。
+//     运行时版本:4.0.30319.42000
+//
+//     对此文件的更改可能会导致不正确的行为,并且如果
+//     重新生成代码,这些更改将会丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace ASP
+{
+    using System;
+    using System.Collections.Generic;
+    
+    #line 1 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+    using System.Diagnostics;
+    
+    #line default
+    #line hidden
+    using System.IO;
+    using System.Linq;
+    using System.Net;
+    using System.Text;
+    using System.Web;
+    using System.Web.Helpers;
+    using System.Web.Mvc;
+    using System.Web.Mvc.Ajax;
+    using System.Web.Mvc.Html;
+    using System.Web.Routing;
+    using System.Web.Security;
+    using System.Web.UI;
+    using System.Web.WebPages;
+    using NewLife;
+    
+    #line 2 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+    using NewLife.Common;
+    
+    #line default
+    #line hidden
+    using NewLife.Cube;
+    
+    #line 3 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+    using NewLife.Cube.Admin;
+    
+    #line default
+    #line hidden
+    using NewLife.Reflection;
+    using NewLife.Web;
+    using XCode;
+    using XCode.Membership;
+    
+    [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")]
+    [System.Web.WebPages.PageVirtualPathAttribute("~/Areas/Admin/Views/Db/Index.cshtml")]
+    public partial class _Areas_Admin_Views_Db_Index_cshtml : System.Web.Mvc.WebViewPage<dynamic>
+    {
+        public _Areas_Admin_Views_Db_Index_cshtml()
+        {
+        }
+        public override void Execute()
+        {
+            
+            #line 4 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+  
+    //ViewBag.Title = "服务器信息";
+    var dbs = Model as IList<DbItem>;
+
+            
+            #line default
+            #line hidden
+WriteLiteral("\r\n<table");
+
+WriteLiteral(" class=\"table table-bordered table-hover table-striped table-condensed\"");
+
+WriteLiteral(">\r\n    <thead>\r\n        <tr>\r\n            <th");
+
+WriteLiteral(" class=\"text-center\"");
+
+WriteLiteral(">名称</th>\r\n            <th");
+
+WriteLiteral(" class=\"text-center\"");
+
+WriteLiteral(">类型</th>\r\n            <th");
+
+WriteLiteral(" class=\"text-center\"");
+
+WriteLiteral(">连接字符串</th>\r\n            <th");
+
+WriteLiteral(" class=\"text-center\"");
+
+WriteLiteral(">版本</th>\r\n            <th");
+
+WriteLiteral(" class=\"text-center\"");
+
+WriteLiteral(">动态</th>\r\n            <th");
+
+WriteLiteral(" class=\"text-center\"");
+
+WriteLiteral(">备份</th>\r\n            <th");
+
+WriteLiteral(" class=\"text-center\"");
+
+WriteLiteral(">下载</th>\r\n        </tr>\r\n    </thead>\r\n    <tbody>\r\n");
+
+            
+            #line 21 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+        
+            
+            #line default
+            #line hidden
+            
+            #line 21 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+         foreach (var item in dbs)
+        {
+
+            
+            #line default
+            #line hidden
+WriteLiteral("            <tr>\r\n                <td>");
+
+            
+            #line 24 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+               Write(item.Name);
+
+            
+            #line default
+            #line hidden
+WriteLiteral("</td>\r\n                <td>");
+
+            
+            #line 25 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+               Write(item.Type);
+
+            
+            #line default
+            #line hidden
+WriteLiteral("</td>\r\n                <td>");
+
+            
+            #line 26 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+               Write(item.ConnStr);
+
+            
+            #line default
+            #line hidden
+WriteLiteral("</td>\r\n                <td>");
+
+            
+            #line 27 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+               Write(item.Version);
+
+            
+            #line default
+            #line hidden
+WriteLiteral("</td>\r\n                <td>\r\n");
+
+            
+            #line 29 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+                    
+            
+            #line default
+            #line hidden
+            
+            #line 29 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+                     if (item.Dynamic)
+                    {
+
+            
+            #line default
+            #line hidden
+WriteLiteral("                        ");
+
+WriteLiteral("是,");
+
+            
+            #line 31 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+                                       
+            
+            #line default
+            #line hidden
+            
+            #line 31 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+                                  Write(Html.ActionLink("静态化", "SetStatic", new { Name = item.Name }));
+
+            
+            #line default
+            #line hidden
+            
+            #line 31 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+                                                                                                     
+                    }
+                    else
+                    {
+
+            
+            #line default
+            #line hidden
+WriteLiteral("                        ");
+
+WriteLiteral("否");
+
+WriteLiteral("\r\n");
+
+            
+            #line 36 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+                    }
+
+            
+            #line default
+            #line hidden
+WriteLiteral("                </td>\r\n                <td>");
+
+            
+            #line 38 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+               Write(Html.ActionLink("备份", "Backup", new { Name = item.Name }));
+
+            
+            #line default
+            #line hidden
+WriteLiteral(",共 ");
+
+            
+            #line 38 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+                                                                            Write(item.Backups.ToString("n0"));
+
+            
+            #line default
+            #line hidden
+WriteLiteral("个</td>\r\n                <td");
+
+WriteLiteral(" class=\"text-center\"");
+
+WriteLiteral(">");
+
+            
+            #line 39 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+                                   Write(Html.ActionLink("下载", "Download", new { Name = item.Name }));
+
+            
+            #line default
+            #line hidden
+WriteLiteral("</td>\r\n            </tr>\r\n");
+
+            
+            #line 41 "..\..\Areas\Admin\Views\Db\Index.cshtml"
+        }
+
+            
+            #line default
+            #line hidden
+WriteLiteral("    </tbody>\r\n</table>");
+
+        }
+    }
+}
+#pragma warning restore 1591
Modified +15 -1
diff --git a/NewLife.Cube/NewLife.Cube.csproj b/NewLife.Cube/NewLife.Cube.csproj
index 8a4f76d..6baa02a 100644
--- a/NewLife.Cube/NewLife.Cube.csproj
+++ b/NewLife.Cube/NewLife.Cube.csproj
@@ -86,6 +86,8 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Areas\Admin\AdminAreaRegistration.cs" />
+    <Compile Include="Areas\Admin\Controllers\DbController.cs" />
+    <Compile Include="Areas\Admin\Controllers\FileController.cs" />
     <Compile Include="Areas\Admin\Controllers\RoleController.cs" />
     <Compile Include="Areas\Admin\Controllers\LogController.cs" />
     <Compile Include="Areas\Admin\Controllers\MenuController.cs" />
@@ -95,6 +97,12 @@
     <Compile Include="Areas\Admin\Controllers\SysController.cs" />
     <Compile Include="Areas\Admin\Controllers\UserController.cs" />
     <Compile Include="Areas\Admin\Index\IndexController.cs" />
+    <Compile Include="Areas\Admin\Models\DbItem.cs" />
+    <Compile Include="Areas\Admin\Views\Db\Index.generated.cs">
+      <DependentUpon>Index.cshtml</DependentUpon>
+      <AutoGen>True</AutoGen>
+      <DesignTime>True</DesignTime>
+    </Compile>
     <Compile Include="Areas\Admin\Views\Index\Index.generated.cs">
       <AutoGen>True</AutoGen>
       <DesignTime>True</DesignTime>
@@ -344,6 +352,10 @@
     </Compile>
   </ItemGroup>
   <ItemGroup>
+    <Content Include="Areas\Admin\Views\Db\Index.cshtml">
+      <Generator>RazorGenerator</Generator>
+      <LastGenOutput>Index.generated.cs</LastGenOutput>
+    </Content>
     <None Include="Content\ace\css\ace-fonts.min.css" />
     <None Include="Content\ace\css\ace-ie.min.css" />
     <None Include="Content\ace\css\ace-part2.min.css" />
@@ -617,7 +629,9 @@
       <LastGenOutput>_List_Pager1.generated.cs</LastGenOutput>
     </None>
   </ItemGroup>
-  <ItemGroup />
+  <ItemGroup>
+    <Folder Include="Areas\Admin\Views\File\" />
+  </ItemGroup>
   <ItemGroup>
     <None Include="packages.config">
       <SubType>Designer</SubType>
Modified +3 -0
diff --git a/NewLife.Cube/Web.config b/NewLife.Cube/Web.config
index 464575a..4aa1671 100644
--- a/NewLife.Cube/Web.config
+++ b/NewLife.Cube/Web.config
@@ -8,6 +8,9 @@
     <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
   </appSettings>
   <connectionStrings>
+    <add name="Front" connectionString="Data Source=..\..\Data\Front.db" providerName="oracle" />
+    <add name="IoT" connectionString="Data Source=..\..\Data\IoT.db" providerName="mssql"/>
+    <add name="TokenLog" connectionString="Data Source=..\..\Data\TokenLog.db" providerName="mysql"/>
     <!--<add name="Membership" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=~\App_Data\Membership.mdb" providerName="Access"/>-->
     <!--<add name="Membership" connectionString="Data Source=~\App_Data\Membership.db" providerName="Sqlite"/>-->
     <!--<add name="Membership" connectionString="Data Source=~\App_Data\Membership.sdf" providerName="SqlCe"/>-->