Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Encodes the List of PreviousUserRequest objects, and stores them in this user's RequestHistory
        /// </summary>
        /// <param name="requestsIn">List of <see cref="PreviousUserRequest"/> objects that should become the current user's RequestHistory</param>
        public void EncodeRequests(List <PreviousUserRequest> requestsIn)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List <PreviousUserRequest>));
            MemoryStream streamOut = new MemoryStream();

            serializer.WriteObject(streamOut, requestsIn);
            MemoryStream streamIn = new MemoryStream(streamOut.ToArray());

            streamOut = new MemoryStream();
            EncodingUtilities.BitWriter writer  = new EncodingUtilities.BitWriter(streamOut);
            AnsBlockEncoder             encoder = new AnsBlockEncoder(1024, writer);

            encoder.EncodeStream(streamIn, 8);
            writer.Flush();
            RequestHistory = streamOut.ToArray();
        }
        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();
        }