Skip to content

Instantly share code, notes, and snippets.

@bertbsky
Last active December 12, 2022 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bertbsky/0dd8f353d071f7a52ad30a8634883d8b to your computer and use it in GitHub Desktop.
Save bertbsky/0dd8f353d071f7a52ad30a8634883d8b to your computer and use it in GitHub Desktop.
ExportVisioUsage
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net.Messages;
public class Script
{
public void Run(Engine engine)
{
var protocols = Engine.SLNet.SendMessage(new GetInfoMessage(InfoType.Protocols)).OfType<GetProtocolsResponseMessage>();
var elements = Engine.SLNet.SendMessage(new GetInfoMessage(InfoType.ElementInfo)).OfType<ElementInfoEventMessage>();
var services = Engine.SLNet.SendMessage(new GetInfoMessage(InfoType.ServiceInfo)).OfType<ServiceInfoEventMessage>();
var views = Engine.SLNet.SendMessage(new GetInfoMessage(InfoType.ViewInfo)).OfType<ViewInfoEventMessage>();
var map = new Dictionary<string, List<DMSMessage>>(StringComparer.InvariantCultureIgnoreCase);
Action<string, DMSMessage> AddToMap = (string visioReference, DMSMessage item) =>
{
var vdxFile = (visioReference ?? "").Split('|')[0];
if (vdxFile != "")
{
if (!map.TryGetValue(vdxFile, out var list))
{
list = new List<DMSMessage>();
map.Add(vdxFile, list);
}
list.Add(item);
}
};
Func<DMSMessage, string> FormatInfo = (DMSMessage msg) =>
{
if (msg is GetProtocolsResponseMessage p) return $"Protocol {p.Protocol}";
if (msg is ElementInfoEventMessage e) return $"Element {e.Name} ({e.DataMinerID}/{e.ElementID}) hosted on agent {e.HostingAgentID}";
if (msg is ServiceInfoEventMessage s) return $"Service {s.Name} ({s.DataMinerID}/{s.ElementID}) hosted on agent {s.HostingAgentID}";
if (msg is ViewInfoEventMessage v) return $"View {v.Name} ({v.ID})";
throw new ArgumentException();
};
foreach (var protocol in protocols)
AddToMap(protocol.VisioName, protocol);
foreach (var element in elements)
AddToMap(element.Visio, element);
foreach (var service in services)
AddToMap(service.VdxFile, service);
foreach (var view in views)
AddToMap(view.VdxFile, view);
var sb = new StringBuilder();
foreach (var kvp in map)
{
sb.AppendLine(kvp.Key);
foreach (var item in kvp.Value)
sb.AppendLine(" * " + FormatInfo(item));
}
File.WriteAllText(@"C:\Skyline DataMiner\Views\UsageExport.txt", sb.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment