Update: Disco Online Services Update Checking

Migrates Disco Update checking to new services at
https://services.discoict.com.au.
This commit is contained in:
Gary Sharp
2014-07-23 19:14:08 +10:00
parent 4b3905b4fc
commit 6700d092b3
31 changed files with 621 additions and 523 deletions
@@ -1,188 +0,0 @@
using Disco.Data.Repository;
using Disco.Models.BI.Interop.Community;
using Disco.Models.Repository;
using Disco.Services.Tasks;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace Disco.BI.Interop.Community
{
public static class UpdateCheck
{
private static string UpdateUrl()
{
return string.Concat(Disco.Data.Configuration.CommunityHelpers.CommunityUrl(), "DiscoUpdate/V1");
}
public static Version CurrentDiscoVersion()
{
return typeof(UpdateCheck).Assembly.GetName().Version;
}
public static string CurrentDiscoVersionFormatted()
{
var v = CurrentDiscoVersion();
return string.Format("{0}.{1}.{2:0000}.{3:0000}", v.Major, v.Minor, v.Build, v.Revision);
}
public static UpdateResponse Check(DiscoDataContext Database, bool UseProxy, IScheduledTaskStatus status)
{
status.UpdateStatus(10, "Building Update Request");
var request = BuildRequest(Database);
status.UpdateStatus(40, "Sending Request");
var DiscoBIVersion = CurrentDiscoVersionFormatted();
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(UpdateUrl());
// Added: 2013-02-08 G#
// Fix for Proxy Servers which dont support KeepAlive
webRequest.KeepAlive = false;
// End Added: 2013-02-08 G#
if (!UseProxy)
webRequest.Proxy = new WebProxy();
webRequest.ContentType = "application/json";
webRequest.Method = WebRequestMethods.Http.Post;
webRequest.UserAgent = string.Format("Disco/{0} (Update)", DiscoBIVersion);
using (var wrStream = webRequest.GetRequestStream())
{
XmlSerializer xml = new XmlSerializer(typeof(UpdateRequestV1));
xml.Serialize(wrStream, request);
}
status.UpdateStatus(50, "Waiting for Response");
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
if (webResponse.StatusCode == HttpStatusCode.OK)
{
status.UpdateStatus(90, "Reading Response");
UpdateResponse result;
using (var wResStream = webResponse.GetResponseStream())
{
XmlSerializer xml = new XmlSerializer(typeof(UpdateResponse));
result = (UpdateResponse)xml.Deserialize(wResStream);
}
Database.DiscoConfiguration.UpdateLastCheck = result;
Database.SaveChanges();
status.SetFinishedMessage(string.Format("The update server reported Version {0} is the latest.", result.Version));
return result;
}
else
{
status.SetTaskException(new WebException(string.Format("Server responded with: [{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription)));
return null;
}
}
}
private static UpdateRequestV1 BuildRequest(DiscoDataContext Database)
{
var m = new UpdateRequestV1();
m.DeploymentId = Database.DiscoConfiguration.DeploymentId;
m.CurrentDiscoVersion = CurrentDiscoVersionFormatted();
m.OrganisationName = Database.DiscoConfiguration.OrganisationName;
m.BroadbandDoeWanId = GetBroadbandDoeWanId();
m.BetaDeployment = Database.DiscoConfiguration.UpdateBetaDeployment;
m.Stat_JobCounts = Database.Jobs.GroupBy(j => j.JobTypeId).Select(g => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = g.Key, Count = g.Count() }).ToList();
m.Stat_OpenJobCounts = Database.Jobs.Where(j => j.ClosedDate == null).GroupBy(j => j.JobTypeId).Select(g => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = g.Key, Count = g.Count() }).ToList();
m.Stat_DeviceModelCounts = Database.DeviceModels.Select(dm => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = dm.Manufacturer + ";" + dm.Model, Count = dm.Devices.Count(d => d.DecommissionedDate == null) }).ToList();
var activeThreshold = DateTime.Now.AddDays(-60);
m.Stat_ActiveDeviceModelCounts = Database.DeviceModels.Select(dm => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = dm.Manufacturer + ";" + dm.Model, Count = dm.Devices.Count(d => d.DecommissionedDate == null && (d.LastNetworkLogonDate == null || d.LastNetworkLogonDate > activeThreshold)) }).ToList();
m.Stat_UserCounts = new List<UpdateRequestV1.Stat>() {
new UpdateRequestV1.Stat(){
Key = "All Users",
Count = Database.Users.Count()
}
};
m.Stat_JobWarrantyVendorCounts = Database.Jobs.Where(j => j.JobTypeId == JobType.JobTypeIds.HWar && j.JobMetaWarranty.ExternalLoggedDate.HasValue && j.JobMetaWarranty.ExternalName != null).GroupBy(j => j.JobMetaWarranty.ExternalName).Select(g => new Disco.Models.BI.Interop.Community.UpdateRequestV1.Stat { Key = g.Key ?? "<Unknown>", Count = g.Count() }).ToList();
m.InstalledPlugins = Disco.Services.Plugins.Plugins.GetPlugins().Select(manifest => new Disco.Models.BI.Interop.Community.UpdateRequestV1.PluginRef { Id = manifest.Id, Version = manifest.VersionFormatted }).ToList();
return m;
}
#region DoE Query
public static string GetBroadbandDoeWanId()
{
// DnsQuery for broadband.doe.wan
IPHostEntry doeWanDnsEntry;
try
{
doeWanDnsEntry = Dns.GetHostEntry("broadband.doe.wan");
}
catch (Exception)
{ return null; } // Fail on error
// Try using IPSearch feature
XDocument doeWanIPSearchResult = TryDownloadDoeIPSearch(false);
if (doeWanIPSearchResult == null)
doeWanIPSearchResult = TryDownloadDoeIPSearch(true);
if (doeWanIPSearchResult == null)
return null;
try
{
return doeWanIPSearchResult.Element("resultset").Element("site").Element("number").Value.ToLower();
}
catch (Exception)
{ return null; } // Fail on error
}
private static XDocument TryDownloadDoeIPSearch(bool useProxy)
{
try
{
var DiscoBIVersion = CurrentDiscoVersionFormatted();
HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php");
// Added: 2013-02-08 G#
// Fix for Proxy Servers which dont support KeepAlive
wReq.KeepAlive = false;
// End Added: 2013-02-08 G#
if (!useProxy)
wReq.Proxy = new WebProxy(); // Empty Proxy Config
wReq.Method = WebRequestMethods.Http.Post;
wReq.ContentType = "application/x-www-form-urlencoded";
wReq.UserAgent = string.Format("Disco/{0}", DiscoBIVersion);
using (var wrStream = wReq.GetRequestStream())
{
using (var wrStreamWriter = new StreamWriter(wrStream))
{
wrStreamWriter.Write("mode=whoami");
}
}
using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse())
{
if (wRes.StatusCode == HttpStatusCode.OK)
{
using (var wResStream = wRes.GetResponseStream())
{
return XDocument.Load(wResStream);
}
}
else
return null;
}
}
catch (Exception)
{ return null; } // Fail on error
}
#endregion
}
}
+1 -3
View File
@@ -146,8 +146,6 @@
<Compile Include="BI\DocumentTemplateBI\Importer\DocumentImporterCleanCacheJob.cs" />
<Compile Include="BI\DocumentTemplateBI\Importer\DocumentImporterLog.cs" />
<Compile Include="BI\Expressions\ExpressionCache.cs" />
<Compile Include="BI\Interop\Community\UpdateCheck.cs" />
<Compile Include="BI\Interop\Community\UpdateCheckTask.cs" />
<Compile Include="BI\Interop\MimeTypes.cs" />
<Compile Include="BI\Interop\Pdf\PdfGenerator.cs" />
<Compile Include="BI\Interop\Pdf\PdfImporter.cs" />
@@ -207,7 +205,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_StartDate="2014/6/1" BuildVersion_BuildAction="Both" BuildVersion_DetectChanges="False" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" />
<UserProperties BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_DetectChanges="False" BuildVersion_BuildAction="Both" BuildVersion_StartDate="2014/6/1" />
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
@@ -1,29 +0,0 @@
using System;
using System.Linq;
using System.Net;
namespace Disco.Data.Configuration
{
public static class CommunityHelpers
{
public static string CommunityUrl()
{
// Special case for DiscoCommunity Hosting Network
try
{
var ip = (from addr in Dns.GetHostEntry(Dns.GetHostName()).AddressList
where addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork
&& addr.ToString().StartsWith("10.131.200.")
select addr).FirstOrDefault();
if (ip != null)
{
return "http://hades3:9393/base/";
}
}
catch (Exception)
{ } // Ignore Errors
return "https://discoict.com.au/base/";
}
}
}
@@ -1,5 +1,5 @@
using Disco.Data.Repository;
using Disco.Models.BI.Interop.Community;
using Disco.Models.Services.Interop.DiscoServices;
using System;
using System.IO;
@@ -269,11 +269,18 @@ namespace Disco.Data.Configuration
return this.Get<string>(null);
}
}
public UpdateResponse UpdateLastCheck
public string DeploymentSecret
{
get
{
return this.Get<UpdateResponse>(null);
return this.Get<string>(null);
}
}
public UpdateResponseV2 UpdateLastCheckResponse
{
get
{
return this.Get<UpdateResponseV2>(null);
}
set
{
+1 -2
View File
@@ -73,7 +73,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\CommunityHelpers.cs" />
<Compile Include="Configuration\ConfigurationBase.cs" />
<Compile Include="Configuration\ConfigurationCache.cs" />
<Compile Include="Configuration\Modules\ActiveDirectoryConfiguration.cs" />
@@ -220,7 +219,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_BuildAction="Both" BuildVersion_UseGlobalSettings="False" BuildVersion_DetectChanges="False" BuildVersion_StartDate="2014/6/1" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" />
<UserProperties BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_StartDate="2014/6/1" BuildVersion_DetectChanges="False" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildAction="Both" />
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
@@ -8,6 +8,9 @@ namespace Disco.Data.Migrations
public override void Up()
{
AddColumn("dbo.DeviceModels", "DefaultRepairProvider", c => c.String(maxLength: 40));
// Clear UpdateLastCheck due to Update Protocol v2
Sql("DELETE [Configuration] WHERE [Scope]='System' AND [Key]='UpdateLastCheck'");
}
public override void Down()
+5
View File
@@ -34,6 +34,11 @@ namespace Disco.Data.Repository
var deploymentId = Guid.NewGuid().ToString("D");
Database.ConfigurationItems.Add(new ConfigurationItem { Scope = "System", Key = "DeploymentId", Value = deploymentId });
}
if (Database.ConfigurationItems.Count(ci => ci.Scope == "System" && ci.Key == "DeploymentSecret") == 0)
{
var deploymentId = Guid.NewGuid().ToString("N");
Database.ConfigurationItems.Add(new ConfigurationItem { Scope = "System", Key = "DeploymentSecret", Value = deploymentId });
}
}
public static void SeedJobTypes(this DiscoDataContext Database)
{
@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Disco.Models.BI.Interop.Community
{
public class UpdateRequestBase
{
public virtual int RequestVersion { get; set; }
}
}
@@ -1,42 +0,0 @@
using System;
using System.Collections.Generic;
namespace Disco.Models.BI.Interop.Community
{
public class UpdateRequestV1 : UpdateRequestBase
{
public UpdateRequestV1()
{
this.RequestVersion = 1;
}
public string DeploymentId { get; set; }
public string CurrentDiscoVersion { get; set; }
public bool BetaDeployment { get; set; }
public string OrganisationName { get; set; }
public string BroadbandDoeWanId { get; set; }
public List<Stat> Stat_JobCounts { get; set; }
public List<Stat> Stat_OpenJobCounts { get; set; }
public List<Stat> Stat_ActiveDeviceModelCounts { get; set; }
public List<Stat> Stat_DeviceModelCounts { get; set; }
public List<Stat> Stat_UserCounts { get; set; }
public List<PluginRef> InstalledPlugins { get; set; }
public List<Stat> Stat_JobWarrantyVendorCounts { get; set; }
public class Stat
{
public string Key { get; set; }
public int Count { get; set; }
}
public class PluginRef
{
public string Id { get; set; }
public string Version { get; set; }
}
}
}
@@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Disco.Models.BI.Interop.Community
{
public class UpdateResponse
{
public string Version { get; set; }
public DateTime VersionReleasedTimestamp { get; set; }
public string Blurb { get; set; }
public string UrlLink { get; set; }
public DateTime ResponseTimestamp { get; set; }
public bool BetaRelease { get; set; }
public bool IsUpdatable(Version TestVersion)
{
var updateVersion = System.Version.Parse(this.Version);
return (updateVersion > TestVersion);
}
}
}
+2 -3
View File
@@ -63,9 +63,6 @@
<Compile Include="BI\Interop\Community\PluginLibraryItem.cs" />
<Compile Include="BI\Interop\Community\PluginLibraryUpdateRequest.cs" />
<Compile Include="BI\Interop\Community\PluginLibraryUpdateResponse.cs" />
<Compile Include="BI\Interop\Community\UpdateRequestBase.cs" />
<Compile Include="BI\Interop\Community\UpdateRequestV1.cs" />
<Compile Include="BI\Interop\Community\UpdateResponse.cs" />
<Compile Include="BI\Job\Statistics\DailyOpenedClosedItem.cs" />
<Compile Include="ClientServices\EnrolResponse.cs" />
<Compile Include="ClientServices\MacEnrol.cs" />
@@ -112,6 +109,8 @@
<Compile Include="Services\Devices\Importing\IDeviceImportContext.cs" />
<Compile Include="Services\Devices\Importing\IDeviceImportField.cs" />
<Compile Include="Services\Interop\ActiveDirectory\ADManagedGroupConfiguration.cs" />
<Compile Include="Services\Interop\DiscoServices\UpdateRequestV2.cs" />
<Compile Include="Services\Interop\DiscoServices\UpdateResponseV2.cs" />
<Compile Include="Services\Jobs\JobLists\JobLocationReference.cs" />
<Compile Include="Services\Jobs\JobLists\JobTableItemModel.cs" />
<Compile Include="Services\Jobs\JobLists\JobTableModel.cs" />
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
namespace Disco.Models.Services.Interop.DiscoServices
{
public class UpdateRequestV2
{
public Guid DeploymentId { get; set; }
public DateTime RequestDate { get; set; }
public string VersionCurrent { get; set; }
public bool IsBetaDeployment { get; set; }
public string OrganisationName { get; set; }
public string BroadbandDoeWanId { get; set; }
public List<StatisticInt> Stat_JobCounts { get; set; }
public List<StatisticInt> Stat_OpenJobCounts { get; set; }
public List<StatisticInt> Stat_ActiveDeviceModelCounts { get; set; }
public List<StatisticInt> Stat_DeviceModelCounts { get; set; }
public List<StatisticInt> Stat_UserCounts { get; set; }
public List<StatisticString> InstalledPlugins { get; set; }
public List<StatisticJob> Stat_Jobs { get; set; }
public class StatisticInt
{
public string K;
public int V;
}
public class StatisticString
{
public string K;
public string V;
}
public class StatisticJob
{
/// <summary>
/// Job Identifier
/// </summary>
public int I { get; set; }
/// <summary>
/// Opened Date
/// </summary>
public DateTime OD { get; set; }
/// <summary>
/// Closed Date
/// </summary>
public DateTime? CD { get; set; }
/// <summary>
/// Job Type
/// </summary>
public string T { get; set; }
/// <summary>
/// Job Sub Types (Semicolon Separated)
/// </summary>
public string ST { get; set; }
/// <summary>
/// Deployment-Unique Device Serial Identifier (Device Serial Number anonymized via hashing salted with Deployment Secret)
/// </summary>
public string D { get; set; }
/// <summary>
/// Deployment-Unique Job User Identifier (Job User Id anonymized via hashing salted with Deployment Secret)
/// </summary>
public string U { get; set; }
/// <summary>
/// Deployment-Unique Job Technician Identifier (Job Technician Id anonymized via hashing salted with Deployment Secret)
/// </summary>
public string TI { get; set; }
/// <summary>
/// Device Model
/// </summary>
public string DM { get; set; }
/// <summary>
/// External Repairer
/// </summary>
public string R { get; set; }
/// <summary>
/// External Repairer Logged
/// </summary>
public DateTime? RL { get; set; }
/// <summary>
/// External Repairer Completed
/// </summary>
public DateTime? RC { get; set; }
}
}
}
@@ -0,0 +1,16 @@
using System;
namespace Disco.Models.Services.Interop.DiscoServices
{
public class UpdateResponseV2
{
public string LatestVersion { get; set; }
public DateTime ReleasedDate { get; set; }
public string Description { get; set; }
public bool IsBetaRelease { get; set; }
public string UrlLink { get; set; }
public DateTime UpdateResponseDate { get; set; }
}
}
+5 -1
View File
@@ -236,6 +236,10 @@
<Compile Include="Interop\ActiveDirectory\ADUserAccount.cs" />
<Compile Include="Interop\ActiveDirectory\Description.cs" />
<Compile Include="Interop\ActiveDirectory\IADObject.cs" />
<Compile Include="Interop\DiscoServices\DiscoServiceHelpers.cs" />
<Compile Include="Interop\VicEduDept\VicSmart.cs" />
<Compile Include="Interop\DiscoServices\UpdateQuery.cs" />
<Compile Include="Interop\DiscoServices\UpdateQueryTask.cs" />
<Compile Include="Jobs\JobExtensions.cs" />
<Compile Include="Jobs\JobLists\JobTableExtensions.cs" />
<Compile Include="Jobs\JobQueues\Cache.cs" />
@@ -364,7 +368,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_StartDate="2014/6/1" BuildVersion_BuildAction="Both" BuildVersion_DetectChanges="False" BuildVersion_UseGlobalSettings="False" />
<UserProperties BuildVersion_UseGlobalSettings="False" BuildVersion_DetectChanges="False" BuildVersion_BuildAction="Both" BuildVersion_StartDate="2014/6/1" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" />
</VisualStudio>
</ProjectExtensions>
<PropertyGroup>
@@ -0,0 +1,21 @@
using System;
namespace Disco.Services.Interop.DiscoServices
{
public static class DiscoServiceHelpers
{
[Obsolete]
public static string CommunityUrl()
{
return "https://discoict.com.au/base/";
}
public static string ServicesUrl
{
get
{
return "https://services.discoict.com.au/";
}
}
}
}
@@ -0,0 +1,209 @@
using Disco.Data.Repository;
using Disco.Models.Repository;
using Disco.Models.Services.Interop.DiscoServices;
using Disco.Services.Tasks;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace Disco.Services.Interop.DiscoServices
{
using StatisticInt = UpdateRequestV2.StatisticInt;
using StatisticJob = UpdateRequestV2.StatisticJob;
using StatisticString = UpdateRequestV2.StatisticString;
public static class UpdateQuery
{
private static string UpdateUrl()
{
return string.Concat(DiscoServiceHelpers.ServicesUrl, "API/Update/V2");
}
public static Version CurrentDiscoVersion()
{
return typeof(UpdateQuery).Assembly.GetName().Version;
}
public static string CurrentDiscoVersionFormatted()
{
var v = CurrentDiscoVersion();
return FormatVersion(v);
}
public static string FormatVersion(Version Version)
{
return string.Format("{0}.{1}.{2:0000}.{3:0000}", Version.Major, Version.Minor, Version.Build, Version.Revision);
}
public static string HashDeploymentData(DiscoDataContext Database, string Data)
{
if (Data == null)
return null;
string clearText = Database.DiscoConfiguration.DeploymentSecret + Data;
byte[] clearTextBytes = Encoding.Unicode.GetBytes(clearText);
byte[] hashBytes;
using (var hashAlgorithm = SHA1.Create())
{
hashBytes = hashAlgorithm.ComputeHash(clearTextBytes);
}
return Convert.ToBase64String(hashBytes);
}
public static UpdateResponseV2 Check(DiscoDataContext Database, bool UseProxy, IScheduledTaskStatus Status)
{
Status.UpdateStatus(10, "Gathering statistics and building update request");
var updateRequest = BuildRequest(Database);
var updateRequestJson = JsonConvert.SerializeObject(updateRequest);
Status.UpdateStatus(40, "Sending statistics and update request");
var discoVersion = CurrentDiscoVersionFormatted();
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(UpdateUrl());
// Fix for Proxy Servers which don't support KeepAlive
request.KeepAlive = false;
if (!UseProxy)
request.Proxy = new WebProxy();
request.ContentType = "application/json; charset=utf-8; encoding=gzip";
request.Method = WebRequestMethods.Http.Post;
request.UserAgent = string.Format("Disco/{0} (Update)", discoVersion);
using (var requestStream = request.GetRequestStream())
{
using (var compressedStream = new GZipStream(requestStream, CompressionLevel.Optimal))
{
using (var requestStreamWriter = new StreamWriter(compressedStream, Encoding.UTF8))
{
requestStreamWriter.Write(updateRequestJson);
requestStreamWriter.Flush();
}
}
}
Status.UpdateStatus(50, "Waiting for update response");
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
if (response.StatusCode == HttpStatusCode.OK)
{
Status.UpdateStatus(90, "Reading update response");
string updateResultJson;
UpdateResponseV2 updateResult;
using (var responseStream = response.GetResponseStream())
{
using (var responseReader = new StreamReader(responseStream))
{
updateResultJson = responseReader.ReadToEnd();
}
}
updateResult = JsonConvert.DeserializeObject<UpdateResponseV2>(updateResultJson);
Database.DiscoConfiguration.UpdateLastCheckResponse = updateResult;
Database.SaveChanges();
Status.SetFinishedMessage(string.Format("The update server reported Version {0} is the latest.", updateResult.LatestVersion));
return updateResult;
}
else
{
Status.SetTaskException(new WebException(string.Format("Server responded with: [{0}] {1}", response.StatusCode, response.StatusDescription)));
return null;
}
}
}
private static UpdateRequestV2 BuildRequest(DiscoDataContext Database)
{
var lastUpdate = Database.DiscoConfiguration.UpdateLastCheckResponse;
var m = new UpdateRequestV2();
m.DeploymentId = Guid.Parse(Database.DiscoConfiguration.DeploymentId);
m.RequestDate = DateTime.Now;
m.VersionCurrent = CurrentDiscoVersionFormatted();
m.IsBetaDeployment = Database.DiscoConfiguration.UpdateBetaDeployment;
m.OrganisationName = Database.DiscoConfiguration.OrganisationName;
var whoAmIResponse = VicEduDept.VicSmart.WhoAmI();
if (whoAmIResponse != null && !string.IsNullOrWhiteSpace(whoAmIResponse.Item1))
m.BroadbandDoeWanId = whoAmIResponse.Item1;
m.Stat_JobCounts = Database.Jobs.GroupBy(j => j.JobTypeId).Select(g => new StatisticInt() { K = g.Key, V = g.Count() }).ToList();
m.Stat_OpenJobCounts = Database.Jobs.Where(j => j.ClosedDate == null).GroupBy(j => j.JobTypeId).Select(g => new StatisticInt() { K = g.Key, V = g.Count() }).ToList();
m.Stat_DeviceModelCounts = Database.DeviceModels.Select(dm => new StatisticInt() { K = dm.Manufacturer + ";" + dm.Model, V = dm.Devices.Count(d => d.DecommissionedDate == null) }).ToList();
var activeThreshold = DateTime.Now.AddDays(-60);
m.Stat_ActiveDeviceModelCounts = Database.DeviceModels.Select(dm => new StatisticInt() { K = dm.Manufacturer + ";" + dm.Model, V = dm.Devices.Count(d => d.DecommissionedDate == null && (d.LastNetworkLogonDate == null || d.LastNetworkLogonDate > activeThreshold)) }).ToList();
m.Stat_UserCounts = new List<StatisticInt>() {
new StatisticInt() { K = "All", V = Database.Users.Count() },
new StatisticInt() { K = "Assigned Current", V = Database.Users.Where(u => u.DeviceUserAssignments.Any(dua => !dua.UnassignedDate.HasValue)).Count() },
new StatisticInt() { K = "Assigned Ever", V = Database.Users.Where(u => u.DeviceUserAssignments.Any()).Count() },
new StatisticInt() { K = "Job Technicians", V = Database.Jobs.Select(j => j.OpenedTechUserId).Distinct().ToList().Concat(Database.Jobs.Select(j => j.ClosedTechUserId).Distinct().ToList()).Distinct().Count() },
new StatisticInt() { K = "Job Users", V = Database.Jobs.Where(j => j.UserId != null).Select(j => j.UserId).Distinct().Count() }
};
IQueryable<Job> jobs;
if (lastUpdate == null)
jobs = Database.Jobs;
else
{
var lastUpdateDate = lastUpdate.UpdateResponseDate.Date;
jobs = Database.Jobs.Where(j => j.OpenedDate >= lastUpdateDate || (j.ClosedDate.HasValue && j.ClosedDate.Value >= lastUpdateDate));
}
var reportedJobs = jobs.Select(j => new
{
Id = j.Id,
OpenedDate = j.OpenedDate,
ClosedDate = j.ClosedDate,
JobType = j.JobTypeId,
JobSubTypes = j.JobSubTypes.Select(jst => jst.Id),
DeviceModelManufacturer = j.Device.DeviceModel.Manufacturer,
DeviceModelModel = j.Device.DeviceModel.Model,
DeviceSerialNumber = j.DeviceSerialNumber,
UserId = j.UserId,
JobTechnicianId = j.OpenedTechUserId,
WarrantyRepairer = j.JobMetaWarranty.ExternalName,
WarrantyRepairerLoggedDate = j.JobMetaWarranty.ExternalLoggedDate,
WarrantyRepairerCompletedDate = j.JobMetaWarranty.ExternalCompletedDate,
Repairer = j.JobMetaNonWarranty.RepairerName,
RepairerLoggedDate = j.JobMetaNonWarranty.RepairerLoggedDate,
RepairerCompletedDate = j.JobMetaNonWarranty.RepairerCompletedDate,
}).ToList();
m.Stat_Jobs = reportedJobs.Select(j => new StatisticJob()
{
I = j.Id,
OD = j.OpenedDate,
CD = j.ClosedDate,
T = j.JobType,
ST = j.JobSubTypes == null ? null : string.Join(";", j.JobSubTypes),
D = HashDeploymentData(Database, j.DeviceSerialNumber),
U = HashDeploymentData(Database, j.UserId),
TI = HashDeploymentData(Database, j.JobTechnicianId),
DM = string.Format("{0};{1}", j.DeviceModelManufacturer, j.DeviceModelModel),
R = j.JobType == JobType.JobTypeIds.HWar ? j.WarrantyRepairer : j.Repairer,
RL = j.JobType == JobType.JobTypeIds.HWar ? j.WarrantyRepairerLoggedDate : j.RepairerLoggedDate,
RC = j.JobType == JobType.JobTypeIds.HWar ? j.WarrantyRepairerCompletedDate : j.RepairerCompletedDate
}).ToList();
m.InstalledPlugins = Disco.Services.Plugins.Plugins.GetPlugins().Select(manifest => new StatisticString() { K = manifest.Id, V = manifest.VersionFormatted }).ToList();
return m;
}
}
}
@@ -4,52 +4,15 @@ using Quartz;
using System;
using System.Linq;
namespace Disco.BI.Interop.Community
namespace Disco.Services.Interop.DiscoServices
{
public class UpdateCheckTask : ScheduledTask
public class UpdateQueryTask : ScheduledTask
{
public override string TaskName { get { return "Disco Community - Check for Update"; } }
public override string TaskName { get { return "Disco ICT - Check for Update"; } }
public override bool SingleInstanceTask { get { return true; } }
public override bool CancelInitiallySupported { get { return false; } }
public static ScheduledTaskStatus ScheduleNow()
{
var runningTasks = ScheduledTasks.GetTaskStatuses(typeof(UpdateCheckTask)).Where(ts => ts.IsRunning).ToList();
if (runningTasks.Count > 0)
return runningTasks.First();
else
{
var t = new UpdateCheckTask();
return t.ScheduleTask();
}
}
public static ScheduledTaskStatus RunningStatus
{
get
{
return ScheduledTasks.GetTaskStatuses(typeof(UpdateCheckTask)).Where(ts => ts.IsRunning).FirstOrDefault();
}
}
public static DateTime? NextScheduled
{
get
{
var runningTasks = ScheduledTasks.GetTaskStatuses(typeof(UpdateCheckTask)).ToList();
DateTime timestamp = DateTime.MaxValue;
foreach (var t in runningTasks)
{
if (t.NextScheduledTimestamp != null && t.NextScheduledTimestamp.Value < timestamp)
timestamp = t.NextScheduledTimestamp.Value;
}
if (timestamp == DateTime.MaxValue)
return null;
else
return timestamp;
}
}
public override void InitalizeScheduledTask(Data.Repository.DiscoDataContext Database)
public override void InitalizeScheduledTask(DiscoDataContext Database)
{
// Random time between midday and midnight.
var rnd = new Random();
@@ -69,15 +32,55 @@ namespace Disco.BI.Interop.Community
{
try
{
UpdateCheck.Check(database, true, this.Status);
UpdateQuery.Check(database, true, this.Status);
}
catch (Exception ex)
{
ScheduledTasksLog.LogScheduledTaskException(this.Status.TaskName, this.Status.SessionId, this.Status.TaskType, ex);
// Could be proxy error - try again without proxy:
UpdateCheck.Check(database, false, this.Status);
UpdateQuery.Check(database, false, this.Status);
}
}
}
public static ScheduledTaskStatus ScheduleNow()
{
var taskStatus = RunningStatus;
if (taskStatus != null)
return taskStatus;
else
{
var task = new UpdateQueryTask();
return task.ScheduleTask();
}
}
public static DateTime? NextScheduled
{
get
{
DateTime timestamp = DateTime.MaxValue;
var tasks = ScheduledTasks.GetTaskStatuses(typeof(UpdateQueryTask)).ToList();
foreach (var t in tasks)
if (t.NextScheduledTimestamp != null && t.NextScheduledTimestamp.Value < timestamp)
timestamp = t.NextScheduledTimestamp.Value;
if (timestamp != DateTime.MaxValue)
return timestamp;
else
return null;
}
}
public static ScheduledTaskStatus RunningStatus
{
get
{
return ScheduledTasks.GetTaskStatuses(typeof(UpdateQueryTask)).Where(ts => ts.IsRunning).FirstOrDefault();
}
}
}
}
@@ -0,0 +1,88 @@
using Disco.Services.Interop.DiscoServices;
using System;
using System.IO;
using System.Net;
using System.Xml.Linq;
namespace Disco.Services.Interop.VicEduDept
{
public class VicSmart
{
/// <summary>
/// Queries DoE VicSmart Service to detect the current site.
/// </summary>
/// <returns>A Tuple where Item1 is the Site Number and Item2 is the Site Name</returns>
public static Tuple<string, string> WhoAmI()
{
// DnsQuery for broadband.doe.wan
IPHostEntry doeWanDnsEntry;
try
{
doeWanDnsEntry = Dns.GetHostEntry("broadband.doe.wan");
}
catch (Exception)
{ return null; } // Fail on error
// Try using IPSearch feature
XDocument doeWanIPSearchResult = TryIPWhoAmISearch(false);
if (doeWanIPSearchResult == null)
doeWanIPSearchResult = TryIPWhoAmISearch(true);
if (doeWanIPSearchResult == null)
return null;
try
{
var site = doeWanIPSearchResult.Element("resultset").Element("site");
var siteNumber = site.Element("number").Value.ToLower();
var siteName = site.Element("name").Value.ToLower();
return Tuple.Create(siteNumber, siteName);
}
catch (Exception)
{ return null; } // Fail on error
}
private static XDocument TryIPWhoAmISearch(bool useProxy)
{
try
{
var DiscoBIVersion = UpdateQuery.CurrentDiscoVersionFormatted();
HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php");
// Fix for Proxy Servers which don't support KeepAlive
wReq.KeepAlive = false;
if (!useProxy)
wReq.Proxy = new WebProxy(); // Empty Proxy Config
wReq.Method = WebRequestMethods.Http.Post;
wReq.ContentType = "application/x-www-form-urlencoded";
wReq.UserAgent = string.Format("Disco/{0}", DiscoBIVersion);
using (var wrStream = wReq.GetRequestStream())
{
using (var wrStreamWriter = new StreamWriter(wrStream))
{
wrStreamWriter.Write("mode=whoami");
}
}
using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse())
{
if (wRes.StatusCode == HttpStatusCode.OK)
{
using (var wResStream = wRes.GetResponseStream())
{
return XDocument.Load(wResStream);
}
}
else
return null;
}
}
catch (Exception)
{ return null; } // Fail on error
}
}
}
@@ -13,6 +13,7 @@ using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Quartz;
using Disco.Services.Interop.DiscoServices;
namespace Disco.Services.Plugins.CommunityInterop
{
@@ -173,11 +174,11 @@ namespace Disco.Services.Plugins.CommunityInterop
private static string PluginLibraryUpdateUrl()
{
return string.Concat(Disco.Data.Configuration.CommunityHelpers.CommunityUrl(), "DiscoPluginLibrary/V1");
return string.Concat(DiscoServiceHelpers.CommunityUrl(), "DiscoPluginLibrary/V1");
}
private static string PluginLibraryCompatibilityUrl()
{
return string.Concat(Disco.Data.Configuration.CommunityHelpers.CommunityUrl(), "DiscoPluginLibrary/CompatibilityV1");
return string.Concat(DiscoServiceHelpers.CommunityUrl(), "DiscoPluginLibrary/CompatibilityV1");
}
public static ScheduledTaskStatus ScheduleNow()
+3 -1
View File
@@ -35,7 +35,9 @@ namespace Disco.Services.Tasks
var scheduledTasksHostAssemblyName = typeof(ScheduledTask).Assembly.GetName().Name;
var scheduledTaskTypes = (from a in appDomain.GetAssemblies()
where !a.GlobalAssemblyCache && !a.IsDynamic && a.GetReferencedAssemblies().Any(ra => ra.Name == scheduledTasksHostAssemblyName)
where !a.GlobalAssemblyCache &&
!a.IsDynamic &&
(a.GetName().Name == scheduledTasksHostAssemblyName || a.GetReferencedAssemblies().Any(ra => ra.Name == scheduledTasksHostAssemblyName))
from type in a.GetTypes()
where typeof(ScheduledTask).IsAssignableFrom(type) && !type.IsAbstract
select type);
+4 -3
View File
@@ -1,4 +1,5 @@
using Disco.Data.Repository;
using Disco.Services.Interop.DiscoServices;
using System;
using System.Linq;
using System.Web;
@@ -70,10 +71,10 @@ namespace Disco.Web
Disco.Services.Tasks.ScheduledTasks.InitalizeScheduledTasks(Database, DiscoApplication.SchedulerFactory, true);
// Schedule Immediate Check for Update (if never updated, or last updated over 2 days ago)
if (Database.DiscoConfiguration.UpdateLastCheck == null ||
Database.DiscoConfiguration.UpdateLastCheck.ResponseTimestamp < DateTime.Now.AddDays(-2))
if (Database.DiscoConfiguration.UpdateLastCheckResponse == null ||
Database.DiscoConfiguration.UpdateLastCheckResponse.UpdateResponseDate < DateTime.Now.AddDays(-2))
{
Disco.BI.Interop.Community.UpdateCheckTask.ScheduleNow();
UpdateQueryTask.ScheduleNow();
}
// Setup Attachment Monitor
@@ -2,6 +2,7 @@
using Disco.Data.Configuration;
using Disco.Services.Authorization;
using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Interop.DiscoServices;
using Disco.Services.Web;
using System;
using System.Collections.Generic;
@@ -66,7 +67,7 @@ namespace Disco.Web.Areas.API.Controllers
[DiscoAuthorize(Claims.Config.System.Show)]
public virtual ActionResult UpdateCheck()
{
var ts = Disco.BI.Interop.Community.UpdateCheckTask.ScheduleNow();
var ts = Disco.Services.Interop.DiscoServices.UpdateQueryTask.ScheduleNow();
ts.SetFinishedUrl(Url.Action(MVC.Config.SystemConfig.Index()));
return RedirectToAction(MVC.Config.Logging.TaskStatus(ts.SessionId));
}
@@ -354,10 +355,10 @@ namespace Disco.Web.Areas.API.Controllers
Database.SaveChanges();
// Try and check for updates if needed - After Proxy Changed
if (Database.DiscoConfiguration.UpdateLastCheck == null
|| Database.DiscoConfiguration.UpdateLastCheck.ResponseTimestamp < DateTime.Now.AddDays(-1))
if (Database.DiscoConfiguration.UpdateLastCheckResponse == null
|| Database.DiscoConfiguration.UpdateLastCheckResponse.UpdateResponseDate < DateTime.Now.AddDays(-1))
{
Disco.BI.Interop.Community.UpdateCheckTask.ScheduleNow();
UpdateQueryTask.ScheduleNow();
}
if (redirect)
@@ -15,7 +15,7 @@ namespace Disco.Web.Areas.Config.Controllers
var m = new Models.Config.IndexModel()
{
UpdateResponse = Database.DiscoConfiguration.UpdateLastCheck
UpdateResponse = Database.DiscoConfiguration.UpdateLastCheckResponse
};
return View(m);
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Disco.Models.BI.Interop.Community;
using Disco.Models.Services.Interop.DiscoServices;
using System;
namespace Disco.Web.Areas.Config.Models.Config
{
@@ -14,13 +11,14 @@ namespace Disco.Web.Areas.Config.Models.Config
{
if (UpdateResponse != null)
{
var updateVersion = Version.Parse(UpdateResponse.Version);
var updateVersion = Version.Parse(UpdateResponse.LatestVersion);
return (updateVersion > typeof(DiscoApplication).Assembly.GetName().Version);
}
return false;
}
}
public UpdateResponse UpdateResponse { get; set; }
public UpdateResponseV2 UpdateResponse { get; set; }
}
}
@@ -1,15 +1,13 @@
using System;
using Disco.Data.Configuration;
using Disco.Models.Services.Interop.DiscoServices;
using Disco.Services.Interop.ActiveDirectory;
using Disco.Services.Interop.DiscoServices;
using Disco.Services.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Disco.Data.Configuration;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlClient;
using Disco.Data.Repository;
using Disco.Models.BI.Interop.Community;
using Disco.Services.Tasks;
using System.DirectoryServices.ActiveDirectory;
using Disco.Services.Interop.ActiveDirectory;
using System.Linq;
namespace Disco.Web.Areas.Config.Models.SystemConfig
{
@@ -98,7 +96,8 @@ namespace Disco.Web.Areas.Config.Models.SystemConfig
public ScheduledTaskStatus UpdateRunningStatus { get; set; }
public DateTime? UpdateNextScheduled { get; set; }
public UpdateResponse UpdateLatestResponse { get; set; }
public UpdateResponseV2 UpdateLatestResponse { get; set; }
public bool UpdateAvailable { get; set; }
public bool UpdateBetaDeployment { get; set; }
public static IndexModel FromConfiguration(SystemConfiguration config)
@@ -111,12 +110,15 @@ namespace Disco.Web.Areas.Config.Models.SystemConfig
ProxyPort = config.ProxyPort,
ProxyUsername = config.ProxyUsername,
ProxyPassword = config.ProxyPassword,
UpdateLatestResponse = config.UpdateLastCheck,
UpdateRunningStatus = Disco.BI.Interop.Community.UpdateCheckTask.RunningStatus,
UpdateNextScheduled = Disco.BI.Interop.Community.UpdateCheckTask.NextScheduled,
UpdateLatestResponse = config.UpdateLastCheckResponse,
UpdateRunningStatus = UpdateQueryTask.RunningStatus,
UpdateNextScheduled = UpdateQueryTask.NextScheduled,
UpdateBetaDeployment = config.UpdateBetaDeployment
};
// Is an update available?
m.UpdateAvailable = m.UpdateLatestResponse != null && (Version.Parse(m.UpdateLatestResponse.LatestVersion) > m.DiscoVersion);
// AD
m.ADDomains = ActiveDirectory.Context.Domains.ToList();
m.ADPrimaryDomain = ActiveDirectory.Context.PrimaryDomain;
@@ -145,7 +145,7 @@
<div id="updateAvailableContainer">
<i class="fa fa-cloud-download info"></i>
<div>An updated version of Disco is available</div>
<a href="@Model.UpdateResponse.UrlLink" class="button small alert" target="_blank">Download v@(Model.UpdateResponse.Version)</a>
<a href="@Model.UpdateResponse.UrlLink" class="button small alert" target="_blank">Download v@(Model.UpdateResponse.LatestVersion)</a>
</div>
<script>
(function () {
@@ -154,7 +154,7 @@
var updateAvailableContainer = $('#updateAvailableContainer');
updateAvailableContainer.appendTo(layout_PageHeading);
@{
if (Model.UpdateResponse.VersionReleasedTimestamp < DateTime.Now.AddDays(-14))
if (Model.UpdateResponse.ReleasedDate < DateTime.Now.AddDays(-14))
{
<text>
updateAvailableContainer.effect("shake", { times: 3 }, 500);
@@ -930,7 +930,7 @@ WriteLiteral(">Download v");
#line 148 "..\..\Areas\Config\Views\Config\Index.cshtml"
Write(Model.UpdateResponse.Version);
Write(Model.UpdateResponse.LatestVersion);
#line default
@@ -954,7 +954,7 @@ WriteLiteral(@" <script>
#line 156 "..\..\Areas\Config\Views\Config\Index.cshtml"
if (Model.UpdateResponse.VersionReleasedTimestamp < DateTime.Now.AddDays(-14))
if (Model.UpdateResponse.ReleasedDate < DateTime.Now.AddDays(-14))
{
@@ -85,22 +85,22 @@
<th style="width: 135px">Last Run:
</th>
<td>
<span>@CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.ResponseTimestamp)</span>
<span>@CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.UpdateResponseDate.ToLocalTime())</span>
</td>
</tr>
if (Model.UpdateLatestResponse.IsUpdatable(typeof(DiscoApplication).Assembly.GetName().Version))
if (Model.UpdateAvailable)
{
<tr>
<th style="width: 135px">Update Available:
</th>
<td>
<div>
<i class="fa fa-info-circle fa-lg information"></i>&nbsp;Version @(Model.UpdateLatestResponse.Version) is available
<i class="fa fa-info-circle fa-lg information"></i>&nbsp;Version @(Model.UpdateLatestResponse.LatestVersion) is available
</div>
<div class="smallMessage">
[Released @(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.VersionReleasedTimestamp))]
[Released @(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.ReleasedDate))]
</div>
<div class="smallMessage">@(new HtmlString(Model.UpdateLatestResponse.Blurb))</div>
<div class="smallMessage">@(new HtmlString(Model.UpdateLatestResponse.Description))</div>
<a href="@(Model.UpdateLatestResponse.UrlLink)" target="_blank">Download Now</a>
</td>
</tr>
@@ -536,15 +536,20 @@
}
var ajaxLoading = button.next('.ajaxLoading').first().show();
$.getJSON(url, data, function (response, result) {
if (result != 'success' || response != 'OK') {
alert('Unable to change property "' + UpdatePropertyName + '":\n' + response);
ajaxLoading.hide();
} else {
ajaxLoading.hide().next('.ajaxOk').show().delay('fast').fadeOut('slow');
$.ajax({
type: 'POST',
dataType: 'json',
url: url,
data: data,
success: function (response, result) {
if (result != 'success' || response != 'OK') {
alert('Unable to change property "' + UpdatePropertyName + '":\n' + response);
ajaxLoading.hide();
} else {
ajaxLoading.hide().next('.ajaxOk').show().delay('fast').fadeOut('slow');
}
}
})
});
});
});
</script>
@@ -269,7 +269,7 @@ WriteLiteral(">Last Run:\r\n </th>\r\n <td>\r\n
#line 88 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.ResponseTimestamp));
Write(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.UpdateResponseDate.ToLocalTime()));
#line default
@@ -278,7 +278,7 @@ WriteLiteral("</span>\r\n </td>\r\n </tr>\r\n");
#line 91 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
if (Model.UpdateLatestResponse.IsUpdatable(typeof(DiscoApplication).Assembly.GetName().Version))
if (Model.UpdateAvailable)
{
@@ -297,7 +297,7 @@ WriteLiteral("></i>&nbsp;Version ");
#line 98 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Model.UpdateLatestResponse.Version);
Write(Model.UpdateLatestResponse.LatestVersion);
#line default
@@ -310,7 +310,7 @@ WriteLiteral(">\r\n [Released ");
#line 101 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.VersionReleasedTimestamp));
Write(CommonHelpers.FriendlyDate(Model.UpdateLatestResponse.ReleasedDate));
#line default
@@ -323,21 +323,21 @@ WriteLiteral(">");
#line 103 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(new HtmlString(Model.UpdateLatestResponse.Blurb));
Write(new HtmlString(Model.UpdateLatestResponse.Description));
#line default
#line hidden
WriteLiteral("</div>\r\n <a");
WriteAttribute("href", Tuple.Create(" href=\"", 3996), Tuple.Create("\"", 4040)
WriteAttribute("href", Tuple.Create(" href=\"", 3941), Tuple.Create("\"", 3985)
#line 104 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
, Tuple.Create(Tuple.Create("", 4003), Tuple.Create<System.Object, System.Int32>(Model.UpdateLatestResponse.UrlLink
, Tuple.Create(Tuple.Create("", 3948), Tuple.Create<System.Object, System.Int32>(Model.UpdateLatestResponse.UrlLink
#line default
#line hidden
, 4003), false)
, 3948), false)
);
WriteLiteral(" target=\"_blank\"");
@@ -704,18 +704,18 @@ WriteLiteral(" <i");
WriteLiteral(" class=\"fa fa-exclamation warning fa-fw fa-lg\"");
WriteAttribute("title", Tuple.Create(" title=\"", 8221), Tuple.Create("\"", 8304)
, Tuple.Create(Tuple.Create("", 8229), Tuple.Create("Unavailable,", 8229), true)
, Tuple.Create(Tuple.Create(" ", 8241), Tuple.Create("will", 8242), true)
, Tuple.Create(Tuple.Create(" ", 8246), Tuple.Create("retry", 8247), true)
, Tuple.Create(Tuple.Create(" ", 8252), Tuple.Create("at", 8253), true)
WriteAttribute("title", Tuple.Create(" title=\"", 8166), Tuple.Create("\"", 8249)
, Tuple.Create(Tuple.Create("", 8174), Tuple.Create("Unavailable,", 8174), true)
, Tuple.Create(Tuple.Create(" ", 8186), Tuple.Create("will", 8187), true)
, Tuple.Create(Tuple.Create(" ", 8191), Tuple.Create("retry", 8192), true)
, Tuple.Create(Tuple.Create(" ", 8197), Tuple.Create("at", 8198), true)
#line 203 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
, Tuple.Create(Tuple.Create(" ", 8255), Tuple.Create<System.Object, System.Int32>(server.AvailableWhen.Value.ToLongTimeString()
, Tuple.Create(Tuple.Create(" ", 8200), Tuple.Create<System.Object, System.Int32>(server.AvailableWhen.Value.ToLongTimeString()
#line default
#line hidden
, 8256), false)
, 8201), false)
);
WriteLiteral("></i>\r\n");
@@ -1639,35 +1639,29 @@ WriteLiteral("\r\n <script>\r\n $(func
#line default
#line hidden
WriteLiteral(@"';
var data = {
ProxyAddress: $('#ProxyAddress').val(),
ProxyPort: $('#ProxyPort').val(),
ProxyUsername: $('#ProxyUsername').val(),
ProxyPassword: $('#ProxyPassword').val()
}
var ajaxLoading = button.next('.ajaxLoading').first().show();
$.getJSON(url, data, function (response, result) {
if (result != 'success' || response != 'OK') {
alert('Unable to change property ""' + UpdatePropertyName + '"":\n' + response);
ajaxLoading.hide();
} else {
ajaxLoading.hide().next('.ajaxOk').show().delay('fast').fadeOut('slow');
}
})
});
});
</script>
</td>
</tr>
</table>
</div>
");
WriteLiteral("\';\r\n var data = {\r\n " +
" ProxyAddress: $(\'#ProxyAddress\').val(),\r\n " +
" ProxyPort: $(\'#ProxyPort\').val(),\r\n ProxyUs" +
"ername: $(\'#ProxyUsername\').val(),\r\n ProxyPas" +
"sword: $(\'#ProxyPassword\').val()\r\n }\r\n " +
" var ajaxLoading = button.next(\'.ajaxLoading\').first().show(" +
");\r\n\r\n $.ajax({\r\n " +
" type: \'POST\',\r\n dataType: \'json\',\r\n " +
" url: url,\r\n dat" +
"a: data,\r\n success: function (response, resul" +
"t) {\r\n if (result != \'success\' || respons" +
"e != \'OK\') {\r\n alert(\'Unable to chang" +
"e property \"\' + UpdatePropertyName + \'\":\\n\' + response);\r\n " +
" ajaxLoading.hide();\r\n " +
" } else {\r\n ajaxLoading.hide().next" +
"(\'.ajaxOk\').show().delay(\'fast\').fadeOut(\'slow\');\r\n " +
" }\r\n }\r\n " +
" });\r\n });\r\n });\r\n " +
" </script>\r\n </td>\r\n </tr>\r\n </table" +
">\r\n </div>\r\n");
#line 555 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 560 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
}
}
else
@@ -1692,7 +1686,7 @@ WriteLiteral(">Address:\r\n </th>\r\n <td>\r\n");
WriteLiteral(" ");
#line 566 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 571 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.DisplayFor(m => m.ProxyAddress));
@@ -1708,7 +1702,7 @@ WriteLiteral(">Port:\r\n </th>\r\n <td>\r\n");
WriteLiteral(" ");
#line 573 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 578 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.DisplayFor(m => m.ProxyPort));
@@ -1724,7 +1718,7 @@ WriteLiteral(">Username:\r\n </th>\r\n <td>\r\n");
WriteLiteral(" ");
#line 580 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 585 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.DisplayFor(m => m.ProxyUsername));
@@ -1739,7 +1733,7 @@ WriteLiteral(">Password:\r\n </th>\r\n <td>*******
"</td>\r\n </tr>\r\n </table>\r\n </div>\r\n");
#line 591 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 596 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
}
@@ -1754,7 +1748,7 @@ WriteLiteral(">\r\n");
WriteLiteral(" ");
#line 593 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
#line 598 "..\..\Areas\Config\Views\SystemConfig\Index.cshtml"
Write(Html.ActionLinkButton("Update Device Last Network Logons", MVC.API.System.UpdateLastNetworkLogonDates()));
+3 -5
View File
@@ -1,12 +1,10 @@
using Disco.Data.Repository;
using Disco.Services.Authorization;
using Disco.Services.Users;
using Disco.Services.Interop.DiscoServices;
using Disco.Services.Web;
using System;
using System.Configuration;
using System.Diagnostics;
using System.Net;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
@@ -44,13 +42,13 @@ namespace Disco.Web
{
// Check for Post-Update
var previousVersion = database.DiscoConfiguration.InstalledDatabaseVersion;
bool isVersionUpdate = previousVersion != Disco.BI.Interop.Community.UpdateCheck.CurrentDiscoVersion();
bool isVersionUpdate = previousVersion != UpdateQuery.CurrentDiscoVersion();
bool ignoreVersionUpdate = false;
if (isVersionUpdate)
{
// Update Database with New Version
database.DiscoConfiguration.InstalledDatabaseVersion = Disco.BI.Interop.Community.UpdateCheck.CurrentDiscoVersion();
database.DiscoConfiguration.InstalledDatabaseVersion = UpdateQuery.CurrentDiscoVersion();
database.SaveChanges();
// Check if configured to Ignore Plugin Updates (Mainly for Dev environment)
+9 -67
View File
@@ -1,18 +1,12 @@
using System;
using System.Collections.Generic;
using Disco.Services.Interop.VicEduDept;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Net;
using System.Xml.Linq;
using System.IO;
using System.Globalization;
namespace Disco.Web.Models.InitialConfig
{
public class WelcomeModel
{
[Required(ErrorMessage="The Organisation Name is required.")]
[Required(ErrorMessage = "The Organisation Name is required.")]
public string OrganisationName { get; set; }
@@ -25,69 +19,17 @@ namespace Disco.Web.Models.InitialConfig
return true;
}
// DnsQuery for broadband.doe.wan
IPHostEntry doeWanDnsEntry;
try
var whoAmIResult = VicSmart.WhoAmI();
if (whoAmIResult != null && !string.IsNullOrWhiteSpace(whoAmIResult.Item2))
{
doeWanDnsEntry = Dns.GetHostEntry("broadband.doe.wan");
}
catch (Exception)
{ return false; } // Fail on error
// Try using IPSearch feature
XDocument doeWanIPSearchResult = TryDownloadDoeIPSearch(true);
if (doeWanIPSearchResult == null)
doeWanIPSearchResult = TryDownloadDoeIPSearch(false);
if (doeWanIPSearchResult == null)
return false;
try
{
var siteName = doeWanIPSearchResult.Element("resultset").Element("site").Element("name").Value.ToLower();
this.OrganisationName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(siteName);
this.OrganisationName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(whoAmIResult.Item2);
_OrganisationNameCache = this.OrganisationName;
return true;
}
catch (Exception)
{ return false; } // Fail on error
}
private XDocument TryDownloadDoeIPSearch(bool useProxy)
{
try
{
HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php");
// Added: 2013-02-08 G#
// Fix for Proxy Servers which dont support KeepAlive
wReq.KeepAlive = false;
// End Added: 2013-02-08 G#
if (!useProxy)
wReq.Proxy = new WebProxy(); // Empty Proxy Config
wReq.Method = WebRequestMethods.Http.Post;
wReq.ContentType = "application/x-www-form-urlencoded";
wReq.UserAgent = string.Format("Disco/{0}", DiscoApplication.Version);
using (var wrStream = wReq.GetRequestStream())
{
using (var wrStreamWriter = new StreamWriter(wrStream))
{
wrStreamWriter.Write("mode=whoami");
}
}
using (HttpWebResponse wRes = (HttpWebResponse)wReq.GetResponse())
{
if (wRes.StatusCode == HttpStatusCode.OK)
{
using (var wResStream = wRes.GetResponseStream())
{
return XDocument.Load(wResStream);
}
}
else
return null;
}
}
catch (Exception)
{ return null; } // Fail on error
return false;
}
}