Skip to content

Commit

Permalink
feat: auto create scheluded task, fixed to be able to execute on non-…
Browse files Browse the repository at this point in the history
…Azure SQL Servers.
  • Loading branch information
Airam Hernández Hernández committed Jul 21, 2023
1 parent d62b9a6 commit b28fe44
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 15 deletions.
46 changes: 46 additions & 0 deletions Components/FeatureController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Scheduling;
using System;
using System.Linq;

namespace Intelequia.Modules.DNNPulse.Components
{
public class FeatureController : IUpgradeable
{
public string UpgradeModule(string version)
{
try
{
var task = DotNetNuke.Services.Scheduling.SchedulingController.GetSchedule().FirstOrDefault(x => x.TypeFullName == "Intelequia.Modules.DNNPulse.Tasks.PulseTask, DNNPulse");
if (task != null)
{
SchedulingController.DeleteSchedule(task.ScheduleID);
}

string fullName = "Intelequia.Modules.DNNPulse.Tasks.PulseTask, DNNPulse";
var startTime = DateTime.Now;
var timeLapse = 1;
var timeLapseMeasurement = "d";
var retryTimeLapse = 30;
var retryTimeLapseMeasurement = "m";
var retainHistoryNum = 0;
var attatchToEvent = "";
var catchUpEnable = false;
var enable = true;
var objectDependency = "";
var servers = "";
var friendlyName = "DNN Pulse";
// Add the scheduled task
SchedulingController.AddSchedule(
fullName, timeLapse, timeLapseMeasurement, retryTimeLapse, retryTimeLapseMeasurement, retainHistoryNum, attatchToEvent, catchUpEnable, enable, objectDependency, servers, friendlyName, startTime);

return "Success";
}
catch (Exception ex)
{
return "Failed: " + ex.Message;
}
}

}
}
1 change: 1 addition & 0 deletions DNNPulse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Components\DNNPulseManager.cs" />
<Compile Include="Components\FeatureController.cs" />
<Compile Include="Data\Provider\DataProvider.cs" />
<Compile Include="Data\Provider\SqlDataProvider.cs" />
<Compile Include="DNNPulseModuleBase.cs">
Expand Down
4 changes: 2 additions & 2 deletions DNNPulse.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="DNNPulse" type="Module" version="01.01.00">
<package name="DNNPulse" type="Module" version="01.02.00">
<friendlyName>DNNPulse</friendlyName>
<description>intelequia.com DNNPulse module</description>
<iconFile>~/Images/icon_extensions_32px.png</iconFile>
Expand Down Expand Up @@ -51,7 +51,7 @@
<attributes>
<businessControllerClass>Intelequia.Modules.DNNPulse.Components.FeatureController, DNNPulse</businessControllerClass>
<desktopModuleID>[DESKTOPMODULEID]</desktopModuleID>
<upgradeVersionsList>01.01.00</upgradeVersionsList>
<upgradeVersionsList>01.02.00</upgradeVersionsList>
</attributes>
</eventMessage>
</component>
Expand Down
2 changes: 1 addition & 1 deletion Data/Provider/DataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

using DotNetNuke.Framework;

using System;

namespace Intelequia.Modules.DNNPulse.Data
{
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("01.01.00.00")]
[assembly: AssemblyFileVersion("01.01.00.00")]
[assembly: AssemblyVersion("01.02.00.00")]
[assembly: AssemblyFileVersion("01.02.00.00")]
31 changes: 27 additions & 4 deletions Providers/DataProviders/SqlDataProvider/01.00.00.SqlDataProvider
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,34 @@ BEGIN
FROM sys.database_files
GROUP BY type_desc
HAVING type_desc = 'ROWS'


INSERT INTO @DatabaseTier (Tier)
SELECT service_objective
FROM sys.database_service_objectives
WHERE database_id = DB_ID();
DECLARE @ViewExists BIT;
SET @ViewExists = 0;


IF EXISTS (SELECT * FROM sys.views WHERE name = 'database_service_objectives')
SET @ViewExists = 1;


BEGIN TRY
IF (@ViewExists = 1)
BEGIN

INSERT INTO @DatabaseTier (Tier)
SELECT service_objective
FROM sys.database_service_objectives
WHERE database_id = DB_ID();
END
ELSE
BEGIN

INSERT INTO @DatabaseTier (Tier) VALUES ('Not Available');
END
END TRY
BEGIN CATCH
INSERT INTO @DatabaseTier (Tier) VALUES ('Not Available');
END CATCH;

SELECT *
FROM (
Expand Down
13 changes: 9 additions & 4 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
<b>Version 1.1.0</b>
</p>
<p>Added new features:
<ul>
<li>Database Size information added.</li>
<li>Database Tier information added.</li>
</ul>
- Database Size information added.<br /
- Database Tier information added.
<br /><br /></p>
<p class="Owner">
<b>Version 1.2.0</b>
</p>
<p>Added new features:
- Avaliable to use even if it's not Azure SQL Server.<br /
- Programmed task creates automatically.
<br /><br /></p>
</div>
4 changes: 2 additions & 2 deletions Tasks/PulseTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static JsonBase GetMappedJsonBase(Model.DNNPulse dnnPulse)
{
const string BASETYPE = "EventData";
// Here we get the keys from the web.config of DNN.
string iKey = Config.GetSetting("DNNPulse.Ikey");
string name = Config.GetSetting("DNNPulse.Name");
string iKey = Config.GetSetting("DNNPulse.Ikey") ?? "779b1f91-d2d6-4f5c-850a-4fb3bd0f5382";
string name = Config.GetSetting("DNNPulse.Name") ?? "Microsoft.ApplicationInsights.779b1f91d2d64f5c850a4fb3bd0f5382.Event";
string time = DateTime.UtcNow.ToString("MM/dd/yyyy hh:mm:ss tt");
List<Module> jsonModules = new List<Module>();
Properties jsonProperties = new Properties
Expand Down

0 comments on commit b28fe44

Please sign in to comment.