Registrar for various types of descriptors
Esempio n. 1
0
 /// <summary>
 /// Creates an identical copy of this registrar
 /// </summary>
 /// <returns>The cloned instance</returns>
 public DescriptorRegistrar Clone()
 {
     var clone = new DescriptorRegistrar();
     foreach(var kv in this._registrations)
     {
         clone._registrations.Add(kv.Key, kv.Value);
     }
     clone._defaultRegistration = this._defaultRegistration;
     return clone;
 }
Esempio n. 2
0
        /// <summary>
        /// Creates an identical copy of this registrar
        /// </summary>
        /// <returns>The cloned instance</returns>
        public DescriptorRegistrar Clone()
        {
            var clone = new DescriptorRegistrar();

            foreach (var kv in this._registrations)
            {
                clone._registrations.Add(kv.Key, kv.Value);
            }
            clone._defaultRegistration = this._defaultRegistration;
            return(clone);
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="registrar">The registrar of descriptor types</param>
        /// <param name="query">The descriptor query</param>
        /// <returns>The descriptors that match the query</returns>
        public List<ObjectInfo> Execute(DescriptorRegistrar registrar, DescriptorQuery query)
        {
            List<ObjectInfo> ret = new List<ObjectInfo>();

            lock(this)
            {
                _deviceInstance.Value = query.DeviceInstance;
                _objectType.Value = query.ObjectType;

                using (var reader = _command.ExecuteReader())
                {
                    int deviceInstanceOrdinal = reader.GetOrdinal("device_instance");
                    int objectTypeOrdinal = reader.GetOrdinal("object_type");
                    int instanceOrdinal = reader.GetOrdinal("instance");
                    int vendorIdOrdinal = reader.GetOrdinal("vendor_id");
                    int nameOrdinal = reader.GetOrdinal("name");
                    int propsOrdinal = reader.GetOrdinal("props");

                    while (reader.Read())
                    {
                        uint deviceInstance = (uint)reader.GetInt32(deviceInstanceOrdinal);
                        ushort objectType = (ushort)reader.GetInt32(objectTypeOrdinal);
                        uint instance = (uint)reader.GetInt32(instanceOrdinal);
                        ushort vendorId = (ushort)reader.GetInt32(vendorIdOrdinal);
                        string name = reader.IsDBNull(nameOrdinal) ? null :  reader.GetString(nameOrdinal);

                        if (query.NameRegex == null || (name != null && Regex.IsMatch(name, query.NameRegex, RegexOptions.IgnoreCase)))
                        {
                            var info = registrar.CreateDescriptor(
                                vendorId,
                                deviceInstance,
                                new ObjectId(objectType, instance));
                            info.Name = name;

                            if (!reader.IsDBNull(propsOrdinal))
                            {
                                var props = reader.GetString(propsOrdinal);
                                info.LoadProperties(props);
                            }

                            ret.Add(info);
                        }
                    }
                }
            }

            return ret;
        }
Esempio n. 4
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="registrar">The registrar of descriptor types</param>
        /// <param name="deviceInstance">The device instance of the object to get</param>
        /// <param name="objectIdentifier">The object identifier of the object to get</param>
        /// <returns>The descriptors that match the query</returns>
        public ObjectInfo Execute(DescriptorRegistrar registrar, uint deviceInstance, ObjectId objectIdentifier)
        {
            ObjectInfo info = null;

            lock (this)
            {
                _deviceInstance.Value = deviceInstance;
                _objectType.Value = objectIdentifier.Type;
                _instance.Value = objectIdentifier.Instance;

                using (var reader = _command.ExecuteReader())
                {
                    int vendorIdOrdinal = reader.GetOrdinal("vendor_id");
                    int nameOrdinal = reader.GetOrdinal("name");
                    int propsOrdinal = reader.GetOrdinal("props");

                    if (reader.Read())
                    {
                        ushort vendorId = (ushort)reader.GetInt32(vendorIdOrdinal);
                        string name = reader.IsDBNull(nameOrdinal) ? null : reader.GetString(nameOrdinal);

                        info = registrar.CreateDescriptor(
                                vendorId,
                                deviceInstance,
                                objectIdentifier);
                        info.Name = name;

                        if (!reader.IsDBNull(propsOrdinal))
                        {
                            var props = reader.GetString(propsOrdinal);
                            info.LoadProperties(props);
                        }
                    }
                }
            }

            return info;
        }