public void SetDeviceState(SetDeviceStateData setDeviceStateData) { var device = UserDeviceService.GetBySecretKey(setDeviceStateData.SecretKey); if (device != null) { DeviceHistoricalState deviceHistoricalState = new DeviceHistoricalState() { State = device.ActualState, StateTransitionDateTime = DateTime.Now, DeviceId = device.Id }; UserDeviceService.SetupFreshLastPing(device); if (UserDeviceService.UpdateDeviceState(device, setDeviceStateData.DeviceState)) { var historialStateES = new EntityService<DeviceHistoricalState>(); historialStateES.Create(deviceHistoricalState); } IKernel kernel = new StandardKernel(new ConnectYourselfNinjectModule()); var deviceEventsContainer = kernel.Get<IDevicesEventsContainer>(); deviceEventsContainer.RegisterDeviceStateChangeEvent(new DeviceStateChangedEvent { DeviceId = device.Id, DateTime = deviceHistoricalState.StateTransitionDateTime, State = setDeviceStateData.DeviceState, AppUserId = device.AppUserId }); } }
private async Task ProcessPostCommand(RestProcessParameters param, CancellationToken ct) { var restQuery = new RestQueryString(param); var entityDefinition = param.Model.EntitiesByPluralName.SafeGet(restQuery.Root); if (entityDefinition == null) { throw new BadRequestException($"Unable to find an entity definition named {restQuery.Root}."); } if (!restQuery.AdditionalQualifier.IsNullOrEmpty()) { throw new BadRequestException($"A post request should not have an additional qualifier."); } var propertyBag = param.RequestSerializer.Deserialize(param.Context.Request.Body); var entity = await EntityFactory.Create(entityDefinition, propertyBag, ct); var result = await EntityService.Create(entity, ct); Respond(param, result.ToPropertyBag(), StatusCodes.Status201Created, new Dictionary <string, string> { { WebConstants.ETagHeader, result.Etag }, { WebConstants.LastModifiedHeader, result.LastModified.SelectOrDefault(x => x.ToUtcIso8601()) }, { "Location", param.Context.Request.AbsoluteUri( $"{_options.Value.MountPoint}/{entityDefinition.Model.Name}/{entityDefinition.PluralName}/{WebUtility.UrlEncode(result.Id.ToString())}") } }); }
public void SetDeviceState(SetDeviceStateData setDeviceStateData) { var device = UserDeviceService.GetBySecretKey(setDeviceStateData.SecretKey); if (device != null) { DeviceHistoricalState deviceHistoricalState = new DeviceHistoricalState() { State = device.ActualState, StateTransitionDateTime = DateTime.Now, DeviceId = device.Id }; UserDeviceService.SetupFreshLastPing(device); if (UserDeviceService.UpdateDeviceState(device, setDeviceStateData.DeviceState)) { var historialStateES = new EntityService <DeviceHistoricalState>(); historialStateES.Create(deviceHistoricalState); } IKernel kernel = new StandardKernel(new ConnectYourselfNinjectModule()); var deviceEventsContainer = kernel.Get <IDevicesEventsContainer>(); deviceEventsContainer.RegisterDeviceStateChangeEvent(new DeviceStateChangedEvent { DeviceId = device.Id, DateTime = deviceHistoricalState.StateTransitionDateTime, State = setDeviceStateData.DeviceState, AppUserId = device.AppUserId }); } }
public async Task <IActionResult> AddEntity(string level, EntityDto entityDto) { var entity = _mapper.Map <Entity>(entityDto); entity.Id = Guid.NewGuid().ToString(); entity.LevelId = level; var result = await _entityService.Create(entity); return(JsonResponse.New(_mapper.Map <EntityDto> (result))); }
public IHttpActionResult SetDeviceState(SetDeviceStateData setDeviceStateData) { var userId = User.Identity.GetUserId(); UserDeviceService userDeviceService = new UserDeviceService(); if (setDeviceStateData == null) { return(BadRequest("Input is null")); } var device = userDeviceService.GetBySecretKey(setDeviceStateData.SecretKey); if (device != null) { DeviceHistoricalState deviceHistoricalState = new DeviceHistoricalState() { State = device.ActualState, StateTransitionDateTime = DateTime.Now, DeviceId = device.Id }; if (userDeviceService.UpdateDeviceState(device, setDeviceStateData.DeviceState)) { var historialStateES = new EntityService <DeviceHistoricalState>(); historialStateES.Create(deviceHistoricalState); IKernel kernel = new StandardKernel(new ConnectYourselfNinjectModule()); var deviceEventsContainer = kernel.Get <IDevicesEventsContainer>(); deviceEventsContainer.RegisterDeviceStateChangeEvent(new DeviceStateChangedEvent { DeviceId = device.Id, DateTime = deviceHistoricalState.StateTransitionDateTime, State = setDeviceStateData.DeviceState, AppUserId = device.AppUserId }); //send state change message to device if (device.ConnectionState == DeviveConnectionState.FullDuplex && !String.IsNullOrEmpty(device.ConnectionId)) { var devicesHub = GlobalHost.ConnectionManager.GetHubContext <DevicesHub>(); devicesHub.Clients.Client(device.ConnectionId).RemoteSetState(setDeviceStateData.DeviceState); } return(Ok()); } else { return(BadRequest("Failed to update state device")); } } else { return(BadRequest("Device does not exists")); } }
public IHttpActionResult CreateSet(Set set) { if (!ModelState.IsValid) { return(BadRequest()); } _setService.Create(set); return(Created(new Uri(Request.RequestUri + "/" + set.IDSet), set)); }
public async Task Create_OneEntity() { using (var context = GetInMemoryContext()) { // Arrange var entityService = new EntityService <Message>(context, new EntityChangedDispatcher <Message>()); // Act await entityService.Create(_testMessageEntity); // Assert Assert.Single(context.Messages); Assert.Equal(_testMessageEntity.AuthorId, context.Messages.Single().AuthorId); } }
/// <summary> /// Update the specific entity with property values specified. /// </summary> /// <param name="entityName">"Category"</param> /// <param name="propValues">List of key value pairs. /// Where the key is the property name, and the value is a string /// representation of the property value.</param> public BoolMessage Create(ScaffoldContext ctx) { BoolMessageItem creationResult = CreateContext(ctx, false, true, true); if (!creationResult.Success) { return(creationResult); } EntityServiceContext entityActionContext = creationResult.Item as EntityServiceContext; // Create the entity using the entity service. EntityService service = new EntityService(); BoolMessage result = service.Create(entityActionContext); return(result); }
///<summary> ///Adds an entity to my work /// </summary> public UserItem AddToMyWork(UserItem entity) { RestConnector.AwaitContinueOnCapturedContext = false; return(es.Create(workspaceContext, entity, null)); }
public ActionResult <TEntity> Create(TEntity entity) { entity = EntityService.Create(entity); return(Ok(JsonConvert.SerializeObject(entity.Id))); }
public async Task CanCreateOrUpdateCustomEntityInstance() { var entityLogicalName = "new_car"; var logicalCollectionName = "new_cars"; var connector = new ServiceConnector(new DemoConnection()); var service = new MetadataService(connector); var metadata = await service.ListAllAsync(); var carMetadata = metadata.Entries.FirstOrDefault(m => m.LogicalName == entityLogicalName); Assert.IsNotNull(carMetadata); var entityDefinition = await service.GetEntityAttributes(entityLogicalName); Assert.IsNotNull(entityDefinition); var cars = new EntityService(connector, logicalCollectionName); var name = "Civic"; var cx3 = new QueryOptions() .Equal(carMetadata.PrimaryNameAttribute, name) .Top(1); var carMatches = await cars.Search(cx3); if (carMatches.Entries.Length > 0) { //update var carId = carMatches.Entries[0][carMetadata.PrimaryIdAttribute]; var teamMetadata = metadata.Entries.FirstOrDefault(m => m.LogicalName == "team"); Assert.IsNotNull(teamMetadata); var teams = new EntityService(connector, teamMetadata.LogicalCollectionName); var smtdemo = new QueryOptions().Equal("name", "Demo Team").Top(1); var matchingTeam = await teams.Search(smtdemo); var carUpdateData = new EntityData { { "new_engine", 3 }, { "new_carname", $"HONDA {name}" } }; if (matchingTeam.Entries.Length > 0) { carUpdateData.Add("*****@*****.**", $"/{teamMetadata.LogicalCollectionName}({matchingTeam.Entries[0][teamMetadata.PrimaryIdAttribute]})"); } await cars.Update(carId, carUpdateData); } else { var carTypePropertyDefinition = entityDefinition.Entries.FirstOrDefault(v => v.LogicalName == "new_cartype"); Assert.IsNotNull(carTypePropertyDefinition); Assert.AreEqual(carTypePropertyDefinition.OdataType, "#Microsoft.Dynamics.CRM.PicklistAttributeMetadata"); var optionSets = await service.GetPickListDefinition(entityLogicalName); Assert.IsNotNull(optionSets); var carTypeOptionSet = optionSets.Entries.FirstOrDefault(optionSet => optionSet.LogicalName == carTypePropertyDefinition.LogicalName); Assert.IsNotNull(carTypeOptionSet); var cartType = carTypeOptionSet.OptionSet.Options.FirstOrDefault(o => o.Label.LocalizedLabels.Any(l => l.Label == "SEDAN")); var entityData = new EntityData { { carMetadata.PrimaryNameAttribute, name }, { "new_cartype", cartType.Value }, { "new_engine", 2 }, { "new_carname", $"HONDA {name}" }, { "*****@*****.**", "/systemusers(3d035ea1-36a7-ea11-a812-000d3a2537aa)" } }; //create var entityId = await cars.Create(entityData); Assert.IsNotNull(entityId); Assert.AreNotEqual(entityId, Guid.Empty); } }
public IHttpActionResult SetDeviceState(SetDeviceStateData setDeviceStateData) { var userId = User.Identity.GetUserId(); UserDeviceService userDeviceService = new UserDeviceService(); if (setDeviceStateData == null) { return BadRequest("Input is null"); } var device = userDeviceService.GetBySecretKey(setDeviceStateData.SecretKey); if (device != null) { DeviceHistoricalState deviceHistoricalState = new DeviceHistoricalState() { State = device.ActualState, StateTransitionDateTime = DateTime.Now, DeviceId = device.Id }; if (userDeviceService.UpdateDeviceState(device, setDeviceStateData.DeviceState)) { var historialStateES = new EntityService<DeviceHistoricalState>(); historialStateES.Create(deviceHistoricalState); IKernel kernel = new StandardKernel(new ConnectYourselfNinjectModule()); var deviceEventsContainer = kernel.Get<IDevicesEventsContainer>(); deviceEventsContainer.RegisterDeviceStateChangeEvent(new DeviceStateChangedEvent { DeviceId = device.Id, DateTime = deviceHistoricalState.StateTransitionDateTime, State = setDeviceStateData.DeviceState, AppUserId = device.AppUserId }); //send state change message to device if (device.ConnectionState == DeviveConnectionState.FullDuplex && !String.IsNullOrEmpty(device.ConnectionId)) { var devicesHub = GlobalHost.ConnectionManager.GetHubContext<DevicesHub>(); devicesHub.Clients.Client(device.ConnectionId).RemoteSetState(setDeviceStateData.DeviceState); } return Ok(); } else { return BadRequest("Failed to update state device"); } } else { return BadRequest("Device does not exists"); } }