예제 #1
0
        // PUT odata/Node(5)
        public IHttpActionResult Put([FromODataUri] Guid key, T node)
        {
            //HTTP PUT method specifies that an update operation MUST be carried out by using replace semantics.
            if (!ModelState.IsValid || node == null)
            {
                return(BadRequest(ModelState));
            }

            if (key != node.Id)
            {
                return(BadRequest());
            }

            T temp = Storage.Get().Where(x => x.Id == key).SingleOrDefault();

            if (temp != null)
            {
                Storage.Remove(temp);
                Storage.Add(node);
            }

            if (!NodeExists(key))
            {
                return(NotFound());
            }

            return(Updated(node));
        }
예제 #2
0
        public void Add_value()
        {
            // act
            var result = _sut.Add(_url);

            // assert
            Assert.Equal(_shortName, result);
        }
예제 #3
0
        public void Init(EShapeType type, int thickness, PaintColor color)
        {
            _newshape           = _shape.CreateShape(type);
            _newshape.Thickness = thickness;
            _newshape.Color     = color;

            _storage.Add(_newshape);
        }
예제 #4
0
        public void Add_ReturnsFalse_WhenKeyAlreadyExists()
        {
            // Arrange
            const string key     = "key";
            IStorage     storage = CreateStorage();

            // Act
            storage.Add(key, DateTime.MaxValue, ByteString.Empty);
            bool added = storage.Add(key, DateTime.MaxValue, ByteString.Empty);

            // Assert
            Assert.False(added);
        }
예제 #5
0
        public void Dispose_ClearsTheData()
        {
            // Arrange
            IStorage storage = CreateStorage();

            storage.Add("first", DateTime.MaxValue, ByteString.Empty);
            storage.Add("second", DateTime.MaxValue, ByteString.Empty);

            // Act
            storage.Dispose();

            // Assert
            Assert.Equal(storage.Count, 0);
            Assert.Equal(storage.ExpiringCount, 0);
        }
 public void Handle(GeneralQueryResult message)
 {
     if (message.Dtos.Any())
     {
         IStorage <IndexProgress> storage = _profile.Get <IndexProgress>(typeof(IndexProgress).Name);
         storage.Clear();
         storage.Add(new IndexProgress
         {
             LastGeneralId = message.Dtos[0].ID.GetValueOrDefault(),
         });
         Send(new CommentQuery
         {
             Hql =
                 string.Format(
                     "select c from Comment c join c.General g left join g.ParentProject p where g.EntityType IN ({0}) and (p is null or p.DeleteDate is null) order by c desc skip 0 take 1",
                     _entityTypeProvider.QueryableEntityTypesIdSqlString),
             IgnoreMessageSizeOverrunFailure = true,
             Params = new object[] { }
         });
     }
     else
     {
         _documentIndexProvider.ShutdownDocumentIndexes(_pluginContext.AccountName, new DocumentIndexShutdownSetup(forceShutdown: true, cleanStorage: true));
         _log.Info("Finished rebuilding indexes");
         MarkAsComplete();
     }
 }
예제 #7
0
        public IActionResult Post(
            string noteText,
            [FromHeader(Name = "X-Platform")] string platform,
            [FromServices] ILoggerFactory loggerFactory)
        {
            noteText = noteText?.Trim();
            if (string.IsNullOrEmpty(noteText))
            {
                // return 400
                return(BadRequest("Can't create empty note"));
            }

            var note = new Note
            {
                Header = noteText.Substring(0, Math.Min(noteText.Length, 32)).Trim(),
                Text   = noteText
            };
            var id = _notes.Add(note);

            var logger = loggerFactory.CreateLogger <NotesControllerV2>();

            logger.LogInformation($"Note {id} was created from {platform}");

            // return 201
            return(CreatedAtAction(nameof(GetById), new { id }, id));
        }
