Esempio n. 1
0
        private Response SetLogin(Request req)
        {
            if (req.TryDecrypt())
            {
                var eu        = new EntryUpdate();
                var reqMsg    = req.Message;
                var url       = reqMsg.GetString("url");
                var uuid      = reqMsg.GetString("uuid");
                var login     = reqMsg.GetString("login");
                var pw        = reqMsg.GetString("password");
                var submitUrl = reqMsg.GetString("submitUrl");

                if (string.IsNullOrEmpty(uuid))
                {
                    eu.CreateEntry(login, pw, url, submitUrl, null);
                }
                else
                {
                    eu.UpdateEntry(uuid, login, pw, url);
                }

                return(req.GetResponse());
            }
            return(new ErrorResponse(req, ErrorType.CannotDecryptMessage));
        }
Esempio n. 2
0
        private Response SetLogin(Request req)
        {
            if (req.TryDecrypt())
            {
                var eu        = new EntryUpdate();
                var reqMsg    = req.Message;
                var url       = reqMsg.GetString("url");
                var uuid      = reqMsg.GetString("uuid");
                var login     = reqMsg.GetString("login");
                var pw        = reqMsg.GetString("password");
                var submitUrl = reqMsg.GetString("submitUrl");
                var groupUuid = reqMsg.GetString("groupUuid");

                bool result;

                if (string.IsNullOrEmpty(uuid))
                {
                    result = eu.CreateEntry(login, pw, url, submitUrl, null, groupUuid);
                }
                else
                {
                    result = eu.UpdateEntry(uuid, login, pw, url);
                }

                var resp = req.GetResponse();

                resp.Message.Add("count", JValue.CreateNull());
                resp.Message.Add("entries", JValue.CreateNull());
                resp.Message.Add("error", result ? "success" : "error");

                return(resp);
            }
            return(new ErrorResponse(req, ErrorType.CannotDecryptMessage));
        }
            /// <summary>
            ///
            /// </summary>
            /// <param name="key"></param>
            /// <returns></returns>
            public EntryUpdate GetEntryUpdate(TKey key)
            {
                EntryUpdate entryUpdate;

                if (!this.EntryUpdates.TryGetValue(key, out entryUpdate))
                {
                    entryUpdate = new EntryUpdate(key);
                    entryUpdate.KeyExistedBeforeUpdate = _owner.ContainsKey(key);
                    this.EntryUpdates.Add(key, entryUpdate);
                }

                return(entryUpdate);
            }
Esempio n. 4
0
        public Entry Update(Journal journal, long entryId, EntryUpdate updateModel)
        {
            if (journal is null)
            {
                throw new ArgumentNullException(nameof(journal));
            }

            var entry = journal.Entries.Find(e => e.Id == entryId);

            if (entry is null)
            {
                throw new EntryNotFoundException($"Entry not found");
            }

            entry.Update(updateModel);
            return(entry);
        }
        private void UpdateEntry(LocalContent local, string checkSum, string mime, int size, List <string> labels)
        {
            var entryForUpdate = _entriesApi.GetEntryByPath(_bucketData.bucketId, local.GetPathInCloud);

            if (!checkSum.Equals(entryForUpdate.ContentHash))
            {
                var entryUpdate   = new EntryUpdate(checkSum, size, mime, labels);
                var entryResponse = _entriesApi.UpdateEntry(_bucketData.bucketId, entryForUpdate.Entryid.ToString(), entryUpdate);

                _windowElements.WriteLog($"Updated entry | path {entryResponse.Path} " + $"| hash {entryResponse.ContentHash} " + $"| size {entryResponse.ContentSize} " + $"| type {entryResponse.ContentType} ");

                Upload(local);
            }
            else
            {
                _windowElements.WriteLog($"Skip updating | file not changed {local.GetPathInCloud}");
            }
        }
Esempio n. 6
0
        public async Task UpdateEntry_JournalAndEntryFound_EntryUpdated_ReturnsEntry()
        {
            // Arrange
            var journal = await PrepDbWithJournal();

            var entryId = journal.Entries[0].Id;
            var update  = new EntryUpdate {
                Body = "Spiffy new body"
            };

            _service = GetJournalService();

            // Act
            var result = await _service.UpdateEntry(journal.Id, entryId, update);

            // Assert
            result.Should().NotBeNull();
            result.Body.Should().Be(update.Body);
        }
Esempio n. 7
0
        public void Update_EntryFound_EntryUpdated_ReturnsEntry()
        {
            // Arrange
            var updateModel = new EntryUpdate
            {
                Title = "Totally Different Title",
                Tags  = "some,new,tags",
                Body  = "And now for something completely different."
            };

            // Act
            var result = _service.Update(_journal, 2L, updateModel);

            // Assert
            result.Should().NotBeNull();
            result.Title.Should().Be(updateModel.Title);
            result.Tags.Should().Be(updateModel.Tags);
            result.Body.Should().Be(updateModel.Body);
            result.LastModified.Should().BeAfter(result.CreatedAt);
        }
Esempio n. 8
0
        public async Task <Entry> UpdateEntry(long journalId, long entryId, EntryUpdate updateModel)
        {
            if (updateModel is null)
            {
                throw new ArgumentNullException(nameof(updateModel));
            }

            using var unitOfWork = GetUnitOfWork();
            var journal = await unitOfWork
                          .Journals.Find(j => j.Id == journalId);

            if (journal is null)
            {
                throw new JournalNotFoundException($"Journal not found: {journalId}");
            }

            var entry = _entryService.Update(journal, entryId, updateModel);
            await unitOfWork.Complete();

            return(entry);
        }
Esempio n. 9
0
        public async Task <IActionResult> UpdateEntry(long journalId, long entryId, [FromBody] EntryUpdate update)
        {
            Entry entry;

            try
            {
                entry = await _journalService.UpdateEntry(journalId, entryId, update);
            }
            catch (ArgumentNullException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (JournalNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (EntryNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }

            return(NoContent());
        }