Update: Plugin Updating

Updating plugins from the plugin catalogue, and automatic updating of
plugins after a newer version of Disco is installed.
This commit is contained in:
Gary Sharp
2013-02-14 19:00:01 +11:00
parent 734b02fa1d
commit 8f769809c2
53 changed files with 3795 additions and 2975 deletions
@@ -1,32 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Disco.BI.Interop.Community
{
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 "http://discoict.com.au/base/";
}
}
}
@@ -1,195 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Disco.Data.Repository;
using Disco.Services.Plugins;
using Disco.Services.Tasks;
using Disco.Models.BI.Interop.Community;
using System.Net;
using System.Xml.Serialization;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Disco.BI.Interop.Community
{
public class PluginLibraryUpdateTask : ScheduledTask
{
public override string TaskName { get { return "Disco Community - Update Plugin Library"; } }
protected override void ExecuteTask()
{
PluginLibraryUpdateRequest updateRequestBody;
PluginLibraryUpdateResponse updateResult;
string catalogueFile;
PluginLibraryCompatibilityRequest compatRequestBody;
PluginLibraryCompatibilityResponse compatResult;
string compatibilityFile;
var DiscoBIVersion = UpdateCheck.CurrentDiscoVersion();
HttpWebRequest webRequest;
#region Update
Status.UpdateStatus(1, "Updating Plugin Library Catalogue", "Building Request");
using (DiscoDataContext dbContext = new DiscoDataContext())
{
catalogueFile = Plugins.CatalogueFile(dbContext);
updateRequestBody = new PluginLibraryUpdateRequest()
{
DeploymentId = dbContext.DiscoConfiguration.DeploymentId,
HostVersion = typeof(Plugins).Assembly.GetName().Version.ToString(4)
};
}
Status.UpdateStatus(10, "Sending Request");
webRequest = (HttpWebRequest)HttpWebRequest.Create(PluginLibraryUpdateUrl());
webRequest.KeepAlive = false;
webRequest.ContentType = "application/json";
webRequest.Method = WebRequestMethods.Http.Post;
webRequest.UserAgent = string.Format("Disco/{0} (PluginLibrary)", DiscoBIVersion);
using (var wrStream = webRequest.GetRequestStream())
{
XmlSerializer xml = new XmlSerializer(typeof(PluginLibraryUpdateRequest));
xml.Serialize(wrStream, updateRequestBody);
}
Status.UpdateStatus(20, "Waiting for Response");
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
if (webResponse.StatusCode == HttpStatusCode.OK)
{
Status.UpdateStatus(45, "Reading Response");
using (var wResStream = webResponse.GetResponseStream())
{
XmlSerializer xml = new XmlSerializer(typeof(PluginLibraryUpdateResponse));
updateResult = (PluginLibraryUpdateResponse)xml.Deserialize(wResStream);
}
}
else
{
Status.SetTaskException(new WebException(string.Format("Server responded with: [{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription)));
return;
}
}
if (!Directory.Exists(Path.GetDirectoryName(catalogueFile)))
Directory.CreateDirectory(Path.GetDirectoryName(catalogueFile));
using (FileStream fs = new FileStream(catalogueFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (StreamWriter fsWriter = new StreamWriter(fs))
{
fsWriter.Write(JsonConvert.SerializeObject(updateResult));
fsWriter.Flush();
}
}
#endregion
#region Compatibility
Status.UpdateStatus(50, "Updating Plugin Library Compatibility", "Building Request");
using (DiscoDataContext dbContext = new DiscoDataContext())
{
compatibilityFile = Plugins.CompatibilityFile(dbContext);
compatRequestBody = new PluginLibraryCompatibilityRequest()
{
DeploymentId = dbContext.DiscoConfiguration.DeploymentId,
HostVersion = typeof(Plugins).Assembly.GetName().Version.ToString(4)
};
}
Status.UpdateStatus(60, "Sending Request");
webRequest = (HttpWebRequest)HttpWebRequest.Create(PluginLibraryCompatibilityUrl());
webRequest.KeepAlive = false;
webRequest.ContentType = "application/json";
webRequest.Method = WebRequestMethods.Http.Post;
webRequest.UserAgent = string.Format("Disco/{0} (PluginLibrary)", DiscoBIVersion);
using (var wrStream = webRequest.GetRequestStream())
{
XmlSerializer xml = new XmlSerializer(typeof(PluginLibraryCompatibilityRequest));
xml.Serialize(wrStream, compatRequestBody);
}
Status.UpdateStatus(70, "Waiting for Response");
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
if (webResponse.StatusCode == HttpStatusCode.OK)
{
Status.UpdateStatus(95, "Reading Response");
using (var wResStream = webResponse.GetResponseStream())
{
XmlSerializer xml = new XmlSerializer(typeof(PluginLibraryCompatibilityResponse));
compatResult = (PluginLibraryCompatibilityResponse)xml.Deserialize(wResStream);
}
}
else
{
Status.SetTaskException(new WebException(string.Format("Server responded with: [{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription)));
return;
}
}
if (!Directory.Exists(Path.GetDirectoryName(compatibilityFile)))
Directory.CreateDirectory(Path.GetDirectoryName(compatibilityFile));
using (FileStream fs = new FileStream(compatibilityFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (StreamWriter fsWriter = new StreamWriter(fs))
{
fsWriter.Write(JsonConvert.SerializeObject(compatResult));
fsWriter.Flush();
}
}
#endregion
Status.SetFinishedMessage("The Plugin Library Catalogue was updated.");
}
private static string PluginLibraryUpdateUrl()
{
return string.Concat(CommunityHelpers.CommunityUrl(), "DiscoPluginLibrary/V1");
}
private static string PluginLibraryCompatibilityUrl()
{
return string.Concat(CommunityHelpers.CommunityUrl(), "DiscoPluginLibrary/CompatibilityV1");
}
public static ScheduledTaskStatus ScheduleNow()
{
var taskStatus = ScheduledTasks.GetTaskStatuses(typeof(PluginLibraryUpdateTask)).Where(ts => ts.IsRunning).FirstOrDefault();
if (taskStatus != null)
return taskStatus;
else
{
var t = new PluginLibraryUpdateTask();
return t.ScheduleTask();
}
}
public static ScheduledTaskStatus RunningStatus
{
get
{
return ScheduledTasks.GetTaskStatuses(typeof(PluginLibraryUpdateTask)).Where(ts => ts.IsRunning).FirstOrDefault();
}
}
}
}
+13 -9
View File
@@ -18,13 +18,17 @@ namespace Disco.BI.Interop.Community
{
private static string UpdateUrl()
{
return string.Concat(CommunityHelpers.CommunityUrl(), "DiscoUpdate/V1");
return string.Concat(Disco.Data.Configuration.CommunityHelpers.CommunityUrl(), "DiscoUpdate/V1");
}
public static string CurrentDiscoVersion()
public static Version CurrentDiscoVersion()
{
var AssemblyVersion = typeof(UpdateCheck).Assembly.GetName().Version;
return string.Format("{0}.{1}.{2:0000}.{3:0000}", AssemblyVersion.Major, AssemblyVersion.Minor, AssemblyVersion.Build, AssemblyVersion.Revision);
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 db, bool UseProxy, ScheduledTaskStatus status = null)
@@ -38,7 +42,7 @@ namespace Disco.BI.Interop.Community
if (status != null)
status.UpdateStatus(40, "Sending Request");
var DiscoBIVersion = CurrentDiscoVersion();
var DiscoBIVersion = CurrentDiscoVersionFormatted();
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(UpdateUrl());
@@ -49,7 +53,7 @@ namespace Disco.BI.Interop.Community
if (!UseProxy)
webRequest.Proxy = new WebProxy();
webRequest.ContentType = "application/json";
webRequest.Method = WebRequestMethods.Http.Post;
webRequest.UserAgent = string.Format("Disco/{0} (Update)", DiscoBIVersion);
@@ -78,7 +82,7 @@ namespace Disco.BI.Interop.Community
db.SaveChanges();
status.SetFinishedMessage(string.Format("The update server reported Version {0} is the latest.", result.Version));
return result;
}
else
@@ -96,7 +100,7 @@ namespace Disco.BI.Interop.Community
m.DeploymentId = db.DiscoConfiguration.DeploymentId;
m.CurrentDiscoVersion = CurrentDiscoVersion();
m.CurrentDiscoVersion = CurrentDiscoVersionFormatted();
m.OrganisationName = db.DiscoConfiguration.OrganisationName;
m.BroadbandDoeWanId = GetBroadbandDoeWanId();
@@ -144,7 +148,7 @@ namespace Disco.BI.Interop.Community
{
try
{
var DiscoBIVersion = CurrentDiscoVersion();
var DiscoBIVersion = CurrentDiscoVersionFormatted();
HttpWebRequest wReq = (HttpWebRequest)HttpWebRequest.Create("http://broadband.doe.wan/ipsearch/showresult.php");
// Added: 2013-02-08 G#
@@ -55,7 +55,7 @@ namespace Disco.BI.Interop.Community
public override void InitalizeScheduledTask(Data.Repository.DiscoDataContext dbContext)
{
// ActiveDirectoryUpdateLastNetworkLogonDateJob @ 11:30pm
// Random time between midday and midnight.
var rnd = new Random();
var rndHour = rnd.Next(12, 23);
+1 -3
View File
@@ -149,8 +149,6 @@
<Compile Include="BI\Interop\ActiveDirectory\ActiveDirectoryUpdateLastNetworkLogonDateJob.cs" />
<Compile Include="BI\Interop\ActiveDirectory\ActiveDirectoryUserAccountExtensions.cs" />
<Compile Include="BI\Expressions\ExpressionCache.cs" />
<Compile Include="BI\Interop\Community\CommunityHelpers.cs" />
<Compile Include="BI\Interop\Community\PluginLibraryUpdateTask.cs" />
<Compile Include="BI\Interop\Community\UpdateCheck.cs" />
<Compile Include="BI\Interop\Community\UpdateCheckTask.cs" />
<Compile Include="BI\Interop\MimeTypes.cs" />
@@ -221,7 +219,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_StartDate="2001/1/1" BuildVersion_BuildAction="ReBuild" BuildVersion_DetectChanges="False" BuildVersion_UseGlobalSettings="True" />
<UserProperties BuildVersion_UseGlobalSettings="True" BuildVersion_DetectChanges="False" BuildVersion_BuildAction="ReBuild" BuildVersion_StartDate="2001/1/1" />
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0212.1702")]
[assembly: AssemblyFileVersion("1.2.0212.1702")]
[assembly: AssemblyVersion("1.2.0214.1848")]
[assembly: AssemblyFileVersion("1.2.0214.1848")]