ServiceClientGenerator.ProjectFileConfiguration.IsValidPlatformPathForProject C# (CSharp) Method

IsValidPlatformPathForProject() public method

Returns true if the specified path folder names conforms with the platform folder names declared for this configuration.
public IsValidPlatformPathForProject ( string sourceFolder ) : bool
sourceFolder string
return bool
        public bool IsValidPlatformPathForProject(string sourceFolder)
        {
            var tokens = sourceFolder.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });

            if (PlatformCodeFolders.Any())
            {
                foreach(var folder in tokens)
                {
                    if (folder.StartsWith("_"))
                    {
                        bool isValid = false;
                        foreach (var pcf in PlatformCodeFolders)
                        {
                            if (folder.Equals(pcf, StringComparison.OrdinalIgnoreCase))
                            {
                                isValid = true;
                                break;
                            }
                        }
                        if (!isValid)
                        {
                            return false;
                        }
                    }
                    
                }
                
            }

            return true;
        }
    }

Usage Example

        /// <summary>
        /// Returns the collection of subfolders containing source code that need to be
        /// included in the project file. This is comprised the standard platform folders
        /// under Generated, plus any custom folders we find that are not otherwise handled
        /// (eg Properties).
        /// </summary>
        /// <param name="projectFileConfiguration">
        /// The .Net project type we are generating. This governs the platform-specific
        /// subfolders that get included in the project.
        /// </param>
        /// <param name="serviceRootFolder">The root output folder for the service code</param>
        /// <returns></returns>
        private IList <string> GetProjectSourceFolders(ProjectFileConfiguration projectFileConfiguration, string serviceRootFolder)
        {
            // Start with the standard generated code folders for the platform
            var sourceCodeFolders = new List <string>
            {
                "Generated",
                @"Generated\Model",
                @"Generated\Model\Internal",
                @"Generated\Model\Internal\MarshallTransformations"
            };

            var platformSubFolders = projectFileConfiguration.PlatformCodeFolders;

            sourceCodeFolders.AddRange(platformSubFolders.Select(folder => Path.Combine(@"Generated", folder)));

            // Augment the returned folders with any custom subfolders already in existence. If the custom folder
            // ends with a recognised platform, only add it to the set if it matches the platform being generated
            if (Directory.Exists(serviceRootFolder))
            {
                var subFolders = Directory.GetDirectories(serviceRootFolder, "*", SearchOption.AllDirectories);
                if (subFolders.Any())
                {
                    foreach (var folder in subFolders)
                    {
                        var serviceRelativeFolder = folder.Substring(serviceRootFolder.Length);

                        if (!serviceRelativeFolder.StartsWith(@"\Custom", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        if (projectFileConfiguration.IsPlatformCodeFolder(serviceRelativeFolder))
                        {
                            if (projectFileConfiguration.IsValidPlatformPathForProject(serviceRelativeFolder))
                            {
                                sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
                            }
                        }
                        else
                        {
                            sourceCodeFolders.Add(serviceRelativeFolder.TrimStart('\\'));
                        }
                    }
                }
            }

            var foldersThatExist = new List <string>();

            foreach (var folder in sourceCodeFolders)
            {
                if (Directory.Exists(Path.Combine(serviceRootFolder, folder)))
                {
                    foldersThatExist.Add(folder);
                }
            }

            // sort so we get a predictable layout
            foldersThatExist.Sort(StringComparer.OrdinalIgnoreCase);
            return(foldersThatExist);
        }
All Usage Examples Of ServiceClientGenerator.ProjectFileConfiguration::IsValidPlatformPathForProject