예제 #1
0
        private Dictionary <string, ParameterInfo> ConvertProperties(IEnumerable <CADProperty> properties)
        {
            using (var monitoredExecutionBlock = monitoredExecutionContext
                                                 .MonitorMethod <RevitHost>(nameof(ConvertProperties))
                                                 .WithParameter(nameof(properties), properties)
                                                 .WithTiming())
            {
                var parameters = new Dictionary <string, ParameterInfo>();
                var type       = Models.ParameterType.Type;
                var valueType  = ParameterValueType.String;

                foreach (var property in properties)
                {
                    if (property.Info.TryGetValue("InjectionType", out var typeValue))
                    {
                        type = typeValue.ToEnum(Models.ParameterType.Type);
                    }

                    object value = null;
                    if (property.Selected && (property.Value.LogicalValue != null || property.Value.NumericValue != null || property.Value.Description != null))
                    {
                        switch (property.Type)
                        {
                        case "N":
                            valueType = ParameterValueType.Numeric;
                            var etimDisplayUnitType = UOLAddInUtilities.ConvertEUCode(property.UnitCode);
                            value = parameterHelper.ConvertToAPI((double)property.Value.NumericValue, etimDisplayUnitType);
                            break;

                        case "L":
                            valueType = ParameterValueType.Boolean;
                            value     = property.Value.LogicalValue;
                            break;

                        default:
                            value     = property.Value.Code ?? property.Value.Description;
                            valueType = ParameterValueType.String;
                            break;
                        }

                        var propertyName = $"{property.Code}_{property.PortCode}_";

                        if (!parameters.ContainsKey(propertyName))
                        {
                            parameters.Add(propertyName, new ParameterInfo()
                            {
                                Name = propertyName, Type = type, Value = value, ValueType = valueType
                            });
                        }
                    }
                }

                return(parameters);
            }
        }