示例#1
0
        protected override string GetParameterName(Enum property, PropertyCache cache)
        {
            //Underscore between property name and channelId is inserted by GetObjectPropertyNameViaCache
            var str = ObjectPropertyParser.GetObjectPropertyNameViaCache(property, cache);

            return($"{str}{channelId}");
        }
示例#2
0
        private string GetParameterActionDescription(params ObjectProperty[] additionalParameters)
        {
            var items = new List <string>();

            foreach (var prop in modifiedSensorParameters
                     .Where(c => !additionalParameters.Any(p => p.ToString() == c.Item1)) //Exclude any additionalParameters; we'll print them specially below
                     .OrderBy(c => c.Item1 != nameof(NewObjectParameters.Name)))          //Ensure property "Name" comes first (if applicable)
            {
                var val = prop.Item2.IsIEnumerable() ? string.Join(", ", prop.Item2.ToIEnumerable()) : prop.Item2?.ToString();

                items.Add($"{prop.Item1} = '{val}'");
            }

            foreach (var param in additionalParameters)
            {
                var name = ObjectPropertyParser.GetObjectPropertyName(param);

                var val = ParametersInternal.GetCustomParameterInternal(name)?.ToString();

                if (val?.Contains("\n") == true)
                {
                    items.Add($"{param} =\n\n{val}\n\n");
                }
                else
                {
                    items.Add($"{param} = '{val}'");
                }
            }

            return(MyInvocation.MyCommand.Name + ": " + string.Join(", ", items));
        }
示例#3
0
        private object DeserializeObjectPropertyInternal(Enum property, string rawValue)
        {
            var cache   = ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property);
            var rawName = ObjectPropertyParser.GetObjectPropertyNameViaCache(property, cache);

            return(XmlReflectionSerializerImpl.DeserializeRawPropertyValue(property, rawName, rawValue));
        }
示例#4
0
        private string GetSetObjectPropertyResponse(string address)
        {
            var queries = UrlUtilities.CrackUrl(address);

            PropertyCache cache;

            if (typeof(TObjectProperty) == typeof(ObjectProperty))
            {
                cache = ObjectPropertyParser.GetPropertyInfoViaTypeLookup((Enum)(object)property);
            }
            else if (typeof(TObjectProperty) == typeof(ChannelProperty))
            {
                cache = ObjectPropertyParser.GetPropertyInfoViaPropertyParameter <Channel>((Enum)(object)property);
            }
            else
            {
                throw new NotImplementedException($"Handler for object property type {nameof(TObjectProperty)} is not implemented");
            }

            var queryName = ObjectPropertyParser.GetObjectPropertyNameViaCache((Enum)(object)property, cache);

            if (typeof(TObjectProperty) == typeof(ChannelProperty))
            {
                queryName += "1"; //Channel ID used for tests
            }
            var val = queries[queryName];

            Assert.IsTrue(val == expectedValue, $"The value of property '{property.ToString().ToLower()}' did not match the expected value. Expected '{expectedValue}', received: '{val}'");

            return("OK");
        }
示例#5
0
        private void TestDeserialization(FakeObjectProperty property, object value, object expected)
        {
            var parser = new DynamicPropertyTypeParser(property, ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property), value);

            var result = parser.DeserializeValue();

            Assert.AreEqual(expected, result);
        }
示例#6
0
        private void ExecuteWithTypeLookupInternal(FakeObjectProperty property, object value, params string[] expected)
        {
            var parameters = new FakeSetObjectPropertyParameters(e => ObjectPropertyParser.GetPropertyInfoViaTypeLookup(e));

            parameters.AddValue(property, value, true);

            AssertEx.AreEqualLists(parameters.CustomParameters.Select(p => p.ToString()).ToList(), expected.ToList(), "Parameter lists were not equal");
        }
        public string GetFactorParameterName(Enum property, PropertyCache cache)
        {
            var str = ObjectPropertyParser.GetObjectPropertyNameViaCache(property, cache);

            str = str.Replace("_factor", $"_{channelId}_factor");

            return(str);
        }
        public void AddPropertyToDictionary_ValueIsNull_PropertyIsNotAdded()
        {
            PropertyInfo                property   = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.EventLimit));
            FullCalendarParameters      parameters = new FullCalendarParameters();
            ObjectPropertyParser        parser     = new ObjectPropertyParser(property, null);
            Dictionary <string, string> target     = new Dictionary <string, string>();

            parser.AddPropertyToDictionary(parameters, ref target);
            target.Should().BeEmpty();
        }
