Пример #1
0
        public async Task <Solution> CreateSolutionAsync(string name, string key, EntityHeader org, EntityHeader user, DateTime createTimestamp,
                                                         PlannerConfiguration planner, DeviceConfiguration deviceConfig, ListenerConfiguration listener)
        {
            await _storageUtils.DeleteIfExistsAsync <Solution>(key, org);

            var solution = new Solution()
            {
                Name = name,
                Key  = key
            };

            AddId(solution);
            AddOwnedProperties(solution, org);
            AddAuditProperties(solution, createTimestamp, org, user);

            solution.Planner = new EntityHeader <PlannerConfiguration>()
            {
                Id = planner.Id, Text = planner.Name
            };
            solution.DeviceConfigurations.Add(new EntityHeader <DeviceConfiguration>()
            {
                Id = deviceConfig.Id, Text = deviceConfig.Name
            });
            solution.Listeners.Add(new EntityHeader <ListenerConfiguration>()
            {
                Id = listener.Id, Text = listener.Name
            });


            var setting = new CustomField
            {
                DefaultValue = "32",
                FieldType    = EntityHeader <ParameterTypes> .Create(ParameterTypes.Integer),
                Label        = "Example Settung 1",
                Key          = "example1",
                Name         = "Example Setting 1",
                HelpText     = "You can create custom settings for your solution you can access from our API or from the scripting environment."
            };

            solution.Settings.Add(setting);

            var setting2 = new CustomField
            {
                DefaultValue = "32",
                FieldType    = EntityHeader <ParameterTypes> .Create(ParameterTypes.Integer),
                Label        = "Example Setting 2",
                Key          = "example2",
                Name         = "Example Setting 2",
                HelpText     = "A second optional setting for your solution."
            };

            solution.Settings.Add(setting2);

            await _solutionMgr.AddSolutionsAsync(solution, org, user);

            return(solution);
        }
Пример #2
0
        public async Task <InvokeResult> AddPlannerConfigurationAsync(PlannerConfiguration plannerConfiguration, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(plannerConfiguration, AuthorizeActions.Create, user, org);

            ValidationCheck(plannerConfiguration, Actions.Create);
            await _plannerConfigurationRepo.AddPlannerConfigurationAsync(plannerConfiguration);

            return(InvokeResult.Success);
        }
Пример #3
0
        public static PlannerSummary Create(PlannerConfiguration planner)
        {
            var summary = new PlannerSummary();

            summary.Id   = planner.Id;
            summary.Key  = planner.Key;
            summary.Name = planner.Name;
            summary.MessageTypeIdParsers = planner.MessageTypeIdParsers;
            summary.DeviceIdParsers      = planner.DeviceIdParsers;
            return(summary);
        }
Пример #4
0
        public async Task <PlannerConfiguration> AddPlanner(string name, string key, EntityHeader org, EntityHeader user, DateTime createTimestamp)
        {
            await _storageUtils.DeleteIfExistsAsync <PlannerConfiguration>(key, org);

            await _storageUtils.DeleteIfExistsAsync <Verifier>("explmotmsgidinpath", org);

            await _storageUtils.DeleteIfExistsAsync <Verifier>("explmotdeveidheader", org);


            var planner = new PlannerConfiguration()
            {
                Id          = Guid.NewGuid().ToId(),
                Name        = name,
                Key         = key,
                Description = "This planner will be used to identify the message id and device id from a URL path.  For the URL path /api/motion/dev001, it will identify the message id [motion] and device id [dev001]."
            };

            AddOwnedProperties(planner, org);
            AddAuditProperties(planner, createTimestamp, org, user);

            planner.DeviceIdParsers.Add(new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField()
            {
                Name           = "Device ID in path",
                Key            = "deviceidinpath",
                Notes          = "Will extract the device id from the provided URL path in this example it would extract [dev001] from the path /api/motion/dev001.  See help for more details.",
                SearchLocation = EntityHeader <DeviceMessaging.Admin.Models.SearchLocations> .Create(DeviceMessaging.Admin.Models.SearchLocations.Path),
                PathLocator    = "/api/*/{deviceidinpath}"
            });

            planner.MessageTypeIdParsers.Add(new DeviceMessaging.Admin.Models.DeviceMessageDefinitionField()
            {
                Name           = "Message Id in path",
                Key            = "messageidinpath",
                Notes          = "Will extract message id from the provided URL path, in this example it would extract [motion] from the path /api/motion/dev001.  See help for more details.",
                SearchLocation = EntityHeader <DeviceMessaging.Admin.Models.SearchLocations> .Create(DeviceMessaging.Admin.Models.SearchLocations.Path),
                PathLocator    = "/api/{messageidinpath}/*"
            });

            await this._pipelineMgr.AddPlannerConfigurationAsync(planner, org, user);

            var deviceIdParserVerifier1 = new Verifier()
            {
                Component = new EntityHeader()
                {
                    Id   = planner.DeviceIdParsers.First().Id,
                    Text = planner.DeviceIdParsers.First().Name
                },
                ExpectedOutput     = "dev001",
                InputType          = EntityHeader <InputTypes> .Create(InputTypes.Text),
                Name               = "Find Device Id in Header",
                Key                = "explmotdeveidheader",
                Description        = "Validates that the Device Id can be extracted from the path",
                PathAndQueryString = "/api/smplmsg001/dev001",
                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 messageIdParserVerifier1 = new Verifier()
            {
                Component = new EntityHeader()
                {
                    Id   = planner.MessageTypeIdParsers.First().Id,
                    Text = planner.MessageTypeIdParsers.First().Name
                },
                ExpectedOutput     = "smplmsg001",
                InputType          = EntityHeader <InputTypes> .Create(InputTypes.Text),
                Name               = "Finds Message id in Header",
                Key                = "explmotmsgidinpath",
                Description        = "Validates that the message id can be extracted from the path",
                PathAndQueryString = "/api/smplmsg001/dev001",
                ShouldSucceed      = true,
                VerifierType       = EntityHeader <VerifierTypes> .Create(VerifierTypes.MessageFieldParser)
            };

            AddId(messageIdParserVerifier1);
            AddOwnedProperties(messageIdParserVerifier1, org);
            AddAuditProperties(messageIdParserVerifier1, createTimestamp, org, user);
            await _verifierMgr.AddVerifierAsync(messageIdParserVerifier1, org, user);

            return(planner);
        }
 public Task <InvokeResult> UpdatePlannerConfigurationAsync([FromBody] PlannerConfiguration plannerConfiguration)
 {
     return(_pipelineModuleManager.UpdatePlannerConfigurationAsync(plannerConfiguration, OrgEntityHeader, UserEntityHeader));
 }
Пример #6
0
 public PlannerMovementBehavior(PlannerConfiguration plannerConfiguration)
 {
     this.plannerConfiguration = plannerConfiguration;
 }
Пример #7
0
        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));
        }