/// <summary> /// Parses the filter and returns a <see cref="MeasurementFilterAttributes"/> 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="MeasurementFilterAttributes"/> with the parsed information.</returns> public static MeasurementFilterAttributes Parse( string partUuids, string measurementUuids, string deep, string limitResult, string order, string requestedMeasurementAttributes, string searchCondition, string statistics, string aggregation, string fromModificationDate, string toModificationDate, string mergeAttributes, string mergeCondition, string mergeMasterPart) { var items = new[] { Tuple.Create(PartUuidsParamName, partUuids), Tuple.Create(MeasurementUuidsParamName, measurementUuids), Tuple.Create(DeepParamName, deep), Tuple.Create(LimitResultParamName, limitResult), Tuple.Create(OrderByParamName, order), Tuple.Create(RequestedMeasurementAttributesParamName, requestedMeasurementAttributes), Tuple.Create(SearchConditionParamName, searchCondition), Tuple.Create(StatisticsParamName, statistics), Tuple.Create(AggregationParamName, aggregation), Tuple.Create(FromModificationDateParamName, fromModificationDate), Tuple.Create(ToModificationDateParamName, toModificationDate), Tuple.Create(MergeAttributesParamName, mergeAttributes), Tuple.Create(MergeConditionParamName, mergeCondition), Tuple.Create(MergeMasterPartParamName, mergeMasterPart) }; var result = new MeasurementFilterAttributes(); foreach (var item in items) { var key = item.Item1; var value = item.Item2; if (string.IsNullOrEmpty(value)) { continue; } try { switch (key) { case PartUuidsParamName: result.PartUuids = RestClientHelper.ConvertStringToGuidList(value); break; case DeepParamName: result.Deep = bool.Parse(value); break; case MeasurementUuidsParamName: result.MeasurementUuids = RestClientHelper.ConvertStringToGuidList(value); break; case LimitResultParamName: result.LimitResult = int.Parse(value, System.Globalization.CultureInfo.InvariantCulture); break; case RequestedMeasurementAttributesParamName: result.RequestedMeasurementAttributes = new AttributeSelector(RestClientHelper.ConvertStringToUInt16List(value)); break; case OrderByParamName: result.OrderBy = value.Split(',').Select(ParseOrderBy).ToArray(); break; case SearchConditionParamName: result.SearchCondition = SearchConditionParser.Parse(value); break; case StatisticsParamName: result.Statistics = ( MeasurementStatistics )Enum.Parse(typeof(MeasurementStatistics), value); break; case AggregationParamName: result.AggregationMeasurements = ( AggregationMeasurementSelection )Enum.Parse(typeof(AggregationMeasurementSelection), value); break; case ToModificationDateParamName: result.ToModificationDate = XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.RoundtripKind); break; case FromModificationDateParamName: result.FromModificationDate = XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.RoundtripKind); break; case MergeAttributesParamName: result.MergeAttributes = RestClientHelper.ConvertStringToUInt16List(value); break; case MergeConditionParamName: result.MergeCondition = (MeasurementMergeCondition)Enum.Parse(typeof(MeasurementMergeCondition), value); break; case MergeMasterPartParamName: result.MergeMasterPart = string.IsNullOrWhiteSpace(value) ? (Guid?)null : Guid.Parse(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, "partUuids: [list of part uuids]\r\n" + "deep: [True|False]\r\n" + "limitResult: [short]\r\n" + "measurementUuids: [list of measurement uuids]\r\n" + "measurementAttributes: [attribute keys csv|Empty for all attributes]\r\n" + "orderBy:[ushort asc|desc, ushort asc|desc, ...]\r\n" + "searchCondition:[search filter string]\r\n" + "aggregation:[Measurements|AggregationMeasurements|Default|All]\r\n" + "statistics:[None|Simple|Detailed]\r\n" + "mergeAttributes:[list of measurement attributes]\r\n" + "mergeCondition: [None|MeasurementsInAtLeastTwoParts|MeasurementsInAllParts]\r\n" + "mergeMasterPart: [part uuid]\r\n" + "fromModificationDate:[Date]\r\n" + "toModificationDate:[Date]"), ex); } } return(result); }
/// <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); }