示例#9
0
        /// <summary>
        /// Retrieves an object that defines the dynamic parameters of this cmdlet.
        /// </summary>
        /// <returns>An object that defines the dynamic parameters of this cmdlet.</returns>
        public object GetDynamicParameters()
        {
            if (dynamicParams == null)
                dynamicParams = new PropertyDynamicParameterSet<ObjectProperty>(
                    new[] {ParameterSet.Dynamic, ParameterSet.DynamicManual },
                    e => ObjectPropertyParser.GetPropertyInfoViaTypeLookup(e).Property.PropertyType
                );

            return dynamicParams.Parameters;
        }
        protected BaseSetObjectPropertyParameters(int[] ids)
        {
            if (ids != null && ids.Length > 0)
            {
                ObjectIdsInternal = ids.Distinct().ToArray();
            }

            CustomParameters = new List <CustomParameter>();
            parser           = new ObjectPropertyParser(this, this, GetParameterName);
        }
示例#11
0
        internal NewObjectParameters(string objectName)
        {
            if (string.IsNullOrEmpty(objectName))
            {
                throw new ArgumentException($"{nameof(objectName)} cannot be null or empty", nameof(objectName));
            }

            parser = new ObjectPropertyParser(this, this, ObjectPropertyParser.GetObjectPropertyNameViaCache);

            Name = objectName;
        }
示例#12
0
        /// <summary>
        /// Retrieves an object that defines the dynamic parameters of this cmdlet.
        /// </summary>
        /// <returns>An object that defines the dynamic parameters of this cmdlet.</returns>
        public object GetDynamicParameters()
        {
            if (dynamicParams == null)
            {
                dynamicParams = new DynamicParameterSet <ObjectProperty>(
                    ParameterSet.Dynamic,
                    e => ObjectPropertyParser.GetPropertyInfoViaTypeLookup(e).Property
                    );
            }

            return(dynamicParams.Parameters);
        }
示例#13
0
        /// <summary>
        /// Retrieves an object that defines the dynamic parameters of this cmdlet.
        /// </summary>
        /// <returns>An object that defines the dynamic parameters of this cmdlet.</returns>
        public object GetDynamicParameters()
        {
            if (dynamicParams == null)
            {
                dynamicParams = new DynamicParameterSet <ChannelProperty>(
                    new[] { ParameterSet.Dynamic, ParameterSet.DynamicManual },
                    e => ObjectPropertyParser.GetPropertyInfoViaPropertyParameter <Channel>(e).Property
                    );
            }

            return(dynamicParams.Parameters);
        }
