Inheritance: INCldrData
        /// <summary>
        /// Loads loads the raw data from the NCldr data file and returns an NCldrData object
        /// </summary>
        /// <returns>An INCldrData object from the NCldr data file</returns>
        public INCldrData Load()
        {
            if (!this.Exists())
            {
                return(null);
            }

            NCldrData  ncldrData  = null;
            FileStream fileStream = new FileStream(this.NCldrDataFilename, FileMode.Open);

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(NCldrData));
                ncldrData = (NCldrData)serializer.Deserialize(fileStream);
            }
            catch (SerializationException exception)
            {
                Console.WriteLine("Failed to deserialize. Reason: " + exception.Message);
                throw;
            }
            finally
            {
                fileStream.Close();
            }

            return(ncldrData);
        }
Example #2
0
        /// <summary>
        /// Loads loads the raw data from the NCldr data file and returns an NCldrData object
        /// </summary>
        /// <returns>An INCldrData object from the NCldr data file</returns>
        public INCldrData Load()
        {
            if (!this.Exists())
            {
                return(null);
            }

            NCldrData ncldrData = null;

            using (FileStream stream = File.OpenRead(this.NCldrDataFilename))
            {
                try
                {
                    BsonReader     bsonReader = new BsonReader(stream);
                    JsonSerializer serializer = new JsonSerializer();
                    ncldrData = serializer.Deserialize <NCldrData>(bsonReader);
                }
                catch (SerializationException exception)
                {
                    Console.WriteLine("Failed to deserialize. Reason: " + exception.Message);
                    throw;
                }
            }

            return(ncldrData);
        }
Example #3
0
        /// <summary>
        /// Loads loads the raw data from the NCldr data file and returns an NCldrData object
        /// </summary>
        /// <returns>An INCldrData object from the NCldr data file</returns>
        public INCldrData Load()
        {
#if WINDOWS_PHONE
            throw new NotImplementedException("NCldrBinaryFileDataSource is not supported on Windows Phone. Use NCldrJsonFileDataSource instead.");
#else
            if (!this.Exists())
            {
                return(null);
            }

            NCldrData  ncldrData  = null;
            FileStream fileStream = new FileStream(this.NCldrDataFilename, FileMode.Open);
            try
            {
                BinaryFormatter formatter = new BinaryFormatter();
                ncldrData = (NCldrData)formatter.Deserialize(fileStream);
            }
            catch (SerializationException exception)
            {
                Console.WriteLine("Failed to deserialize. Reason: " + exception.Message);
                throw;
            }
            finally
            {
                fileStream.Close();
            }

            return(ncldrData);
#endif
        }
        /// <summary>
        /// Loads loads the raw data from the NCldr data file and returns an NCldrData object
        /// </summary>
        /// <returns>An INCldrData object from the NCldr data file</returns>
        public INCldrData Load()
        {
            if (!this.Exists())
            {
                return(null);
            }

            NCldrData ncldrData = null;
            string    data      = File.ReadAllText(this.NCldrDataFilename);

            try
            {
                ncldrData = JsonConvert.DeserializeObject <NCldrData>(data);
            }
            catch (SerializationException exception)
            {
                Console.WriteLine("Failed to deserialize. Reason: " + exception.Message);
                throw;
            }

            return(ncldrData);
        }