我有一个类,它使用外部进程来创建文件,并作为下载结果返回,此时我想从服务器中删除该文件。我通常喜欢避免临时磁盘文件,但在这种情况下这是无法避免的。
我最初尝试使用 Dispose 方法来实现这一点:
public class SetupFile : IDisposable
{
/// <summary>Local file path</summary>
public string LocalFilePath { get; set; }
/// <summary>Filename to present to user</summary>
public string DownloadFilename { get; set; }
public void Dispose()
{
System.IO.File.Delete(LocalFile);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器代码创建并操作该文件,然后将结果返回为FilePathResult:
public class DownloadController : Controller
{
public SetupFileGenerator Generator { get; set; }
public DigitalSignatureTool Signer { get; set; }
[HttpPost, Route("/download")]
public ActionResult Download(InstallParams params)
{
using (SetupFile file = Generator.Generate(params)) {
{
Signer.Sign(file.LocalFilePath); // …Run Code Online (Sandbox Code Playgroud) 我正在使用嵌套集(又名修改的预序树遍历)来存储组列表,并且我正在尝试找到一种快速方法来一次为所有组生成面包屑(作为字符串,而不是表格)。我的数据也是使用邻接表模型存储的(有触发器可以保持两者同步)。
例如:
ID Name ParentId Left Right
0 Node A 0 1 12
1 Node B 0 2 5
2 Node C 1 3 4
3 Node D 0 6 11
4 Node E 3 7 8
5 Node F 4 9 9
Run Code Online (Sandbox Code Playgroud)
其中代表树:
我希望能够有一个返回表的用户定义函数:
ID Breadcrumb
0 Node A
1 Node A > Node B
2 Node A > Node B > Node C
3 Node A > Node D …Run Code Online (Sandbox Code Playgroud) 我基本上有一个开箱即用的MVC 5.2 app,启用了基于属性的路由(routes.MapMvcAttributeRoutes();从提供的RouteConfig.RegisterRoutes(RouteCollection routes)方法调用).
以下是HomeController:
[Route("hello.txt")]
[Route("hellotxt-testing")]
public ActionResult ShowFile()
{
return Content("Hello world");
}
Run Code Online (Sandbox Code Playgroud)
我可以成功访问/hellotxt-testing(证明基于属性的路由正常工作):

但如果我访问,我会得到404页/hello.txt:

与我去的/hello404地方相比,我得到了另一个404页面:

我猜第二个404页面来自ASP.NET,而第一个是来自IIS甚至没有将请求传递给ASP.NET?
我该怎么做才能确保我能确保ASP.NET获取这些包含句点的URL?还有其他"特殊"字符也会导致问题吗?
我有一个类:
public class ContainerClass
{
public guid Group { get; set; }
public int Value { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
包含在:
IEnumerable<ContainerClass>
Run Code Online (Sandbox Code Playgroud)
如何将其转换为以下字典?
Dictionary<guid, List<int>>
Run Code Online (Sandbox Code Playgroud)
我看过类似的问题(例如
,在列表中创建一个带分组的字典),但这与Dictionary<guid, List<ContainerClass>>我想要的不同.
我知道我可以做一个辅助linq查询,只是在我有一个IEnumerable之后获取值条目,但这看起来很混乱; 似乎应该有一种方法可以在一个语句中直接执行此操作.
编辑:注意,我知道Lookup(),但在这种情况下,我实际上正在进行Group的批量处理,所以我确实需要Dictionary(或者每个组都有一组Values的东西).在这种情况下,每个组都被发送到一个资源,我想要批量发送该资源的所有值:如果我有10个组,每个组有50个值(总共列表中有500个条目),我想制作10个电话.
class kk{
public static void main(String args[]){
int n=0;
for (byte i = 0; i<=255; i++)
{
n++;
}
System.out.println(n);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的for循环继续无限.如果有人能回答为什么,我将不胜感激?
我试图在MAC OS X 10.9(Mavericks)下制作静态二进制文件,这不需要单声道运行时.这几乎是干净的机器,带有最新的更新和最新的XCode.
如果我没有设置构建体系结构,我有以下内容:
mkbundle client-patcher.exe -o client-patcher
OS is: Darwin
Sources: 1 Auto-dependencies: False
embedding: /Users/radubalan/tmp/client-patcher.exe
Compiling:
as -o temp.o temp.s
cc -g -o client-patcher -Wall temp.c `pkg-config --cflags --libs mono-2` temp.o
ld: warning: ignoring file /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/libmono-2.0.dylib, file was built for i386 which is not the architecture being linked (x86_64): /Library/Frameworks/Mono.framework/Versions/3.4.0/lib/libmono-2.0.dylib
Undefined symbols for architecture x86_64:
"_mono_main", referenced from:
_main in temp-b1f73b.o
"_mono_register_bundled_assemblies", referenced from:
_mono_mkbundle_init in temp-b1f73b.o
"_mono_set_dirs", referenced from:
_main in temp-b1f73b.o
ld: symbol(s) not found …Run Code Online (Sandbox Code Playgroud) 在.NET中有没有办法在给定System.Type的情况下创建源代码类定义?
public class MyType
{
public string Name { get; set; }
public int Age { get; set; }
}
string myTypeSourceCode = GetSourceCode( typeof(MyType) );
Run Code Online (Sandbox Code Playgroud)
基本上我在寻找GetSourceCode()是什么.
我意识到会有限制:如果有属性getter/setter或私有成员,则不包含源,但我不需要.假设类型是数据传输对象,因此只需公开公共属性/字段.
我正在使用它的是自动生成的Web API代码示例.
c# ×3
.net ×2
asp.net-mvc ×2
.net-4.0 ×1
asp.net ×1
breadcrumbs ×1
iis ×1
iis-8 ×1
java ×1
linq ×1
macos ×1
mkbundle ×1
mono ×1
mptt ×1
nested-sets ×1
reflection ×1
sql ×1