我正在使用以下C#代码从远程服务提供商FTP一个~40MB的CSV文件.大约50%的时间,下载挂起并最终超时.在我的应用程序日志中,我得到一行:
> Unable to read data from the transport
> connection: A connection attempt
> failed because the connected party did
> not properly respond after a period of
> time, or established connection failed
> because connected host has failed to
> respond.
Run Code Online (Sandbox Code Playgroud)
当我使用像LeechFTP这样的图形客户端以交互方式下载文件时,下载几乎从不挂起,并在大约45秒内完成.我有一段时间了解出了什么问题.
任何人都可以建议我如何使用此代码来更深入地了解正在发生的事情,或者更好地下载此文件的方法?我应该增加缓冲区大小吗?多少钱?避免缓冲写入磁盘并尝试吞下内存中的整个文件?任何建议赞赏!
...
private void CreateDownloadFile()
{
_OutputFile = new FileStream(_SourceFile, FileMode.Create);
}
public string FTPDownloadFile()
{
this.CreateDownloadFile();
myReq = (FtpWebRequest)FtpWebRequest.Create(new Uri(this.DownloadURI));
myReq.Method = WebRequestMethods.Ftp.DownloadFile;
myReq.UseBinary = true;
myReq.Credentials = new NetworkCredential(_ID, _Password);
FtpWebResponse myResp = …Run Code Online (Sandbox Code Playgroud) 我正在HttpModule以这样的方式处理异常:
int errorCode = 500;
HttpApplication httpApp = (HttpApplication)sender;
try
{
if (httpApp.Server != null)
{
Exception ex;
for (ex = httpApp.Server.GetLastError(); ex != null; ex = ex.InnerException)
{
try
{
HttpException httpEx = ex as HttpException;
if (httpEx != null)
errorCode = httpEx.GetHttpCode();
// ... retrieve appropriate content based on errorCode
}
catch { }
}
}
Run Code Online (Sandbox Code Playgroud)
对于HTTP状态代码(例如:302,404,503等),一切都很好.但是,对于IIS状态代码(例如:401.5,403.4等),可以GetHttpCode检索这些,因为它的返回值是整数吗?
我有
FormsAuthentication.SetAuthCookie("someName", True)
Run Code Online (Sandbox Code Playgroud)
作为我的自定义登录序列的一部分.后来,我有一些页面只允许一个特定的角色:
<location path="myPage.aspx">
<system.web>
<authorization>
<allow roles="SomeRole"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
Run Code Online (Sandbox Code Playgroud)
据我所知,这会调用我的角色提供程序的GetRolesForUser实现.它似乎从Web.HttpContext.Current.User.Identity.Name获取用户名参数.
我的问题是...... 来自auth cookie的用户名何时被设置为我当前用户身份中的名称?
有没有人有一个Emacs宏来缩进(和unindenting)文本块?
我的意思是"缩进",在通常理解的意义上,而不是在Emacspeak中.换句话说,我想标记一个区域,按Cu 2,运行此宏,并在区域中的每一行之前添加两个空格.
或者在运行宏之前按Cu -2,并从区域中每行的开头删除两个空格.如果线条没有足够的前导空格,则会产生奖励.
我正在测试ClickOnce应用程序部署.我在我的机器上设置了一个虚拟目录(运行IIS).我已在Visual Studio的"发布"选项卡中将http:// localhost/SampleApplication指定为"安装文件夹URL".但是,当我发布应用程序时,我收到以下错误:
警告:无法从http:// chrish/SampleApplication /下载文件.
远程服务器返回错误:(407)需要代理身份验证.发布成功.
警告:无法在http://chrish/SampleApplication/publish.htm查看已发布的应用程序 . HTTP://chrish/SampleApplication/publish.htm
请注意它是如何将我的URL从Localhost更改为我的登录名.为什么?一周前没有发生这种情况.
我正在尝试以编程方式随时检索我的iPhone应用程序正在使用的内存量.是的我知道ObjectAlloc/Leaks.我对这些不感兴趣,只知道是否可以编写一些代码并获取正在使用的字节数并通过NSLog报告.
谢谢.
我正在写一个网络蜘蛛,并希望使用boost regex库而不是制作一些复杂的解析函数.
我看了一下这个例子:
#include <string>
#include <map>
#include <boost/regex.hpp>
// purpose:
// takes the contents of a file in the form of a string
// and searches for all the C++ class definitions, storing
// their locations in a map of strings/int's
typedef std::map<std::string, int, std::less<std::string> > map_type;
boost::regex expression(
"^(template[[:space:]]*<[^;:{]+>[[:space:]]*)?"
"(class|struct)[[:space:]]*"
"(\\<\\w+\\>([[:blank:]]*\\([^)]*\\))?"
"[[:space:]]*)*(\\<\\w*\\>)[[:space:]]*"
"(<[^;:{]+>[[:space:]]*)?(\\{|:[^;\\{()]*\\{)");
void IndexClasses(map_type& m, const std::string& file)
{
std::string::const_iterator start, end;
start = file.begin();
end = file.end();
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
while(regex_search(start, end, what, …Run Code Online (Sandbox Code Playgroud) 如果您创建一个存储库类来封装给定实体的所有持久性逻辑(例如PersonRepository),但您的存储库类不实现工作单元模式或身份映射模式,它是否仍被视为存储库?换句话说,存储库实现是否需要工作单元和身份映射,或者我们可以只调用将持久性逻辑封装到存储库的任何类吗?
我应该补充一点.如果存储库不需要这些模式并且它实际上只是持久性方法的容器,那么存储库和DAO(数据访问对象)之间有什么区别?我们只是为同一个对象创建多个名称,还是我们错过了存储库应该是什么的一部分?
非常感谢以下的一些建议 - 是否可以通过oracle中的sql中的某种检查约束来验证电子邮件和邮政编码字段?或者这种事情,因为我怀疑pl/sql与正则表达式?
谢谢
我需要对测试驱动开发进行简短的演示(2-4小时),并且需要提出一个我可以使用TDD方法构建的小类.该课程必须相对较小,但"出售"TDD的概念.
如果有人读过James Newkirk的书,即Microsoft.Net中的测试驱动开发,那么Stack的例子就是完美的.它是一个小类,有一个可管理的测试/要求列表,创建过程销售TDD(恕我直言).
我不想使用Stack示例或类似的数据结构(队列,列表等)来担心影响Newkirk的工作.
所以,我正在为样本课寻找一些好主意.
谢谢.