/// <summary> /// Open file button logic. /// </summary> private void buttonOpenFile_Click(object sender, RoutedEventArgs e) { try { OpenFileDialog dialog = new OpenFileDialog(); String[] availableFiles = Directory.GetFiles("./", "*.dll"); List <String> featureModelModules = new List <String>(); List <Type> extensions = new List <Type>(); //Searches amongst available libraries for valid Feature Model extensions foreach (String s in availableFiles) { Assembly asm = Assembly.LoadFrom(s); Type[] types = asm.GetTypes(); foreach (Type t in types) { Type[] interfaces = t.GetInterfaces(); if (interfaces.Contains(typeof(IConfigurationFormat))) { IConfigurationFormat extension = (IConfigurationFormat)Activator.CreateInstance(t); string filter = extension.GetFilter(); if (!dialog.Filter.Equals("")) { filter = "|" + filter; } dialog.Filter += filter; extensions.Add(t); } } } if (dialog.ShowDialog() == false) { return; } string fileToLoad = dialog.FileName; string ext = fileToLoad.Split('.').Last(); //Searches amongst valid extensions for the one selected foreach (Type t in extensions) { IConfigurationFormat extension = (IConfigurationFormat)Activator.CreateInstance(t); if (extension.GetFilter().Contains(ext)) { ComponentDiagramBragi bragi = extension.LoadFrom(fileToLoad); this.BragiStruct = bragi; this.UpdateVisualTree(); return; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "PlugSPL Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void SaveTo(ComponentDiagramBragi atlas, string filename) { using (TextWriter writer = new StreamWriter(filename)){ XmlSerializer serializer = new XmlSerializer(typeof(AtlasFeatureModel)); serializer.Serialize(writer, atlas); } }
public ComponentDiagramBragi LoadFrom(string filename) { TextReader reader = new StreamReader(filename); XmlSerializer serializer = new XmlSerializer(typeof(ComponentDiagramBragi)); ComponentDiagramBragi atlas = (ComponentDiagramBragi)serializer.Deserialize(reader); reader.Close(); return(atlas); }
public void SaveTo(AtlasFeatureModel atlas, string filename) { this.model = atlas; this.bragi = new ComponentDiagramBragi(); AtlasFeature rootFeature = atlas.GetFeature(atlas.RootFeatureName); this.ParseComponent(null, rootFeature); this.bragi.AddStereotype(new Stereotype("Mutex")); this.bragi.AddStereotype(new Stereotype("Requires")); XmlSerializer serializer = new XmlSerializer(typeof(ComponentDiagramBragi)); using (TextWriter writer = new StreamWriter(filename)){ serializer.Serialize(writer, this.bragi); } }
/// <summary> /// Import bragi file and builds an Danu struct with it. /// </summary> private void buttonLoadDanu_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "UML Component Diagram / Smarty (*.plugcd)|*.plugcd"; if (dialog.ShowDialog() != true) { return; } ComponentDiagramBragi plugcd = null; XmlSerializer serializer = new XmlSerializer(typeof(ComponentDiagramBragi)); using (TextReader reader = new StreamReader(dialog.FileName)) { try { plugcd = (ComponentDiagramBragi)serializer.Deserialize(reader); } catch (Exception) { MessageBox.Show("Wrong data format. Given file has no valid structure inside it.", "PlugSPL Error", MessageBoxButton.OK, MessageBoxImage.Error); } } if (plugcd == null) { return; } lastPlugCD = dialog.FileName; lastPlugCD = lastPlugCD.Split('\\').Last().Split('.')[0]; this.danu = new DanuProductConfigurator(plugcd); this.loadDanuIntoGui(); }
public DanuProductConfigurator(ComponentDiagramBragi bragi) { components = new Dictionary <string, DanuComponent>(); constraints = new Dictionary <string, DanuConstraint>(); interfaces = new Dictionary <string, DanuInterfaceObject>(); foreach (Component component in bragi.Components) { AddComponent(component); } foreach (Association assoc in bragi.Associations) { AddConstraint(assoc); } foreach (Component component in bragi.Components) { foreach (Socket so in component.Sockets) { AddSocket(so); } } }