Code: Select all
using System;
using System.Text;
using Microsoft.MediaCenter.Guide;
using Microsoft.MediaCenter.Store;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
namespace MCEGuideDate
{
class Program
{
static void Main(string[] args)
{
if (checkargs(args) == 1)
{
Console.WriteLine("Non numeric arguments passed.");
Environment.Exit(2);
}
if (args.Length == 0)
{
DateTime LatestGuideStartDate = GetLatestStartTime();
Console.WriteLine(LatestGuideStartDate);
Environment.Exit(0);
}
else if (args.Length == 1)
{
Console.WriteLine("Critial - To few parameters");
Environment.Exit(2);
}
else if (args.Length == 2)
{
DateTime LatestGuideStartDate = GetLatestStartTime();
var DaysBetween = (LatestGuideStartDate - DateTime.Now).Days;
if (DaysBetween < Convert.ToInt64(args[1]))
{
Console.WriteLine("Critical - " + DaysBetween + " Days left (" + LatestGuideStartDate + ")");
Environment.Exit(2);
}
else if (DaysBetween < Convert.ToInt64(args[0]))
{
Console.WriteLine("Warning - " + DaysBetween + " Days left (" + LatestGuideStartDate + ")");
Environment.Exit(1);
}
else
{
Console.WriteLine("OK - " + DaysBetween + " Days left (" + LatestGuideStartDate + ")");
Environment.Exit(0);
}
}
else
{
Console.WriteLine("Critial - To many parameters");
Environment.Exit(2);
}
}
static DateTime GetLatestStartTime()
{
string s = "Unable upgrade recording state.";
byte[] bytes = Convert.FromBase64String("FAAODBUITwADRicSARc=");
byte[] buffer2 = Encoding.ASCII.GetBytes(s);
for (int i = 0; i != bytes.Length; i++)
{
bytes[i] = (byte)(bytes[i] ^ buffer2[i]);
}
string clientId = Microsoft.MediaCenter.Store.ObjectStore.GetClientId(true);
SHA256Managed managed = new SHA256Managed();
byte[] buffer = Encoding.Unicode.GetBytes(clientId);
clientId = Convert.ToBase64String(managed.ComputeHash(buffer));
string FriendlyName = Encoding.ASCII.GetString(bytes);
string DisplayName = clientId;
ObjectStore TVstore = Microsoft.MediaCenter.Store.ObjectStore.Open("", FriendlyName, DisplayName, true);
ScheduleEntries entriesInStore = new ScheduleEntries(TVstore);
DateTime latestStartTime = new DateTime(0);
long serviceidchange = 0; // Speed up Code
foreach (ScheduleEntry entry in entriesInStore)
{
if (!(entry.Service == null || entry.Program == null))
{
if (serviceidchange == 0) // Speed up Code
{ // Speed up Code
serviceidchange = entry.Service.Id; // Speed up Code
} // Speed up Code
if (entry.StartTime > latestStartTime) latestStartTime = entry.StartTime;
if (!(entry.Service.Id == serviceidchange)) // Speed up Code
{ // Speed up Code
return latestStartTime; // Speed up Code
} // Speed up Code
}
}
return latestStartTime;
}
static int checkargs(string[] argss)
{
// Make sure this can is either an int or a double
var regex = new Regex(@"(^[0-9]+$)|(^[0-9]+\.[0-9]+$)");
int returnval = 0;
foreach (var arg in argss)
{
if (!regex.IsMatch(arg))
returnval = 1;
else
{
if (!(returnval == 1))
returnval = 0;
}
}
return returnval;
}
}
}
The updated code came back with: 8/20/2016 5:00:00AM
So I don't know if the first row of data it found wasn't complete or I interpreted things in code wrong or data is not sorted appropriately. Basically set a variable to 0. if service and program are not null, I set it to the current service.id. I will keep looping thru until the service.id changes and then return the current date/time it has.
JR