Beispiel #1
0
        /// <summary>
        /// Checks to see if the specified field is updatable.
        /// </summary>
        /// <param name="field">The field to inspect.</param>
        /// <returns>True if updatable, false if otherwise.</returns>
        private bool IsUserCounterUpdatable(IDeviceField field)
        {
            if (field == null)
            {
                return(false);
            }

            // The *Account,*Total files indicate they are writable, but older firmware will throw a MANAGEMENT_BAD_OBJECT_ID.
            // These fields are NOT writable even though the capability may indicate otherwise.
            return(field.Type.IsNumeric() &&
                   !(field.Name ?? String.Empty).EndsWith("Account", StringComparison.CurrentCultureIgnoreCase) &&
                   !(field.Name ?? String.Empty).EndsWith("Total", StringComparison.CurrentCultureIgnoreCase));
        }
Beispiel #2
0
        /// <summary>
        /// Converts the raw device field into an external field object for consumption by the service.
        /// </summary>
        /// <param name="field">The raw device field to convert.</param>
        /// <returns>The converted ICounter value if valid; otherwise returns null.</returns>
        public static field ToField(this IDeviceField field)
        {
            if (field == null)
            {
                return(null);
            }

            return(new field()
            {
                name = field.Name,
                type = field.GetExternalType(),
                value = field.GetExternalValue()
            });
        }
Beispiel #3
0
        /// <summary>
        /// Check to see if any of the boolean <see cref="IDeviceField"/> values are true that match the specified name.
        /// </summary>
        /// <param name="fields">The fields to search.</param>
        /// <param name="names">The names of the <see cref="IDeviceField" /> to check.</param>
        /// <returns>True if any of the boolean values are true, false if otherwise, null if none of the specified names exist.</returns>
        public static bool?Any(this IEnumerable <IDeviceField> fields, IEnumerable <string> names)
        {
            if (fields == null)
            {
                return(false);
            }

            IDeviceField <bool> result = Get <bool>(fields, (f) => names.Any(n => String.Equals(f.Name, n, StringComparison.CurrentCultureIgnoreCase))).FirstOrDefault();

            if (result == null)
            {
                return(null);
            }
            return(result.Value);
        }
Beispiel #4
0
        /// <summary>
        /// Add the specified field item to the list of field. Null field items are ignored.
        /// </summary>
        /// <param name="field">The field to add. If null, then the field is ignored.</param>
        protected virtual void Add(IDeviceField field)
        {
            if (field == null)
            {
                return;
            }

            lock (_mutex) {
                if (_fields == null)
                {
                    _fields = new List <IDeviceField>();
                }
                _fields.Add(field);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Retrieve the specified field value.
        /// </summary>
        /// <param name="fields">The field to search.</param>
        /// <param name="filter">The custom filter to use to search.</param>
        /// <param name="defaultValue">The default value to use if the specified tag is not found.</param>
        /// <returns>The value of the specified counter. If not specified, then 0 is returned.</returns>
        public static T GetValue <T>(this IEnumerable <IDeviceField> fields, Func <IDeviceField, bool> filter, T defaultValue = default(T))
        {
            IDeviceField <T> f = Get <T>(fields, filter).FirstOrDefault();

            return(f != null ? f.Value : defaultValue);
        }
Beispiel #6
0
        /// <summary>
        /// Retrieve the specified field value.
        /// </summary>
        /// <param name="fields">The field to search.</param>
        /// <param name="name">The name of the <see cref="IDeviceField" /> to find.</param>
        /// <param name="defaultValue">The default value to use if the specified tag is not found.</param>
        /// <returns>The value of the specified counter. If not specified, then 0 is returned.</returns>
        public static T GetValue <T>(this IEnumerable <IDeviceField> fields, string name, T defaultValue = default(T))
        {
            IDeviceField <T> f = Get <T>(fields, name);

            return(f != null ? f.Value : defaultValue);
        }