Created
September 14, 2019 11:26
-
-
Save patfog/c601c545b30a0f68bff7963f6d344188 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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