示例#14
0
        private void WarnSuspiciousPropertyName(string name)
        {
            if (name.EndsWith("_"))
                return;

            var inherited = Enum.GetValues(typeof(ObjectProperty)).Cast<ObjectProperty>().Where(v => v.GetEnumAttribute<LiteralValueAttribute>() != null).ToArray();
            var raw = inherited.Select(i => ObjectPropertyParser.GetObjectPropertyName(i)).ToArray();

            if (raw.Contains(name))
                return;

            WriteWarning($"Property '{name}' does not look correct. If request does not work try with '{name}_' instead. To suppress this message specify -WarningAction SilentlyContinue.");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SetChannelProperty"/> class.
 /// </summary>
 public SetChannelProperty()
 {
     implementation = new InternalSetSubObjectPropertyCmdlet <Channel, ChannelParameter, ChannelProperty>(
         this,
         "Sensor",
         "Channel",
         (p, v) => new ChannelParameter(p, v),
         (c, p) => client.SetChannelProperty(c, p),
         (c, p) => client.SetChannelProperty(c, p),
         (o, s, p) => client.SetChannelProperty(o, s, p),
         e => ObjectPropertyParser.GetPropertyInfoViaPropertyParameter <Channel>(e).Property.PropertyType
         );
 }
        public void AddPropertyToDictionary_ValueIsISerializableObject_PropertyIsAddedAsSerializedObject()
        {
            PropertyInfo           property   = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.DateIncrement));
            FullCalendarParameters parameters = new FullCalendarParameters
            {
                DateIncrement = new Duration
                {
                    Days = 4
                }
            };
            ObjectPropertyParser        parser = new ObjectPropertyParser(property, new JavaScriptSerializer());
            Dictionary <string, string> target = new Dictionary <string, string>();

            parser.AddPropertyToDictionary(parameters, ref target);
            target.Should().Contain("data-fc-DateIncrement", "{'days':4,'weeks':0,'months':0}");
        }
示例#17
0
        internal NewObjectParameters(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name), "An object name cannot be null.");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Name cannot be empty or whitespace.", nameof(name));
            }

            parser = new ObjectPropertyParser(this, this, ObjectPropertyParser.GetObjectPropertyNameViaCache);

            Name = name;
        }
        public void AddPropertyToDictionary_ValueIsNotISerializableObject_PropertyIsAddedAsString()
        {
            PropertyInfo           property   = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.ButtonIcons));
            FullCalendarParameters parameters = new FullCalendarParameters
            {
                ButtonIcons = new
                {
                    prev = "left-single-arrow"
                }
            };
            ObjectPropertyParser        parser = new ObjectPropertyParser(property, new JavaScriptSerializer());
            Dictionary <string, string> target = new Dictionary <string, string>();

            parser.AddPropertyToDictionary(parameters, ref target);
            target.Should().Contain("data-fc-ButtonIcons", "{ prev = left-single-arrow }");
        }
示例#19
0
        private void TestArrayDeserialization(FakeObjectProperty property, object value, object expected)
        {
            var parser = new DynamicPropertyTypeParser(property, ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property), value);

            var result = parser.DeserializeValue();

            if (result == null)
            {
                Assert.AreEqual(expected, result);
            }
            else
            {
                Assert.IsInstanceOfType(expected, typeof(string[]));
                Assert.IsInstanceOfType(result, typeof(string[]));

                AssertEx.AreEqualLists(((string[])expected).ToList(), (((string[])result).ToList()), "Expected and result were not equal");
            }
        }
示例#20
0
        private string GetObjectPropertyName(Enum property, bool forceOriginalName = false)
        {
            var name = ObjectPropertyParser.GetObjectPropertyName(property);

            if (forceOriginalName)
            {
                return(name);
            }

            string realName;

            if (property is ObjectProperty && nameOverrideMap.TryGetValue((ObjectProperty)property, out realName))
            {
                name = realName;
            }

            return(name);
        }
示例#21
0
        internal static T GetObjectProperties <T>(PrtgResponse response, XmlEngine xmlEngine, ObjectProperty mandatoryProperty)
        {
            var xml  = HtmlParser.Default.GetXml(response);
            var xDoc = new XDocument(xml);

            //If the response does not contain the mandatory property, we are executing as a read only user, and
            //should return null

            var name = HtmlParser.DefaultPropertyPrefix + ObjectPropertyParser.GetObjectPropertyName(mandatoryProperty).TrimEnd('_');

            if (xDoc.Descendants(name).ToList().Count > 0)
            {
                var items = xmlEngine.DeserializeObject <T>(xDoc.CreateReader());

                return(items);
            }

            return(default(T));
        }
