Пример #1
0
        public async Task <InvokeResult> AddDeviceWorkflowAsync(DeviceWorkflow deviceWorkflow, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(deviceWorkflow, AuthorizeResult.AuthorizeActions.Create, user, org);

            ValidationCheck(deviceWorkflow, Actions.Create);
            await _deviceWorkflowRepo.AddDeviceWorkflowAsync(deviceWorkflow);

            return(InvokeResult.Success);
        }
Пример #2
0
        public async Task <InvokeResult> UpdateDeviceWorkflowAsync(DeviceWorkflow deviceWorkflow, EntityHeader org, EntityHeader user)
        {
            await AuthorizeAsync(deviceWorkflow, AuthorizeResult.AuthorizeActions.Update, user, org);

            ValidationCheck(deviceWorkflow, Actions.Update);
            deviceWorkflow.LastUpdatedBy   = user;
            deviceWorkflow.LastUpdatedDate = DateTime.Now.ToJSONString();
            await _deviceWorkflowRepo.UpdateDeviceWorkflowAsync(deviceWorkflow);

            return(InvokeResult.Success);
        }
Пример #3
0
        protected DeviceWorkflow GetWorkflow(string name = "wf1", string key = "wf1")
        {
            var workflow = new DeviceWorkflow();

            workflow.Name = name;
            workflow.Key  = key;
            SetAuditParams(workflow);
            workflow.OutputCommands.Add(GetOutputCommand());
            workflow.Inputs.Add(GetInput());

            return(workflow);
        }
        public void Init()
        {
            _messageDefinition = GetDeviceMessage();
            _deviceWorkflow    = GetWorkflow();
            _moduleConfig      = new RouteModuleConfig
            {
                PrimaryOutput = new RouteConnection()
            };
            RefreshMapping();

            _outputTranslatorConfig = new OutputTranslatorConfiguration()
            {
                Key = "key1"
            };
        }
        protected DeviceWorkflow GetDeviceWorkflow()
        {
            var workflow = new DeviceWorkflow()
            {
                Id           = Guid.NewGuid().ToId(),
                Key          = "workflow123",
                Name         = "My First Workflow",
                CreatedBy    = EntityHeader.Create(Guid.NewGuid().ToId(), "NAME"),
                CreationDate = DateTime.UtcNow.ToJSONString()
            };

            workflow.LastUpdatedBy   = workflow.CreatedBy;
            workflow.LastUpdatedDate = workflow.CreationDate;

            return(workflow);
        }
        /// <summary>
        /// Assert the record is invalid.
        /// </summary>
        /// <param name="workflow"></param>
        /// <param name="errorCount">Expected number of errors</param>
        /// <param name="warningCount">Expected number of warnings</param>
        protected void AssertIsInValid(DeviceWorkflow workflow, int errorCount = 1, int warningCount = 0)
        {
            var result = Validator.Validate(workflow);

            AssertIsInValid(result, errorCount, warningCount);
        }
        protected void AssertIsValid(DeviceWorkflow workflow)
        {
            var result = Validator.Validate(workflow);

            AssertIsValid(result);
        }
Пример #8
0
 public Task <InvokeResult> UpdateDeviceWorkflowAsync([FromBody] DeviceWorkflow workflow)
 {
     SetUpdatedProperties(workflow);
     return(_deviceAdminManager.UpdateDeviceWorkflowAsync(workflow, OrgEntityHeader, UserEntityHeader));
 }
Пример #9
0
 public Task <InvokeResult> AddDeviceWorkflowAsync([FromBody] DeviceWorkflow deviceWorkflow)
 {
     return(_deviceAdminManager.AddDeviceWorkflowAsync(deviceWorkflow, OrgEntityHeader, UserEntityHeader));
 }
