예제 #1
0
        // webservice method: HTTP GET request
        public object Get(GetNotesRequest request)
        {
            try {
                using (var note_repo = GetNotes ()) {
                    var notes = GetStoredNotes (note_repo);

                    // check if we need to include the note body
                    bool include_note_body = true;
                    string include_notes = Request.GetParam ("include_notes");
                    if (!string.IsNullOrEmpty (include_notes) && !bool.TryParse (include_notes, out include_note_body))
                        throw new InvalidRequestDtoException () {ErrorMessage = "unable to parse parameter include_notes to boolean"};

                    // check if we transform the note content to HTML
                    bool notes_as_html = false;
                    string to_html = Request.GetParam ("notes_as_html");
                    if (!string.IsNullOrEmpty (to_html) && !bool.TryParse (to_html, out notes_as_html))
                        throw new InvalidRequestDtoException () {ErrorMessage = "unable to parse parameter notes_as_html to boolean"};

                    // if since is given, we might only need to return a subset of notes
                    string since = Request.GetParam ("since");
                    long since_revision = -1;
                    if (!string.IsNullOrEmpty (since) && !long.TryParse (since, out since_revision))
                        throw new InvalidRequestDtoException () {ErrorMessage = "unable to parse parameter since to long"};

                    // select only those notes that changed since last sync
                    // which means, only those notes that have a HIGHER revision as "since"
                    var changed_notes = notes.Notes.Where (n => {
                        if (!note_repo.Manifest.NoteRevisions.Keys.Contains (n.Guid))
                            // the note is in the storage, but not in the manifest
                            // this might happen when low-level adding nodes to the storage
                            return true;
                        else if (note_repo.Manifest.NoteRevisions [n.Guid] > since_revision)
                                return true;
                        else
                            return false;
                    });

                    if (include_note_body) {
                        notes.Notes = changed_notes.ToList ();

                        if (notes_as_html) {
                            notes.Notes = notes.Notes.Select (n => { n.Text = n.Text.ToHtml (); return n; }).ToList ();
                        }
                    } else {
                        // empty the note Text
                        notes.Notes = changed_notes.Select (n => {
                            n.Text = "";
                            return n; }).ToList ();
                    }

                    return notes;
                }
            } catch (Exception e) {
                Logger.DebugFormat ("CAUGHT EXCEPTION: {0} {1}", e.Message, e.StackTrace);
                throw;
            }
        }
예제 #2
0
        public IHttpActionResult GetNotes(GetNotesRequest notesRequest)
        {
            List <Note> noteList = new List <Note>();

            try
            {
                noteList = Database.GetNotes(notesRequest.projectID, notesRequest.attributeIDs);
            }
            catch (Exception)
            {
                return(BadRequest());
            }

            return(Ok(noteList));
        }
예제 #3
0
        public void GetNotesUseCaseEqualTest()
        {
            GetNotesRequest getNotesRequest = new GetNotesRequest(idAccount);

            IUnitOfWorkFactory unitOfWorkFactory = new UnitOfWorkFactory();
            IUnitOfWork        unitOfWork        = unitOfWorkFactory.CreateUnitOfWork();

            unitOfWork.GetNotesFromDatabase();
            IActivityFactory activityFactory  = new ActivityFactory(unitOfWork, new ValidationRuleFactory());
            IUseCaseFactory  useCaseFactory   = new UseCaseFactory(activityFactory);
            GetNotesResponse getNotesResponse = useCaseFactory.CreateGetNotesUseCase().Execute(getNotesRequest);

            Assert.AreEqual(getNotesResponse.Notes[0].Topic, this.topic);
            Assert.AreEqual(getNotesResponse.Notes[0].Text, this.text);
            Assert.AreEqual(getNotesResponse.Notes[0].Date, this.date);
            Assert.AreEqual(getNotesResponse.Notes[0].Image, this.image);
        }
        /// <summary>Handles a request</summary>
        /// <param name="request">The request</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Response from the request</returns>
        public async Task <Result <IReadOnlyCollection <NoteDto> > > Handle(GetNotesRequest request, CancellationToken cancellationToken)
        {
            if (request.Page == 0)
            {
                request.Page = 1;
            }

            var result = await _noteRepository.GetAsync(request.Page, request.PageSize);

            if (result.IsFailed)
            {
                return(result.ToResult());
            }

            IReadOnlyCollection <NoteDto> notes = result.ValueOrDefault.Select(note => this._mapper.Map <NoteDto>(note)).ToList();

            return(notes.ToResult());
        }
예제 #5
0
        // webservice method: HTTP GET request
        public object Get(GetNotesRequest request)
        {
            try {
                using (var note_repo = GetNotes (request.Username)) {
                    var notes = GetStoredNotes (note_repo);

                    // check if we need to include the note body
                    bool include_note_body = true;
                    string include_notes = Request.GetParam ("include_notes");
                    if (!string.IsNullOrEmpty (include_notes) && !bool.TryParse (include_notes, out include_note_body))
                        throw new Exception ("unable to parse parameter include_notes to boolean");

                    // if since is given, we might only need to return a subset of notes
                    string since = Request.GetParam ("since");
                    long since_revision = -1;
                    if (!string.IsNullOrEmpty (since) && !long.TryParse (since, out since_revision))
                        throw new Exception ("unable to parse parameter since to long");

                    // select only those notes that changed since last sync
                    // which means, only those notes that have a HIGHER revision as "since"
                    var changed_notes = notes.Notes.Where (n => {
                        if (note_repo.Manifest.NoteRevisions.Keys.Contains (n.Guid)) {
                            if (note_repo.Manifest.NoteRevisions [n.Guid] > since_revision)
                                return true;
                        }
                        return false;
                    });

                    if (include_note_body) {
                        notes.Notes = changed_notes.ToList ();
                    } else {
                        // empty the note Text
                        notes.Notes = changed_notes.Select (n => {
                            n.Text = "";
                            return n; }).ToList ();
                    }

                    return notes;
                }
            } catch (Exception e) {
                Logger.DebugFormat ("CAUGHT EXCEPTION: {0} {1}", e.Message, e.StackTrace);
                throw;
            }
        }
예제 #6
0
        public async Task <OperationStatusInfo> ShowNotes(int idAccount)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);
                GetNotesRequest getNotesRequest = new GetNotesRequest(idAccount);

                try
                {
                    GetNotesResponse getNotesResponse = hubController.UseCaseFactory.CreateGetNotesUseCase().Execute(getNotesRequest);
                    List <NotesDTO> notesDTO = hubController.TransformNotes(getNotesResponse.Notes);
                    operationStatusInfo.AttachedObject = notesDTO;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
예제 #7
0
 public override Task <GetNotesResponse> GetNotes(GetNotesRequest request, ServerCallContext context)
 => _getNotesHandler.Handle(request, context).AsTask();