Commits

Clément Bourgeois committed e5fa47a

Added size info to the backups history.

  • Participants
  • Parent commits 46ba5e4

Comments (0)

Files changed (7)

File SQLServerBackupTool.Web/Lib/BackupsManager.cs

 using System.Security.Principal;
 using System.Threading.Tasks;
 using System.Web;
-using System.Xml.Serialization;
 
 namespace SQLServerBackupTool.Web.Lib
 {
                     }
                 }
 
+                var fInfo = new FileInfo(fullZipPath);
+
                 var h = new BackupHistory
                 {
                     Path     = fullZipPath,
                     Url      = string.Format("~/{0}", fullZipPath.Replace(server.MapPath("~/"), string.Empty).Replace('\\', '/')),
                     Expires  = DateTime.Now.AddDays(1),
                     Username = user.Identity.Name,
+                    Size     = fInfo.Length,
                 };
 
                 using (var ddb = new SSBTDbContext())

File SQLServerBackupTool.Web/Lib/Extensions/NumberExtensions.cs

+using System;
+using System.Globalization;
+
+namespace SQLServerBackupTool.Web.Lib.Extensions
+{
+    public static class NumberExtensions
+    {
+        public static string[] SizeUnits = new[] { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
+
+        public static bool IsBetween(this string val, int down, int up)
+        {
+            int realVal;
+
+            return int.TryParse(val, out realVal) && IsBetween(realVal, down, up);
+        }
+
+        public static bool IsBetween(this int val, int down, int up)
+        {
+            return val >= down && val <= up;
+        }
+
+        public static string BytesToString(this long byteCount, int decimals = 1)
+        {
+            var bytes = Math.Abs(byteCount);
+            var place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
+            var num   = Math.Round(bytes / Math.Pow(1024, place), decimals);
+
+            return (Math.Sign(byteCount) * num).ToString(CultureInfo.InvariantCulture) + SizeUnits[place];
+        }
+    }
+}

File SQLServerBackupTool.Web/Models/BackupHistory.cs

             get;
             set;
         }
+
+        public long Size
+        {
+            get;
+            set;
+        }
     }
 }

File SQLServerBackupTool.Web/SQLServerBackupTool.Web.csproj

     <Compile Include="App_Start\AutoInstall.cs" />
     <Compile Include="App_Start\BundleConfig.cs" />
     <Compile Include="Lib\BackupsManager.cs" />
+    <Compile Include="Lib\Extensions\NumberExtensions.cs" />
     <Compile Include="Lib\Mvc\FlashMessages.cs" />
     <Compile Include="Lib\Interfaces\IMembershipUser.cs" />
     <Compile Include="Models\DatabaseSizeInfo.cs" />

File SQLServerBackupTool.Web/Views/Home/Index.cshtml

                 <th>Database</th>
                 <th>User</th>
                 <th>Expiration</th>
+                <th style="width: 50px;">Size</th>
                 <th style="width: 30px;"></th>
             </tr>
         </thead>
             else
             {
                 <tr class="no-row">
-                    <td colspan="5"><i>No available database backup</i></td>
+                    <td colspan="6"><i>No available database backup</i></td>
                 </tr>
             }
         </tbody>
         {
             <tfoot>
                 <tr>
-                    <td colspan="5">
+                    <td colspan="6">
                         <a id="backup-purge" href="@Url.Action("BackupsPurge")" onclick="return false;" class="btn btn-danger">
                             <i class="icon-warning-sign icon-white"></i><span>&nbsp;Purge</span>
                         </a>

File SQLServerBackupTool.Web/Views/Home/_BackupItem.cshtml

     <td>@Model.Database</td>
     <td>@Model.Username</td>
     <td>@Model.Expires</td>
+    <td>@Model.Size.BytesToString(2)</td>
     <td>
         <div class="btn-group">
             <a class="btn" href="@Url.Action("Download", new { id=Model.Id })">

File SQLServerBackupTool.Web/Views/Web.config

         <add namespace="System.Web.Mvc.Html" />
         <add namespace="System.Web.Routing" />
         <add namespace="System.Web.Optimization" />
+        <add namespace="SQLServerBackupTool.Web.Lib.Extensions" />
         <add namespace="SQLServerBackupTool.Web.Models" />
         <add namespace="SQLServerBackupTool.Web.ViewModels" />
         <add namespace="SQLServerBackupTool.Web.Lib.Mvc"/>