Beispiel #1
0
        /// <summary>
        /// Save the PlateTypes to file. Likely to have no practical use other than the initial
        /// population of the xml file!
        /// </summary>
        private void SavePlateTypes(string fileName)
        {
            // Double-check locking for thread safety
            if (null != _plateTypes)
            {
                lock (_plateTypesLock)
                {
                    if (null != _plateTypes)
                    {
                        // Attempt to write the list of plate types
                        try
                        {
                            OXML.PlateTypes  oXmlPlateTypes = new OXML.PlateTypes();
                            OXML.PlateType[] oXmlPlateType  = new OXML.PlateType[_plateTypes.Length];
                            oXmlPlateTypes.PlateType = oXmlPlateType;
                            int i = 0;
                            foreach (PlateType plateType in _plateTypes)
                            {
                                oXmlPlateType[i]            = new OXML.PlateType();
                                oXmlPlateType[i].ID         = plateType.ID;
                                oXmlPlateType[i].Name       = plateType.Name;
                                oXmlPlateType[i].NumColumns = plateType.NumColumns;
                                oXmlPlateType[i].NumRows    = plateType.NumRows;
                                oXmlPlateType[i].NumDrops   = plateType.NumDrops;
                                i++;
                            }

                            StreamWriter  writer     = new StreamWriter(fileName);
                            XmlSerializer serializer = new XmlSerializer(typeof(OXML.PlateTypes));
                            serializer.Serialize(writer, oXmlPlateTypes);
                            writer.Close();

                            // Log the action
                            ILog log = LogManager.GetLogger(this.GetType());
                            log.Info("Saved PlateTypes: " + this.ToString());
                        }
                        catch (Exception e)
                        {
                            // System.Diagnostics.Trace.TraceError("Failed to save PlateTypes file: " + e.Message);
                            throw new System.Exception("Failed to save PlateTypes file: " + e.Message, e);
                        }
                    }
                }
            }
            // End thread-safe block
        }
Beispiel #2
0
        /// <summary>
        /// Load the PlateTypes from file. If you want this to re-read the file you must set
        /// the private static IPlateType[] member _plateTypes back to null before calling
        /// this method again.
        /// </summary>
        private void LoadPlateTypes()
        {
            // Double-check locking for thread safety
            if (null == _plateTypes)
            {
                lock (_plateTypesLock)
                {
                    if (null == _plateTypes)
                    {
                        // Attempt to read the list of plate types
                        try
                        {
                            StreamReader    reader         = new StreamReader(PLATETYPES_FILE_PATH_NAME);
                            XmlSerializer   serializer     = new XmlSerializer(typeof(OXML.PlateTypes));
                            OXML.PlateTypes oXmlPlateTypes = (OXML.PlateTypes)serializer.Deserialize(reader);
                            reader.Close();

                            IPlateType[] tmpPlateTypes = new PlateType[oXmlPlateTypes.PlateType.Length];
                            int          i             = 0;
                            foreach (OXML.PlateType oXmlPlateType in oXmlPlateTypes.PlateType)
                            {
                                tmpPlateTypes[i] = new PlateType(oXmlPlateType.ID, oXmlPlateType.Name, oXmlPlateType.NumColumns, oXmlPlateType.NumRows, oXmlPlateType.NumDrops);
                                i++;
                            }
                            _plateTypes = tmpPlateTypes;

                            // Log the new configuration
                            ILog log = LogManager.GetLogger(this.GetType());
                            log.Info("Read PlateTypes: " + this.ToString());
                        }
                        catch (Exception e)
                        {
                            // System.Diagnostics.Trace.TraceError("Failed to read PlateTypes file: " + e.Message);
                            throw new System.Exception("Failed to read PlateTypes file: " + e.Message, e);
                        }
                    }
                }
            }
            // End thread-safe block
        }