小编Jon*_*ell的帖子

HtmlAgilityPack和身份验证

如果给定一个特定的url,我有一个获取id和xpath的方法.如何通过请求传递用户名和密码,以便我可以抓取需要用户名和密码的网址?

using HtmlAgilityPack;

_web = new HtmlWeb();

internal Dictionary<string, string> GetidsAndXPaths(string url)
{
    var webidsAndXPaths = new Dictionary<string, string>();
    var doc = _web.Load(url);
    var nodes = doc.DocumentNode.SelectNodes("//*[@id]");
    if (nodes == null) return webidsAndXPaths;
    // code to get all the xpaths and ids
Run Code Online (Sandbox Code Playgroud)

我应该使用Web请求获取页面源,然后将该文件传递给上面的方法吗?

var wc = new WebClient();
wc.Credentials = new NetworkCredential("UserName", "Password");
wc.DownloadFile("http://somewebsite.com/page.aspx", @"C:\localfile.html");
Run Code Online (Sandbox Code Playgroud)

c# networkcredentials html-agility-pack

6
推荐指数
1
解决办法
5182
查看次数

为什么两个新对象没有相同的哈希码?

我写了一个自定义比较器类.

public class ItemComparer : IEqualityComparer<Item>
{
    public int GetHashCode(Item x)
    {
        return (x == null) ? 0 : new { x.Name, x.CompanyCode,
           x.ShipToDate, x.Address }.GetHashCode();
    }
Run Code Online (Sandbox Code Playgroud)

当我新建两个项目并比较哈希码时,我的测试失败了.为什么哈希不同?

[TestMethod]
public void Two_New_Items_Have_The_Same_Hash_Code()
{
     // arrange
     var comparer = new ItemComparer();
     Item x = new Item();
     Item y = new Item();

     // act
     int xHash = comparer.GetHashCode(x);
     int yHash = comparer.GetHashCode(y);

     // assert
     Assert.AreEqual(xHash, yHash);
}
Run Code Online (Sandbox Code Playgroud)

编辑 - 这是完整的课程.我简单地使用上面的例子来简洁,但需要更多的信息

public class DtoPolicy : DtoBase
{
    [Description("The Policy Number")]
    public string PolicyNumber …
Run Code Online (Sandbox Code Playgroud)

c#

6
推荐指数
1
解决办法
156
查看次数

在while循环中添加项目时,处理队列中的项目

我有一种方法,我在while循环中监听UDP数据包.我想在它们到达时使用另一个类中的另一个方法来解析数据包,并对应用程序的另一部分中的每个数据包进行许多不同的解析和分析.我认为让PacketParser方法在循环之外处理Queue 会更好.是否有可能只是将数据包添加到a Queue进入,然后让应用程序的另一部分在进入Queue时监听项目并执行其他操作,因为原始while循环一直在侦听数据包并将它们添加到队列?我想有另一个功能监视队列并处理数据包,是否有东西Java监视QueueStack?有一个更好的方法吗?

public void read(String multicastIpAddress, int multicastPortNumber) {
        PacketParser parser = new PacketParser(logger);
        InetAddress multicastAddress = null;
        MulticastSocket multicastSocket = null;
        final int PortNumber = multicastPortNumber;
        try {
            multicastAddress = InetAddress.getByName(multicastIpAddress);
            multicastSocket = new MulticastSocket(PortNumber);
            String hostname = InetAddress.getLocalHost().getHostName();
            byte[] buffer = new byte[8192];
            multicastSocket.joinGroup(multicastAddress);
            System.out.println("Listening from " + hostname + " at " + multicastAddress.getHostName());
            int numberOfPackets = 0;
            while (true) {
                numberOfPackets++;
                DatagramPacket datagramPacket = new DatagramPacket(buffer, …
Run Code Online (Sandbox Code Playgroud)

java

6
推荐指数
1
解决办法
500
查看次数

实体类型<T>不是当前上下文的模型的一部分

我已经测试了模型中的其他表格并且它们正在运行.但是,我添加了两个新表,它们不在模型中.

如何确保数据库表是模型的一部分?

OnModelCreating 在此代码中未调用. 在此输入图像描述

The entity type AppToLeadRequestLine is not part of the model for the current context.
Run Code Online (Sandbox Code Playgroud)

向表中添加项时会抛出此异常.

public void Add<T>(T obj) where T : class
{
   Set<T>().Add(obj);
}
Run Code Online (Sandbox Code Playgroud)

我将这两个表添加到数据库中.

在此输入图像描述

将这两个表添加到数据库后,我使用了在模型中生成它们Update Model from Database,并且两个表都出现在模型中. 在此输入图像描述

当我查看表映射时,它们似乎映射到正确的POCO.我不是百分百肯定的.

在此输入图像描述 在此输入图像描述

这些类看起来像这样: 在此输入图像描述 在此输入图像描述

c# entity-framework

5
推荐指数
1
解决办法
3388
查看次数

5
推荐指数
1
解决办法
5980
查看次数

OSError:[WinError87]参数不正确

我有一个使用python 3.4.3编写的python脚本,它会输入一个ip地址,用户名和密码的.csv文件,以传递给另一个批处理脚本.

import pdb
import csv
import os
import subprocess
import datetime
import time
import signal
from multiprocessing import Process

def callGetDimmBatchFile(logFile, batchFileName, ipAddress, userName, passWord):
    print('\nId: {0}'.format(counter) + '\n', file=logFile, flush=True)
    command ='{0} -i {1} -u {2} -p {3}'.format(batchFileName, ipAddress, userName, passWord)
    print(command, file=logFile, flush=True)
    print("IP Address is {0}".format(ipAddress))
    print("User name is {0}".format(userName))
    print("Password is {0}".format(passWord))
    timeout = 60
    start = datetime.datetime.now()
    process = subprocess.Popen(command, stdout=logFile, stderr=logFile)
    while process.poll() is None:
        time.sleep(0.1)
        now = datetime.datetime.now()
        if (now - start).seconds …
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
8210
查看次数

检查observableArray中是否存在某个项目

为什么重复检查Artist总是返回false

有关可运行的演示,请参阅此JSFiddle.

淘汰赛代码

$(function() {

  function Artist(name) {
    this.name = name;
  }

  function ViewModel() {
    var self = this;
    self.favoriteArtists = ko.observableArray([]);
    self.artistToAdd = ko.observableArray("");
    self.addArtist = function () {
      var newFavoriteArtist = new Artist(self.artistToAdd());
      console.log("New Favorite Artist: " + newFavoriteArtist.name);
      var artistExists = self.favoriteArtists.indexOf(newFavoriteArtist) > 0;
      console.log("Artist Exists: " + artistExists);
      if(!artistExists) {
          self.favoriteArtists.push(newFavoriteArtist);
          console.log("A new artist has been added:" + self.artistToAdd());
      } else {
        console.log("Artist already in favorites.");
      }
    };
  }  
  ko.applyBindings(new …
Run Code Online (Sandbox Code Playgroud)

javascript knockout.js

4
推荐指数
2
解决办法
2万
查看次数

使用连接字符串连接到数据库以使用LINQ

我有一个连接字符串,我想使用LINQ来查询远程数据库.在Microsoft示例中,他们使用DataContext该类.但是DataContext,Intellisense中没有出现.它说它使用'System.Data.Linq`但我也没有看到.http://msdn.microsoft.com/en-us/library/bb350721(v=vs.110).aspx

是否有使用连接字符串和LINQ的Hello World示例?

public void SimpleQuery()
{
    var connectionString = @"Server=10.1.10.1;database=Mydatabase;uid=myusername;password=mypassword;";
    DataContext dc = new DataContext(connectionString);

    var q =
        from n in dc.table
        select n;

    Console.WriteLine(n);
}
Run Code Online (Sandbox Code Playgroud)

c# sql linq

3
推荐指数
1
解决办法
6100
查看次数

如何使用TortoiseSVN签出旧版本

如何将文件或文件夹签出到我的工作副本中的特定修订版?我只想查看文件,而不是编辑或检查它们.

我更愿意使用TortoiseSVN客户端.

svn tortoisesvn

3
推荐指数
1
解决办法
5313
查看次数

确定字符串列表中的条件

我习惯了C#并编写了一个python脚本.我想确定列表中的任何字符串是否包含字符串"ERROR".

在C#中我会做这样的事情:

string myMatch = "ERROR";
List<string> myList = new List<string>();
bool matches = myList.Any(x => x.Contains(myMatch));
Run Code Online (Sandbox Code Playgroud)

我在python中的尝试告诉返回,TRUE即使列表包含包含该单词的字符串ERROR.

def isGood (linesForItem):
    result = True;
    if 'ERROR' in linesForItem:
        result = False
    return result
Run Code Online (Sandbox Code Playgroud)

python python-3.4

2
推荐指数
1
解决办法
39
查看次数