Skip to content

Commit

Permalink
- support cross references
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Mar 29, 2019
1 parent 0969e93 commit 23606cf
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 18 deletions.
31 changes: 18 additions & 13 deletions CombineCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,34 @@ static void Main(string[] args)
Console.WriteLine(" org : " + creator.Organization);
Console.WriteLine();
}
Console.WriteLine();


}
foreach (var xref in entry.CrossReferences)
Console.WriteLine(" xref : " + xref);

//var archive =
// CombineArchive.FromFile(@"C:\Users\fbergmann\Desktop\isola_oscillations_sed.sed.omex");

//Console.WriteLine("Num SEDML files: {0}", archive.GetNumFilesWithFormat("SEDML"));
//Console.WriteLine("Num SBML files: {0}", archive.GetNumFilesWithFormat("sbml"));
//Console.WriteLine("Num SBML files: {0}", archive.GetNumFilesWithFormat("sbml"));

//archive.SaveTo(@"C:\Users\fbergmann\Desktop\isola.omex");
}

//var archive =
// CombineArchive.FromFile(@"C:\Users\fbergmann\Desktop\isola_oscillations_sed.sed.omex");

//Console.WriteLine("Num SEDML files: {0}", archive.GetNumFilesWithFormat("SEDML"));
//Console.WriteLine("Num SBML files: {0}", archive.GetNumFilesWithFormat("sbml"));
//Console.WriteLine("Num SBML files: {0}", archive.GetNumFilesWithFormat("sbml"));

//var omex = CombineArchive.FromFile(@"C:\Users\fbergmann\Desktop\Boris.omex");
//archive.SaveTo(@"C:\Users\fbergmann\Desktop\isola.omex");

//if (omex.HasEntriesWithFormat("pdf"))
// omex.GetEntriesWithFormat("PDF").First().OpenLocation();


//Console.ReadKey();
}
//var omex = CombineArchive.FromFile(@"C:\Users\fbergmann\Desktop\Boris.omex");

//if (omex.HasEntriesWithFormat("pdf"))
// omex.GetEntriesWithFormat("PDF").First().OpenLocation();


//Console.ReadKey();
}
}
}

19 changes: 17 additions & 2 deletions FormsCombineArchive/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ private void AddEntry(Entry entry)
ToolTipText = GetToolTip(entry)
};

foreach (var xref in entry.CrossReferences)
{
var xentry = Archive[xref];
if (xentry == null)
continue;

var xitem = new ListViewItem.ListViewSubItem
{
Text = GetNameForLocation(xref),
Tag = xentry,

};
item.SubItems.Add(xitem);
}

lstEntries.Items.Add(item);
}
private void UpdateUI()
Expand Down Expand Up @@ -125,7 +140,7 @@ public void OpenFile(string fileName)
}
catch (Exception ex)
{
MessageBox.Show("An error occured while opening the file. The exception was: " + Environment.NewLine + Environment.NewLine + ex.Message, "Could not open archive", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("An error occurred while opening the file. The exception was: " + Environment.NewLine + Environment.NewLine + ex.Message, "Could not open archive", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Expand Down Expand Up @@ -160,7 +175,7 @@ public void SaveFile(string fileName)
}
catch (Exception ex)
{
MessageBox.Show("An error occured while saving the file. Please ensure that all files in this archive are closed, so they can be read. The exception was: " + Environment.NewLine + Environment.NewLine + ex.Message, "Could not save archive", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("An error occurred while saving the file. Please ensure that all files in this archive are closed, so they can be read. The exception was: " + Environment.NewLine + Environment.NewLine + ex.Message, "Could not save archive", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Expand Down
35 changes: 32 additions & 3 deletions LibCombine/CombineArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ public Entry AddEntry(string fileName, string format, OmexDescription descriptio

}

public Entry this[int index]
{
get { return Entries[index]; }
}

public Entry this[string location]
{
get { return Entries.Where(e => e.Location == location).FirstOrDefault(); }
}


public List<Entry> GetEntriesWithFormat(string format)
{
UpdateRefs();
Expand Down Expand Up @@ -211,6 +222,14 @@ private void ParseManifest(string fileName)
entry.IsMaster = true;
MainEntry = entry;
}

var xrefs = element.GetElementsByTagName("crossRef", currentNs);
foreach (var node in xrefs)
{
var xref = ((XmlElement)node).GetAttribute("location");
entry.CrossReferences.Add(xref);
}

Entries.Add(entry);

}
Expand Down Expand Up @@ -364,8 +383,7 @@ public string ToManifest()
var root = new XElement(ns + "omexManifest");
foreach (var entry in Entries)
{
root.Add(
new XElement(ns + "content",
var el = new XElement(ns + "content",
new XAttribute("location",
entry.Location
.Replace(BaseDir, "./")
Expand All @@ -375,7 +393,18 @@ public string ToManifest()
.Replace("./manifest.xml", ".")
),
new XAttribute("format", entry.Format),
new XAttribute("master", entry == MainEntry || entry.IsMaster ? "true" : "false")));
new XAttribute("master", entry == MainEntry || entry.IsMaster ? "true" : "false"));
foreach (var xref in entry.CrossReferences)
{
el.Add(new XElement(ns + "crossRef"),
new XAttribute("location", xref
.Replace(BaseDir, "./")
.Replace("././", "./")
.Replace("./\\", "./")
.Replace(".//", "./")
));
}
root.Add(el);
}
var srcTree = new XDocument(root);
return
Expand Down
12 changes: 12 additions & 0 deletions LibCombine/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ public static Dictionary<string, string> KnownFormats
/// </summary>
public bool IsMaster { get; set; }


/// <summary>
/// A list of cross references to other entries this entry is related too. It is optional
/// </summary>
public List<string> CrossReferences { get; set; }

public Entry()
{
CrossReferences = new List<string> ();
}

/// <summary>
/// Resolves the local file name of this entry
/// </summary>
Expand Down Expand Up @@ -332,6 +343,7 @@ public static string GuessFormat(string fileName)
if (snippet.Contains("<sbml")) return LookupFormat("sbml");
if (snippet.Contains("<sedML")) return LookupFormat("sedml");
if (snippet.Contains("<cell")) return LookupFormat("cellml");
if (snippet.Contains("<COPASI ")) return LookupFormat("copasi");
}
}
string extension = ext.Replace(".", "");
Expand Down

0 comments on commit 23606cf

Please sign in to comment.