Feature: AD Update Last Network Logon Date

Ability to run this task on-demand from the web UI is added
This commit is contained in:
Gary Sharp
2013-02-07 18:30:51 +11:00
parent a9bbcabd87
commit c7cbef9189
4 changed files with 1297 additions and 1327 deletions
@@ -1,230 +1,220 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Disco.BI;
using Disco.BI.Extensions;
using System.IO;
using System.Drawing;
using System.Text;
using Disco.Services.Tasks;
using Disco.BI.Interop.ActiveDirectory;
using Disco.Models.Repository;
namespace Disco.Web.Areas.API.Controllers
{
public partial class SystemController : dbAdminController
{
public virtual ActionResult UpdateLastNetworkLogonDates()
{
//ActiveDirectoryUpdateLastNetworkLogonDateJob updateJob = new ActiveDirectoryUpdateLastNetworkLogonDateJob();
ActiveDirectoryUpdateLastNetworkLogonDateJob.UpdateLastNetworkLogonDates(dbContext);
var resultCount = dbContext.SaveChanges();
var model = new Models.System.UpdateLastNetworkLogonDatesModel()
{
Result = "OK",
UpdateCount = resultCount
};
return Json(model, JsonRequestBehavior.AllowGet);
}
public virtual ActionResult UpdateAttachmentThumbnails()
{
// Device Attachments
var das = dbContext.DeviceAttachments.Where(da => da.MimeType == "application/pdf");
foreach (var da in das)
{
var fileName = da.RepositoryThumbnailFilename(dbContext);
if (!System.IO.File.Exists(fileName))
{
da.GenerateThumbnail(dbContext);
}
}
// User Attachments
var uas = dbContext.UserAttachments.Where(ua => ua.MimeType == "application/pdf");
foreach (var ua in uas)
{
var fileName = ua.RepositoryThumbnailFilename(dbContext);
if (!System.IO.File.Exists(fileName))
{
ua.GenerateThumbnail(dbContext);
}
}
// Job Attachments
var jas = dbContext.JobAttachments.Where(ja => ja.MimeType == "application/pdf");
foreach (var ja in jas)
{
var fileName = ja.RepositoryThumbnailFilename(dbContext);
if (!System.IO.File.Exists(fileName))
{
ja.GenerateThumbnail(dbContext);
}
}
return Content("Done", "text/text");
}
public virtual ActionResult UpdateCheck()
{
var ts = Disco.BI.Interop.Community.UpdateCheckTask.ScheduleNow();
ts.SetFinishedUrl(Url.Action(MVC.Config.SystemConfig.Index()));
return RedirectToAction(MVC.Config.Logging.TaskStatus(ts.SessionId));
}
#region Organisation
#region Organisation Name
public virtual ActionResult UpdateOrganisationName(string OrganisationName, bool redirect = false)
{
if (string.IsNullOrWhiteSpace(OrganisationName))
dbContext.DiscoConfiguration.OrganisationName = null;
else
dbContext.DiscoConfiguration.OrganisationName = OrganisationName;
dbContext.SaveChanges();
DiscoApplication.OrganisationName = dbContext.DiscoConfiguration.OrganisationName;
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
#endregion
#region Organisation Logo
[OutputCache(Duration = 31536000, Location = System.Web.UI.OutputCacheLocation.Any, VaryByParam = "*")]
public virtual ActionResult OrganisationLogo(int Width = 256, int Height = 256, string v = null)
{
if (Width < 1)
throw new ArgumentOutOfRangeException("Width");
if (Height < 1)
throw new ArgumentOutOfRangeException("Height");
using (Stream logoStream = dbContext.DiscoConfiguration.OrganisationLogo)
{
using (Image logoBitmap = Bitmap.FromStream(logoStream))
{
return File(logoBitmap.ResizeImage(Width, Height).SavePng(), "image/png");
}
}
}
[HttpPost]
public virtual ActionResult OrganisationLogo(bool redirect, HttpPostedFileBase Image, bool? ResetLogo = null)
{
if (ResetLogo.HasValue && ResetLogo.Value)
{
dbContext.DiscoConfiguration.OrganisationLogo = null;
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
if (Image != null && Image.ContentLength > 0)
{
if (Image.ContentType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase))
{
dbContext.DiscoConfiguration.OrganisationLogo = Image.InputStream;
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
else
{
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("Invalid Content Type", JsonRequestBehavior.AllowGet);
}
}
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("No Image Supplied", JsonRequestBehavior.AllowGet);
}
#endregion
#region Organisation Addresses
public virtual ActionResult UpdateOrganisationAddress(Disco.Models.BI.Config.OrganisationAddress organisationAddress, bool redirect = false)
{
if (organisationAddress == null)
{
ModelState.AddModelError("Address", "No address was supplied");
}
if (ModelState.IsValid)
{
dbContext.DiscoConfiguration.OrganisationAddresses.SetAddress(organisationAddress);
dbContext.SaveChanges();
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
else
{
// Build Error Message
var em = new StringBuilder();
em.AppendLine("Error:");
foreach (var item in ModelState)
{
foreach (var errorItem in item.Value.Errors)
{
em.Append(item.Key);
em.Append(": ");
em.AppendLine(errorItem.ErrorMessage);
}
}
if (redirect)
throw new InvalidOperationException(em.ToString());
else
return Json(em.ToString(), JsonRequestBehavior.AllowGet);
}
}
public virtual ActionResult DeleteOrganisationAddress(int Id, bool redirect = false)
{
dbContext.DiscoConfiguration.OrganisationAddresses.RemoveAddress(Id);
dbContext.SaveChanges();
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
#endregion
#region MultiSiteMode
public virtual ActionResult UpdateMultiSiteMode(bool MultiSiteMode, bool redirect = false)
{
dbContext.DiscoConfiguration.MultiSiteMode = MultiSiteMode;
dbContext.SaveChanges();
DiscoApplication.MultiSiteMode = dbContext.DiscoConfiguration.MultiSiteMode;
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
#endregion
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Disco.BI;
using Disco.BI.Extensions;
using System.IO;
using System.Drawing;
using System.Text;
using Disco.Services.Tasks;
using Disco.BI.Interop.ActiveDirectory;
using Disco.Models.Repository;
namespace Disco.Web.Areas.API.Controllers
{
public partial class SystemController : dbAdminController
{
public virtual ActionResult UpdateLastNetworkLogonDates()
{
var taskStatus = ActiveDirectoryUpdateLastNetworkLogonDateJob.ScheduleImmediately();
return RedirectToAction(MVC.Config.Logging.TaskStatus(taskStatus.SessionId));
}
public virtual ActionResult UpdateAttachmentThumbnails()
{
// Device Attachments
var das = dbContext.DeviceAttachments.Where(da => da.MimeType == "application/pdf");
foreach (var da in das)
{
var fileName = da.RepositoryThumbnailFilename(dbContext);
if (!System.IO.File.Exists(fileName))
{
da.GenerateThumbnail(dbContext);
}
}
// User Attachments
var uas = dbContext.UserAttachments.Where(ua => ua.MimeType == "application/pdf");
foreach (var ua in uas)
{
var fileName = ua.RepositoryThumbnailFilename(dbContext);
if (!System.IO.File.Exists(fileName))
{
ua.GenerateThumbnail(dbContext);
}
}
// Job Attachments
var jas = dbContext.JobAttachments.Where(ja => ja.MimeType == "application/pdf");
foreach (var ja in jas)
{
var fileName = ja.RepositoryThumbnailFilename(dbContext);
if (!System.IO.File.Exists(fileName))
{
ja.GenerateThumbnail(dbContext);
}
}
return Content("Done", "text/text");
}
public virtual ActionResult UpdateCheck()
{
var ts = Disco.BI.Interop.Community.UpdateCheckTask.ScheduleNow();
ts.SetFinishedUrl(Url.Action(MVC.Config.SystemConfig.Index()));
return RedirectToAction(MVC.Config.Logging.TaskStatus(ts.SessionId));
}
#region Organisation
#region Organisation Name
public virtual ActionResult UpdateOrganisationName(string OrganisationName, bool redirect = false)
{
if (string.IsNullOrWhiteSpace(OrganisationName))
dbContext.DiscoConfiguration.OrganisationName = null;
else
dbContext.DiscoConfiguration.OrganisationName = OrganisationName;
dbContext.SaveChanges();
DiscoApplication.OrganisationName = dbContext.DiscoConfiguration.OrganisationName;
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
#endregion
#region Organisation Logo
[OutputCache(Duration = 31536000, Location = System.Web.UI.OutputCacheLocation.Any, VaryByParam = "*")]
public virtual ActionResult OrganisationLogo(int Width = 256, int Height = 256, string v = null)
{
if (Width < 1)
throw new ArgumentOutOfRangeException("Width");
if (Height < 1)
throw new ArgumentOutOfRangeException("Height");
using (Stream logoStream = dbContext.DiscoConfiguration.OrganisationLogo)
{
using (Image logoBitmap = Bitmap.FromStream(logoStream))
{
return File(logoBitmap.ResizeImage(Width, Height).SavePng(), "image/png");
}
}
}
[HttpPost]
public virtual ActionResult OrganisationLogo(bool redirect, HttpPostedFileBase Image, bool? ResetLogo = null)
{
if (ResetLogo.HasValue && ResetLogo.Value)
{
dbContext.DiscoConfiguration.OrganisationLogo = null;
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
if (Image != null && Image.ContentLength > 0)
{
if (Image.ContentType.StartsWith("image/", StringComparison.InvariantCultureIgnoreCase))
{
dbContext.DiscoConfiguration.OrganisationLogo = Image.InputStream;
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
else
{
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("Invalid Content Type", JsonRequestBehavior.AllowGet);
}
}
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("No Image Supplied", JsonRequestBehavior.AllowGet);
}
#endregion
#region Organisation Addresses
public virtual ActionResult UpdateOrganisationAddress(Disco.Models.BI.Config.OrganisationAddress organisationAddress, bool redirect = false)
{
if (organisationAddress == null)
{
ModelState.AddModelError("Address", "No address was supplied");
}
if (ModelState.IsValid)
{
dbContext.DiscoConfiguration.OrganisationAddresses.SetAddress(organisationAddress);
dbContext.SaveChanges();
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
else
{
// Build Error Message
var em = new StringBuilder();
em.AppendLine("Error:");
foreach (var item in ModelState)
{
foreach (var errorItem in item.Value.Errors)
{
em.Append(item.Key);
em.Append(": ");
em.AppendLine(errorItem.ErrorMessage);
}
}
if (redirect)
throw new InvalidOperationException(em.ToString());
else
return Json(em.ToString(), JsonRequestBehavior.AllowGet);
}
}
public virtual ActionResult DeleteOrganisationAddress(int Id, bool redirect = false)
{
dbContext.DiscoConfiguration.OrganisationAddresses.RemoveAddress(Id);
dbContext.SaveChanges();
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
#endregion
#region MultiSiteMode
public virtual ActionResult UpdateMultiSiteMode(bool MultiSiteMode, bool redirect = false)
{
dbContext.DiscoConfiguration.MultiSiteMode = MultiSiteMode;
dbContext.SaveChanges();
DiscoApplication.MultiSiteMode = dbContext.DiscoConfiguration.MultiSiteMode;
if (redirect)
return RedirectToAction(MVC.Config.Organisation.Index());
else
return Json("OK", JsonRequestBehavior.AllowGet);
}
#endregion
#endregion
}
}
@@ -1,178 +1,179 @@
@model Disco.Web.Areas.Config.Models.SystemConfig.IndexModel
@{
ViewBag.Title = Html.ToBreadcrumb("Configuration", MVC.Config.Config.Index(), "System");
}
@using (Html.BeginForm())
{
<div class="form" style="width: 450px">
<table>
<tr>
<th style="width: 135px">Disco Version:
</th>
<td>
<div>
<code>@Model.DiscoVersion.ToString(4)</code>
</div>
<div class="smallMessage" title="@Model.DiscoVersionBuilt.ToFullDateTime()">
Built @Model.DiscoVersionBuilt.ToFuzzy("Unknown")
</div>
</td>
</tr>
<tr>
<th style="width: 135px">Database Connection:
</th>
<td>
<table class="sub">
<tr>
<th>Server:</th>
<td><span class="code">@Model.DatabaseServer</span></td>
</tr>
<tr>
<th>Database:</th>
<td><span class="code">@Model.DatabaseName</span></td>
</tr>
<tr>
<th>Authentication:</th>
<td>@Model.DatabaseAuthentication</td>
</tr>
@{if (Model.DatabaseSqlAuthUsername != null)
{
<tr>
<th>SQL&nbsp;User:</th>
<td><span class="code">@Model.DatabaseSqlAuthUsername</span></td>
</tr>
}
}
</table>
</td>
</tr>
<tr>
<th style="width: 135px">Data Store Location:
</th>
<td>
<span class="code">@Model.DataStoreLocation</span>
@* @Html.EditorFor(m => m.DataStoreLocation)<br />
@Html.ValidationMessageFor(m => m.DataStoreLocation)*@
</td>
</tr>
</table>
</div>
<div class="form" style="width: 450px; margin-top: 15px;">
<h2>Updates</h2>
<table>
@{
if (Model.UpdateLatestResponse == null)
{
<tr>
<th style="width: 135px">Last Check:
</th>
<td>
<div class="error"><span class="icon error" style="margin-right: 6px;"></span>Never</div>
</td>
</tr>
}
else
{
<tr>
<th style="width: 135px">Last Run:
</th>
<td>
<span>@CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.ResponseTimestamp)</span>
</td>
</tr>
if (Model.UpdateLatestResponse.IsUpdatable(typeof(DiscoApplication).Assembly.GetName().Version))
{
<tr>
<th style="width: 135px">Update Available:
</th>
<td>
<div>
<span class="icon warning" style="margin-right: 6px;"></span>Version @(Model.UpdateLatestResponse.Version) is available
</div>
<div class="smallMessage">
[Released @(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.VersionReleasedTimestamp))]
</div>
<div class="smallMessage">@(new HtmlString(Model.UpdateLatestResponse.Blurb))</div>
<a href="@(Model.UpdateLatestResponse.UrlLink)" target="_blank">Download Now</a>
</td>
</tr>
}
else
{
<tr>
<th style="width: 135px">Status:
</th>
<td>
<span class="icon success" style="margin-right: 6px;"></span><span>The latest version is installed</span>
</td>
</tr>
}
}
}
<tr>
<th style="width: 135px">Check for Update:@{
if (Model.UpdateBetaDeployment)
{
<div class="alert"><span class="icon warning" style="margin-right: 6px;"></span>Beta Deployment</div>
}
}
</th>
<td>
@{
if (Model.UpdateRunningStatus == null)
{
<div>@Html.ActionLink("Check Now", MVC.API.System.UpdateCheck())</div>
}
else
{
<div>Running now - @Html.ActionLink("Check Status", MVC.Config.Logging.TaskStatus(Model.UpdateRunningStatus.SessionId))</div>
}
}
<div class="smallMessage">
Next Scheduled: @CommonHelpers.FriendlyDate(Model.UpdateNextScheduled, "Unknown")
</div>
</td>
</tr>
</table>
</div>
<div class="form" style="width: 450px; margin-top: 15px;">
<h2>Proxy Settings</h2>
<table>
<tr>
<th style="width: 135px">Address:
</th>
<td>
@Html.EditorFor(m => m.ProxyAddress)<br />
@Html.ValidationMessageFor(m => m.ProxyAddress)
</td>
</tr>
<tr>
<th style="width: 135px">Port:
</th>
<td>
@Html.EditorFor(m => m.ProxyPort)<br />
@Html.ValidationMessageFor(m => m.ProxyPort)
</td>
</tr>
<tr>
<th style="width: 135px">Username:
</th>
<td>
@Html.EditorFor(m => m.ProxyUsername)<br />
@Html.ValidationMessageFor(m => m.ProxyUsername)
</td>
</tr>
<tr>
<th style="width: 135px">Password:
</th>
<td>
@Html.EditorFor(m => m.ProxyPassword)<br />
@Html.ValidationMessageFor(m => m.ProxyPassword)
</td>
</tr>
</table>
</div>
<div class="actionBar">
<input type="submit" class="button" value="Save Configuration" />
</div>
}
@model Disco.Web.Areas.Config.Models.SystemConfig.IndexModel
@{
ViewBag.Title = Html.ToBreadcrumb("Configuration", MVC.Config.Config.Index(), "System");
}
@using (Html.BeginForm())
{
<div class="form" style="width: 450px">
<table>
<tr>
<th style="width: 135px">Disco Version:
</th>
<td>
<div>
<code>@Model.DiscoVersion.ToString(4)</code>
</div>
<div class="smallMessage" title="@Model.DiscoVersionBuilt.ToFullDateTime()">
Built @Model.DiscoVersionBuilt.ToFuzzy("Unknown")
</div>
</td>
</tr>
<tr>
<th style="width: 135px">Database Connection:
</th>
<td>
<table class="sub">
<tr>
<th>Server:</th>
<td><span class="code">@Model.DatabaseServer</span></td>
</tr>
<tr>
<th>Database:</th>
<td><span class="code">@Model.DatabaseName</span></td>
</tr>
<tr>
<th>Authentication:</th>
<td>@Model.DatabaseAuthentication</td>
</tr>
@{if (Model.DatabaseSqlAuthUsername != null)
{
<tr>
<th>SQL&nbsp;User:</th>
<td><span class="code">@Model.DatabaseSqlAuthUsername</span></td>
</tr>
}
}
</table>
</td>
</tr>
<tr>
<th style="width: 135px">Data Store Location:
</th>
<td>
<span class="code">@Model.DataStoreLocation</span>
@* @Html.EditorFor(m => m.DataStoreLocation)<br />
@Html.ValidationMessageFor(m => m.DataStoreLocation)*@
</td>
</tr>
</table>
</div>
<div class="form" style="width: 450px; margin-top: 15px;">
<h2>Updates</h2>
<table>
@{
if (Model.UpdateLatestResponse == null)
{
<tr>
<th style="width: 135px">Last Check:
</th>
<td>
<div class="error"><span class="icon error" style="margin-right: 6px;"></span>Never</div>
</td>
</tr>
}
else
{
<tr>
<th style="width: 135px">Last Run:
</th>
<td>
<span>@CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.ResponseTimestamp)</span>
</td>
</tr>
if (Model.UpdateLatestResponse.IsUpdatable(typeof(DiscoApplication).Assembly.GetName().Version))
{
<tr>
<th style="width: 135px">Update Available:
</th>
<td>
<div>
<span class="icon warning" style="margin-right: 6px;"></span>Version @(Model.UpdateLatestResponse.Version) is available
</div>
<div class="smallMessage">
[Released @(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.VersionReleasedTimestamp))]
</div>
<div class="smallMessage">@(new HtmlString(Model.UpdateLatestResponse.Blurb))</div>
<a href="@(Model.UpdateLatestResponse.UrlLink)" target="_blank">Download Now</a>
</td>
</tr>
}
else
{
<tr>
<th style="width: 135px">Status:
</th>
<td>
<span class="icon success" style="margin-right: 6px;"></span><span>The latest version is installed</span>
</td>
</tr>
}
}
}
<tr>
<th style="width: 135px">Check for Update:@{
if (Model.UpdateBetaDeployment)
{
<div class="alert"><span class="icon warning" style="margin-right: 6px;"></span>Beta Deployment</div>
}
}
</th>
<td>
@{
if (Model.UpdateRunningStatus == null)
{
<div>@Html.ActionLink("Check Now", MVC.API.System.UpdateCheck())</div>
}
else
{
<div>Running now - @Html.ActionLink("Check Status", MVC.Config.Logging.TaskStatus(Model.UpdateRunningStatus.SessionId))</div>
}
}
<div class="smallMessage">
Next Scheduled: @CommonHelpers.FriendlyDate(Model.UpdateNextScheduled, "Unknown")
</div>
</td>
</tr>
</table>
</div>
<div class="form" style="width: 450px; margin-top: 15px;">
<h2>Proxy Settings</h2>
<table>
<tr>
<th style="width: 135px">Address:
</th>
<td>
@Html.EditorFor(m => m.ProxyAddress)<br />
@Html.ValidationMessageFor(m => m.ProxyAddress)
</td>
</tr>
<tr>
<th style="width: 135px">Port:
</th>
<td>
@Html.EditorFor(m => m.ProxyPort)<br />
@Html.ValidationMessageFor(m => m.ProxyPort)
</td>
</tr>
<tr>
<th style="width: 135px">Username:
</th>
<td>
@Html.EditorFor(m => m.ProxyUsername)<br />
@Html.ValidationMessageFor(m => m.ProxyUsername)
</td>
</tr>
<tr>
<th style="width: 135px">Password:
</th>
<td>
@Html.EditorFor(m => m.ProxyPassword)<br />
@Html.ValidationMessageFor(m => m.ProxyPassword)
</td>
</tr>
</table>
</div>
<div class="actionBar">
@Html.ActionLinkButton("Update Device Last Network Logons", MVC.API.System.UpdateLastNetworkLogonDates())
<input type="submit" class="button" value="Save Configuration" />
</div>
}
File diff suppressed because it is too large Load Diff