Esempio n. 1
0
        private static PathInformation ColloquialString2PathInformationInternal([NotNull] string path, InspectionPlanEntity entity)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException("The path string must not be null or empty.", nameof(path));
            }

            // fast code path for root path
            if (path == DelimiterString)
            {
                if (entity != InspectionPlanEntity.Part)
                {
                    throw new ArgumentException("The root path must always be of type part.", nameof(entity));
                }

                return(PathInformation.Root);
            }

            // convert to database format by prepending a delimiter if it is not already present
            if (!path.StartsWith(DelimiterString))
            {
                path = DelimiterString + path;
            }
            // convert to database format by appending a delimiter if it is not already present (beware of escaping)
            if (!path.EndsWith(DelimiterString) || path.EndsWith(EscapedDelimiter))
            {
                path = path + DelimiterString;
            }

            return(String2PathInformationInternal(path, null, i => entity));
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public PathElement(InspectionPlanEntity type = InspectionPlanEntity.Part, string value = "")
 {
     Type  = type;
     Value = value ?? string.Empty;
 }
Esempio n. 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public PathElement( InspectionPlanEntity type = InspectionPlanEntity.Part, string value = "" )
 {
     Type = type;
     Value = value ?? string.Empty;
 }
Esempio n. 4
0
        /// <summary> Internal method to create a <see cref="PathInformation"/> object from <paramref name="path"/>. </summary>
        private static PathInformation String2PathInformationInternal( string path, string structure, InspectionPlanEntity? entity )
        {
            var resultPath = PathInformation.Root;
            if( !string.IsNullOrEmpty( path ) && !( path == Delimiter.ToString() && string.IsNullOrEmpty( structure ) ) )
            {
                var result = new List<PathElement>( structure != null ? structure.Length : 10 );

                int i = 0;
                var startIndex = path[ 0 ] == Delimiter ? 1 : 0;
                var sb = new StringBuilder( path.Length );
                for( int j = startIndex; j < path.Length; j++ ) // ersten Slash überlesen
                {
                    char current = path[ j ];
                    if( current == '\\' )
                    {
                        current = path[ ++j ];
                        sb.Append( current );
                    }
                    else if( current == Delimiter )
                    {
                        if( structure == null )
                            result.Add( new PathElement( entity.GetValueOrDefault( InspectionPlanEntity.Part ), sb.ToString() ) );
                        else if (structure.Length <= i)
                            throw new ArgumentException( string.Format( "The path structure does not match the actual path: The path is '{0}' but structure is '{1}' ({2} segements).", path, structure, structure.Length ), "structure" );
                        else if( structure[ i++ ] == 'P' )
                            result.Add( new PathElement( InspectionPlanEntity.Part, sb.ToString() ) );
                        else
                            result.Add( new PathElement( InspectionPlanEntity.Characteristic, sb.ToString() ) );

                        sb = new StringBuilder( path.Length );
                    }
                    else
                    {
                        sb.Append( current );
                    }
                }
                if( sb.Length > 0 )
                {
                    if( structure == null )
                        result.Add( new PathElement( entity.GetValueOrDefault( InspectionPlanEntity.Part ), sb.ToString() ) );
                    else if( structure.Length <= i )
                        throw new ArgumentException( string.Format( "The path structure does not match the actual path: The path is '{0}' but structure is '{1}' ({2} segements).", path, structure, structure.Length ), "structure" );
                    else if( structure[ i++ ] == 'P' )
                        result.Add( new PathElement( InspectionPlanEntity.Part, sb.ToString() ) );
                    else
                        result.Add( new PathElement( InspectionPlanEntity.Characteristic, sb.ToString() ) );
                }

                resultPath = new PathInformation( result );
            }
            return resultPath;
        }