public static bool WriteConfigurationFile(DatabaseConfigurationFileContents fileContents) { string contents = fileContents.Serialize(); if (contents == null) { return(false); } AnsBlockEncoder fileWriter; BitWriter writerOut; try { writerOut = new BitWriter(new FileStream(ConfigurationFileLocation, FileMode.Create, FileAccess.Write)); fileWriter = new AnsBlockEncoder(1024, writerOut); } catch (IOException) { return(false); } byte[] toWrite = Encoding.UTF8.GetBytes(contents); MemoryStream streamOut = new MemoryStream(toWrite); fileWriter.EncodeStream(streamOut, 8); writerOut.Close(); return(true); }
/** * <summary>Attempts to add the MechanicQuery specified by toAdd to the file MechanicQueryFilePath</summary> * <param name="toAdd">Mechanic Query to add</param> */ public override bool AddData(MechanicQuery toAdd) { DataContractJsonSerializer querySerializer = new DataContractJsonSerializer( typeof(List <MechanicQuery>) ); List <MechanicQuery> retList = LoadMechanicQueries(); retList.Add(toAdd); MemoryStream streamOut = new MemoryStream(); try { querySerializer.WriteObject(streamOut, retList); } catch (SerializationException) { return(false); } BitWriter writerOut = new BitWriter( new FileStream(MechanicQueryFilePath, FileMode.Create, FileAccess.Write) ); streamOut = new MemoryStream(streamOut.ToArray()); AnsBlockEncoder encoder = new AnsBlockEncoder(1048576, writerOut); encoder.EncodeStream(streamOut, 8); writerOut.Flush(); writerOut.Close(); return(true); }
/** * <summary>Attempts to add the KeywordTrainingExample specified by toAdd to the file KeywordDataFilePath</summary> * <param name="ex">KeywordTrainingExample to add</param> */ public bool AddKeywordExample(KeywordTrainingExample ex) { DataContractJsonSerializer querySerializer = new DataContractJsonSerializer( typeof(List <KeywordTrainingExample>) ); List <KeywordTrainingExample> retList = LoadKeywordTrainingExamples(); retList.Add(ex); MemoryStream streamOut = new MemoryStream(); try { querySerializer.WriteObject(streamOut, retList); } catch (SerializationException) { return(false); } BitWriter writerOut = new BitWriter( new FileStream(KeywordDataFilePath, FileMode.Create, FileAccess.Write) ); streamOut = new MemoryStream(streamOut.ToArray()); AnsBlockEncoder encoder = new AnsBlockEncoder(1048576, writerOut); encoder.EncodeStream(streamOut, 8); writerOut.Flush(); writerOut.Close(); return(true); }
public void Expect_Stream_RemainsOpen_AfterClose() { var testStream = new HelperMemoryStream(); var bitWriter = new BitWriter(testStream, Encoding.Default, true); bitWriter.Close(); Assert.IsFalse(testStream.IsClosed); }
public void Expect_Stream_IsClosed_AfterClose() { var testStream = new HelperMemoryStream(); var bitWriter = new BitWriter(testStream, Encoding.Default); bitWriter.Close(); Assert.IsTrue(testStream.IsClosed); }
private void WriteInitialFiles() { byte[] memoryStore = new byte[] { 91, 93 }; MemoryStream toWrite = new MemoryStream(memoryStore); BitWriter writerOut = new BitWriter( new FileStream(KeywordDataFilePath, FileMode.Create, FileAccess.Write) ); AnsBlockEncoder encoder = new AnsBlockEncoder(1048576, writerOut); encoder.EncodeStream(toWrite, 8); writerOut.Flush(); writerOut.Close(); toWrite = new MemoryStream(memoryStore); writerOut = new BitWriter( new FileStream(MechanicQueryFilePath, FileMode.Create, FileAccess.Write) ); encoder = new AnsBlockEncoder(1048576, writerOut); encoder.EncodeStream(toWrite, 8); writerOut.Flush(); writerOut.Close(); }