Пример #10
0
        public async Task <DeviceWorkflow> AddDeviceWorkflow(String name, string key, EntityHeader org, EntityHeader user, DateTime createTimestamp)
        {
            await _storageUtils.DeleteIfExistsAsync <DeviceWorkflow>(key, org);

            var appUser = await _userManager.FindByIdAsync(user.Id);

            var wf = new DeviceWorkflow()
            {
                Id   = Guid.NewGuid().ToId(),
                Name = name,
                Key  = key,
            };

            wf.Pages.Add(new Page()
            {
                PageNumber = 1,
                Name       = DeviceLibraryResources.Common_PageNumberOne
            });

            var attr = new DeviceAdmin.Models.Attribute()
            {
                Name = "Motion Status",
                Key  = "motionstatus",
            };

            attr.AttributeType = EntityHeader <ParameterTypes> .Create(ParameterTypes.String);

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

            attr.IncomingConnections.Add(new Connection()
            {
                NodeKey  = "motionstatus",
                NodeName = "Motion Status",
                NodeType = "workflowinput"
            });

            attr.OnSetScript = @"/* 
 * Provide a script to customize setting an attribute:
 *
 * The default setter method for the Motion Status attribute is:
 * 
 *     Attributes.motionstatus = value;
 *
 * If you do not provide a script, the attribute will be
 * set automatically, if a script is present, you will be
 * responsible for taking the value as an input parameter
 * and making the assignment.  
 * 
 * You can add conditional logic so that the attribute will
 * not get set.
 */
function onSet(value /* String */) {    
    let phoneNumber = '" + appUser.PhoneNumber + @"';
    Attributes.motionstatus = value;
    if(value === 'True'){
        sendSMS(phoneNumber, 'Motion detected on ' + IoTDevice.name);
    } 
    else {
        sendSMS(phoneNumber, 'Motion cleared on ' + IoTDevice.name);
    }
};";

            attr.DiagramLocations.Add(new DiagramLocation()
            {
                Page = 1,
                X    = 120,
                Y    = 120,
            });

            var input = new DeviceAdmin.Models.WorkflowInput()
            {
                Name = "Motion Status",
                Key  = "motionstatus",
            };

            input.InputType = EntityHeader <ParameterTypes> .Create(ParameterTypes.String);

            input.OutgoingConnections.Add(new Connection()
            {
                NodeKey  = "motionstatus",
                NodeName = "Motion Status",
                NodeType = "attribute"
            });

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

            input.DiagramLocations.Add(new DiagramLocation()
            {
                Page = 1,
                X    = 20,
                Y    = 20,
            });

            wf.Attributes.Add(attr);
            wf.Inputs.Add(input);

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

            await this._deviceAdminMgr.AddDeviceWorkflowAsync(wf, org, user);


            return(wf);
        }
Пример #11
0
        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);
        }
Пример #12
0
        public async Task <InvokeResult <DeviceWorkflow> > LoadFullDeviceWorkflowAsync(string id, EntityHeader org, EntityHeader user)
        {
            DeviceWorkflow deviceWorkflow = null;

            try
            {
                deviceWorkflow = await _deviceWorkflowRepo.GetDeviceWorkflowAsync(id);
            }
            catch (RecordNotFoundException)
            {
                return(InvokeResult <DeviceWorkflow> .FromErrors(ErrorCodes.CouldNotLoadDeviceWorkflow.ToErrorMessage($"WorkflowId={id}")));
            }

            if (deviceWorkflow.Attributes == null)
            {
                deviceWorkflow.Attributes = new List <Models.Attribute>();
            }
            if (deviceWorkflow.Inputs == null)
            {
                deviceWorkflow.Inputs = new List <WorkflowInput>();
            }

            var result = new InvokeResult <DeviceWorkflow>();

            foreach (var attribute in deviceWorkflow.Attributes)
            {
                if (attribute.AttributeType != null && attribute.AttributeType.Value == ParameterTypes.ValueWithUnit)
                {
                    /* Will catch validation errors later, so just try to load */
                    if (!EntityHeader.IsNullOrEmpty(attribute.UnitSet))
                    {
                        try
                        {
                            attribute.UnitSet.Value = await GetAttributeUnitSetAsync(attribute.UnitSet.Id, org, user);
                        }
                        catch (RecordNotFoundException)
                        {
                            result.Errors.Add(ErrorCodes.CouldNotLoadUnitSet.ToErrorMessage($"AttributeId={attribute.Id},UnitSetId={attribute.UnitSet.Id}"));
                        }
                    }
                }

                if (!EntityHeader.IsNullOrEmpty(attribute.StateSet))
                {
                    try
                    {
                        attribute.StateSet.Value = await GetStateSetAsync(attribute.StateSet.Id, org, user);
                    }
                    catch (RecordNotFoundException)
                    {
                        result.Errors.Add(ErrorCodes.CouldNotLoadStateSet.ToErrorMessage($"AttributeId={attribute.Id},StateSetId={attribute.StateSet.Id}"));
                    }
                }
            }

            foreach (var input in deviceWorkflow.Inputs)
            {
                if (!EntityHeader.IsNullOrEmpty(input.UnitSet))
                {
                    try
                    {
                        input.UnitSet.Value = await GetAttributeUnitSetAsync(input.UnitSet.Id, org, user);
                    }
                    catch (RecordNotFoundException)
                    {
                        result.Errors.Add(ErrorCodes.CouldNotLoadUnitSet.ToErrorMessage($"InputId={input.Id},UnitSetId={input.UnitSet.Id}"));
                    }
                }

                if (!EntityHeader.IsNullOrEmpty(input.StateSet))
                {
                    try
                    {
                        input.StateSet.Value = await GetStateSetAsync(input.StateSet.Id, org, user);
                    }
                    catch (RecordNotFoundException)
                    {
                        result.Errors.Add(ErrorCodes.CouldNotLoadStateSet.ToErrorMessage($"InputId={input.Id},StateSetId={input.StateSet.Id}"));
                    }
                }
            }

            foreach (var inputCommand in deviceWorkflow.InputCommands)
            {
                if (inputCommand.Parameters != null)
                {
                    foreach (var param in inputCommand.Parameters)
                    {
                        if (param.ParameterType.Value == ParameterTypes.State)
                        {
                            param.StateSet.Value = await _stateSetRepo.GetStateSetAsync(param.StateSet.Id);
                        }
                    }
                }
            }

            if (result.Successful)
            {
                return(InvokeResult <DeviceWorkflow> .Create(deviceWorkflow));
            }

            return(result);
        }