示例#22
0
        private Expression GetCaseBody(Enum property, Expression rawValue)
        {
            var viaObject = false;

            var typeLookup = property.GetEnumAttribute <TypeLookupAttribute>()?.Class; //ObjectPropertyInternal members don't necessarily have a type lookup

            if (typeLookup == null)
            {
                return(null);
            }

            var mappings   = ReflectionCacheManager.Map(typeLookup).Cache;
            var cache      = ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property);
            var xmlElement = cache.GetAttribute <XmlElementAttribute>(); //todo: what if this objectproperty doesnt point to a member with an xmlelementattribute?

            XmlMapping mapping = null;

            if (xmlElement != null)
            {
                mapping = mappings.FirstOrDefault(m => m.AttributeValue[0] == xmlElement.ElementName);
            }
            else
            {
                var mergeAttribute = property.GetEnumAttribute <MergeableAttribute>();

                //If we're a property like LocationName, we don't exist server side - we're only used for constructing requests
                if (mergeAttribute != null)
                {
                    return(null);
                }

                //We have a property like Interval which uses a backing property instead.
                //Get the backing property so that we may extract the real value from the public
                //property
                var rawName     = ObjectPropertyParser.GetObjectPropertyNameViaCache(property, cache);
                var elementName = $"{HtmlParser.DefaultPropertyPrefix}{rawName.TrimEnd('_')}";

                mapping = mappings.FirstOrDefault(m => m.AttributeValue[0] == elementName);

                if (mapping != null)
                {
                    viaObject = true;
                }
            }

            if (mapping != null)
            {
                var deserializer = new ValueDeserializer(mapping, null, rawValue);
                var result       = deserializer.Deserialize();

                if (viaObject)
                {
                    //Construct an expression like return new TableSettings { intervalStr = "60|60 seconds" }.Interval;
                    var settingsObj    = Expression.Variable(typeLookup, "obj");
                    var assignObj      = settingsObj.Assign(Expression.New(typeLookup));
                    var internalProp   = Expression.MakeMemberAccess(settingsObj, mapping.PropertyCache.Property);
                    var assignInternal = internalProp.Assign(result);
                    var externalProp   = Expression.MakeMemberAccess(settingsObj, cache.Property);

                    return(Expression.Block(
                               new[] { settingsObj },
                               assignObj,
                               assignInternal,
                               Expression.Convert(externalProp, typeof(object))
                               ));
                }

                return(result);
            }

            //Property is not deserializable
            return(null);
        }
示例#23
0
 public override PropertyCache GetPropertyCache(Enum property)
 {
     return(ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property));
 }
示例#24
0
 public override PropertyCache GetPropertyCache(Enum property)
 {
     return(ObjectPropertyParser.GetPropertyInfoViaPropertyParameter <Channel>(property));
 }
