以下是我问题的详细信息
我有一个.sqlproj文件,其中包含构建,文件和位置的 XML ,该文件看起来像这样...
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="WriteDacVersion;Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<ItemGroup>
<Folder Include="dbo" />
<Folder Include="dboTables" />
<Folder Include="dboStored Procedures" />
<Folder Include="dboFunction" />
</ItemGroup>
<ItemGroup>
<Build Include="stockTablesstock.tblTable.sql" />
<Build Include="stockStored Proceduresstock.spStoredProc.sql" />
<Build Include="stockFunctionsstock.Function.sql" />
</ItemGroup>
</Project>
我想知道2件事,
1。如何检查物理驱动器位置和文件到XML
中的位置和文件2。迭代遍历,如果文件和路径与XML匹配,则可以,但是,如果不匹配,即在驱动器上归档,而不是在XML中归档,则错误。
我仍然无法弄清楚如何在linq中做到这一点,所以我以正常的方式求助于此操作,这是我的代码...
// grab the files and locations out of the xml file.
string[] xmlFiles = xdoc.Descendants("ItemGroup")
.Descendants("Build")
.Select(s => s.Attribute("Include"))
.Select(s => s.Value)
.Where(s => s.Contains("Stored Procedures") || s.Contains("Tables") || s.Contains("Functions") || s.Contains("Views"))
.ToArray();
for (int i = 0; i < xmlFiles.Length; i++)
{
string fileXml = xmlFiles[i];
// get just the file name
string path = fileXml;
string[] pathArr = path.Split('\');
string[] fileArr = pathArr.Last().Split('\');
string fileNameXml = fileArr.Last().ToString();
String[] filesOnDrive = Directory.GetFiles(_filePath, fileNameXml, SearchOption.AllDirectories);
for (int j = 0; j == filesOnDrive.Length; j++)
{
Console.WriteLine("no file = " + fileNameXml);
}
}
在Linq中,我认为我需要对此进行左手加入,
//Get folder list from xml
string[] folders = xdoc.Descendants("ItemGroup")
.Descendants("Folder")
.Select(f => f.Attribute("Include"))
.Select(f => f.Value)
.Where(f => f.Contains(("Stored Procedures")))
//.Where(f => File.Exists(fileName))
.ToArray();
和这个,
// grab the files and locations out of the xml file.
string[] sps = xdoc.Descendants("ItemGroup")
.Descendants("Build")
.Select(s => s.Attribute("Include"))
.Select(s => s.Value)
.Where(s => s.Contains("Stored Procedures"))
.ToArray();
如果有人有任何想法,我真的很感激。