Пример #13
0
        public void InputTranslatorToWorkflowValidation(ValidationResult result, DeviceMessageDefinition message, DeviceWorkflow workflow)
        {
            if (PrimaryOutput != null)
            {
                if (PrimaryOutput.Mappings == null)
                {
                    PrimaryOutput.Mappings = new List <KeyValuePair <string, object> >();
                }

                foreach (var mapping in PrimaryOutput.Mappings)
                {
                    var mapResult = new ValidationResult();

                    var fieldKey = mapping.Key;
                    if (mapping.Value == null)
                    {
                        mapResult.AddUserError($"Missing Input Key for mapping on work flow {workflow.Name} for input mapping.");
                    }
                    else
                    {
                        var inputKey = mapping.Value.ToString();
                        if (String.IsNullOrEmpty(inputKey))
                        {
                            mapResult.AddUserError($"Missing Input Key for mapping on work flow {workflow.Name} for input mapping.");
                        }

                        if (String.IsNullOrEmpty(fieldKey))
                        {
                            mapResult.AddUserError($"Missing Message Field Key for mapping on work flow {workflow.Name} for input mapping.");
                        }

                        if (mapResult.Successful)
                        {
                            var input = workflow.Inputs.Where(inp => inp.Key == inputKey).FirstOrDefault();
                            var field = message.Fields.Where(fld => fld.Key == fieldKey).FirstOrDefault();

                            if (input == null)
                            {
                                mapResult.AddUserError($"Could not find input {inputKey} on workflow {workflow.Name}");
                            }

                            if (field == null)
                            {
                                mapResult.AddUserError($"Could not find field {fieldKey} on message {message.Name} on workflow {workflow.Name} for input mapping.");
                            }

                            if (field != null && input != null)
                            {
                                if (EntityHeader.IsNullOrEmpty(field.StorageType))
                                {
                                    mapResult.AddUserError($"On field {field.Name} for message {message.Name} storage type is empty.");
                                }
                                else if (EntityHeader.IsNullOrEmpty(input.InputType))
                                {
                                    mapResult.AddUserError($"On input {field.Name} for workflow {workflow.Name} storage type is empty.");
                                }
                                else
                                {
                                    if (field.StorageType.Id != input.InputType.Id)
                                    {
                                        mapResult.AddUserError($"On Mapping for field {field.Name} for message {message.Name} and input {input.Name} type mismatch, {field.StorageType.Text} can not be mapped to {input.InputType.Text}.");
                                    }
                                    else if (field.StorageType.Value == ParameterTypes.State)
                                    {
                                        if (EntityHeader.IsNullOrEmpty(field.StateSet))
                                        {
                                            result.AddUserError($"State Set Not provided on Message {message.Name}, Field {field.Name}.");
                                        }
                                        else if (EntityHeader.IsNullOrEmpty(input.StateSet))
                                        {
                                            result.AddUserError($"State Set Not provided on Input {input.Name}, for work flow {workflow.Name}");
                                        }
                                        else if (field.StateSet.Id != input.StateSet.Id)
                                        {
                                            result.AddUserError($"State Set are different on mapping between Message Field {message.Name}/{field.Name} and input {input.Name} on workflow {workflow.Name} (Field={field.StateSet.Text}, Input={input.StateSet.Text}).");
                                        }
                                    }
                                    else if (field.StorageType.Value == ParameterTypes.ValueWithUnit)
                                    {
                                        if (EntityHeader.IsNullOrEmpty(field.UnitSet))
                                        {
                                            result.AddUserError($"Unit Set Not provided on Message {message.Name}, Field {field.Name}.");
                                        }
                                        else if (EntityHeader.IsNullOrEmpty(input.UnitSet))
                                        {
                                            result.AddUserError($"Unit Set Not provided on Input {input.Name}, for work flow {workflow.Name}");
                                        }
                                        else if (field.UnitSet.Id != input.UnitSet.Id)
                                        {
                                            result.AddUserError($"Units Set are different on mapping between message {message.Name}/{field.Name} and input {input.Name} on workflow {workflow.Name} (Field={field.UnitSet.Text}, Input={input.UnitSet.Text}).");
                                        }
                                    }
                                }
                            }
                        }

                        result.Concat(mapResult);
                    }
                }
            }
        }
Пример #14
0
        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}"));
                    }
                }
            }
        }
Пример #15
0
 public void Init()
 {
     _messageDefinition = GetDeviceMessage();
     _deviceWorkflow    = GetWorkflow();
 }
Пример #16
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));
        }