public SimulatorRuntime(ISimulatorRuntimeServices runtimeService, INotificationPublisher notificationPublisher, IAdminLogger adminLogger, LagoVista.IoT.Simulator.Admin.Models.SimulatorInstance instance)
        {
            _runtimeService = runtimeService;
            _instance       = instance;

            _notificationPublisher = notificationPublisher;
            _connected             = DateTime.UtcNow;
            _lastAccess            = _connected;

            _simulator = instance.Simulator.Value;

            _adminLogger = adminLogger;

            InstanceId = Guid.NewGuid().ToId();

            SetState("default");
        }
Exemplo n.º 2
0
        public async Task <LagoVista.IoT.Simulator.Admin.Models.Simulator> CreateSimulator(DeploymentInstance instance, Device device, string name, string key,
                                                                                           EntityHeader org, EntityHeader user, DateTime createTimestamp)
        {
            await _storageUtils.DeleteIfExistsAsync <LagoVista.IoT.Simulator.Admin.Models.Simulator>(key, org);

            var sim = new LagoVista.IoT.Simulator.Admin.Models.Simulator()
            {
                Name = name,
                Key  = key,
            };

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

            sim.DefaultEndPoint    = instance.DnsHostName;
            sim.DefaultPort        = 80;
            sim.Anonymous          = true;
            sim.BasicAuth          = false;
            sim.DefaultPayloadType = EntityHeader <PaylodTypes> .Create(PaylodTypes.String);

            sim.DefaultTransport = EntityHeader <Simulator.Admin.Models.TransportTypes> .Create(Simulator.Admin.Models.TransportTypes.RestHttp);

            sim.DeviceId    = device.DeviceId;
            sim.Description = "This simulator is created as part of the Motion Tutorial, it will demonstrate how to send two messages, one that indicates motion has been seen and one that motion is no longer active.";

            var motionMessage = new MessageTemplate()
            {
                ContentType        = "application/json",
                HttpVerb           = "POST",
                PayloadType        = EntityHeader <PaylodTypes> .Create(PaylodTypes.String),
                Name               = "Motion Detected",
                Key                = "motiondetected",
                Id                 = Guid.NewGuid().ToId(),
                TextPayload        = "{'motion':true}",
                PathAndQueryString = "/api/motion/~deviceid~",
                EndPoint           = sim.DefaultEndPoint,
                Transport          = EntityHeader <TransportTypes> .Create(TransportTypes.RestHttp),
            };

            var motionClearedMessage = new MessageTemplate()
            {
                ContentType        = "application/json",
                HttpVerb           = "POST",
                PayloadType        = EntityHeader <PaylodTypes> .Create(PaylodTypes.String),
                Name               = "Motion Cleared",
                Key                = "motioncleared",
                Id                 = Guid.NewGuid().ToId(),
                TextPayload        = "{'motion':false}",
                EndPoint           = sim.DefaultEndPoint,
                PathAndQueryString = "/api/motion/~deviceid~",
                Transport          = EntityHeader <TransportTypes> .Create(TransportTypes.RestHttp),
            };

            sim.MessageTemplates.Add(motionMessage);
            sim.MessageTemplates.Add(motionClearedMessage);

            await this._simulatorMgr.AddSimulatorAsync(sim, org, user);

            return(sim);
        }