private void ThisAddIn_Startup(object sender, System.EventArgs e) { this.Application.WindowSelectionChange += new Word.ApplicationEvents4_WindowSelectionChangeEventHandler(Application_WindowSelectionChange); this.Application.DocumentChange += new Word.ApplicationEvents4_DocumentChangeEventHandler(Application_DocumentChange); this.Application.DocumentBeforeClose += new Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(Application_DocumentBeforeClose); log4net.Config.XmlConfigurator.Configure(); serializer = new Serializer(); if (!Deserialize()) { currentBatch = new TaxonList(); } if (currentBatch.Count > 0) { currentTaxon = currentBatch.Current; } else { currentTaxon = new Taxon(); currentBatch.Add(currentTaxon); } Globals.Ribbons.Ribbon.UpdateCount(); }
internal bool Deserialize() { try { string filename = CollectionData.BatchFile; currentBatch = serializer.DeSerializeObject(filename); return(true); } catch (DirectoryNotFoundException) { // MessageBox.Show("Deserialization error (directory not found). " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (FileNotFoundException) { // MessageBox.Show("Deserialization error (file not found). " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (IOException) { //MessageBox.Show("Deserialization error (error accessing file). " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (InvalidOperationException ex) { MessageBox.Show("Error loading batch file. This is most likely due to invalid characters in one or more fields." + Environment.NewLine + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (Exception) { throw; } }
public void SerializeObject(string filename, TaxonList objectToSerialize) { XmlWriterSettings ws = new XmlWriterSettings(); ws.NewLineHandling = NewLineHandling.Entitize; XmlSerializer serializer = new XmlSerializer(typeof(TaxonList)); using (XmlWriter wr = XmlWriter.Create(filename, ws)) { serializer.Serialize(wr, objectToSerialize); } }