Ejemplo n.º 1
0
        /// <summary>
        /// Create streamer collection by given device params.
        /// </summary>
        public static StreamerCollection CreateStreamerCollection(IEnumerable <DeviceType> deviceTypes, IDictionary <DeviceType, IDevice> devices, IClock clock,
                                                                  out IDictionary <DeviceType, IStreamer> deviceStreamers)
        {
            deviceStreamers = new Dictionary <DeviceType, IStreamer>();
            var streamers = new StreamerCollection();

            foreach (var deviceType in deviceTypes)
            {
                // ReSharper disable once RedundantAssignment
                if (!devices.TryGetValue(deviceType, out var instance))
                {
                    instance = null;
                }
                if (deviceType.StreamerFactory == null)
                {
                    continue;
                }
                if (deviceType.StreamerFactory.IsDeviceDependent && instance == null)
                {
                    continue;
                }
                var streamer = deviceType.StreamerFactory.Create(instance, clock);
                System.Diagnostics.Debug.Assert(streamer != null);
                streamers.Add(deviceStreamers[deviceType] = streamer);
            }
            if (!deviceStreamers.TryGetValue(MarkerSourceDeviceType, out _))
            {
                streamers.Add(deviceStreamers[MarkerSourceDeviceType] = new MarkerStreamer(null, clock));
            }
            return(streamers);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create streamer collection by given device params.
        /// </summary>
        public static StreamerCollection CreateStreamerCollection(IDictionary <string, DeviceParams> devices, IClock clock,
                                                                  out IDictionary <DeviceType, IStreamer> deviceStreamers)
        {
            deviceStreamers = new Dictionary <DeviceType, IStreamer>();
            var streamers = new StreamerCollection();

            streamers.Add(new MarkerStreamer(clock));
            foreach (var deviceType in App.Instance.Registries.Registry <PluginDeviceType>().Registered)
            {
                if (!devices.TryGetValue(deviceType.DeviceType.Name, out var entity) || entity.Device.Id == null)
                {
                    continue;
                }
                if (!App.Instance.Registries.Registry <PluginDevice>().LookUp(entity.Device.Id, out var device))
                {
                    throw new ArgumentException($"Cannot find device by id: {entity.Device.Id}");
                }
                var deviceInstance = device.NewInstance(device.DeserializeParams(entity.Device.Params));
                var streamer       = device.Factory.DeviceType.StreamerFactory?.Create(deviceInstance, clock);
                if (streamer != null)
                {
                    streamers.Add(deviceStreamers[deviceType.DeviceType] = streamer);
                }
            }
            return(streamers);
        }