/** * <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); }
// override object.Equals public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } // TODO: write your implementation of Equals() here KeywordTrainingExample other = obj as KeywordTrainingExample; if (other.KeywordPairs.Count != KeywordPairs.Count) { return(false); } for (int i = 0; i < KeywordPairs.Count; i++) { if (!KeywordPairs[i].Equals(other.KeywordPairs[i])) { return(false); } } return(other.IsCorrect == this.IsCorrect); }