Created
May 8, 2018 01:13
-
-
Save Raggles/c4dcffa3dbe4485c25af9896b68e74d2 to your computer and use it in GitHub Desktop.
Finds the styles used in a ArchestrA Graphic
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 ArchestrA.GRAccess; | |
using ArchestrA.Visualization.GraphicAccess; | |
using System.Xml.Linq; | |
using System.Linq; | |
using System.Collections.Generic; | |
using System.IO; | |
namespace StyleFinder | |
{ | |
class StyleFinder | |
{ | |
[STAThread] | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
string gal = args[0]; //Galaxy name | |
string user = args[1]; //username | |
string pass = args[2]; //password | |
string stylesFile = args[3]; //filename of your styles file | |
string graphic = args[4];//the graphic name you want to check | |
GRAccessApp grAccess = new GRAccessAppClass(); | |
IGalaxies gals = grAccess.QueryGalaxies("localhost"); | |
if (gals == null || grAccess.CommandResult.Successful == false) | |
{ | |
Console.WriteLine(grAccess.CommandResult.CustomMessage + grAccess.CommandResult.Text); | |
return; | |
} | |
IGalaxy galaxy = gals[gal]; | |
ICommandResult cmd; | |
galaxy.Login(user, pass); | |
cmd = galaxy.CommandResult; | |
if (!cmd.Successful) | |
{ | |
Console.WriteLine("Login to galaxy Failed :" + cmd.Text + " : " + cmd.CustomMessage); | |
return; | |
} | |
GraphicAccess ff = new GraphicAccess(); | |
var graphicFile = Path.GetTempFileName(); | |
ff.ExportGraphicToXml(galaxy, graphic, graphicFile); | |
cmd = ff.CommandResult; | |
if (!cmd.Successful) | |
{ | |
Console.WriteLine(string.Format("Error exporting {0}. {1}", graphic, cmd.CustomMessage)); | |
return; | |
} | |
galaxy.Logout(); | |
XElement xmlGraphic = XElement.Load(graphicFile); | |
List<string> ids = new List<string>(); | |
var nodes = xmlGraphic.Descendants().Attributes("ElementStyleID").Select(x => x.Value).Distinct(); | |
ids.AddRange(nodes); | |
nodes = xmlGraphic.Descendants().Elements("TrueElementStyle").Select(x => x.Value).Distinct(); | |
ids.AddRange(nodes); | |
nodes = xmlGraphic.Descendants().Elements("FalseElementStyle").Select(x => x.Value).Distinct(); | |
ids.AddRange(nodes); | |
nodes = xmlGraphic.Descendants().Elements("ElementStyle").Where(x=> x.HasElements == false).Select(x => x.Value).Distinct(); | |
ids.AddRange(nodes); | |
XElement xmlStyles = XElement.Load(stylesFile); | |
foreach(string id in ids.Distinct()) | |
{ | |
Console.WriteLine(xmlStyles.Elements("ES").Where(x => x.Attribute("Id").Value == id).Select(x => x.Attribute("Name").Value).FirstOrDefault()); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.ToString()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment