-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathProgram.cs
77 lines (74 loc) · 2.72 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Configuration.Install;
using System.Net.Http;
using System.Reflection;
using System.ServiceProcess;
using System.Threading.Tasks;
namespace IPTVTuner
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
// Install or uninstall the service when invoked interactively.
string parameter = string.Concat(args);
switch (parameter)
{
case "--install":
ManagedInstallerClass.InstallHelper(new[] {
Assembly.GetExecutingAssembly().Location
});
break;
case "--uninstall":
ManagedInstallerClass.InstallHelper(new[] {
"/u", Assembly.GetExecutingAssembly().Location
});
break;
case "--update-epg":
// Update the EPG by rebuilding epg.xml.
// Use a scheduled task to periodically refresh the EPG data.
UpdateEpg().Wait();
break;
default:
// Run as a service.
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Service() };
ServiceBase.Run(ServicesToRun);
break;
}
}
/**
* Invoke the service and ask it to update the EPG.
*/
static async Task UpdateEpg()
{
try
{
var config = new Config(null);
using (HttpClient client = new HttpClient())
{
// Open a stream to the Provider M3U.
var res = await client.GetAsync(config.ServerUrl("/update-epg"));
if (res.IsSuccessStatusCode)
{
// EPG update request succeeded.
Console.WriteLine("Started an EPG update.");
}
else
{
// Something unexpected happened.
throw new Exception(String.Format("Unexpected response code {0}.", res.StatusCode));
}
}
}
catch (Exception e)
{
// There was an error; probably the service is not running.
Console.WriteLine("Failed to request an EPG update: " + e.Message);
}
}
}
}