private IEnumerable<DeviceBlueprint> Load(string manifest) { JToken root = JsonConvert.DeserializeObject(manifest) as JToken; var globalSettingsToken = root["globalSettings"]; if (globalSettingsToken != null) { GlobalSettings.Instance.Load(globalSettingsToken); } var devices = new List<DeviceBlueprint>(); var groups = root["deviceGroups"] as JArray; foreach (var group in groups) { var name = group.Value<string>("name"); var jobs = group["jobs"] as JArray; var template = new DeviceTemplate(name, jobs); var deviceCredentials = group["devices"] as JArray; foreach (var deviceCredential in deviceCredentials) { var deviceId = deviceCredential.Value<string>("deviceId"); var deviceSecret = deviceCredential.Value<string>("deviceSecret"); var device = new DeviceBlueprint(deviceId, deviceSecret, template); devices.Add(device); } } return devices; }
public void Start(DeviceBlueprint blueprint) { DeviceId = blueprint.DeviceId; DeviceSecret = blueprint.DeviceSecret; Trace.TraceInformation(string.Format(CultureInfo.InvariantCulture, "Device {0} status = Booting", DeviceId)); var tasks = new List<Task>(); foreach (var job in blueprint.Template.Jobs) { try { //Instance filters var sourceFilter = ActivatorExternsion.CreateInstance<ISource>(job.Source.Type); sourceFilter.Initialize(job.Source.Parameters, this); //Chris Han - try to inject DeviceId //Newtonsoft.Json.Linq.JObject did = (Newtonsoft.Json.Linq.JObject)job.Source.Parameters;//.Value<Newtonsoft.Json.Linq.JToken>("DeviceId"); //var p = did["parameters"]["DeviceId"]; //var k = DeviceId; sourceFilter.Initialize(job.Source.Parameters, this); var intermediaFilters = job.Intermedias.Select(f => { var filter = ActivatorExternsion.CreateInstance<IIntermedia>(f.Type); filter.Initialize(f.Parameters, this); return filter; }); var sinkFilter = ActivatorExternsion.CreateInstance<ISink>(job.Sink.Type); sinkFilter.Initialize(job.Sink.Parameters, this); //Kick-off the Job. Record the task object for checking while they were stopped tasks.Add(JobEntry(job.Name, job.Interval, sourceFilter, intermediaFilters, sinkFilter, _source.Token)); } catch (TypeLoadException ex) { Trace.TraceError(string.Format(CultureInfo.InvariantCulture, "Failed to start device {0} due to exception {1}", DeviceId, ex.ToString())); } } _runningTasks = tasks.ToArray(); Trace.TraceInformation(string.Format(CultureInfo.InvariantCulture, "Device {0} status = Running", DeviceId)); }
public void ClearSelectedDeviceBlueprint() { deviceToBuild = null; }
public void SelectDeviceToBuild(DeviceBlueprint device) { deviceToBuild = device; }