// Deserializes the class from the config file. public bool Load() { bool loaded = false; XmlSerializer mySerializer = null; FileStream myFileStream = null; try { // Create a Type array. Type [] extraTypes = new Type[3]; extraTypes[0] = typeof(NPoint); extraTypes[1] = typeof(TeachPoint); extraTypes[2] = typeof(TeachPointHistory); // Create the XmlSerializer instance. mySerializer = new XmlSerializer(typeof(TeachPointStore), extraTypes); FileInfo fi = new FileInfo(_fileName); // If the config file exists, open it. if (fi.Exists) { // Reading a file requires a FileStream. myFileStream = fi.OpenRead(); // Create a new instance of the PersistentXML by deserializing the config file. TeachPointStore pointStoreCopy = (TeachPointStore)mySerializer.Deserialize(myFileStream); foreach (TeachPoint tpoint in pointStoreCopy.Points) { TeachPoint localTeachPoint = GetPoint(tpoint.Name); if (localTeachPoint != null) { localTeachPoint.ShallowClone(tpoint); } } DBUpdate(); if (PointStoreChanged != null) { PointStoreChanged(); } loaded = true; } } catch (Exception ex) { Console.WriteLine("Failed to deserialize. Reason: " + ex.Message); } finally { // If the FileStream is open, close it. if (myFileStream != null) { myFileStream.Close(); } } return(loaded); }
// Methods ------------------------------------------------------------- public void AssignPointStore(TeachPointStore pointStore) { this.pointStore = pointStore; gridTeachPoints.DataSource = pointStore.TeachPointTable; gridTeachPoints.Refresh(); pointStore.PointStoreChanged += new TeachPointStore.PointStoreContentChangedEventHandler(pointStore_OnUpdate); }
public void AssignPointStore(TeachPointStore pointStore) { ucTeachPointGrid1.AssignPointStore(pointStore); ucTeachPointGrid1.AttachDisplays(ucTeachPointHistory1, ucTeachPointHistoryChart1, ucTeachPointStat1); }