Exemplo n.º 1
0
        /// <inheritdoc />
        async Task <IValueView> IValueViewFactory.CreateAsync(IParameterLink link, NonEmptyString stringValue)
        {
            if (!Fraction.TryParse(stringValue, out var fraction))
            {
                return(new ValueView(link, stringValue));
            }

            var commandText = string.Intern($@"
				select min_val, max_val
				from pg_catalog.pg_settings
				where name = @{nameof(IParameterLink.Name)};"                );

            var connection = await Connection();

            var(minValue, maxValue) = await connection.QuerySingleAsync <(decimal, decimal)>(
                commandText,
                new { link.Name });

            var multiplier = (minValue, maxValue) switch
            {
                (decimal.Zero, decimal.One) => decimal.One,
                (decimal.Zero, 100) => 100,
                _ => throw new NotSupportedException(
                          $"Fraction parameter range [{minValue} .. {maxValue}] is not " +
                          $"supported (parameter '{link.Name}').")
            };

            var normalizedValue = (fraction.Value * multiplier).ToString(CultureInfo.InvariantCulture);

            return(new ValueView(link, normalizedValue));
        }
Exemplo n.º 2
0
        public static ParameterMap AddParameterLinks(this ParameterMap parameterMap, IEnumerable <IParameterLink> parameterLinks, bool merge = true)
        {
            if (parameterMap == null)
            {
                return(null);
            }

            if (parameterMap.Type == null || parameterLinks == null || parameterLinks.Count() == 0)
            {
                return(parameterMap);
            }

            IEnumerable <PropertyInfo> propertyInfos = Query.MapPropertyInfos(parameterMap.Type);

            if (propertyInfos == null)
            {
                return(parameterMap);
            }

            ParameterMap clonedMap = parameterMap.ShallowClone();

            if (clonedMap.ParameterLinks == null)
            {
                clonedMap.ParameterLinks = new List <IParameterLink>();
            }
            else
            {
                clonedMap.ParameterLinks = new List <IParameterLink>(parameterMap.ParameterLinks);
            }

            foreach (IParameterLink parameterLink in parameterLinks)
            {
                Type           linkType     = parameterLink.GetType();
                IParameterLink existingLink = clonedMap.ParameterLinks.Find(x => x.PropertyName == parameterLink.PropertyName && x.GetType() == linkType);
                if (existingLink == null)
                {
                    clonedMap.ParameterLinks.Add(parameterLink);
                }
                else
                {
                    clonedMap.ParameterLinks.Remove(existingLink);
                    if (merge)
                    {
                        IParameterLink newLink = existingLink.ShallowClone();
                        newLink.ParameterNames = new HashSet <string>(existingLink.ParameterNames);
                        newLink.ParameterNames.UnionWith(parameterLink.ParameterNames);
                        clonedMap.ParameterLinks.Add(newLink);
                    }
                    else
                    {
                        clonedMap.ParameterLinks.Add(parameterLink);
                    }
                }
            }

            return(clonedMap);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        async Task <RawParameterValue> IDatabaseServer.GetRawParameterValueAsync(IParameterLink parameterLink)
        {
            await Task.CompletedTask;

            return(parameterLink.Name.ToString() switch
            {
                "max_connections" => new RawParameterValue("100", RawValueType.Integer),
                "max_locks_per_transaction" => new RawParameterValue("8", RawValueType.Integer),
                _ => throw new NotSupportedException($"Parameter '{parameterLink.Name}' can't be handled by fake service.")
            });
Exemplo n.º 4
0
        /// <inheritdoc />
        async Task <RawParameterValue> IDatabaseServer.GetRawParameterValueAsync(IParameterLink parameterLink)
        {
            var commandText = string.Intern($@"
				select
					current_setting(name),
					vartype,
					min_val,
					max_val
				from pg_catalog.pg_settings
				where name = @{nameof(IParameterLink.Name)};"                );

            var connection = await Connection();

            var(value, typeString, minValue, maxValue) = await connection
                                                         .QuerySingleAsync <(NonEmptyString, NonEmptyString, decimal?, decimal?)>(
                commandText,
                new { parameterLink.Name });

            var rawType = typeString.ByStringRepresentation <RawValueType>();

            return(minValue.HasValue && maxValue.HasValue
                                ? new RawRangeParameterValue(value, rawType, (minValue.Value, maxValue.Value))
                                : new RawParameterValue(value, rawType));
        }
 /// <inheritdoc />
 IParameterValue IParameterValueParser.Parse(IParameterLink parameterLink, RawParameterValue rawParameterValue)
 => rawParameterValue.Value switch
 {
     { } when Regex.IsMatch(rawParameterValue.Value, "^[0-9]+(ms|s|min|h)$")
Exemplo n.º 6
0
 public FractionParameterValue(IParameterLink parameterLink, Fraction value)
     : base(parameterLink, value)
 {
 }
Exemplo n.º 7
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static RevitParameter ParameterFromRevit(this Parameter parameter, IEnumerable <IParameterLink> parameterLinks = null, bool onlyLinked = false)
        {
            if (parameter == null)
            {
                return(null);
            }

            string name = parameter.Definition.Name;

            IParameterLink parameterLink = parameterLinks.ParameterLink(parameter);

            if (parameterLink != null)
            {
                name = parameterLink.PropertyName;
            }
            else if (onlyLinked)
            {
                return(null);
            }

            object value = null;

            switch (parameter.StorageType)
            {
            case StorageType.Double:
                value = parameter.AsDouble().ToSI(parameter.Definition.UnitType);
                break;

            case StorageType.ElementId:
                ElementId elementID = parameter.AsElementId();
                if (elementID != null)
                {
                    value = elementID.IntegerValue;
                }
                break;

            case StorageType.Integer:
                if (parameter.Definition.ParameterType == ParameterType.YesNo)
                {
                    value = parameter.AsInteger() == 1;
                }
                else if (parameter.Definition.ParameterType == ParameterType.Invalid)
                {
                    value = parameter.AsValueString();
                }
                else
                {
                    value = parameter.AsInteger();
                }
                break;

            case StorageType.String:
                value = parameter.AsString();
                break;

            case StorageType.None:
                value = parameter.AsValueString();
                break;
            }

            return(new RevitParameter {
                Name = name, Value = value
            });
        }
Exemplo n.º 8
0
 public TimeSpanParameterValue(IParameterLink parameterLink, PositiveTimeSpan value)
     : base(parameterLink, value)
 {
 }
 private protected ParameterValueBase(IParameterLink parameterLink, T value)
 {
     Link  = parameterLink;
     Value = value;
 }
Exemplo n.º 10
0
 private NullValue(IParameterLink link) => Link = link;
 public BooleanParameterValue(IParameterLink parameterLink, bool value)
     : base(parameterLink, value)
 {
 }
Exemplo n.º 12
0
 public IntegerParameterValue(IParameterLink parameterLink, uint value)
     : base(parameterLink, value)
 {
 }
Exemplo n.º 13
0
 public MemoryParameterValue(IParameterLink parameterLink, Memory value)
     : base(parameterLink, value)
 {
 }