-
-
Save bertbsky/0dd8f353d071f7a52ad30a8634883d8b to your computer and use it in GitHub Desktop.
ExportVisioUsage
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.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