Exemplo n.º 1
0
        /// <summary>
        /// Reads Json binary file and returns it as a string.
        /// If the file cannot be found, the method returns null.
        /// </summary>
        /// <param name="fullFilePath"></param>
        /// <returns></returns>
        public static string ReadJsonFromFile(string fullFilePath)
        {
            string result = null;

            try
            {
                JsonSerializer jsonSerializer = new JsonSerializer();

                if (File.Exists(fullFilePath))
                {
                    BsonReader bReader = new BsonReader(new BinaryReader(fullFilePath));
                    result = jsonSerializer.Deserialize <object>(bReader).ToString();
                    bReader.Close();
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logging.Exception(@"SyncProMethods \ ReadJsonFromFile - Failed to read file with exception - ", ex);
                return(null);
            }
            return(result);
        }
Exemplo n.º 2
0
        public void CloseInput()
        {
            MemoryStream ms     = new MemoryStream();
            BsonReader   reader = new BsonReader(ms);

            Assert.IsTrue(ms.CanRead);
            reader.Close();
            Assert.IsFalse(ms.CanRead);

            ms     = new MemoryStream();
            reader = new BsonReader(ms)
            {
                CloseInput = false
            };

            Assert.IsTrue(ms.CanRead);
            reader.Close();
            Assert.IsTrue(ms.CanRead);
        }