我已经创建了一个示例应用程序,其中我使用了nuget包HtmlRenderer.PdfSharp
我在我的控制台应用程序中使用以下代码从html生成pdf:
string input = File.ReadAllText("..//..//HTML//dfdf.html");
PdfDocument document = new PdfDocument();
document.Info.Title = "Test";
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
//XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
// Create a font
TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerateConfig pdfconfg = new TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerateConfig();
pdfconfg.PageSize = PdfSharp.PageSize.A4;
document = PdfGenerator.GeneratePdf(input, pdfconfg);
document.Save("..//..//PDF//dfdf.pdf");
Run Code Online (Sandbox Code Playgroud)
但是当html页面的文本很长时,它就不会重新发送内容.只生成空白页.请帮忙.我想使用这个库,因为它提供了所需的输出.
我有一个简单的DTO类,我将其设置为窗体上绑定源的数据源.
表单包含具有Value属性的自定义控件.这是属性:
[Browsable(false)]
[Bindable(BindableSupport.Yes, BindingDirection.TwoWay)]
public virtual T Value
{
get { return this.value; }
set { this.value = value; }
}
Run Code Online (Sandbox Code Playgroud)
当控件绑定到bindingsource时,setter被调用6次.当控件未绑定时,setter仅被调用2次
在这两种情况下,第一次调用是因为设计器代码有一行:
mycontrol.Value = null;
Run Code Online (Sandbox Code Playgroud)
最后一次调用是因为我设置了一个值.所以第一次和最后一次通话都是正常的.但是当绑定控件时,为什么setter被称为额外4次?
我有一个asp.net MVC5应用程序,其中有用户注册到系统。我一直在遵循并运行的http://www.asp.net/mvc/overview/security/aspnet-mvc-5-app-with-sms-and-email-two-factor-authentication教程。我希望在用户注册时默认启用两因素身份验证。
由此,我修改了注册模型以包括经过测试的Phone,并将其插入ASP.Net users表中没有问题。我的问题是我似乎无法解决如何默认启用两个因素
我需要await UserManager.SupportsUserTwoFactor();在register方法中使用类似的东西吗?
我的控制器是
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
// Comment the following line to prevent log in until the user is confirmed.
// await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account",
new { userId …Run Code Online (Sandbox Code Playgroud) 我正在开发一个项目,该项目有一些跑步者,每个跑步者都可以同时上传文件。任意地我会得到一个“流不支持并发 IO 读或写操作”错误。
我们已经看到它发生在小文件(5Mb~10Mb)和大文件(1Gb~2Gb)上。我们甚至尝试了完全相同的文件,有时我们能够重现它。
我们的设置具有 NTLM 身份验证、自签名证书并使用 OWIN/Katana 自托管。全部使用 .Net 编写。
它只发生在(到目前为止)在虚拟机上,我们还没有使用物理机来解决这个问题,尽管其中一些虚拟机真的很强大
这是我的代码:
客户
public Guid Upload(string filePath, Guid taskId)
{
if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("Value cannot be empty.", "filePath"); }
var key = Guid.Empty;
var fileInfo = new System.IO.FileInfo(filePath);
using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open))
{
var content = new StreamContent(fileStream);
content.Headers.Add("TaskId", taskId.ToString());
content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
content.Headers.ContentDisposition.FileName = fileInfo.Name;
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
content.Headers.ContentLength = fileInfo.Length;
key = HttpClient.PostGet<Guid>(content, "https://localhost:1234/Files/Upload");
}
return key;
}
public T …Run Code Online (Sandbox Code Playgroud) 我正在使用GDI32.dll捕获窗口快照,虽然我遇到了硬件加速Windows的问题,我想知道是否有办法规避.
我在这里找到了这个惊人的代码:
public static Image CaptureWindow(IntPtr handle)
{
IntPtr hdcSrc = User32.GetWindowDC(handle);
Rect windowRect = new Rect();
User32.GetWindowRect(handle, ref windowRect);
int width = windowRect.Right - windowRect.Left;
int height = windowRect.Bottom - windowRect.Top;
IntPtr hdcDest = Gdi32.CreateCompatibleDC(hdcSrc);
IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcSrc, width, height);
IntPtr hOld = Gdi32.SelectObject(hdcDest, hBitmap);
Gdi32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY);
Gdi32.SelectObject(hdcDest, hOld);
Gdi32.DeleteDC(hdcDest);
User32.ReleaseDC(handle, hdcSrc);
Image image = Image.FromHbitmap(hBitmap);
Gdi32.DeleteObject(hBitmap);
return image;
}
Run Code Online (Sandbox Code Playgroud)
适用于所有窗户,除了我的镀铬窗户.在chrome中禁用硬件加速修复了这个问题虽然我不想这样做.
任何人对此问题有任何建议/解决方案吗?
感谢您的帮助,
- 保罗
我在 .NET 应用程序中卸载 AppDomain 时遇到问题。
我有以下代码,它只是将 dll 加载到目录中并检查它们是否具有特定属性:
AppDomainSetup info = new AppDomainSetup();
Assembly arAssembly = typeof(AssemblyResolver).Assembly;
info.ApplicationBase = Path.GetDirectoryName(arAssembly.Location);
AppDomain appDomain = AppDomain.CreateDomain("AssemblyResolver", null, info);
//Find all the assemblies with the attribute defined
AssemblyName[] assemblyNames = null;
AssemblyResolver ar = (AssemblyResolver)appDomain.CreateInstanceAndUnwrap(arAssembly.FullName, typeof(AssemblyResolver).FullName) as AssemblyResolver;
assemblyNames = ar.PrivateFindAssembliesWithAttribute(attributeType, path, includeSubdirs);
//Finally unload the AppDomain
AppDomain.Unload(appDomain); <-- HANGS HERE
appDomain = null;
Run Code Online (Sandbox Code Playgroud)
这对于我所有具有相关属性的 dll 来说效果很好。但我有一个 dll,其中包含对第 3 方 dll 的引用(PelcoSDK.dll,请参阅:http ://pdn.pelco.com/sdk#sthash.ERuOPMO6.dpbs )
每当包含此 dll 时,以下行就会冻结:
AppDomain.Unload(appDomain);
Run Code Online (Sandbox Code Playgroud)
通过此链接: https: //social.msdn.microsoft.com/Forums/en-US/3f0f10ae-7fcb-459d-9112-6556a9b5b456/appdomainunload-deadlock ?forum=csharplanguage …
支持我的应用程序的SQL表和模型与下面显示的非常相似。
Id | CustomerName | FruitName | Charge
_____________________________________
1 | Bob | Banana | 3.00
2 | Jill | Apple | 2.00
3 | Bob | Apple | 3.00
4 | Marvin | Banana | 1.00
5 | Sam | Pear | 4.00
Run Code Online (Sandbox Code Playgroud)
[Key]
public int Id {get; set;}
public string CustomerName { get; set; }
public string FruitName { get; set;}
public string Charge {get; set;}
Run Code Online (Sandbox Code Playgroud)
我想这样做是拉动明显FruitName和Charge.Sum()并显示它ToList()在我的视野。这是我尝试过的
var fruitToList = (from f …Run Code Online (Sandbox Code Playgroud) 有谁知道如何检索解决方案中的所有可用类型(语义)?从多个项目中创建汇编很容易。
MSBuildWorkspace workspace = MSBuildWorkspace.Create();
var solution = await workspace.OpenSolutionAsync(solutionPath, cancellationToken);
var compilations = await Task.WhenAll(solution.Projects.Select(x => x.GetCompilationAsync(cancellationToken)));
Run Code Online (Sandbox Code Playgroud)
仅迭代所有ClassDeclarations对我来说是不够的,因为我想要所有类型以及它们之间的连接。
foreach (var tree in compilation.SyntaxTrees)
{
var source = tree.GetRoot(cancellationToken).DescendantNodes();
var classDeclarations = source.OfType<ClassDeclarationSyntax>();
}
Run Code Online (Sandbox Code Playgroud) 我在这里有一种非常奇怪的感觉,我错过了一些东西,但现在我已经在这个问题上苦苦挣扎了几个小时,但无法得到它。我有一种任务调度类,它主要接收它启动的正常同步操作,而不是通过 Task.Run() 异步操作。但是,当它收到传递的异步操作时,它会返回而不等待等待任务。我将其简化为以下示例:
private async void Button_OnClick(object sender, RoutedEventArgs e)
{
Logger("Click event received");
await OperationProcessor(async () =>
{
Logger(">>> Starting ACTION, waiting 5 seconds");
await Task.Delay(5000);
Logger(">>> ACTION finished");
});
Logger("Click event finished");
}
private static async Task OperationProcessor(Action operation)
{
Logger("Processing started, waiting a second");
await Task.Delay(1000);
Logger("Launching action");
await Task.Run(operation);
Logger("Returned from action, waiting another second");
await Task.Delay(1000);
Logger("Processing finished");
}
private static void Logger(string message)
{
Console.WriteLine($"{DateTime.Now:dd.MM.yy HH:mm:ss} [{Thread.CurrentThread.ManagedThreadId}] {message}");
}
Run Code Online (Sandbox Code Playgroud)
这会产生以下输出:
1: 16.07.19 10:58:06 [1] …Run Code Online (Sandbox Code Playgroud) 我有同样的情况Decrypt Rijndael 256 Block Size with BouncyCastle
所以我从那篇文章中修复了代码,并替换了我的旧代码
public static string Decrypt(string cipherText, string superSecretPassPhrase)
{
if (cipherText == null)
{
throw new ArgumentNullException(nameof(cipherText));
}
// Get the complete stream of bytes that represent:
// [32 bytes of Salt] + [32 bytes of IV] + [n bytes of CipherText]
var cipherTextBytesWithSaltAndIv = Convert.FromBase64String(cipherText);
// Get the saltbytes by extracting the first 32 bytes from the supplied cipherText bytes.
var saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize / 8).ToArray();
// Get the IV bytes …Run Code Online (Sandbox Code Playgroud) c# ×10
.net ×3
asp.net-mvc ×2
appdomain ×1
asp.net ×1
asynchronous ×1
bitblt ×1
bouncycastle ×1
data-binding ×1
encryption ×1
gdi ×1
rendering ×1
rijndael ×1
roslyn ×1
task ×1
upload ×1
winforms ×1