本文整理汇总了C#中FilePath.IsChildPathOf方法的典型用法代码示例。如果您正苦于以下问题:C# FilePath.IsChildPathOf方法的具体用法?C# FilePath.IsChildPathOf怎么用?C# FilePath.IsChildPathOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePath
的用法示例。
在下文中一共展示了FilePath.IsChildPathOf方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRepository
Repository GetRepository (FilePath path)
{
path = path.FullPath;
Project p = IdeApp.Workspace.GetProjectContainingFile (path);
if (p != null)
return VersionControlService.GetRepository (p);
foreach (Project prj in IdeApp.Workspace.GetAllProjects ()) {
if (path == prj.BaseDirectory || path.IsChildPathOf (prj.BaseDirectory))
return VersionControlService.GetRepository (prj);
}
foreach (Solution sol in IdeApp.Workspace.GetAllSolutions ()) {
if (path == sol.BaseDirectory || path.IsChildPathOf (sol.BaseDirectory))
return VersionControlService.GetRepository (sol);
}
return null;
}
示例2: Compile
public void Compile (PythonProject project,
FilePath fileName,
PythonConfiguration config,
BuildResult result)
{
if (String.IsNullOrEmpty (fileName))
throw new ArgumentNullException ("fileName");
else if (config == null)
throw new ArgumentNullException ("config");
else if (result == null)
throw new ArgumentNullException ("result");
else if (Runtime == null)
throw new InvalidOperationException ("No supported runtime!");
// Get our relative path within the project
if (!fileName.IsChildPathOf (project.BaseDirectory)) {
Console.WriteLine ("File is not within our project!");
return;
}
FilePath relName = fileName.ToRelative (project.BaseDirectory);
string outFile = relName.ToAbsolute (config.OutputDirectory);
if (!outFile.EndsWith (".py"))
return;
// Create the destination directory
FileInfo fileInfo = new FileInfo (outFile);
if (!fileInfo.Directory.Exists)
fileInfo.Directory.Create ();
// Create and start our process to generate the byte code
Process process = BuildCompileProcess (fileName, outFile, config.Optimize);
process.Start ();
process.WaitForExit ();
// Parse errors and warnings
string output = process.StandardError.ReadToEnd ();
// Extract potential Warnings
foreach (Match m in m_WarningRegex.Matches (output)) {
string lineNum = m.Groups[m_WarningRegex.GroupNumberFromName ("line")].Value;
string message = m.Groups[m_WarningRegex.GroupNumberFromName ("message")].Value;
result.AddWarning (fileName, Int32.Parse (lineNum), 0, String.Empty, message);
}
// Extract potential SyntaxError
foreach (Match m in m_ErrorRegex.Matches (output)) {
string lineNum = m.Groups[m_ErrorRegex.GroupNumberFromName ("line")].Value;
result.AddError (fileName, Int32.Parse (lineNum), 0, String.Empty, "SyntaxError");
}
}
示例3: IsReferenceFromPackage
public static bool IsReferenceFromPackage (this ProjectReference projectReference, FilePath packagesFolderPath)
{
if (!projectReference.IsAssemblyReference ())
return false;
var project = projectReference.OwnerProject as DotNetProject;
if (project == null)
return false;
var assemblyFilePath = new FilePath (projectReference.GetFullAssemblyPath ());
if (assemblyFilePath.IsNullOrEmpty)
return false;
return assemblyFilePath.IsChildPathOf (packagesFolderPath);
}
示例4: IsReferenceFromPackage
public static bool IsReferenceFromPackage (this ProjectReference projectReference)
{
if (!projectReference.IsAssemblyReference ())
return false;
var project = projectReference.OwnerProject as DotNetProject;
if ((project == null) || !project.HasPackages ())
return false;
var assemblyFilePath = new FilePath (projectReference.GetFullAssemblyPath ());
if (assemblyFilePath.IsNullOrEmpty)
return false;
var packagesPath = new SolutionPackageRepositoryPath (project);
var packagesFilePath = new FilePath (packagesPath.PackageRepositoryPath);
return assemblyFilePath.IsChildPathOf (packagesFilePath);
}
示例5: GetRepositoryReference
public override Repository GetRepositoryReference(FilePath path, string id)
{
if (path.IsNullOrEmpty)
return null;
foreach (var repo in repositoriesCache)
{
if (repo.Key == path || path.IsChildPathOf(repo.Key))
{
repo.Value.Refresh();
return repo.Value;
}
if (repo.Key.IsChildPathOf(path))
{
repositoriesCache.Remove(repo.Key);
var repo1 = GetRepository(path, id);
repositoriesCache.Add(path, repo1);
return repo1;
}
}
var repository = GetRepository(path, id);
if (repository != null)
repositoriesCache.Add(path, repository);
return repository;
}
示例6: TransferFiles
public void TransferFiles (IProgressMonitor monitor, Project sourceProject, FilePath sourcePath, Project targetProject,
FilePath targetPath, bool removeFromSource, bool copyOnlyProjectFiles)
{
// When transfering directories, targetPath is the directory where the source
// directory will be transfered, including the destination directory or file name.
// For example, if sourcePath is /a1/a2/a3 and targetPath is /b1/b2, the
// new folder or file will be /b1/b2
if (targetProject == null)
throw new ArgumentNullException ("targetProject");
if (!targetPath.IsChildPathOf (targetProject.BaseDirectory))
throw new ArgumentException ("Invalid project folder: " + targetPath);
if (sourceProject != null && !sourcePath.IsChildPathOf (sourceProject.BaseDirectory))
throw new ArgumentException ("Invalid project folder: " + sourcePath);
if (copyOnlyProjectFiles && sourceProject == null)
throw new ArgumentException ("A source project must be specified if copyOnlyProjectFiles is True");
bool sourceIsFolder = Directory.Exists (sourcePath);
bool movingFolder = (removeFromSource && sourceIsFolder && (
!copyOnlyProjectFiles ||
IsDirectoryHierarchyEmpty (sourcePath)));
// We need to remove all files + directories from the source project
// but when dealing with the VCS addins we need to process only the
// files so we do not create a 'file' in the VCS which corresponds
// to a directory in the project and blow things up.
List<ProjectFile> filesToRemove = null;
List<ProjectFile> filesToMove = null;
try {
//get the real ProjectFiles
if (sourceProject != null) {
if (sourceIsFolder) {
var virtualPath = sourcePath.ToRelative (sourceProject.BaseDirectory);
// Grab all the child nodes of the folder we just dragged/dropped
filesToRemove = sourceProject.Files.GetFilesInVirtualPath (virtualPath).ToList ();
// Add the folder itself so we can remove it from the soruce project if its a Move operation
var folder = sourceProject.Files.Where (f => f.ProjectVirtualPath == virtualPath).FirstOrDefault ();
if (folder != null)
filesToRemove.Add (folder);
} else {
filesToRemove = new List<ProjectFile> ();
var pf = sourceProject.Files.GetFileWithVirtualPath (sourceProject.GetRelativeChildPath (sourcePath));
if (pf != null)
filesToRemove.Add (pf);
}
}
//get all the non-project files and create fake ProjectFiles
if (!copyOnlyProjectFiles || sourceProject == null) {
var col = new List<ProjectFile> ();
GetAllFilesRecursive (sourcePath, col);
if (sourceProject != null) {
var names = new HashSet<string> (filesToRemove.Select (f => sourceProject.BaseDirectory.Combine (f.ProjectVirtualPath).ToString ()));
foreach (var f in col)
if (names.Add (f.Name))
filesToRemove.Add (f);
} else {
filesToRemove = col;
}
}
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not get any file from '{0}'.", sourcePath), ex);
return;
}
// Strip out all the directories to leave us with just the files.
filesToMove = filesToRemove.Where (f => f.Subtype != Subtype.Directory).ToList ();
// If copying a single file, bring any grouped children along
ProjectFile sourceParent = null;
if (filesToMove.Count == 1 && sourceProject != null) {
var pf = filesToMove[0];
if (pf != null && pf.HasChildren)
foreach (ProjectFile child in pf.DependentChildren)
filesToMove.Add (child);
sourceParent = pf;
}
// Ensure that the destination folder is created, even if no files
// are copied
try {
if (sourceIsFolder && !Directory.Exists (targetPath) && !movingFolder)
FileService.CreateDirectory (targetPath);
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not create directory '{0}'.", targetPath), ex);
return;
}
// Transfer files
// If moving a folder, do it all at once
if (movingFolder) {
try {
FileService.MoveDirectory (sourcePath, targetPath);
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Directory '{0}' could not be moved.", sourcePath), ex);
//.........这里部分代码省略.........
示例7: AddFilesToProject
public IList<ProjectFile> AddFilesToProject (Project project, FilePath[] files, FilePath targetDirectory,
string buildAction)
{
Debug.Assert (targetDirectory.CanonicalPath == project.BaseDirectory.CanonicalPath
|| targetDirectory.IsChildPathOf (project.BaseDirectory));
var targetPaths = new FilePath[files.Length];
for (int i = 0; i < files.Length; i++)
targetPaths[i] = targetDirectory.Combine (files[i].FileName);
return AddFilesToProject (project, files, targetPaths, buildAction);
}
示例8: GetFileStatus
private VersionInfo GetFileStatus (Repository repo, FilePath sourcefile, bool getRemoteStatus)
{
SubversionRepository srepo = (SubversionRepository)repo;
SubversionVersionControl vcs = (SubversionVersionControl)repo.VersionControlSystem;
// If the directory is not versioned, there is no version info
if (!Directory.Exists (GetDirectoryDotSvn (vcs, sourcefile.ParentDirectory)))
return VersionInfo.CreateUnversioned (sourcefile, false);
if (!sourcefile.IsChildPathOf (srepo.RootPath))
return VersionInfo.CreateUnversioned (sourcefile, false);
var statuses = new List<VersionInfo> (Status (repo, sourcefile, SvnRevision.Head, false, false, getRemoteStatus));
if (statuses.Count == 0)
return VersionInfo.CreateUnversioned (sourcefile, false);
if (statuses.Count != 1)
return VersionInfo.CreateUnversioned (sourcefile, false);
VersionInfo ent = statuses [0];
if (ent.IsDirectory)
return VersionInfo.CreateUnversioned (sourcefile, false);
return ent;
}
示例9: GetRepository
NGit.Repository GetRepository (FilePath localPath)
{
var submodules = new NGit.Api.Git (RootRepository).SubmoduleStatus ().Call ();
var submodule = submodules.Where (s => {
var fullPath = ((FilePath) s.Key).ToAbsolute (RootPath);
return localPath.IsChildPathOf (fullPath) || localPath.CanonicalPath == fullPath.CanonicalPath;
}).Select (s => s.Key).FirstOrDefault ();
return submodule == null ? RootRepository : NGit.Submodule.SubmoduleWalk.GetSubmoduleRepository (RootRepository, submodule);
}
示例10: IsExternalAssembly
bool IsExternalAssembly (FilePath p)
{
return !p.IsChildPathOf (project.ParentSolution.BaseDirectory) && !p.IsChildPathOf (project.ParentSolution.ItemDirectory);
}
示例11: IsNuGetAssembly
bool IsNuGetAssembly (FilePath p)
{
return p.IsChildPathOf (nugetDir);
}
示例12: GetChangeLogForFile
// Returns the path of the ChangeLog where changes of the provided file have to be logged.
// Returns null if no ChangeLog could be found.
// Returns an empty string if changes don't have to be logged.
public static string GetChangeLogForFile (string baseCommitPath, FilePath file, out SolutionItem parentEntry, out ChangeLogPolicy policy)
{
parentEntry = null;
policy = null;
if (!IdeApp.Workspace.IsOpen)
return null;
// Find the project that contains the file. If none is found
// find a combine entry at the file location
string bestPath = null;
file = file.CanonicalPath;
foreach (SolutionItem e in IdeApp.Workspace.GetAllSolutionItems ()) {
if (e is Project && ((Project)e).Files.GetFile (file) != null) {
parentEntry = e;
break;
}
FilePath epath = e.BaseDirectory.CanonicalPath;
if ((file == epath || file.IsChildPathOf (epath)) && (bestPath == null || bestPath.Length < epath.ToString().Length)) {
bestPath = epath.ToString();
parentEntry = e;
}
}
if (parentEntry == null)
return null;
policy = GetPolicy (parentEntry);
if (baseCommitPath == null)
baseCommitPath = parentEntry.ParentSolution.BaseDirectory;
baseCommitPath = FileService.GetFullPath (baseCommitPath);
if (policy.VcsIntegration == VcsIntegration.None)
return "";
switch (policy.UpdateMode)
{
case ChangeLogUpdateMode.None:
return string.Empty;
case ChangeLogUpdateMode.Nearest: {
string dir = FileService.GetFullPath (Path.GetDirectoryName (file));
do {
string cf = Path.Combine (dir, "ChangeLog");
if (File.Exists (cf))
return cf;
dir = Path.GetDirectoryName (dir);
} while (dir.Length >= baseCommitPath.Length);
return null;
}
case ChangeLogUpdateMode.ProjectRoot:
return Path.Combine (parentEntry.BaseDirectory, "ChangeLog");
case ChangeLogUpdateMode.Directory:
string fileDir = Path.GetDirectoryName (file);
return Path.Combine (fileDir, "ChangeLog");
default:
LoggingService.LogError ("Could not handle ChangeLogUpdateMode: " + policy.UpdateMode);
return null;
}
}
示例13: CanAdd
public bool CanAdd (Repository repo, FilePath sourcepath)
{
SubversionRepository srepo = (SubversionRepository) repo;
// Do some trivial checks
if (!sourcepath.IsChildPathOf (srepo.RootPath))
return false;
bool foundSvnDir = false;
FilePath parentDir = sourcepath.CanonicalPath;
do {
parentDir = parentDir.ParentDirectory;
if (Directory.Exists (GetDirectoryDotSvn (parentDir))) {
foundSvnDir = true;
break;
}
}
while (parentDir != srepo.RootPath);
if (File.Exists (sourcepath)) {
if (File.Exists (GetTextBase (sourcepath)))
return false;
} else if (Directory.Exists (sourcepath)) {
if (Directory.Exists (GetTextBase (sourcepath)))
return false;
} else
return false;
// Allow adding only if the path is not already scheduled for adding
VersionInfo ver = this.GetVersionInfo (repo, sourcepath, false);
if (ver == null)
return true;
return !ver.IsVersioned;
}
示例14: TransferFiles
public void TransferFiles (IProgressMonitor monitor, Project sourceProject, FilePath sourcePath, Project targetProject,
FilePath targetPath, bool removeFromSource, bool copyOnlyProjectFiles)
{
// When transfering directories, targetPath is the directory where the source
// directory will be transfered, including the destination directory or file name.
// For example, if sourcePath is /a1/a2/a3 and targetPath is /b1/b2, the
// new folder or file will be /b1/b2
if (targetProject == null)
throw new ArgumentNullException ("targetProject");
if (!targetPath.IsChildPathOf (targetProject.BaseDirectory))
throw new ArgumentException ("Invalid project folder: " + targetPath);
if (sourceProject != null && !sourcePath.IsChildPathOf (sourceProject.BaseDirectory))
throw new ArgumentException ("Invalid project folder: " + sourcePath);
if (copyOnlyProjectFiles && sourceProject == null)
throw new ArgumentException ("A source project must be specified if copyOnlyProjectFiles is True");
bool sourceIsFolder = Directory.Exists (sourcePath);
bool movingFolder = (removeFromSource && sourceIsFolder && (
!copyOnlyProjectFiles ||
IsDirectoryHierarchyEmpty (sourcePath)));
// Get the list of files to copy
List<ProjectFile> filesToMove = null;
try {
//get the real ProjectFiles
if (sourceProject != null) {
var virtualPath = sourcePath.ToRelative (sourceProject.BaseDirectory);
filesToMove = sourceProject.Files.GetFilesInVirtualPath (virtualPath).ToList ();
}
//get all the non-project files and create fake ProjectFiles
if (!copyOnlyProjectFiles || sourceProject == null) {
var col = new List<ProjectFile> ();
GetAllFilesRecursive (sourcePath, col);
if (sourceProject != null) {
var names = new HashSet<string> (filesToMove.Select (f => sourceProject.BaseDirectory.Combine (f.ProjectVirtualPath).ToString ()));
foreach (var f in col)
if (names.Add (f.Name))
filesToMove.Add (f);
} else {
filesToMove = col;
}
}
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not get any file from '{0}'.", sourcePath), ex);
return;
}
// If copying a single file, bring any grouped children along
if (filesToMove.Count == 1 && sourceProject != null) {
var pf = filesToMove[0];
if (pf != null && pf.HasChildren)
foreach (ProjectFile child in pf.DependentChildren)
filesToMove.Add (child);
}
// Ensure that the destination folder is created, even if no files
// are copied
try {
if (sourceIsFolder && !Directory.Exists (targetPath) && !movingFolder)
FileService.CreateDirectory (targetPath);
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not create directory '{0}'.", targetPath), ex);
return;
}
// Transfer files
// If moving a folder, do it all at once
if (movingFolder) {
try {
FileService.MoveDirectory (sourcePath, targetPath);
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Directory '{0}' could not be moved.", sourcePath), ex);
return;
}
}
monitor.BeginTask (GettextCatalog.GetString ("Copying files..."), filesToMove.Count);
foreach (ProjectFile file in filesToMove) {
bool fileIsLink = file.Project != null && file.IsLink;
var sourceFile = fileIsLink
? file.Project.BaseDirectory.Combine (file.ProjectVirtualPath)
: file.FilePath;
var newFile = sourceIsFolder ? targetPath.Combine (sourceFile.ToRelative (sourcePath)) : targetPath;
if (!movingFolder && !fileIsLink) {
try {
FilePath fileDir = newFile.ParentDirectory;
if (!Directory.Exists (fileDir) && !file.IsLink)
FileService.CreateDirectory (fileDir);
if (removeFromSource)
//.........这里部分代码省略.........