我正在使用HtmlAgilityPack.
我将鼠标悬停在父节点上,其ChildNodes显示多个#text节点.XPath值显示/code[1]/#text[1].我尝试使用//#text获取所有文本节点,但我得到了错误:
错误: Expression must evaluate to a node-set.
我已经尝试过//text什么也没得到,但没有错误.
示例文本(我突出显示了所需/的文本):
对[@ Key = 2] /项目/项目[人/姓名='马丁'] /日期
我试图让每个正斜线都不在方括号内,任何人都可以帮助我解决这个问题吗?用途是:
string[] result = Regex.Split(text, pattern);
Run Code Online (Sandbox Code Playgroud)
我已经用这段代码完成了它,但是想知道是否有一个更简单的正则表达式可以做同样的事情:
private string[] Split()
{
List<string> list = new List<string>();
int pos = 0, i = 0;
bool within = false;
Func<string> add = () => Format.Substring(pos, i - pos);
//string a;
for (; i < Format.Length; i++)
{
//a = add();
char c = Format[i];
switch (c)
{
case '/':
if (!within)
{
list.Add(add());
pos = i + 1;
} …Run Code Online (Sandbox Code Playgroud) 通过使用C#与MySQL数据库的SSH连接,我获得了使用此库进行连接的链接.
这是图书馆的链接,因为你不需要手动打开SSH频道,很多人会觉得这很有趣.
这是一个非常详细的库,有很多功能,但我想要做的很简单.我只想在每次要写入数据库时打开SSH通道.
虽然我是通过提供的源搜索我走到它可以发现在这部分代码TestSshCommand.cs,我想我可以用这部分我的连接,但我需要你们的帮助让我有它的工作我的连接字符串我不知道如何连接所有它.
码:
public void Test_Execute_SingleCommand()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var result = ExecuteTestCommand(client);
client.Disconnect();
Assert.IsTrue(result);
}
Run Code Online (Sandbox Code Playgroud)
我连接到非SSH通道的代码是:
con.ConnectionString = ConfigurationManager.ConnectionStrings["Con2"].ConnectionString;
con.Open();
cmd = new MySqlCommand("SELECT COUNT(*) FROM " + ConfigSettings.ReadSetting("main"), con);
//...... more of the code
Run Code Online (Sandbox Code Playgroud)
那么如何将此代码与上面的代码结合起来,以便它可以先打开一个SSH通道然后执行我的查询?
我需要将我的代码放入连接和断开连接功能吗?
还有一个想法我在引用中添加.dll文件,我必须说没有任何导入工作.那么有人可以下载库并尝试这个简单的代码来查看引用是否适用于您的项目,以便每个人(很多)可以为他们未来的项目提供有效的解决方案?
编辑:
这是我以后尝试做的代码.我的SSH连接现在只需将两者结合起来就可以了.
问题是我需要在我的电脑上本地拥有一个数据库,并且需要连接到服务器.因此,端口转发将不起作用,因为somone在论坛上说我无法移植,而mysql已经有端口用于运行
using (var client = new SshClient("cpanel****", "******", "******"))
{
client.Connect();
con = new MySqlConnection(GetConnectionString());
con.Open();
cmd = new …Run Code Online (Sandbox Code Playgroud) 我想获取xml文件中的所有元素.
我只获得了第一个元素.
XmlDocument XDoc = new XmlDocument();
XDoc.Load("d://avi.xml");
XmlNodeList XList = XDoc.SelectNodes("//level1");
foreach (XmlNode XNode in XList)
{
Console.WriteLine("the current node is - {0}", XNode.Name);
}
Run Code Online (Sandbox Code Playgroud)
xml:
<?xml version="1.0" encoding="utf-8"?>
<level1>
<level2>
<level3>header3</level3>
<level4>another</level4>
<level31>header31</level31>
</level2>
<level2>
<level3>nnn</level3>
<level31>nnnnn</level31>
</level2>
</level1>
<!--test test-->
Run Code Online (Sandbox Code Playgroud) 我有这个,
public enum Condition : uint // bitwise
{
None = 0,
NewLine = 1,
Space = 2
}
Rule.Condition someCondition = Rule.Condition.Space | Rule.Condition.NewLine;
Run Code Online (Sandbox Code Playgroud)
我想转换这个,
if ((Rule.Condition.Space & condition) == Rule.Condition.Space) return true;
if ((Rule.Condition.NewLine & condition) == Rule.Condition.NewLine) return true;
Run Code Online (Sandbox Code Playgroud)
进入类似的东西,
if((someCondition & condition) == someCondition) return true;
Run Code Online (Sandbox Code Playgroud)
但它没有用.我忘记了什么?
我正在尝试在web项目中使用libgit2sharp.问题是libgit2sharp的解决方案适用于VS2010而我正在使用VS2008.所以我不得不创建一个新的解决方案并修改代码而不使用默认参数.这不是问题,除了我尝试使用已编译的libgit2sharp DLL时,我在标题中列出了异常.
我已尝试在git2.dll中链接,但这没有帮助.将git2.dll复制到Web项目中也没有帮助.
编辑:问题是在LibGit2Sharp问题跟踪器上处理的:https://github.com/libgit2/libgit2sharp/issues/39
我已经尝试过我在网上找到的所有解决方案都没有成功.我不断得到错误:
Running transformation: System.InvalidOperationException: The SSDL generated by the activity
called 'CsdlToSsdlAndMslActivity' is not valid and has the following errors:
No Entity Framework provider found for the ADO.NET provider with invariant name
'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework'
section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for
more information.
Run Code Online (Sandbox Code Playgroud)
我有一个空的Console项目和一个非常基本的模型来测试它.通过NuGet包控制台我会执行:Install-Package MySQL.Data.Entities里面装EF6,MySQL.Data并MySQL.Data.Entities和迷上了所有引用和复制相关的DLL的到bin/Debug文件夹中.
我在下面连接了提供程序(列出了整个配置文件)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> …Run Code Online (Sandbox Code Playgroud) 我已经尝试了几种选择,但没有什么能给我全部的话.
这给了我部分的话,
`@"(?<![.])\w+"`
Run Code Online (Sandbox Code Playgroud)
我正在解析c#代码,所以字符串"Regex.Match(" ", " ")"应该返回Regex而不是Match.
我最终只使用了\w+这个检查,
if ((match.Index > 0) && ('.' == text[match.Index - 1]))
continue;
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,但只是好奇,如果有一个正则表达式也会这样做.
我有一个运行良好的自定义安装程序,但每次更新应用程序时它都会要求用户提供管理员权限。我正在创建一个跳过这部分的 Windows 服务,但 Windows 服务仅授予该文件的系统和管理员权限,并且用户无法执行新的更新。
为了纠正这个问题,我正在尝试(在文件下载/安装到正确的位置之后(从 Windows 服务中,它具有帐户 ServiceAccount.LocalSystem),
FileSecurity access = file.GetAccessControl();
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
access.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.ReadAndExecute, AccessControlType.Allow));
Run Code Online (Sandbox Code Playgroud)
但设置不生效。从这里我应该做什么?
我已经创建了一个属性来处理一些信息,然后调用一个方法,但它没有被调用.
我想记录一些处理的值并存储在类中的静态字段中,这是我的类的其他方法调用的结果.
所以有人可以指导它.
[AttributeUsage(AttributeTargets.Method)]
internal class MyAttrib : Attribute
{
public MyAttrib()
{
//This is not getting called. what am i missing
Console.WriteLine("My Attrib called!!");
}
}
class MyClass
{
public MyClass()
{
Console.WriteLine("Constructor Created");
}
[MyAttrib]
public int Opt1()
{
Console.WriteLine("Op1 Performed");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
}
static void Main(string[] args)
{
MyClass cla = new MyClass();
cla.Opt1();
cla.Opt2();
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)