有没有人有一个脚本的例子可以在IE/Firefox中可靠地工作,以检测浏览器是否能够显示嵌入式Flash内容.我说得可靠,因为我知道它不可能100%的时间.
考虑这种方法:
private static int GenerateRandomNumber(int seed, int max)
{
return new Random(seed).Next(max);
}
Run Code Online (Sandbox Code Playgroud)
在我的机器上,执行此循环会产生相同数量的1500次迭代:
for (int i = 0; i < 1501; i++)
{
int random = GenerateRandomNumber(100000000, 999999999);
Console.WriteLine(random.ToString());
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
每次迭代我得到145156561.
我没有一个紧迫的问题,我只是好奇这个问题的原因.接下来(最大值)说:"返回一个非负随机比指定的最大数量较少,也许我不理解一些基本的东西.
我无法将我创建的word文档流式传输到浏览器.我不断收到来自Microsoft Word的消息,该文档已损坏.
当我通过控制台应用程序运行代码并将ASP.NET从图片中删除时,文档生成正确,没有任何问题.我相信一切都围绕着写下文件.
这是我的代码:
using (MemoryStream mem = new MemoryStream())
{
// Create Document
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document, true))
{
// Add a main document part.
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
new Document(new Body()).Save(mainPart);
Body body = mainPart.Document.Body;
body.Append(new Paragraph(new Run(new Text("Hello World!"))));
mainPart.Document.Save();
// Stream it down to the browser
// THIS IS PROBABLY THE CRUX OF THE MATTER <---
Response.AppendHeader("Content-Disposition", "attachment;filename=HelloWorld.docx");
Response.ContentType = "application/vnd.ms-word.document";
mem.WriteTo(Response.OutputStream);
Response.End();
}
}
Run Code Online (Sandbox Code Playgroud)
我看了很多链接 - 但没有什么可行的.我很多人使用MemoryStream.WriteTo
和使用BinaryWrite …
我们有一个应用程序,除其他外,检查cookie的存在并读取和解密cookie的内容.虽然存储在cookie中的数据不敏感,但它已通过TripleDes加密进行加密.今天提出的问题是,保存在单个PC上的cookie是否可以复制到另一台PC上,以及Web应用程序是否会在另一台机器上检测到这个复制的cookie的存在,并最终解密它在原始PC上的内容.
我的问题是:我们使用标准的ASP.NET实现来保存cookie(即通过HttpResponse),index.dat文件是否阻止cookie从一台机器移植到另一台机器?如果index.dat文件也被传输和复制,或者index.dat中是否存在将cookie绑定到特定机器的内部结构,该怎么办?
我正在使用TouchXml,因为NSXML在实际的iPhone上存在限制.无论如何,我刚刚开始使用Objective-C,我来自C#背景,感觉就像在学习一些新东西......但是......这是我的xml文件......
<?xml version="1.0" encoding="utf-8"?>
<FundInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/webservices">
<FundsReleaseDate>2009-02-11T00:00:00</FundsReleaseDate>
<FundValue>7800</FundValue>
<FundShares>1000</FundShares>
</FundInfo>
Run Code Online (Sandbox Code Playgroud)
我想获得7800,即FundValue.有人点我在正确的方向,我现在用的是TouchXml CXMLDocument和myParser的类型是CXMLDocument的,我曾尝试
NSArray *nodes = [myParser nodesForXPath:@"//FundInfo" error:&err];
Run Code Online (Sandbox Code Playgroud)
基本上节点的评估结果为零
if ([nodes count] > 0 ) {
amount = [nodes objectAtIndex:1];
}
Run Code Online (Sandbox Code Playgroud)
更新1:我已经使用XPath放弃解析,并用的NSURLRequest取代它,所以现在我有一个字符串在整个XML,但我的粗鲁介绍客观-C继续...我只是意识到如何撒娇我已经成为了.NET BCL,像Regex这样的东西很容易获得.
UPDATE2:我已经想通了如何使用RegexKitLite的正则表达式.
所以,现在的问题是,我该如何获得"7800"由内FundValue现在是一个大的字符串.我已确认我有它在我的NSString使用NSLog的写它.
我的NSString值为@"78000".我如何以货币格式获得此信息,即78,000美元,其余为NSString.
所以我试图从另一个Mocked类型返回一个模拟类型,我已经取得了一些进展但是我被困在这里(界面名称已被简化)
考虑接口IFoo和IFooItem.在IFoo类型上调用Add,传入IBar会返回一个IFooItem
interface IFoo
{
IFooItem Add(IBar bar);
}
interface IFooItem
{
int fooItemId {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我还有一个IFooRepository,我正在尝试使用Moq来模拟,所以我可以模拟添加一个项目.
所以,
var mockFooRepository = new Mock<IFooRepository>();
mockFooRepository.Setup(m=> m.Add(It.IsAny<IBar>()))
.Returns(
// What is the correct way to mock properties of a new IFooItem from
// mocked properties of IBar
// essentially a new mocked type of IFooItem that can read from IBar
// so IFooItem.Property = somevalue, IFooItem.Property2 = IBar.SomeProp
);
Run Code Online (Sandbox Code Playgroud) 我有Windows服务,必须定期从服务器打印PDF文档.我的功能是
private void PrintFormPdfData(byte[] formPdfData)
{
string tempFile;
tempFile = Path.GetTempFileName();
using (FileStream fs = new FileStream(tempFile, FileMode.Create))
{
fs.Write(formPdfData, 0, formPdfData.Length);
fs.Flush();
}
string pdfArguments = string.Format("/p /h\"{0}\"", tempFile);
string pdfPrinterLocation = @"C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe";
ProcessStartInfo newProcess = new ProcessStartInfo(pdfPrinterLocation, pdfArguments);
newProcess.CreateNoWindow = true;
newProcess.RedirectStandardOutput = true;
newProcess.UseShellExecute = false;
newProcess.RedirectStandardError = true;
Process pdfProcess = new Process();
pdfProcess.StartInfo = newProcess;
pdfProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pdfProcess.Start();
pdfProcess.WaitForExit();
}
Run Code Online (Sandbox Code Playgroud)
当我在Windows应用程序中实现它时,它可以工作,但是当我在Windows服务中实现它时,它不起作用.
你能帮助我吗?
我的设备具有唯一的序列号(字符串增量)例如:AS1002和AS1003.
我需要找出一种算法来为每个序列号生成一个唯一的激活密钥.
对此最好的方法是什么?
谢谢 !
(这必须离线完成)
我正在尝试登录vbulletin论坛.我到目前为止:
private string login(string url, string username, string password)
{
string values = "vb_login_username={0}&vb_login_password={1}"
values += "&securitytoken=guest&cookieuser=checked&do=login";
values = string.Format(values, username, password);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
CookieContainer a = new CookieContainer();
req.CookieContainer = a;
System.Net.ServicePointManager.Expect100Continue = false; // prevents 417 error
using (StreamWriter writer = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
{ writer.Write(values); }
this.response = (HttpWebResponse)req.GetResponse();
StringBuilder output = new StringBuilder();
foreach (var cookie in response.Cookies)
{
output.Append(cookie.ToString());
output.Append(";");
}
return output.ToString();
}
Run Code Online (Sandbox Code Playgroud)
看起来我正在登录,但是当我下载页面时,我找不到我的用户名.
你们看到我可能做错了吗?
提前致谢!