示例#25
0
        internal static List <T> CreateFromDropDownOptions(string response, ObjectProperty name, Func <string, T> createObj)
        {
            var val = ObjectPropertyParser.GetObjectPropertyName(name).TrimEnd('_');

            return(CreateFromDropDownOptions(response, val, createObj));
        }
        public static IPropertyParser GetPropertyParser(PropertyInfo property)
        {
            IPropertyParser propertyParser = null;

            if (property.Name == nameof(FullCalendarParameters.ButtonIcons) || property.Name == nameof(FullCalendarParameters.ThemeButtonIcons) ||
                property.Name == nameof(FullCalendarParameters.BootstrapGlyphicons))
            {
                propertyParser = new ButtonIconsPropertyParser(property, SerializationHelpers.GetSerializer());
            }
            else if (property.Name == nameof(FullCalendarParameters.WeekNumberCalculation) || property.Name == nameof(FullCalendarParameters.DropAccept) ||
                     property.Name == nameof(FullCalendarParameters.EventLimitClick) || property.Name == nameof(FullCalendarParameters.EventLimitText) ||
                     property.Name == nameof(FullCalendarParameters.ColumnHeaderText) || property.Name == nameof(FullCalendarParameters.ColumnHeaderHtml))
            {
                propertyParser = new FunctionPropertyParser(property, SerializationHelpers.GetSerializer());
            }
            else if (property.PropertyType == typeof(EventCollection))
            {
                propertyParser = new EventCollectionPropertyParser(property, SerializationHelpers.GetSerializer(true));
            }
            else if (property.PropertyType == typeof(ClientSideEvents))
            {
                propertyParser = new ClientSideEventsPropertyParser(property, SerializationHelpers.GetSerializer());
            }
            else if (property.PropertyType == typeof(Dictionary <string, CustomButton>))
            {
                propertyParser = new CustomButtonsPropertyParser(property, SerializationHelpers.GetSerializer());
            }
            else if (property.PropertyType == typeof(Dictionary <string, View>))
            {
                propertyParser = new CustomViewPropertyParser(property, SerializationHelpers.GetSerializer(true));
            }
            else if (property.PropertyType == typeof(IEnumerable <BusinessHour>))
            {
                propertyParser = new BusinessHoursPropertyParser(property, SerializationHelpers.GetSerializer(true));
            }
            else if (property.PropertyType == typeof(IEnumerable <EventSource>))
            {
                propertyParser = new EventSourcesPropertyParser(property, SerializationHelpers.GetSerializer(true));
            }
            else if (property.PropertyType == typeof(DayOfWeek))
            {
                propertyParser = new DayOfWeekPropertyParser(property);
            }
            else if (property.PropertyType == typeof(ThemeSystem))
            {
                propertyParser = new ThemeSystemPropertyParser(property);
            }
            else if (property.PropertyType == typeof(bool) || property.PropertyType == typeof(bool?))
            {
                propertyParser = new BoolPropertyParser(property);
            }
            else if (Nullable.GetUnderlyingType(property.PropertyType)?.IsEnum == true)
            {
                propertyParser = new EnumPropertyParser(property);
            }
            else if (property.PropertyType == typeof(TimeSpan))
            {
                propertyParser = new TimeSpanPropertyParser(property);
            }
            else if (property.PropertyType == typeof(DateTime))
            {
                propertyParser = new DateTimePropertyParser(property);
            }
            else if (property.PropertyType == typeof(string))
            {
                propertyParser = new StringPropertyParser(property);
            }
            else if (property.PropertyType == typeof(double))
            {
                propertyParser = new DoublePropertyParser(property);
            }
            else if (property.PropertyType == typeof(float))
            {
                propertyParser = new FloatPropertyParser(property);
            }
            else if (property.PropertyType == typeof(int) || property.PropertyType == typeof(int?))
            {
                propertyParser = new IntegerPropertyParser(property);
            }
            else if (property.PropertyType == typeof(Color))
            {
                propertyParser = new ColorPropertyParser(property);
            }
            else if (property.PropertyType == typeof(Unit))
            {
                propertyParser = new UnitPropertyParser(property);
            }
            else if (property.PropertyType.IsArray)
            {
                propertyParser = new ArrayPropertyParser(property, SerializationHelpers.GetSerializer());
            }
            else
            {
                propertyParser = new ObjectPropertyParser(property, SerializationHelpers.GetSerializer(true));
            }

            return(propertyParser);
        }
 protected virtual string GetParameterName(Enum property, PropertyCache cache)
 {
     return(ObjectPropertyParser.GetObjectPropertyNameViaCache(property, cache));
 }
示例#28
0
        private void ParseValue()
        {
            var prop = ObjectPropertyParser.GetPropertyInfoViaTypeLookup(Property);

            Value = ParseValueIfRequired(prop.Property, Value);
        }
示例#29
0
        private string GetObjectPropertyName(Enum property)
        {
            var name = ObjectPropertyParser.GetObjectPropertyName(property);

            return(name);
        }
示例#30
0
 PropertyCache IPropertyCacheResolver.GetPropertyCache(Enum property)
 {
     return(ObjectPropertyParser.GetPropertyInfoViaTypeLookup(property));
 }