Skip to content

Instantly share code, notes, and snippets.

@patfog
Created September 14, 2019 11:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patfog/c601c545b30a0f68bff7963f6d344188 to your computer and use it in GitHub Desktop.
Save patfog/c601c545b30a0f68bff7963f6d344188 to your computer and use it in GitHub Desktop.
using System;
using System.Configuration;
using System.Linq;
using inRiver.Remoting;
using inRiver.Remoting.Objects;
namespace goof.ConnectorStateViewer
{
public class Program
{
private const string DateFormat = "yyyy-MM-dd HH:mm:ss";
public static void Main(string[] args)
{
var url = ConfigurationManager.AppSettings["ipmc:url"];
var apiKey = ConfigurationManager.AppSettings["ipmc:apiKey"];
var remoteManager = RemoteManager.CreateInstance(url, apiKey);
Console.Write("Enter connector id: ");
var connectorId = Console.ReadLine();
var connectorStates = remoteManager.UtilityService.GetAllConnectorStatesForConnector(connectorId);
Console.WriteLine();
var maxDataLength = connectorStates.Max(s => s.Data.Length);
var dateFormatLength = DateFormat.Length;
var hLine = new string('-', 10 + dateFormatLength * 2 + maxDataLength);
Console.WriteLine(hLine);
Console.WriteLine($"| {AlignCentre("Created", dateFormatLength)} | {AlignCentre("Modified", dateFormatLength)} | {AlignCentre("State", maxDataLength)} |");
foreach (var state in connectorStates)
{
PrintRow(state, maxDataLength);
}
Console.WriteLine(hLine);
Console.WriteLine("Press any key...");
Console.ReadKey();
}
private static void PrintRow(ConnectorState state, int maxDataLength)
{
Console.Write($"| {state.Created.ToString(DateFormat)} | {state.Modified.ToString(DateFormat)} | {AlignCentre(state.Data, maxDataLength)} |");
Console.WriteLine();
}
private static string AlignCentre(string data, int width)
{
data = data.Length > width ? data.Substring(0, width - 3) + "..." : data;
if (string.IsNullOrEmpty(data))
{
return new string(' ', width);
}
return data.PadRight(width - (width - data.Length) / 2).PadLeft(width);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment