public static void PersistCatalogue(DeviceCatalogue catalogue, string filename) { lock (catalogue) { //try //{ // using (Stream stream = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) // { // try // { // if (catalogue.Catalogue.Count > 0) // { // IFormatter formatter = new BinaryFormatter(); // formatter.Serialize(stream, catalogue); // CNXLog.WarnFormat("Persisted Catalogue {0}.", catalogue.ToString()); // } // } // catch (Exception ee) // { // CNXLog.Error("PersistCatalogue", ee); // } // } //} //catch (Exception e) //{ // CNXLog.Error("PersistCatalogue", e); //} } }
public CANCommsServer(CANClient client, NMEAGPSClient.NMEAGPSClient gpsClient) { mCANClient = client; mGpsClient = gpsClient; // make a device catalogue mDeviceCatalogue = CreateCatalogue(TrackingService.VarPath + mCatalogueFilename); // start time for cataloge and status reporting mCatalogueTimer = new Timer(OnTimedEvent, null, CatalogueTime, CatalogueTime); // subscribe to gps events mGpsClient.RaiseGPSPositionChangedEvent += GPSPositionChangedEventHandler; // get the current gps status mGPSStatus = mGpsClient.Status; mGpsClient.RaiseGPSStatusChangedEvent += GPSStatusChangedEventHandler; // subscribe to CAN frame events mCANClient.RaiseFrameReceivedEvent += FrameReceivedEventHandler; }
private static DeviceCatalogue CreateCatalogue(string filename) { DeviceCatalogue catalogue = null; //try //{ // using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None)) // { // // load existing catalogue // try // { // IFormatter formatter = new BinaryFormatter(); // catalogue = (DeviceCatalogue)formatter.Deserialize(stream); // //System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(DeviceCatalogue), new Type[] { typeof(DeviceCatalogueInfo) }); // //catalogue = (DeviceCatalogue)x.Deserialize(stream); // catalogue.ResetStatus(); // CNXLog.WarnFormat("CreateCatalogue : from ({0}), {1}.", filename, catalogue.ToString()); // } // catch (FileNotFoundException) // { // CNXLog.WarnFormat("CreateCatalogue : Could not open catalogue ({0}), Creating a new one.", filename); // } // } //} //catch (Exception e) //{ // CNXLog.Error("CreateCatalogue", e); //} // may have a failure or no persitant catalogue if (catalogue == null) { catalogue = new DeviceCatalogue(); } return(catalogue); }