private BlueprintDto EnsureProjectBlueprint(M2MgoCloudAgentConfiguration config, UicProject project) { string blueprintCode = _projectBlueprintTranslator.GetBlueprintCodeFrom(project); BlueprintDto[] searchResult = _apiWrapper.SearchBlueprint(config, _projectTranslator.GetProjectDomain(project), blueprintCode); if (searchResult.Count() > 1) { throw new Exception(String.Format("found more than 1 project blueprints {0} in Domain {1}", _projectTranslator.GetProjectDomain(project), blueprintCode)); } if (searchResult.Any()) { BlueprintDto blueprint = _projectBlueprintTranslator.UpdateProjectDomain(searchResult.Single()); string result = _apiWrapper.UpdateBlueprint(config, blueprint); _logger.Information("Updateing Blueprint: " + result); return(blueprint); } else { BlueprintDto projectBlueprintDto = _projectBlueprintTranslator.GetProjectBlueprintDto(project, _projectTranslator.GetProjectDomain(project)); projectBlueprintDto.PrepareMasterForCreation(); string result = _apiWrapper.CreateBlueprint(config, _projectTranslator.GetProjectDomain(project), projectBlueprintDto); _logger.Information("CreateBlueprint Blueprint: " + result); return(_apiWrapper.SearchBlueprint(config, _projectTranslator.GetProjectDomain(project), blueprintCode).Single()); } }
internal BlueprintDto UpdateProjectDomain(BlueprintDto exisingBlueprint) { ProjectDatapointTask[] allDataPointTasks = _project.DatapointTasks.ToArray(); foreach (ProjectDatapointTask datapoint in _project.DatapointTasks) { if (exisingBlueprint.Sensors.All(d => GetKeyFrom(datapoint.Definition) != d.SensorKey)) { exisingBlueprint.Sensors.Add(GetSensorsOf(datapoint)); } } foreach (var datapoint in allDataPointTasks) { UdpateSensorAndCorrespondingCommands(exisingBlueprint, datapoint); } foreach (AttributeDefinition property in _project.Attributes) { Attribute attribute = GetAttributesOf(property); if (exisingBlueprint.Attributes.All(s => s.Name != attribute.Name)) { exisingBlueprint.Attributes.Add(attribute); } } if (exisingBlueprint.Attributes.All(s => s.Name != M2mgoGatewayBlueprintTranslator.AttributeKeySerialId)) { exisingBlueprint.Attributes.Add(new Attribute { Description = "Matching Anchor for autoomatic dashboard over gatway datasource", Name = M2mgoGatewayBlueprintTranslator.AttributeKeySerialId }); } return(exisingBlueprint); }
internal string UpdateBlueprint(M2MgoCloudAgentConfiguration config, BlueprintDto blueprint) { if (blueprint == null) { throw new ArgumentNullException("blueprint"); } return(_userTokenWebApiWrapper.RetryWithTokenUpdate(config, () => { var request = (HttpWebRequest)WebRequest.Create(config.BaseUrl + "api/devicetype/" + blueprint.Identifier.ID.ToString("D")); request.Method = "PUT"; string serializeObject = _serializer.Serialize(blueprint); return _webApiRequestExecutor.ExecuteRequest(request, serializeObject, _userTokenWebApiWrapper.GetToken(), _logger); })); }
private void UdpateSensorAndCorrespondingCommands(BlueprintDto exisingBlueprint, ProjectDatapointTask datapoint) { Sensor sensor = GetSensorsOf(datapoint); Sensor existingSensor = exisingBlueprint.Sensors.SingleOrDefault(s => s.SensorKey == sensor.SensorKey); if (existingSensor == null) { exisingBlueprint.Sensors.Add(sensor); } else { existingSensor.Metadata = sensor.Metadata; } AddDistinctCommand(exisingBlueprint.Commands, datapoint); }
public ApplianceBlueprints SynchronizeWithCloud(M2MgoCloudAgentConfiguration config, string serialId, UicProject project, M2mgoGetwayProjectDto m2MgoGetwayProjectDto) { BlueprintDto gatewayBlueprint = EnsureGatewayBlueprint(config, project); EnsureDevice(config, serialId, gatewayBlueprint, m2MgoGetwayProjectDto.Gateway); UpdateGatewayAttributes(config, serialId, project, gatewayBlueprint); BlueprintDto projectBlueprint = EnsureProjectBlueprint(config, project); EnsureDevice(config, serialId, projectBlueprint, m2MgoGetwayProjectDto.Gateway); UpdateProjectDeviceAttributes(config, serialId, projectBlueprint); SetRelevantDevicesOfGateway(config, m2MgoGetwayProjectDto.Gateway.Identifier.ID, projectBlueprint, serialId); return(new ApplianceBlueprints(gatewayBlueprint, projectBlueprint)); }
internal BlueprintDto GetProjectBlueprintDto(UicProject project, Guid domainId) { var commands = new List <CommandDto>(); var attributes = new List <Attribute>(); var sensors = new List <Sensor>(); if (project.Attributes != null) { foreach (AttributeDefinition attribute in project.Attributes) { attributes.Add(GetAttributesOf(attribute)); } attributes.Add(new Attribute { Description = "Matching Anchor for autoomatic dashboard over gatway datasource", Name = M2mgoGatewayBlueprintTranslator.AttributeKeySerialId }); } if (project.DatapointTasks != null) { foreach (var datapointTask in project.DatapointTasks) { Sensor sensor = GetSensorsOf(datapointTask); sensors.Add(sensor); AddDistinctCommand(commands, datapointTask); } } var blueprint = new BlueprintDto { Commands = commands, Attributes = attributes, Sensors = sensors, DomainIdentifier = new Identifier { ID = domainId }, Name = GetBlueprintNameFrom(project), Label = GetBlueprintNameFrom(project), Code = GetBlueprintCodeFrom(project), MaxDevices = 50, }; return(blueprint); }
private BlueprintDto EnsureGatewayBlueprint(M2MgoCloudAgentConfiguration config, UicProject project) { BlueprintDto[] searchResult = _apiWrapper.SearchBlueprint(config, config.SgetDomainID, M2mgoGatewayBlueprintTranslator.CloudMapperGatewayAnchorBlueprintCode); if (searchResult.Count() > 1) { throw new Exception(String.Format("found more than 1 masterdefinitions {0} in Domain {1}", _projectTranslator.GetProjectDomain(project), M2mgoGatewayBlueprintTranslator.CloudMapperGatewayAnchorBlueprintCode)); } if (searchResult.Any()) { _logger.Information("Gateway Blueprint {0} alredy exists.", M2mgoGatewayBlueprintTranslator.CloudMapperGatewayAnchorBlueprintCode); return(searchResult.Single()); } BlueprintDto gatewayBlueprintDefiniton = _m2MgoGatewayBlueprintTranslator.GetGatewayBlueprintDefiniton(project); gatewayBlueprintDefiniton.PrepareMasterForCreation(); string result = _apiWrapper.CreateBlueprint(config, _projectTranslator.GetProjectDomain(project), gatewayBlueprintDefiniton); _logger.Information("CreateBlueprint Blueprint: " + result); return(_apiWrapper.SearchBlueprint(config, _projectTranslator.GetProjectDomain(project), M2mgoGatewayBlueprintTranslator.CloudMapperGatewayAnchorBlueprintCode).Single()); }
public ApplianceBlueprints(BlueprintDto gatewayBlueprint, BlueprintDto projectBlueprint) { GatewayBlueprint = gatewayBlueprint; ProjectBlueprint = projectBlueprint; }
private void UpdateProjectDeviceAttributes(M2MgoCloudAgentConfiguration config, string serialId, BlueprintDto projectBlueprintDto) { _apiWrapper.PostAttributes(config, projectBlueprintDto.Identifier.ID, serialId, M2mgoGatewayBlueprintTranslator.AttributeKeySerialId, serialId); }
private void UpdateGatewayAttributes(M2MgoCloudAgentConfiguration config, string serialId, UicProject project, BlueprintDto gatewayBlueprint) { _apiWrapper.PostAttributes(config, gatewayBlueprint.Identifier.ID, serialId, M2mgoGatewayBlueprintTranslator.AttributeKeySerialId, serialId); _apiWrapper.PostAttributes(config, gatewayBlueprint.Identifier.ID, serialId, M2mgoGatewayBlueprintTranslator.AttributeKeyProjectKey, project.ProjectKey); _apiWrapper.PostAttributes(config, gatewayBlueprint.Identifier.ID, serialId, M2mgoGatewayBlueprintTranslator.AttributeKeyProjectName, project.Name); _apiWrapper.PostAttributes(config, gatewayBlueprint.Identifier.ID, serialId, M2mgoGatewayBlueprintTranslator.AttributeKeyCustomer, project.Owner); }
private void SetRelevantDevicesOfGateway(M2MgoCloudAgentConfiguration config, Guid gatewayDevice, BlueprintDto projectBlueprint, string serialId) { var relevantSensors = projectBlueprint.Sensors.Select(s => new RelevantSensor { DisplayChartLeftAxis = true, DisplayChartRightAxis = false, DisplayInTable = true, Label = s.Label, Path = "", SensorKey = s.SensorKey }).ToArray(); var relevantDevice = new RelevantDevice { DeviceCustomID = serialId, DeviceTypeDomain = projectBlueprint.DomainIdentifier.ID, DeviceTypeName = projectBlueprint.Code, RelevantSensors = relevantSensors }; _gatewayApiWrapper.PostRelevantDevices(config, gatewayDevice, new [] { relevantDevice }); }
private void EnsureDevice(M2MgoCloudAgentConfiguration config, string deviceIdentifier, BlueprintDto blueprint, GatewayGetModel gateway) { _apiWrapper.AuthenticateDevice(config, blueprint.Identifier.ID, deviceIdentifier, gateway.Identifier.ID); }