public async Task <InvokeResult> UpdateOutputTranslatorConfigurationAsync(OutputTranslatorConfiguration outputTranslatorConfiguration, EntityHeader org, EntityHeader user) { await AuthorizeAsync(outputTranslatorConfiguration, AuthorizeActions.Update, user, org); ValidationCheck(outputTranslatorConfiguration, Actions.Update); await _outputTranslatorConfigurationRepo.UpdateOutputTranslatorConfigurationAsync(outputTranslatorConfiguration); return(InvokeResult.Success); }
public void Init() { _messageDefinition = GetDeviceMessage(); _deviceWorkflow = GetWorkflow(); _moduleConfig = new RouteModuleConfig { PrimaryOutput = new RouteConnection() }; RefreshMapping(); _outputTranslatorConfig = new OutputTranslatorConfiguration() { Key = "key1" }; }
public async Task <OutputTranslatorConfiguration> AddOutputTranslatorsAsync(EntityHeader org, EntityHeader user, DateTime createTimestamp) { var outputTranslator = new OutputTranslatorConfiguration(); outputTranslator.Name = "Default Output Translator"; outputTranslator.Key = DEFAULT; outputTranslator.Description = "The default output translator will use the definition of the message to build the contents of the outgoing message."; outputTranslator.OutputTranslatorType = EntityHeader <OutputTranslatorConfiguration.OutputTranslatorTypes> .Create(OutputTranslatorConfiguration.OutputTranslatorTypes.MessageBased); this.AddAuditProperties(outputTranslator, createTimestamp, org, user); this.AddId(outputTranslator); this.AddOwnedProperties(outputTranslator, org); await this._pipelineMgr.AddOutputTranslatorConfigurationAsync(outputTranslator, org, user); return(outputTranslator); }
public async Task <DeviceConfiguration> AddDeviceConfigAsync(string name, string key, SentinelConfiguration sentinal, InputTranslatorConfiguration input, DeviceWorkflow workflow, OutputTranslatorConfiguration output, DeviceMessageDefinition msg, EntityHeader org, EntityHeader user, DateTime createTimestamp) { if (sentinal == null) { throw new ArgumentNullException(nameof(sentinal)); } if (input == null) { throw new ArgumentNullException(nameof(input)); } if (workflow == null) { throw new ArgumentNullException(nameof(workflow)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } if (msg == null) { throw new ArgumentNullException(nameof(msg)); } await _storageUtils.DeleteIfExistsAsync <DeviceConfiguration>(key, org); var deviceConfig = new DeviceConfiguration() { Id = Guid.NewGuid().ToId(), Name = name, Key = key, }; AddOwnedProperties(deviceConfig, org); AddAuditProperties(deviceConfig, createTimestamp, org, user); var route = Route.Create(); route.Name = "Motion Message Handler"; route.Key = EXAMPLE_MOTION_KEY; AddId(route); AddAuditProperties(route, createTimestamp, org, user); route.MessageDefinition = new EntityHeader <DeviceMessageDefinition>() { Id = msg.Id, Text = msg.Name }; var sentinalConfig = route.PipelineModules.Where(pm => pm.ModuleType.Value == PipelineModuleType.Sentinel).First(); sentinalConfig.Name = sentinal.Name; sentinalConfig.Key = sentinal.Key; sentinalConfig.Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = sentinal.Id, Text = sentinal.Name }; var inputTranslator = route.PipelineModules.Where(pm => pm.ModuleType.Value == PipelineModuleType.InputTranslator).First(); inputTranslator.Name = input.Name; inputTranslator.Key = input.Key; inputTranslator.Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = input.Id, Text = input.Name }; inputTranslator.PrimaryOutput.Mappings.Add(new KeyValuePair <string, object>("motion", "motionstatus")); var wf = route.PipelineModules.Where(pm => pm.ModuleType.Value == PipelineModuleType.Workflow).First(); wf.Key = workflow.Key; wf.Name = workflow.Name; wf.Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = workflow.Id, Text = workflow.Name }; var outputTranslator = route.PipelineModules.Where(pm => pm.ModuleType.Value == PipelineModuleType.OutputTranslator).First(); outputTranslator.Name = output.Name; outputTranslator.Key = output.Key; outputTranslator.Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = output.Id, Text = output.Name }; deviceConfig.Routes.Add(route); await _deviceCfgMgr.AddDeviceConfigurationAsync(deviceConfig, org, user); return(deviceConfig); }
public void WorkflowToOutputTranslatorValidation(ValidationResult result, DeviceWorkflow workflow, OutputTranslatorConfiguration outputTranslator) { if (PrimaryOutput != null) { if (PrimaryOutput.Mappings == null) { PrimaryOutput.Mappings = new List <KeyValuePair <string, object> >(); } foreach (var mapping in PrimaryOutput.Mappings) { if (mapping.Value != null) { var outputCommandMapping = JsonConvert.DeserializeObject <OutputCommandMapping>(mapping.Value.ToString()); if (EntityHeader.IsNullOrEmpty(outputCommandMapping.OutgoingDeviceMessage) || outputCommandMapping.FieldMappings == null) { result.Errors.Add(Resources.DeploymentErrorCodes.InvalidInputCommandMapping.ToErrorMessage($"Workflow={workflow.Key};OutputTranslator={outputTranslator.Key}")); } else { var outputCommand = workflow.OutputCommands.Where(cmd => cmd.Key == mapping.Key).FirstOrDefault(); if (outputCommand == null) { result.AddUserError($"Could not find output command for key {mapping.Key}, for work flow {workflow.Name}"); } else { var msg = outputCommandMapping.OutgoingDeviceMessage.Value; foreach (var fieldMapping in outputCommandMapping.FieldMappings) { var outputParameter = outputCommand.Parameters.Where(param => param.Key == fieldMapping.Key).FirstOrDefault(); var field = msg.Fields.Where(fld => fld.Key == fieldMapping.Value).FirstOrDefault(); if (outputParameter == null) { result.AddUserError($"Could not find output parameter for key {fieldMapping.Key} on output {outputCommand.Name}, for work flow {workflow.Name}."); } else if (field == null) { result.AddUserError($"Could not find field on message {msg.Name} with key {fieldMapping.Value} for output command {outputCommand.Name}, for work flow {workflow.Name}."); } else if (EntityHeader.IsNullOrEmpty(outputParameter.ParameterType)) { result.AddUserError($"Parameter type not found on output parameter {outputParameter.Name} for output command {outputCommand.Name}, for work flow {workflow.Name}."); } else if (EntityHeader.IsNullOrEmpty(field.StorageType)) { result.AddUserError($"Storage type not found on message {msg.Name} for field {field.Name} with command {outputCommand.Name}, for work flow {workflow.Name}."); } else if (outputParameter.ParameterType.Id != field.StorageType.Id) { result.AddUserError($"Mis-match storage type not for output command {outputCommand.Name}, {outputParameter.Name}/{outputParameter.ParameterType.Text} to message {msg.Name} for field {field.Name}/{field.StorageType.Text} with command {outputParameter.Name}, for work flow {workflow.Name}."); } else if (outputParameter.ParameterType.Value == ParameterTypes.State) { if (EntityHeader.IsNullOrEmpty(outputParameter.StateSet)) { result.AddUserError($"State Set Not provided on Output Command {outputCommand.Name}, Output Parameter {outputParameter.Name}"); } else if (EntityHeader.IsNullOrEmpty(field.StateSet)) { result.AddUserError($"State Set Not provided on Message {msg.Name}, Field {field.Name}."); } else if (outputParameter.StateSet.Id != field.StateSet.Id) { result.AddUserError($"State Set are different on mapping between Output Command {outputCommand.Name}/{outputParameter.Name} and Message {msg.Name}/{field.Name} on workflow {workflow.Name}."); } } else if (outputParameter.ParameterType.Value == ParameterTypes.ValueWithUnit) { if (EntityHeader.IsNullOrEmpty(outputParameter.UnitSet)) { result.AddUserError($"Unit Set Not provided on Output Command {outputCommand.Name}, Output Parameter {outputParameter.Name}."); } else if (EntityHeader.IsNullOrEmpty(field.UnitSet)) { result.AddUserError($"Unit Set Not provided on Message {msg.Name}, Field {field.Name}."); } else if (outputParameter.UnitSet.Id != field.UnitSet.Id) { result.AddUserError($"Units Set are different on mapping between Output Command {outputCommand.Name}/{outputParameter.Name} and Message {msg.Name}/{field.Name} on workflow {workflow.Name}."); } } } } } } else { result.Errors.Add(Resources.DeploymentErrorCodes.InvalidInputCommandMapping.ToErrorMessage($"Workflow={workflow.Key};OutputTranslator={outputTranslator.Key}")); } } } }
public Task <InvokeResult> UpdateOutputTranslatorConfigurationAsync([FromBody] OutputTranslatorConfiguration outputTranslatorConfiguration) { return(_pipelineModuleManager.UpdateOutputTranslatorConfigurationAsync(outputTranslatorConfiguration, OrgEntityHeader, UserEntityHeader)); }
public async Task <InvokeResult <Solution> > CreateSimpleSolutionAsync(EntityHeader org, EntityHeader user, DateTime createTimeStamp) { /* Create unit/state sets */ var stateSet = new StateSet() { Key = "onoff", Name = "On/Off", Description = "Provides two simple states, On and Off", States = new List <State> { new State() { Key = "on", Name = "On", IsInitialState = true }, new State() { Key = "off", Name = "Off" } } }; AddId(stateSet); AddOwnedProperties(stateSet, org); AddAuditProperties(stateSet, createTimeStamp, org, user); await _deviceAdminMgr.AddStateSetAsync(stateSet, org, user); var unitSet = new UnitSet() { Key = "Temperature", Name = "temperature", Units = new List <Unit>() { new Unit() { Key = "fahrenheit", Name = "Fahrenheit", IsDefault = true }, new Unit() { Key = "celsius", Name = "Celsius", IsDefault = false }, } }; AddId(unitSet); AddOwnedProperties(unitSet, org); AddAuditProperties(unitSet, createTimeStamp, org, user); await _deviceAdminMgr.AddUnitSetAsync(unitSet, org, user); /* Create Pipeline Modules */ var restListener = new ListenerConfiguration() { Name = "Sample Rest", Key = "samplereset", ListenerType = EntityHeader <ListenerTypes> .Create(ListenerTypes.Rest), RestServerType = EntityHeader <RESTServerTypes> .Create(RESTServerTypes.HTTP), ListenOnPort = 80, ContentType = EntityHeader <DeviceMessaging.Admin.Models.MessageContentTypes> .Create(DeviceMessaging.Admin.Models.MessageContentTypes.JSON), UserName = "******", Password = "******" }; AddId(restListener); AddOwnedProperties(restListener, org); AddAuditProperties(restListener, createTimeStamp, org, user); await _pipelineMgr.AddListenerConfigurationAsync(restListener, org, user); var msgTempDefinition = new DeviceMessaging.Admin.Models.DeviceMessageDefinition() { Name = "Sample Temperature Message", Key = "sampletempmsg", SampleMessages = new List <DeviceMessaging.Admin.Models.SampleMessage>() { new DeviceMessaging.Admin.Models.SampleMessage() { Id = Guid.NewGuid().ToId(), Name = "Example Temperature Message", Key = "exmpl001", Payload = "98.5,38", Headers = new System.Collections.ObjectModel.ObservableCollection <DeviceMessaging.Admin.Models.Header>() { new DeviceMessaging.Admin.Models.Header() { Name = "x-deviceid", Value = "device001" }, new DeviceMessaging.Admin.Models.Header() { Name = "x-messageid", Value = "tmpmsg001" } } } }, MessageId = "smpltmp001", ContentType = EntityHeader <DeviceMessaging.Admin.Models.MessageContentTypes> .Create(DeviceMessaging.Admin.Models.MessageContentTypes.Delimited), Fields = new List <DeviceMessaging.Admin.Models.DeviceMessageDefinitionField>() { new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField() { Id = Guid.NewGuid().ToId(), Name = "Temperature", Key = "temp", DelimitedIndex = 0, UnitSet = new EntityHeader <UnitSet>() { Id = unitSet.Id, Text = unitSet.Name, Value = unitSet }, StorageType = EntityHeader <ParameterTypes> .Create(ParameterTypes.State), }, new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField() { Id = Guid.NewGuid().ToId(), Name = "Humidity", Key = "humidity", DelimitedIndex = 1, StorageType = EntityHeader <ParameterTypes> .Create(ParameterTypes.Integer), } } }; AddId(msgTempDefinition); AddOwnedProperties(msgTempDefinition, org); AddAuditProperties(msgTempDefinition, createTimeStamp, org, user); await _deviceMsgMgr.AddDeviceMessageDefinitionAsync(msgTempDefinition, org, user); var motionMsgDefinition = new DeviceMessaging.Admin.Models.DeviceMessageDefinition() { Name = "Sample Motion Message", Key = "samplemptionmsg", SampleMessages = new List <DeviceMessaging.Admin.Models.SampleMessage>() { new DeviceMessaging.Admin.Models.SampleMessage() { Id = Guid.NewGuid().ToId(), Name = "Example Motion Message", Key = "exmpl001", Payload = "{'motion':'on','level':80}", PathAndQueryString = "/motion/device001" } }, MessageId = "smplmot001", ContentType = EntityHeader <DeviceMessaging.Admin.Models.MessageContentTypes> .Create(DeviceMessaging.Admin.Models.MessageContentTypes.JSON), Fields = new List <DeviceMessaging.Admin.Models.DeviceMessageDefinitionField>() { new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField() { Id = Guid.NewGuid().ToId(), Name = "Motion", Key = "motion", JsonPath = "motion", StateSet = new EntityHeader <StateSet>() { Id = stateSet.Id, Text = stateSet.Name, Value = stateSet }, StorageType = EntityHeader <ParameterTypes> .Create(ParameterTypes.State), }, new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField() { Id = Guid.NewGuid().ToId(), Name = "Level", Key = "level", JsonPath = "level", StorageType = EntityHeader <ParameterTypes> .Create(ParameterTypes.Integer), } } }; AddId(motionMsgDefinition); AddOwnedProperties(motionMsgDefinition, org); AddAuditProperties(motionMsgDefinition, createTimeStamp, org, user); await _deviceMsgMgr.AddDeviceMessageDefinitionAsync(motionMsgDefinition, org, user); var deviceIdParser1 = new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField() { SearchLocation = EntityHeader <DeviceMessaging.Admin.Models.SearchLocations> .Create(DeviceMessaging.Admin.Models.SearchLocations.Header), HeaderName = "x-deviceid", Name = "Device Id in Header", Key = "xdeviceid" }; var deviceIdParser2 = new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField() { SearchLocation = EntityHeader <DeviceMessaging.Admin.Models.SearchLocations> .Create(DeviceMessaging.Admin.Models.SearchLocations.Path), PathLocator = "/*/{deviceid}", Name = "Device Id in Path", Key = "pathdeviceid" }; var messageIdParser1 = new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField() { SearchLocation = EntityHeader <DeviceMessaging.Admin.Models.SearchLocations> .Create(DeviceMessaging.Admin.Models.SearchLocations.Header), HeaderName = "x-messageid", Name = "Message Id in Header", Key = "xmessageid", }; var messageIdParser2 = new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField() { SearchLocation = EntityHeader <DeviceMessaging.Admin.Models.SearchLocations> .Create(DeviceMessaging.Admin.Models.SearchLocations.Path), PathLocator = "/{messageid}/*", Name = "Message Id in Path", Key = "pathmessageid" }; var verifier = new Verifier() { Component = new EntityHeader() { Id = motionMsgDefinition.Id, Text = motionMsgDefinition.Name }, ExpectedOutputs = new System.Collections.ObjectModel.ObservableCollection <ExpectedValue>() { new ExpectedValue() { Key = "motion", Value = "on" }, new ExpectedValue() { Key = "level", Value = "80" } }, InputType = EntityHeader <InputTypes> .Create(InputTypes.Text), Name = "Simple Message Verifier", Key = "smplmsgver", Description = "Validates that a Sample Motion Message has the proper field parsers", Input = "{'motion':'on','level':80}", PathAndQueryString = "/smplmot001/device001", ShouldSucceed = true, VerifierType = EntityHeader <VerifierTypes> .Create(VerifierTypes.MessageParser) }; AddId(verifier); AddOwnedProperties(verifier, org); AddAuditProperties(verifier, createTimeStamp, org, user); await _verifierMgr.AddVerifierAsync(verifier, org, user); var deviceIdParserVerifier1 = new Verifier() { Component = new EntityHeader() { Id = deviceIdParser1.Id, Text = deviceIdParser1.Name }, ExpectedOutput = "device001", InputType = EntityHeader <InputTypes> .Create(InputTypes.Text), Name = "Find Device Id in Header", Key = "msgidheader", Description = "Validates that the Device Id can be extracted from the header", Headers = new System.Collections.ObjectModel.ObservableCollection <DeviceMessaging.Admin.Models.Header>() { new DeviceMessaging.Admin.Models.Header() { Name = "x-messageid", Value = "device001" } }, ShouldSucceed = true, VerifierType = EntityHeader <VerifierTypes> .Create(VerifierTypes.MessageFieldParser) }; AddId(deviceIdParserVerifier1); AddOwnedProperties(deviceIdParserVerifier1, org); AddAuditProperties(deviceIdParserVerifier1, createTimeStamp, org, user); await _verifierMgr.AddVerifierAsync(deviceIdParserVerifier1, org, user); var deviceIdParserVerifier2 = new Verifier() { Component = new EntityHeader() { Id = deviceIdParser2.Id, Text = deviceIdParser2.Name }, ExpectedOutput = "device002", InputType = EntityHeader <InputTypes> .Create(InputTypes.Text), Name = "Finds Device Id in Path", Key = "msgidpath", Description = "Validats the the device id can be extracted from thepath", PathAndQueryString = "/smplmot001/device002", ShouldSucceed = true, VerifierType = EntityHeader <VerifierTypes> .Create(VerifierTypes.MessageFieldParser) }; AddId(deviceIdParserVerifier2); AddOwnedProperties(deviceIdParserVerifier2, org); AddAuditProperties(deviceIdParserVerifier2, createTimeStamp, org, user); await _verifierMgr.AddVerifierAsync(deviceIdParserVerifier2, org, user); var messageIdParserVerifier1 = new Verifier() { Component = new EntityHeader() { Id = messageIdParser1.Id, Text = messageIdParser1.Name }, ExpectedOutput = "smplmsg001", InputType = EntityHeader <InputTypes> .Create(InputTypes.Text), Name = "Finds Message id in Header", Key = "msgidheader", Description = "Validates that the message id can be extracted from the header", Headers = new System.Collections.ObjectModel.ObservableCollection <DeviceMessaging.Admin.Models.Header>() { new DeviceMessaging.Admin.Models.Header() { Name = "x-messageid", Value = "smplmsg001" } }, ShouldSucceed = true, VerifierType = EntityHeader <VerifierTypes> .Create(VerifierTypes.MessageFieldParser) }; AddId(messageIdParserVerifier1); AddOwnedProperties(messageIdParserVerifier1, org); AddAuditProperties(messageIdParserVerifier1, createTimeStamp, org, user); await _verifierMgr.AddVerifierAsync(messageIdParserVerifier1, org, user); var messageIdParserVerifier2 = new Verifier() { Component = new EntityHeader() { Id = messageIdParser2.Id, Text = messageIdParser2.Name }, ExpectedOutput = "smplmot002", InputType = EntityHeader <InputTypes> .Create(InputTypes.Text), Name = "Finds Message id in Path", Key = "msgidpath", Description = "Validates that the message id can be extracted from path.", PathAndQueryString = "/smplmot002/device001", ShouldSucceed = true, VerifierType = EntityHeader <VerifierTypes> .Create(VerifierTypes.MessageFieldParser) }; AddId(messageIdParserVerifier2); AddOwnedProperties(messageIdParserVerifier2, org); AddAuditProperties(messageIdParserVerifier2, createTimeStamp, org, user); await _verifierMgr.AddVerifierAsync(messageIdParserVerifier2, org, user); var planner = new PlannerConfiguration() { Name = "Sample Planner", Key = "sampleplanner", MessageTypeIdParsers = new List <DeviceMessaging.Admin.Models.DeviceMessageDefinitionField>() { messageIdParser1, messageIdParser2 }, DeviceIdParsers = new List <DeviceMessaging.Admin.Models.DeviceMessageDefinitionField>() { deviceIdParser1, deviceIdParser2 } }; AddId(planner); AddOwnedProperties(planner, org); AddAuditProperties(planner, createTimeStamp, org, user); await _pipelineMgr.AddPlannerConfigurationAsync(planner, org, user); /* Create Pipeline Modules */ var sentinelConfiguration = new SentinelConfiguration() { Name = "Sample Sentinel", Key = "samplereset", }; AddId(sentinelConfiguration); AddOwnedProperties(sentinelConfiguration, org); AddAuditProperties(sentinelConfiguration, createTimeStamp, org, user); await _pipelineMgr.AddSentinelConfigurationAsync(sentinelConfiguration, org, user); var inputTranslator = new InputTranslatorConfiguration() { Name = "Sample Input Translator", Key = "sampleinputtranslator", InputTranslatorType = EntityHeader <InputTranslatorConfiguration.InputTranslatorTypes> .Create(InputTranslatorConfiguration.InputTranslatorTypes.MessageBased), }; AddId(inputTranslator); AddOwnedProperties(inputTranslator, org); AddAuditProperties(inputTranslator, createTimeStamp, org, user); await _pipelineMgr.AddInputTranslatorConfigurationAsync(inputTranslator, org, user); var wf = new DeviceWorkflow() { Key = "sampleworkflow", Name = "Sample Workflow", Description = "Sample Workflow", Attributes = new List <DeviceAdmin.Models.Attribute>() { }, Inputs = new List <WorkflowInput>() { }, InputCommands = new List <InputCommand>() { }, StateMachines = new List <StateMachine>() { }, OutputCommands = new List <OutputCommand>() { } }; AddId(wf); AddOwnedProperties(wf, org); AddAuditProperties(wf, createTimeStamp, org, user); await _deviceAdminMgr.AddDeviceWorkflowAsync(wf, org, user); var outTranslator = new OutputTranslatorConfiguration() { Name = "Sample Output Translator", Key = "sampleinputtranslator", OutputTranslatorType = EntityHeader <OutputTranslatorConfiguration.OutputTranslatorTypes> .Create(OutputTranslatorConfiguration.OutputTranslatorTypes.MessageBased), }; AddId(outTranslator); AddOwnedProperties(outTranslator, org); AddAuditProperties(outTranslator, createTimeStamp, org, user); await _pipelineMgr.AddOutputTranslatorConfigurationAsync(outTranslator, org, user); var tmpOutTrn = new RouteModuleConfig() { Id = Guid.NewGuid().ToId(), Name = outTranslator.Name, Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = outTranslator.Id, Text = outTranslator.Name, Value = outTranslator }, ModuleType = EntityHeader <PipelineModuleType> .Create(PipelineModuleType.OutputTranslator) }; var tmpWf = new RouteModuleConfig() { Id = Guid.NewGuid().ToId(), Name = wf.Name, Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = wf.Id, Text = wf.Name, Value = wf }, PrimaryOutput = new RouteConnection() { Id = tmpOutTrn.Id, Name = outTranslator.Name, Mappings = new List <KeyValuePair <string, object> >() }, ModuleType = EntityHeader <PipelineModuleType> .Create(PipelineModuleType.Workflow) }; var tmpInputTrn = new RouteModuleConfig() { Id = Guid.NewGuid().ToId(), Name = inputTranslator.Name, Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = inputTranslator.Id, Text = inputTranslator.Name, Value = inputTranslator }, PrimaryOutput = new RouteConnection() { Id = tmpWf.Id, Name = wf.Name, Mappings = new List <KeyValuePair <string, object> >() }, ModuleType = EntityHeader <PipelineModuleType> .Create(PipelineModuleType.InputTranslator) }; var tmpSent = new RouteModuleConfig() { Id = Guid.NewGuid().ToId(), Name = sentinelConfiguration.Name, Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = sentinelConfiguration.Id, Text = sentinelConfiguration.Name, Value = sentinelConfiguration }, PrimaryOutput = new RouteConnection() { Id = tmpInputTrn.Id, Name = inputTranslator.Name, Mappings = new List <KeyValuePair <string, object> >() }, ModuleType = EntityHeader <PipelineModuleType> .Create(PipelineModuleType.Sentinel) }; /* Create Route */ var temperatureRoute = new Route() { Name = "Sample Temperature Route", Key = "sampletemproute", MessageDefinition = new EntityHeader <DeviceMessaging.Admin.Models.DeviceMessageDefinition>() { Id = msgTempDefinition.Id, Text = msgTempDefinition.Name, Value = msgTempDefinition }, PipelineModules = new List <RouteModuleConfig>() }; var motOutTran = new RouteModuleConfig() { Id = Guid.NewGuid().ToId(), Name = outTranslator.Name, Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = outTranslator.Id, Text = outTranslator.Name, Value = outTranslator }, ModuleType = EntityHeader <PipelineModuleType> .Create(PipelineModuleType.OutputTranslator) }; var motWf = new RouteModuleConfig() { Id = Guid.NewGuid().ToId(), Name = wf.Name, Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = wf.Id, Text = wf.Name, Value = wf }, PrimaryOutput = new RouteConnection() { Id = motOutTran.Id, Name = outTranslator.Name, Mappings = new List <KeyValuePair <string, object> >() }, ModuleType = EntityHeader <PipelineModuleType> .Create(PipelineModuleType.Workflow) }; var motInputTrn = new RouteModuleConfig() { Id = Guid.NewGuid().ToId(), Name = inputTranslator.Name, Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = inputTranslator.Id, Text = inputTranslator.Name, Value = inputTranslator }, PrimaryOutput = new RouteConnection() { Id = motWf.Id, Name = wf.Name, Mappings = new List <KeyValuePair <string, object> >() }, ModuleType = EntityHeader <PipelineModuleType> .Create(PipelineModuleType.InputTranslator) }; var motSent = new RouteModuleConfig() { Id = Guid.NewGuid().ToId(), Name = sentinelConfiguration.Name, Module = new EntityHeader <DeviceAdmin.Interfaces.IPipelineModuleConfiguration>() { Id = sentinelConfiguration.Id, Text = sentinelConfiguration.Name, Value = sentinelConfiguration }, PrimaryOutput = new RouteConnection() { Id = motInputTrn.Id, Name = inputTranslator.Name, Mappings = new List <KeyValuePair <string, object> >() }, ModuleType = EntityHeader <PipelineModuleType> .Create(PipelineModuleType.Sentinel) }; /* Create Route */ var motionRoute = new Route() { Name = "Sample Motion Route", Key = "sampletemproute", MessageDefinition = new EntityHeader <DeviceMessaging.Admin.Models.DeviceMessageDefinition>() { Id = motionMsgDefinition.Id, Text = motionMsgDefinition.Name, Value = motionMsgDefinition }, PipelineModules = new List <RouteModuleConfig>() { motSent, motInputTrn, motWf, motOutTran } }; var deviceConfig = new DeviceConfiguration() { ConfigurationVersion = 1.0, Name = "Sample Device Config", Key = "sampledeviceconfig", Properties = new List <CustomField>() { new CustomField() { Id = Guid.NewGuid().ToId(), DefaultValue = "90", FieldType = EntityHeader <ParameterTypes> .Create(ParameterTypes.Decimal), Key = "setpoint", Name = "Setpoint", Label = "Setpoint", HelpText = "Setpoint where temperature will trigger warning", IsRequired = true, Order = 1 } }, Routes = new List <Route>() { temperatureRoute, motionRoute } }; AddId(deviceConfig); AddOwnedProperties(deviceConfig, org); AddAuditProperties(deviceConfig, createTimeStamp, org, user); await _deviceCfgMgr.AddDeviceConfigurationAsync(deviceConfig, org, user); var deviceType = new DeviceType() { Name = "Sample Device Type", Key = "sampledevicetype", DefaultDeviceConfiguration = new EntityHeader() { Id = deviceConfig.Id, Text = deviceConfig.Name } }; AddId(deviceType); AddOwnedProperties(deviceType, org); AddAuditProperties(deviceType, createTimeStamp, org, user); await _deviceTypeMgr.AddDeviceTypeAsync(deviceType, org, user); /* Create Solution */ var solution = new Solution() { Id = "Sample App", Name = "sampleapp", Listeners = new List <EntityHeader <ListenerConfiguration> >() { new EntityHeader <ListenerConfiguration>() { Id = restListener.Id, Text = restListener.Name, Value = restListener } }, Planner = new EntityHeader <PlannerConfiguration>() { Id = planner.Id, Text = planner.Name, Value = planner }, DeviceConfigurations = new List <EntityHeader <DeviceConfiguration> >() { new EntityHeader <DeviceConfiguration>() { Id = deviceConfig.Id, Text = deviceConfig.Name, Value = deviceConfig } }, }; AddId(solution); AddOwnedProperties(solution, org); AddAuditProperties(solution, createTimeStamp, org, user); return(InvokeResult <Solution> .Create(solution)); }