public T Get(int id) { T objectFromXml; // get file by id FileInfo file = this.directory.GetFiles($"{type.Name}{id}.xml").FirstOrDefault(); if (file == null) { return(null); } ; using (FileStream fs = new FileStream($"{this.type.Name}/{file.Name}", FileMode.Open)) { // deserialize object objectFromXml = (T)this.serializer.Deserialize(fs); if (this.objectHasPasswordProperty) { // encode password XmlMaker.EncodePasswordAndSetToObject(ref objectFromXml); } } return(objectFromXml); }
public IEnumerable <T> GetAll() { List <T> entities = new List <T>(); Directory.CreateDirectory($"{this.type.Name}"); // Get all xml files from our type directory FileInfo[] files = this.directory.GetFiles("*.xml"); if (files == null) { return(entities); } foreach (var file in files) { using (FileStream fs = new FileStream(file.FullName, FileMode.Open)) { // deserialize object T objFromXml = (T)this.serializer.Deserialize(fs); if (this.objectHasPasswordProperty) { XmlMaker.EncodePasswordAndSetToObject(ref objFromXml); } entities.Add(objFromXml); } } return(entities); }
public override void Execute(App app) { XmlMaker maker = new XmlMaker(); Translator translator = new Translator(); foreach (PdbSymbol symbol in app._pdb.Symbols) { maker.AddNamed(symbol.TranslateBy(translator), symbol.Name); } maker.Save(Console.OpenStandardOutput()); }
// Creates the Xml in the form I want it to and places it in the archive path private void GenXml_Click(object sender, EventArgs e) { Pathing.CreateBasicStructure(); string music_dir = MusicDirectory.Text; string[] file_exts = FileExtensions.Text.Split(','); string song_xml_path = ArchivePath.Text; List <String> songs = FileListGenerator.Generate(music_dir, file_exts); XmlMaker.CreateXmlFromSongs(songs, music_dir, song_xml_path); }
public void Add(T objToXml) { // Generate ID and add to object int id = XmlMaker.GenareteId(this.directory); typeof(T).GetProperty("Id").SetValue(objToXml, id); // decode password if (this.objectHasPasswordProperty) { XmlMaker.DecodePasswordAndSetToObject(ref objToXml); } // Create directory if not exist Directory.CreateDirectory($"{this.type.Name}"); // add object to xml using (FileStream fs = new FileStream($"{this.type.Name}/{this.type.Name}{id}.xml", FileMode.Create)) { this.serializer.Serialize(fs, objToXml); } }
public void Update(T objectToUpdate) { Thread.Sleep(200); using (FileStream fs = new FileStream($"{this.type.Name}/{this.type.Name}{typeof(T).GetProperty("Id").GetValue(objectToUpdate)}.xml", FileMode.Create)) { if (this.objectHasPasswordProperty) { // decode password XmlMaker.DecodePasswordAndSetToObject(ref objectToUpdate); } // serialize this.serializer.Serialize(fs, objectToUpdate); if (this.objectHasPasswordProperty) { // encode password XmlMaker.EncodePasswordAndSetToObject(ref objectToUpdate); } } }