예제 #8
0
        public async Task HandleAsync(RecordCreated @event)
        {
            Console.WriteLine($"Record: '{@event.Key}' was created.");
            _storage.Add(@event.Key);

            await Task.CompletedTask;
        }
 public void Handle(GeneralQueryResult message)
 {
     if (message.Dtos.Any())
     {
         IStorage <IndexProgress> storage = _profileReadonly.Get <IndexProgress>(typeof(IndexProgress).Name);
         storage.Clear();
         storage.Add(new IndexProgress
         {
             LastGeneralId = message.Dtos[0].ID.GetValueOrDefault(),
         });
         Send(new CommentQuery
         {
             Hql =
                 string.Format(
                     "select c from Comment c join c.General g left join g.ParentProject p where g.EntityType IN ({0}) and (p is null or p.DeleteDate is null) order by c desc skip 0 take 1",
                     _entityTypeProvider.QueryableEntityTypesIdSqlString),
             IgnoreMessageSizeOverrunFailure = true,
             Params = new object[] {}
         });
     }
     else
     {
         MarkAsComplete();
     }
 }
        public IHttpActionResult Add(Models.BoardGame game)
        {
            game.UserName = User.GetCurrentUsernameOrThrow();
            var result = _storage.Add(game);

            return(Ok(result));
        }
예제 #11
0
        private async void Process()
        {
            var frozenQueue = _fileQueue;

            _fileQueue = new ConcurrentDictionary <string, FileSystemEventArgs>();

            foreach (var key in frozenQueue.Keys)
            {
                var eventArgs = frozenQueue[key];
                try
                {
                    if (File.Exists(key))
                    {
                        if (eventArgs == null || eventArgs.ChangeType != WatcherChangeTypes.Renamed)
                        {
                            _storage.Add(_provider.Provide(key), key);
                        }
                        else
                        {
                            var renamedEventArgs = eventArgs as RenamedEventArgs;
                            if (renamedEventArgs != null)
                            {
                                if (frozenQueue.ContainsKey(renamedEventArgs.OldFullPath))
                                {
                                    _storage.Delete(renamedEventArgs.OldFullPath);
                                    _storage.Add(_provider.Provide(key), renamedEventArgs.FullPath);
                                }
                                else
                                {
                                    _storage.Move(renamedEventArgs.OldFullPath, renamedEventArgs.FullPath);
                                }
                            }
                        }
                    }
                    else
                    {
                        Log.TraceEvent(TraceEventType.Information, 103, "File {0} not found for processing", key);
                    }
                }
                catch (Exception)
                {
                    Log.TraceEvent(TraceEventType.Information, 102, "{0} failed to process, re-adding", key);
                    _fileQueue.TryAdd(key, eventArgs);
                }
            }
        }
예제 #12
0
        public override InsertResponse Reply(InsertRequest request, IStorage storage)
        {
            bool added = storage.Add(request.Key, request.Expiry?.ToDateTime(), request.Data);

            return(new InsertResponse {
                Added = added
            });
        }
예제 #13
0
        public async Task Add_OverridesValue_WhenKeyWasExpired()
        {
            // Arrange
            const string key        = "key";
            IStorage     storage    = CreateStorage();
            TimeSpan     expiryTime = TimeSpan.FromSeconds(1);
            DateTime     now        = DateTime.UtcNow;

            // Act
            storage.Add(key, now + expiryTime, ByteString.Empty);
            await Task.Delay(TimeSpan.FromTicks(expiryTime.Ticks * 2)); // multiply by 2, mono behaves differently... Race condition?

            bool added = storage.Add(key, DateTime.MaxValue, ByteString.Empty);

            // Assert
            Assert.True(added);
        }
예제 #14
0
        public async Task HandleAsync(RecordCreated @event)
        {
            Console.WriteLine($"Record with key {@event.Key} has been created !");

            _storage.Add(@event.Key);

            await Task.CompletedTask;
        }
예제 #15
0
 public void Add(CarWorkshop item)
 {
     if (workshops.ExistsKey(item.Id) ||
         workshops.CountByPropertValue(i => i.Name == item.Name) > 0)
     {
         return;
     }
     workshops.Add(item);
 }
        public async Task <Unit> Handle(InsertClientCommand request, CancellationToken cancellationToken)
        {
            var client = new Client(request.Name);
            await _clientStorage.Add(client);

            await _eventBus.Publish(client.PendingEvents.ToArray());

            return(Unit.Value);
        }
예제 #17
0
        public IActionResult PutSaleModel([FromRoute] Guid id, [FromBody] SaleModel saleModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != saleModel.Id)
            {
                return(BadRequest());
            }

            _storage.Remove(id);
            _storage.Add(saleModel);
            _storage.Save();

            return(NoContent());
        }
