Skip to content

Instantly share code, notes, and snippets.

@moaschterle
Last active December 14, 2015 14:49
Show Gist options
  • Save moaschterle/5103414 to your computer and use it in GitHub Desktop.
Save moaschterle/5103414 to your computer and use it in GitHub Desktop.
public static void GetImagefromUUID(string theuuid)
{
string myuuid = "cf6a0e34-0301-4f61-999b-f16295c8f1dc";
var doc = XDocument.Load("XMLInput/media.smg.images.data.pois.ort.Andrian-0.xml");
var parser = new NodeParser();
var elements = parser.GetNodes(doc);
foreach (var item in elements.Where(n => n.UUID == myuuid))
{
foreach (var node in item.SubNodes.Where(n => n.Name == "original"))
{
dynamic dnode = node;
string filename = dnode.fileName;
string extension = dnode.extension;
int size = int.Parse(dnode.size);
string binary = dnode["jcr:data"];
try
{
FileStream fs = File.Create(filename + "." + extension, 2048, FileOptions.None);
BinaryWriter bw = new BinaryWriter(fs);
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(binary);
bw.Write(ba);
bw.Close();
fs.Close();
//oder
using (FileStream fs = File.Create(filename + "." + extension, 2048, FileOptions.None))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, Encoding.Unicode.GetBytes(binary));
}
}
catch (Exception e)
{
Console.Write(e.Message);
Console.ReadKey(true);
}
}
}
}
static object GetValue(XElement element)
{
var type = element.Attribute(Namespaces.sv + "type").Value;
var value = element.Element(Namespaces.sv + "value");
switch (type)
{
case "String":
case "Name":
return GetString(value);
case "Boolean":
return bool.Parse(value.Value);
case "Date":
return DateTime.Parse(value.Value);
case "Binary":
return GetString(value);
case "Long":
return long.Parse(value.Value);
default:
throw new InvalidOperationException("The type " + type + " is not supported at the moment.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment