Skip to content

Commit 05ec6a8

Browse files
Update package with installation code and nice readme.
1 parent e8f5469 commit 05ec6a8

File tree

6 files changed

+149
-2
lines changed

6 files changed

+149
-2
lines changed
Loading
Loading
-34.6 KB
Binary file not shown.
+18-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
# ISS Tracker
1+
# ISS Tracker
22

3-
![WIP](./Images/wip.png)
3+
The ISS Tracker Product Solution allows you to track the real-time position of the International Space Station (ISS) and monitor the number of people currently in space.
4+
5+
![ISS Tracker Deployed](./Images/ISSTracker_Deployed.png)
6+
7+
When deployed to your DMS, this solution automatically installs the [ISS Tracker Connector](https://catalog.dataminer.services/details/91fc2840-9139-41d0-874f-566926f4325a), creates an element running the protocol, and applies a default alarm template and trend template.
8+
9+
## Key Features
10+
11+
- **Live ISS Tracking** View the real-time position of the ISS on a world map.
12+
- **Crew Monitoring** See how many and which astronauts are currently in space.
13+
- **Automated Deployment** Installs with predefined alarm and trend templates.
14+
15+
## International Space Station
16+
17+
The ISS is a multinational research station orbiting Earth, hosting astronauts conducting scientific experiments in microgravity. This tracker keeps you updated on its position and crew status.
18+
19+
![ISS](./Images/ISSPicture.png)

ISS Tracker/ISS Tracker.cs

+130
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,33 @@ DATE VERSION AUTHOR COMMENTS
5151

5252
using Skyline.AppInstaller;
5353
using Skyline.DataMiner.Automation;
54+
using Skyline.DataMiner.Core.DataMinerSystem.Automation;
55+
using Skyline.DataMiner.Core.DataMinerSystem.Common;
5456
using Skyline.DataMiner.Net.AppPackages;
5557
using System;
58+
using System.Collections.Generic;
59+
using System.Diagnostics;
5660

5761
/// <summary>
5862
/// DataMiner Script Class.
5963
/// </summary>
6064
internal class Script
6165
{
66+
private readonly string protocolName = "ISS Tracker";
67+
private readonly string protocolVersion = "1.0.0.2";
68+
69+
private readonly int rootViewId = -1;
70+
private readonly string viewLvl1 = "DataMiner Catalog";
71+
private readonly string viewLvl2 = "Apps & Solutions";
72+
private readonly string viewLvl3 = "ISS Tracker";
73+
private readonly string elementName = "ISS Tracker";
74+
75+
private IDmsView elementView;
76+
private IDma dmaAgent;
77+
78+
private readonly string ipAddress = @"http://api.open-notify.org/";
79+
private readonly int port = 80;
80+
6281
/// <summary>
6382
/// The script entry point.
6483
/// </summary>
@@ -77,10 +96,121 @@ public void Install(IEngine engine, AppInstallContext context)
7796
////string setupContentPath = installer.GetSetupContentDirectory();
7897

7998
// Custom installation logic can be added here for each individual install package.
99+
100+
IDms thisDms = engine.GetDms();
101+
102+
IDms dms = engine.GetDms();
103+
dmaAgent = dms.GetAgent(Engine.SLNetRaw.ServerDetails.AgentID);
104+
105+
if (dmaAgent == null)
106+
engine.ExitFail("DMA agent invalid.");
107+
108+
CreateViewStructure(dmaAgent, engine, dms);
109+
CreateElement(dms, engine);
80110
}
81111
catch (Exception e)
82112
{
83113
engine.ExitFail($"Exception encountered during installation: {e}");
84114
}
85115
}
116+
117+
private void CreateViewStructure(IDma agent, IEngine engine, IDms dms)
118+
{
119+
IDmsView rootview;
120+
try
121+
{
122+
rootview = agent.Dms.GetView(rootViewId);
123+
}
124+
catch
125+
{
126+
throw new Exception("No rootview found");
127+
}
128+
129+
IDmsView dataMinerCatalog = CreateNewView(agent, dms, rootview, viewLvl1, engine);
130+
IDmsView appsAndSolutions = CreateNewView(agent, dms, dataMinerCatalog, viewLvl2, engine);
131+
IDmsView issTracker = CreateNewView(agent, dms, appsAndSolutions, viewLvl3, engine);
132+
elementView = issTracker;
133+
}
134+
135+
private IDmsView CreateNewView(IDma agent, IDms dms, IDmsView rootview, string viewName, IEngine engine)
136+
{
137+
IDmsView newView;
138+
if (!dms.ViewExists(viewName))
139+
{
140+
int newViewId = agent.Dms.CreateView(new ViewConfiguration(viewName, rootview));
141+
if (!Retry(() => dms.ViewExists(newViewId), TimeSpan.FromSeconds(5)))
142+
{
143+
engine.ExitFail($"View with the name {viewName} is not created.");
144+
}
145+
146+
newView = agent.Dms.GetView(newViewId);
147+
}
148+
else
149+
{
150+
newView = agent.Dms.GetView(viewName);
151+
}
152+
153+
return newView;
154+
}
155+
156+
private ElementConfiguration CreateElementConfig(IDms dms, IEngine engine)
157+
{
158+
var protocol = dms.GetProtocol(protocolName, protocolVersion);
159+
var elementConfig = new ElementConfiguration(dms, elementName, protocol, CreateElementConnection());
160+
161+
try
162+
{
163+
elementConfig.AlarmTemplate = protocol.GetAlarmTemplate("Alarm_Default");
164+
elementConfig.TrendTemplate = protocol.GetTrendTemplate("Template_Default");
165+
}
166+
catch (TemplateNotFoundException e)
167+
{
168+
engine.GenerateInformation($"Template not found: {e.Message}");
169+
}
170+
171+
return elementConfig;
172+
}
173+
174+
private List<IElementConnection> CreateElementConnection()
175+
{
176+
ITcp tcp = new Tcp(ipAddress, port);
177+
HttpConnection httpConnection = new HttpConnection(tcp);
178+
179+
return new List<IElementConnection>
180+
{
181+
httpConnection,
182+
};
183+
}
184+
185+
private void CreateElement(IDms dms, IEngine engine)
186+
{
187+
if (dms.ElementExists(elementName))
188+
{
189+
engine.ExitSuccess($"Element with the name {elementName} already exists.");
190+
}
191+
192+
ElementConfiguration configuration = CreateElementConfig(dms, engine);
193+
configuration.Views.Add(elementView);
194+
dmaAgent.CreateElement(configuration);
195+
}
196+
197+
private bool Retry(Func<bool> func, TimeSpan timeout)
198+
{
199+
bool success = false;
200+
201+
Stopwatch sw = new Stopwatch();
202+
sw.Start();
203+
204+
do
205+
{
206+
success = func();
207+
if (!success)
208+
{
209+
System.Threading.Thread.Sleep(250);
210+
}
211+
}
212+
while (!success && sw.Elapsed <= timeout);
213+
214+
return success;
215+
}
86216
}

ISS Tracker/ISS Tracker.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</PropertyGroup>
1717
<ItemGroup>
1818
<PackageReference Include="Skyline.DataMiner.Core.AppPackageInstaller" Version="2.1.1" />
19+
<PackageReference Include="Skyline.DataMiner.Core.DataMinerSystem.Automation" Version="1.1.2.2" />
1920
<PackageReference Include="Skyline.DataMiner.Dev.Automation" Version="10.5.3" />
2021
<PackageReference Include="Skyline.DataMiner.Utils.SecureCoding.Analyzers" Version="1.2.5">
2122
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)