public async Task <ActionResult> Delete(string key)
        {
            if (!_consensusContext.IsLeader())
            {
                return(Redirect($"{_consensusContext.NodeVote.LeaderNode.Address}/api/key-values"));
            }

            var service = _kvPropertyService.Get(key);

            if (service == null)
            {
                return(NotFound());
            }

            var actionConfirmation = await _kvPropertyService.Delete(key);

            if (actionConfirmation.WasSuccessful)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(actionConfirmation));
            }
        }
示例#2
0
        public bool OnLogReplication(AppendEntriesEvent appendEntriesEvent)
        {
            if (appendEntriesEvent.Entries != null && appendEntriesEvent.Entries.Count > 0)
            {
                foreach (var item in appendEntriesEvent.Entries)
                {
                    if (item.ObjectType == typeof(ServiceHealth).FullName)
                    {
                        var serviceHealth = JsonConvert.DeserializeObject <ServiceHealth>(item.Value.ToString());
                        _serviceHealthService.Create(serviceHealth.ServiceId, serviceHealth);
                    }
                    else if (item.ObjectType == typeof(Service).FullName)
                    {
                        var serviceData = JsonConvert.DeserializeObject <Service>(item.Value.ToString());
                        switch (item.Method)
                        {
                        case MethodType.Create:
                            _servicesService.Create(serviceData);
                            break;

                        case MethodType.Update:
                            _servicesService.Update(serviceData);
                            break;

                        case MethodType.Delete:
                            _servicesService.Delete(serviceData.Id);
                            break;
                        }
                    }
                    else if (item.ObjectType == typeof(KvProperty).FullName)
                    {
                        var kvProperty = JsonConvert.DeserializeObject <KvProperty>(item.Value.ToString());
                        switch (item.Method)
                        {
                        case MethodType.Create:
                            _kvPropertyService.Create(kvProperty);
                            break;

                        case MethodType.Update:
                            _kvPropertyService.Update(kvProperty);
                            break;

                        case MethodType.Delete:
                            _kvPropertyService.Delete(kvProperty.Key);
                            break;
                        }
                    }
                }
            }

            return(true);
        }