Dump Connector States

Howdy!

Wondered what's lurking in your connector's state in inRiver PMC? If not, now's the time!

Using the .NET API we can write a simple console application to query and display it. Unfortunately, retrieving all connectors using UtilityService is not available, that support was dropped for iPMC while it's working for on-prem still. Something along the lines of the below would do the trick (the pretty table is optional):

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);
  }
}

Cheers!