/// <summary>
        /// Parses the filter and returns a <see cref="InspectionPlanFilterAttributes"/> object that represents the filter values.
        /// If the parse operation was not successful, an <see cref="InvalidOperationException"/> will be thrown.
        /// </summary>
        /// <returns>The <see cref="InspectionPlanFilterAttributes"/> with the parsed information.</returns>
        public static InspectionPlanFilterAttributes Parse( string depth, string partUuids, string withHistory, string requestedPartAttributes, string requestedCharacteristicsAttributes )
        {
            var items = new[]
            {
                Tuple.Create( DepthParamName, depth ),
                Tuple.Create( PartUuidsParamName, partUuids ),
                Tuple.Create( WithHistoryParamName, withHistory ),
                Tuple.Create( RequestedPartAttributesParamName, requestedPartAttributes ),
                Tuple.Create( RequestedCharacteristicsAttributesParamName, requestedCharacteristicsAttributes ),
            };

            var result = new InspectionPlanFilterAttributes();
            foreach( var item in items )
            {
                var key = item.Item1;
                var value = item.Item2;

                if( string.IsNullOrEmpty( value ) )
                    continue;

                try
                {
                    switch( key )
                    {
                        case DepthParamName:
                            result.Depth = ushort.Parse( value, System.Globalization.CultureInfo.InvariantCulture );
                            break;
                        case PartUuidsParamName:
                            result.PartUuids = RestClientHelper.ConvertStringToGuidList( value );
                            break;
                        case WithHistoryParamName:
                            result.WithHistory = bool.Parse( value );
                            break;
                        case RequestedPartAttributesParamName:
                            if( string.Equals( value, "None", StringComparison.OrdinalIgnoreCase ) )
                                result.RequestedPartAttributes = new AttributeSelector( AllAttributeSelection.False );
                            else if( string.Equals( value, "All", StringComparison.OrdinalIgnoreCase ) )
                                result.RequestedPartAttributes = new AttributeSelector( AllAttributeSelection.True );
                            else
                                result.RequestedPartAttributes = new AttributeSelector( RestClientHelper.ConvertStringToUInt16List( value ) );
                            break;
                        case RequestedCharacteristicsAttributesParamName:
                            if( string.Equals( value, "None", StringComparison.OrdinalIgnoreCase ) )
                                result.RequestedCharacteristicAttributes = new AttributeSelector( AllAttributeSelection.False );
                            else if( string.Equals( value, "All", StringComparison.OrdinalIgnoreCase ) )
                                result.RequestedCharacteristicAttributes = new AttributeSelector( AllAttributeSelection.True );
                            else
                                result.RequestedCharacteristicAttributes = new AttributeSelector( RestClientHelper.ConvertStringToUInt16List( value ) );
                            break;
                    }
                }
                catch( Exception ex )
                {
                    throw new InvalidOperationException( string.Format( "Invalid filter value '{0}' for parameter '{1}'. The can be specified via url parameter in the form of 'key=value'. The following keys are valid: {2}",
                        value, key,
                        "withHistory = [True|False]\r\n" +
                        "depth = [short]\r\n" +
                        "partUuids = [list of part uuids]\r\n" +
                        "partAttributes = [All|None|Attribute keys csv|Empty for all attributes]\r\n" +
                        "characteristicAttributes = [All|None|Attribute keys csv|Empty for all attributes]\r\n" ), ex );
                }
            }
            return result;
        }
Exemple #2
0
        /// <summary>
        /// Parses the filter and returns a <see cref="InspectionPlanFilterAttributes"/> object that represents the filter values.
        /// If the parse operation was not successful, an <see cref="InvalidOperationException"/> will be thrown.
        /// </summary>
        /// <returns>The <see cref="InspectionPlanFilterAttributes"/> with the parsed information.</returns>
        public static InspectionPlanFilterAttributes Parse(string depth, string partUuids, string withHistory, string requestedPartAttributes, string requestedCharacteristicsAttributes)
        {
            var items = new[]
            {
                Tuple.Create(DepthParamName, depth),
                Tuple.Create(PartUuidsParamName, partUuids),
                Tuple.Create(WithHistoryParamName, withHistory),
                Tuple.Create(RequestedPartAttributesParamName, requestedPartAttributes),
                Tuple.Create(RequestedCharacteristicsAttributesParamName, requestedCharacteristicsAttributes),
            };

            var result = new InspectionPlanFilterAttributes();

            foreach (var item in items)
            {
                var key   = item.Item1;
                var value = item.Item2;

                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                try
                {
                    switch (key)
                    {
                    case DepthParamName:
                        result.Depth = ushort.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case PartUuidsParamName:
                        result.PartUuids = RestClientHelper.ConvertStringToGuidList(value);
                        break;

                    case WithHistoryParamName:
                        result.WithHistory = bool.Parse(value);
                        break;

                    case RequestedPartAttributesParamName:
                        if (string.Equals(value, "None", StringComparison.OrdinalIgnoreCase))
                        {
                            result.RequestedPartAttributes = new AttributeSelector(AllAttributeSelection.False);
                        }
                        else if (string.Equals(value, "All", StringComparison.OrdinalIgnoreCase))
                        {
                            result.RequestedPartAttributes = new AttributeSelector(AllAttributeSelection.True);
                        }
                        else
                        {
                            result.RequestedPartAttributes = new AttributeSelector(RestClientHelper.ConvertStringToUInt16List(value));
                        }
                        break;

                    case RequestedCharacteristicsAttributesParamName:
                        if (string.Equals(value, "None", StringComparison.OrdinalIgnoreCase))
                        {
                            result.RequestedCharacteristicAttributes = new AttributeSelector(AllAttributeSelection.False);
                        }
                        else if (string.Equals(value, "All", StringComparison.OrdinalIgnoreCase))
                        {
                            result.RequestedCharacteristicAttributes = new AttributeSelector(AllAttributeSelection.True);
                        }
                        else
                        {
                            result.RequestedCharacteristicAttributes = new AttributeSelector(RestClientHelper.ConvertStringToUInt16List(value));
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException(string.Format("Invalid filter value '{0}' for parameter '{1}'. The can be specified via url parameter in the form of 'key=value'. The following keys are valid: {2}",
                                                                      value, key,
                                                                      "withHistory = [True|False]\r\n" +
                                                                      "depth = [short]\r\n" +
                                                                      "partUuids = [list of part uuids]\r\n" +
                                                                      "partAttributes = [All|None|Attribute keys csv|Empty for all attributes]\r\n" +
                                                                      "characteristicAttributes = [All|None|Attribute keys csv|Empty for all attributes]\r\n"), ex);
                }
            }
            return(result);
        }