public virtual async Task <int> DeleteClientPropertyAsync(ClientProperty clientProperty) { var propertyToDelete = await DbContext.ClientProperties.Where(x => x.Id == clientProperty.Id).SingleOrDefaultAsync(); DbContext.ClientProperties.Remove(propertyToDelete); return(await AutoSaveChangesAsync()); }
public async Task <bool> Handle(SaveClientPropertyCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var client = await _clientRepository.FindByClientIdAsync(request.ClientId); if (client == null) { await _bus.RaiseEvent(new DomainNotification("key_not_found", $"Client named {request.ClientId} not found")); return(false); } var property = new ClientProperty { Client = client, Key = request.Key, Value = request.Value }; await _clientPropertyRepository.AddAsync(property); if (Commit()) { await _bus.RaiseEvent(new ClientPropertyAddedEvent(request.ClientId, property.Id, request.Key, request.Value)); return(true); } return(false); }
public async Task <int> DeleteClientPropertyAsync(ClientProperty clientProperty) { using (var dbContext = ConnectionDatabase.Get(_configuration)) { return(await dbContext.ExecuteAsync("delete from ClientProperties where id=@Id", new { clientProperty.Id })); } }
public async Task <bool> Handle(SaveClientPropertyCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var savedClient = await _clientRepository.GetByClientId(request.ClientId); if (savedClient == null) { await Bus.RaiseEvent(new DomainNotification("1", "Client not found")); return(false); } var property = new ClientProperty() { Client = savedClient, Value = request.Value, Key = request.Key }; _clientPropertyRepository.Add(property); if (Commit()) { await Bus.RaiseEvent(new NewClientPropertyEvent(request.Id, request.ClientId, property.Key, property.Value)); return(true); } return(false); }
public string GetClientVarString(ClientProperty flag) { if (!Connection.IsConnected) { Log("Not connected"); return(String.Empty); } IntPtr retVal = IntPtr.Zero; IntPtr flg = new IntPtr((int)flag); if (ID == Connection.LocalClientId) { if (Functions.getClientSelfVariableAsString(Connection.ID, flag, ref retVal) == ERROR_OK) { var s = ReadString(retVal); return(s); } } else { if (Functions.getClientVariableAsString(Connection.ID, ID, flag, ref retVal) == ERROR_OK) { var s = ReadString(retVal); return(s); } } return(String.Empty); }
private void btnAddProperty_Click(object sender, EventArgs e) { if (PropertiesUri != null) { var newProperty = new ClientProperty { name = String.Format("Property{0}", SessionProperties.properties.Count), value = String.Format("Value{0}", SessionProperties.properties.Count) }; Switch.PostAsJsonAsync(PropertiesUri.AbsoluteUri, newProperty).ContinueWith( responseTask => { if (responseTask.Result.IsSuccessStatusCode) { SessionProperties.properties.Add(newProperty.name, newProperty.value); InitializeList(SessionProperties.properties); } else { var msg = responseTask.Result.Content.ReadAsStringAsync().Result; MessageBox.Show(String.Format("POST {0} failed!\nReason - {1}, {2}\n{3}", PropertiesUri.AbsoluteUri, responseTask.Result.StatusCode, responseTask.Result.ReasonPhrase, msg)); } }); } }
private void SetInt(ClientProperty flag, int value) { if (this != Connection.Self) { throw new NotSupportedException(); } Library.Api.SetClientSelfVariableAsInt(Connection, flag, value); FlushClientSelfUpdates(); }
public virtual async Task <int> AddClientPropertyAsync(int clientId, ClientProperty clientProperty) { var client = await DbContext.Clients.Where(x => x.Id == clientId).SingleOrDefaultAsync(); clientProperty.Client = client; await DbContext.ClientProperties.AddAsync(clientProperty); return(await AutoSaveChangesAsync()); }
private void SetUInt64(ClientProperty flag) { if (this != Connection.Self) { throw new NotSupportedException(); } Library.Api.GetClientVariableAsUInt64(this, flag); FlushClientSelfUpdates(); }
public static PropertyModel FromEntity(ClientProperty prop) { return(new PropertyModel { Id = prop.Id, Key = prop.Key, Value = prop.Value, Client = ClientModel.FromEntity(prop.Client), }); }
private void SetString(ClientProperty flag, string value, ref string cache) { if (this != Connection.Self) { throw new NotSupportedException(); } Library.Api.SetClientSelfVariableAsString(Connection, flag, value); FlushClientSelfUpdates(); cache = value; }
public void DeleteClientProperty(int id) { ClientProperty clientProperty = this.Session.Get <ClientProperty>(id); if (clientProperty == null) { return; } this.Session.Delete(clientProperty); this.Session.Flush(); }
public async Task EditClientPropertyWhenNotFound() { var clientProp = new ClientProperty { ClientId = 796659, ClientPropertyId = 13029, Value = "Hello" }; await Assert.ThrowsAsync <ArgumentException>(() => SystemUnderTest.EditAsync(clientProp)); }
public void GetClientPropertyTest() { //Arrange Worker target = new Worker(); //Act ClientProperty actual = target.GetClientProperty(); //Assert Assert.AreEqual(typeof(ServiceConcrete2), actual.Service.GetType()); }
public void AddClientProperty(ClientPropertyDto clientPropertyDto) { ClientProperty clientProperty = clientPropertyDto.ToEntity(); if (!CanInsertProperty(clientProperty)) { throw new FluentValidationException($"属性{clientPropertyDto.Key}重复。"); } this.Session.Save(clientProperty); this.Session.Flush(); }
public async Task <int> Insert(ClientProperty clientProperty) { var isKeyExists = await CheckExistsByKey(clientProperty.Id, clientProperty.ClientId, clientProperty.Key); if (isKeyExists) { return(-1); } _clientPropertyRepository.Create(clientProperty); return(await Context.SaveChangesAsync()); }
public async Task <int> AddClientPropertyAsync(int clientId, ClientProperty clientProperty) { using (var dbContext = ConnectionDatabase.Get(_configuration)) { return(await dbContext.QueryFirstAsync <int>("insert into ClientProperties values(@Key, @Value, @clientId); select SCOPE_IDENTITY();", new { clientProperty.Key, clientProperty.Value, clientId })); } }
public async Task EditClientPropertyWhenNotAuthorized() { Configuration.ApiKey = "ajfkjeinodafkejlkdsjklj"; var clientProp = new ClientProperty { ClientId = 796659, ClientPropertyId = 13027, Value = "Hello" }; await Assert.ThrowsAsync <NotAuthorizedException>(() => SystemUnderTest.EditAsync(clientProp)); }
public void Save(ClientProperty entity) { if (entity.ClientPropertyId > 0) { _context.ClientProperties.Attach(entity); _context.Entry <ClientProperty>(entity).State = System.Data.EntityState.Modified; } else { _context.ClientProperties.Add(entity); } _context.SaveChanges(); }
public void PropertyTestFluent() { //Arrange ServiceConcrete1 expected = new ServiceConcrete1(); var container = DIHelper.GetContainer(); //Act ClientProperty actual = container.Resolve <ClientProperty>(); //Assert Assert.IsNotNull(actual); Assert.AreEqual(expected.GetType(), actual.Service.GetType()); }
private string GetString(ClientProperty flag, string cache) { string result; Error error = Library.Api.TryGetClientVariableAsString(this, flag, out result); if (error == Error.Ok) { return(result); } else { return(cache); } }
private int GetInt(ClientProperty flag) { int res = 0; if (ID == Connection.LocalClientId) { Check(Functions.getClientSelfVariableAsInt(Connection.ID, flag, out res)); } else { Check(Functions.getClientVariableAsInt(Connection.ID, ID, (IntPtr)flag, out res)); } return(res); }
internal void OnSelfVariableChanged(ClientProperty flag, string oldValue, string newValue) { if (flag == ClientProperty.CLIENT_INPUT_MUTED) { IsMicrophoneMuted = newValue == "1"; VoicePlugin.voiceClient.SendMicrophoneStatusChanged(IsMicrophoneMuted); return; } if (flag == ClientProperty.CLIENT_OUTPUT_MUTED) { IsSpeakersMuted = newValue == "1"; VoicePlugin.voiceClient.SendSpeakersStatusChanged(IsSpeakersMuted); return; } }
public async Task EditClientPropertyWhenText() { var clientProp = new ClientProperty { ClientId = 796659, ClientPropertyId = 13027, Value = "Hello" }; var result = await SystemUnderTest.EditAsync(clientProp); Assert.Equal(clientProp.Value, (string)result.Value); clientProp.Value = ""; await SystemUnderTest.EditAsync(clientProp); }
public void UpdateClientProperty(int id, ClientPropertyDto clientPropertyDto) { ClientProperty clientProperty = this.Session.Get <ClientProperty>(id); if (clientProperty == null) { throw new FluentValidationException($"客户端属性{id}不存在。"); } clientProperty = clientPropertyDto.ToEntity(clientProperty); if (!CanInsertProperty(clientProperty)) { throw new FluentValidationException($"属性{clientPropertyDto.Key}重复。"); } this.Session.Save(clientProperty); this.Session.Flush(); }
public async Task CreateClientPropertyWhenCheckBox() { var clientProp = new ClientProperty { ClientId = 796659, ClientPropertyId = 7804, Value = "1" }; var result = await SystemUnderTest.EditAsync(clientProp); Assert.True((bool)result.Value); clientProp.Value = "0"; await SystemUnderTest.EditAsync(clientProp); }
public static ClientProperty Clone(ClientProperty srcPro) { ClientProperty newProperty = new ClientProperty(); newProperty.MaxDurability = srcPro.MaxDurability; newProperty.MaxEnergy = srcPro.MaxEnergy; newProperty.MaxArmor = srcPro.MaxArmor; newProperty.MaxShield = srcPro.MaxShield; newProperty.MaxShuttleTeam = srcPro.MaxShuttleTeam; newProperty.MaxEccm = srcPro.MaxEccm; newProperty.MaxSpeed = srcPro.MaxSpeed; newProperty.MaxSwspeed = srcPro.MaxSwspeed; newProperty.MaxForceShield = srcPro.MaxForceShield; return(newProperty); }
public static Offset <ClientProperty> CreateClientProperty(FlatBufferBuilder builder, StringOffset nodeNameOffset = default(StringOffset), StringOffset myIpOffset = default(StringOffset), bool isPublisher = false, int topicPort = 0, StringOffset targetNodeNameOffset = default(StringOffset), StringOffset targetIPOffset = default(StringOffset), int targetPort = 0) { builder.StartObject(7); ClientProperty.AddTargetPort(builder, targetPort); ClientProperty.AddTargetIP(builder, targetIPOffset); ClientProperty.AddTargetNodeName(builder, targetNodeNameOffset); ClientProperty.AddTopicPort(builder, topicPort); ClientProperty.AddMyIp(builder, myIpOffset); ClientProperty.AddNodeName(builder, nodeNameOffset); ClientProperty.AddIsPublisher(builder, isPublisher); return(ClientProperty.EndClientProperty(builder)); }
public async Task <int> Update(ClientProperty clientProperty) { var isKeyExists = await CheckExistsByKey(clientProperty.Id, clientProperty.ClientId, clientProperty.Key); if (isKeyExists) { return(-1); } var info = await GetInfo(clientProperty.Id); if (info == null) { return(-2); } info.Key = clientProperty.Key; info.Value = clientProperty.Value; return(await Context.SaveChangesAsync()); }
public bool CanInsertProperty(ClientProperty clientProperty) { if (clientProperty.Id == 0) { var existsWithClientName = this.Session.CreateCriteria <Client>() .Add(NHibernate.Criterion.Restrictions.Eq("ClientId", clientProperty.Id)) .Add(NHibernate.Criterion.Restrictions.Eq("Key", clientProperty.Key)) .List <Client>() .FirstOrDefault(); return(existsWithClientName == null); } else { var existsWithClientName = this.Session.CreateCriteria <Client>() .Add(NHibernate.Criterion.Restrictions.Eq("ClientId", clientProperty.Id)) .Add(NHibernate.Criterion.Restrictions.Eq("Key", clientProperty.Key)) .Add(NHibernate.Criterion.Restrictions.Not(NHibernate.Criterion.Restrictions.Eq("Id", clientProperty.Id))) .List <Client>() .FirstOrDefault(); return(existsWithClientName == null); } }
// public static ClientShip Clone(ClientShip ship) { var newShip = new ClientShip(); newShip.Id = ship.Id; newShip.InFightID = ship.InFightID; newShip.Level = ship.Level; newShip.Reference = ship.Reference; newShip.Position = ship.Position; newShip.DefenseClass_ = ship.DC; newShip.FormationList = ship.FormationList; for (int i = 0; i < ship.PartsList.Count; i++) { var parts = ship.PartsList[i]; parts.Owner = newShip; parts.CoolDownTime = 0; newShip.PartsList.Add(parts); } foreach (var part in ship.PartsDic) { newShip.PartsDic[part.Key] = part.Value; } foreach (var skill in ship.SkillDic) { skill.Value.CoolDownTime = 0; newShip.SkillDic[skill.Key] = skill.Value; } newShip.ShipProperty_ = ClientProperty.Clone(ship.ShipProperty_); newShip.Durability = newShip.ShipProperty_.MaxDurability; newShip.Armor = ship.Armor; newShip.Energy = ship.Energy; return(newShip); }