예제 #18
0
        public void TryRemove_RemovesEntryFromStorage()
        {
            // Arrange
            const string firstKey  = "key1";
            const string secondKey = "key2";

            IStorage storage = CreateStorage();

            storage.Add(firstKey, null, ByteString.Empty);
            storage.Add(secondKey, null, ByteString.Empty);

            // Act
            bool deleted = storage.TryRemove(firstKey);

            // Assert
            Assert.True(deleted);
            Assert.Equal(storage.Count, 1);
        }
예제 #19
0
        public virtual IActionResult Post([FromBody] T payload)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = _Storage.Add(payload);

            return(Ok(payload));
        }
        public async Task Register(ApplicationEntity applicationEntity)
        {
            applicationEntity.IsRegistered = true;
            applicationEntity.Registered   = DateTime.Now;
            applicationEntity.IsOnline     = true;
            applicationEntity.IsHealthy    = true;
            await _storage.Add(_cosmosSettings.DatabaseName, _cosmosSettings.CollectionName, applicationEntity);

            await _storage.Update(_cosmosSettings.DatabaseName, _cosmosSettings.CollectionName, applicationEntity.Name, applicationEntity);
        }
예제 #21
0
 public void Add(User item)
 {
     if (users.ExistsKey(item.Id) ||
         users.CountByPropertValue(i => i.UserName == item.UserName) > 0 ||
         users.CountByPropertValue(i => i.Email == item.Email) > 0)
     {
         return;
     }
     users.Add(item);
 }
예제 #22
0
        public IActionResult Post([FromBody] LabData value)
        {
            var validationResult = value.Validate();

            if (!validationResult.IsValid) return BadRequest(validationResult.Errors);

            _memCache.Add(value);

            return Ok($"{value.ToString()} has been added");
        }
예제 #23
0
        public IActionResult Post([FromBody] TicketsData value)
        {
            var validationResult = value.Validate();

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }
            _memCache.Add(value);
            return(Ok($"{value.ToString()} has been added"));
        }
예제 #24
0
        public IActionResult Post([FromBody] string url)
        {
            if (NotValidUrl(url))
            {
                return(BadRequest());
            }

            var shortName = _storage.Add(url);

            return(CreatedAtRoute("Follow", new { id = shortName }, url));
        }
 public void Send(ITargetProcessMessage message)
 {
     if (!_profile.Initialized)
     {
         _storage.Add(message);
     }
     else
     {
         _bus.SendLocalWithContext(_profile.Name, _accountName, message);
     }
 }
        private CardOperationsImport SaveImportToStorage()
        {
            var newImport = new CardOperationsImport
            {
                Date = DateTime.Now
            };

            _cardOperationsImportStorage.Add(newImport);

            return(newImport);
        }
예제 #27
0
        public async Task Add_CallsCleaner()
        {
            // Arrange
            ICleaner cleaner = Substitute.For <ICleaner>();
            IStorage storage = await CreateStorageWithSchedulerAndWait(cleaner);

            // Act
            storage.Add("", null, ByteString.Empty);

            // Assert
            cleaner.Received(1).Clear(Arg.Any <PriorityQueue <ExpiringKey> >(), Arg.Any <Dictionary <Key, Element> >());
        }
        public IActionResult Post([FromBody]User user)
        {
            // option SuppressModelStateInvalidFilter should be enabled
            if (!ModelState.IsValid) return BadRequest(ModelState);
            
            _logger.LogInformation($"New user registration from {Platform}");

            var id = _users.Add(user);

            // return 201
            return CreatedAtAction(nameof(GetById), new {id}, id);
        }
예제 #29
0
        public IActionResult Post([FromBody] Lab1Data value)
        {
            var validationResult = value.Validate();

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            _memCache.Add(value);

            return(Ok($"{value.ToString()} - запись успешно добавлена!"));
        }
예제 #30
0
        public IActionResult Post([FromBody] Lab1Mod value)
        {
            var validationResult = value.Validate();

            if (!validationResult.IsValid)
            {
                return
                    (BadRequest(validationResult.Errors));
            }
            _memCache.Add(value);
            Log.Information("Post record");
            return(Ok($"{value.ToString()} has been added"));
        }
예제 #31
0
        public SessionStorage(IStorage storage, ILog log)
        {
            if (storage == null)
            {
                throw Error.ArgumentNull("storage");
            }

            if (log == null)
            {
                throw Error.ArgumentNull("log");
            }

            InternalStorage = storage;
            InternalStorage.Add(SessionStorageKey, new Dictionary<string, ISession>());
            Log = log;
        }