/// <summary> /// Gets an annotation from the client annotation database and the where condition specified /// </summary> /// <returns>Annotation with GUID id and additional where condition</returns> public static IAnnotation getAnnotation(Guid id, SQLiteConnection database, string whereCondition) { IAnnotation annotationToReturn = null; string query = String.Format("SELECT id, type, time, text, photo_path, server_id, author, question_id, author_id, saved FROM {0} WHERE (id='{1}')", SensorShareConfig.AnnotationTableName, id); if (whereCondition != String.Empty) { query = String.Format("{0} AND ({1})", query, whereCondition); } Debug.WriteLine(query); using (SQLiteCommand command = new SQLiteCommand(query, database)) { if (command.Connection.State != ConnectionState.Open) { command.Connection.Open(); } SQLiteDataReader dataReader = command.ExecuteReader(); if (dataReader.Read()) { Object[] dataRow = new Object[dataReader.FieldCount]; dataReader.GetValues(dataRow); Guid author_id = (Guid)dataRow[8]; AnnotationType type = (AnnotationType)dataReader.GetInt32(1); if ((Boolean)dataRow[9]) { switch (type) { case AnnotationType.Image: Bitmap image = new Bitmap(1, 1); try { image = new Bitmap((String)dataRow[4]); } catch (FileNotFoundException ex) { Debug.WriteLine(String.Format("File not found: {0}", (String)dataRow[4])); } using (MemoryStream ms = new MemoryStream()) { image.Save(ms, ImageFormat.Jpeg); ImageAnnotation iAnnotation = new ImageAnnotation( (Guid)dataRow[0], (Guid)dataRow[5], author_id, (DateTime)dataRow[2], (String)dataRow[6], (String)dataRow[3], ms.ToArray()); annotationToReturn = iAnnotation; } break; case AnnotationType.Text: TextAnnotation tAnnotation = new TextAnnotation( (Guid)dataRow[0], (Guid)dataRow[5], author_id, (DateTime)dataRow[2], (String)dataRow[6], (String)dataRow[3]); annotationToReturn = tAnnotation; break; case AnnotationType.QuestionAndAnswer: QuestionMessage question = null; if ((bool)dataRow[9]) { question = getQuestionMessage(dataReader.GetGuid(7), database); } if (question != null) { QuestionAndAnswerAnnotation qaAnnotation = new QuestionAndAnswerAnnotation( question, (Guid)dataRow[0], author_id, (String)dataRow[6], (String)dataRow[3]); annotationToReturn = qaAnnotation; } else { // Can't find the question so return an annotationbase annotationToReturn = new AnnotationBase( (Guid)dataRow[0], (Guid)dataRow[5], author_id, (DateTime)dataRow[2], (String)dataRow[6]); } break; //case AnnotationType.Base: default: annotationToReturn = new AnnotationBase( (Guid)dataRow[0], (Guid)dataRow[5], author_id, (DateTime)dataRow[2], (String)dataRow[6]); break; } } else { annotationToReturn = new AnnotationBase( (Guid)dataRow[0], (Guid)dataRow[5], author_id, (DateTime)dataRow[2], (String)dataRow[6], type); } } dataReader.Close(); } return annotationToReturn; }