有没有办法获取给定的XML文件并转换(最好使用C#Generics)它到T的具体可枚举列表中,其中T是我的具体类
例如,我可能有一个类似的XML文件
<fruits>
<fruit>
<id>1</id>
<name>apple</name>
</fruit>
<fruit>
<id>2</id>
<name>orange</name>
</fruit>
</fruits>
Run Code Online (Sandbox Code Playgroud)
我想看一个水果对象列表
它有类似的属性
public class Fruit : IFruit
{
public string name;
public int id;
}
Run Code Online (Sandbox Code Playgroud)
我假设我需要某种映射,如果我要使用泛型,因为我希望这适用于理想的IFruit接口(不确定是否可能)
提前致谢
好吧,所以我试图权衡使用各种不同纹理压缩技术的专业人士和骗子.我花了99.999%的时间使用DirectX为Windows机器编写2D精灵游戏.
到目前为止,我已经看了纹理打包(SpriteSheets)与alpha修剪,这似乎是获得更多性能的好方法.现在我开始看看它们存储的纹理格式; 目前所有内容都存储为*.PNGs.
我听说*.DDS文件很好,尤其是当与DXT5(/ 3/1取决于任务)压缩一起使用时,因为纹理在VRAM中保持压缩状态?还有人说,因为它们已经是DirectDraw Surfaces,所以它们加载的速度也快得多.
所以我创建了一个应用程序来测试它; 我将该行调用20次以下,在每次调用之间释放纹理.
for (int i = 0; i < 20; i++)
{
if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, L"Test.dds", &g_pTexture ) ) )
{
return E_FAIL;
}
g_pTexture->Release();
g_pTexture = NULL;
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我尝试使用DXT5纹理,它需要比在简单的*.PNG中加载要长5倍.我听说如果你不生成Mipmap,它会变慢,所以我仔细检查了一下.然后我改变了我用来生成*.DDS文件的程序,切换到NVIDIA自己的nvcompress.exe,但没有任何效果.
编辑:我忘了提到文件(*.png和*.dds)都是相同的图像,只是以不同的格式保存.(相同大小,alpha数量,一切!)
编辑2:当使用以下参数时,它的加载速度提高了近2.5倍,并且消耗的VRAM少了很少!
D3DXCreateTextureFromFileEx( g_pd3dDevice, L"Test.dds", D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_FROM_FILE, 0, D3DFMT_FROM_FILE, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, NULL, NULL, &g_pTexture )
Run Code Online (Sandbox Code Playgroud)
但是,我现在正在失去纹理的所有透明度,我看了DXT5纹理,它在Paint.NET和DirectX DDS Viewer中看起来很好.但是当装入所有透明度时变成纯黑色.ColorKey问题?
编辑3:忽略最后一点,我是愚蠢的,在我的"快速示例"中,我忘了在D3DXSprite-> Begin()上启用Alpha-Blending.卫生署!
我的团队正在进行更好的辩论:Windows服务或计划任务.我们有一个专门用于运行作业的服务器,目前它们都是计划任务.某些作业会获取文件,重命名并将它们放在网络上的其他目录中.其他作业从SQL中提取数据,对其进行修改并将其发送到其他位置.其他工作ftp文件输出.有很多种,但总而言之,它们相当简单.
我倾向于将每个运行作为Windows服务而不是计划任务运行,因为监视Windows服务比计划任务更容易.有些人截然相反.最后,我们都没有那么多经验来提供两种方法之间的实际事实比较.我正在寻找一些关于其他人经历过的反馈.
典型的调用performSelectorOnMainThread:看起来像这样:
[target performSelectorOnMainThread:action withObject:foo waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud)
其中"result"是传递给"action"的参数.相应的行动将是:
- (void)doSomethingWithThing1:(id *)thing1
Run Code Online (Sandbox Code Playgroud)
调用> 1参数的动作的正确语法是什么?如:
- (void)doSomethingWithThing1:(id *)thing1 andThing2(id *)thing2 andAlsoThing3(id *)thing3
[target performSelectorOnMainThread:action withObject:??? waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud) 好的,我查看了其他问题,似乎没有得到我的答案,所以希望有人在这里.
非常简单的问题为什么DisplayMemberPath属性不绑定到项目?
<ComboBox Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PromptList}" DisplayMemberPath="{Binding Name}" SelectedItem="{Binding Prompt}"/>
Run Code Online (Sandbox Code Playgroud)
跟踪输出显示它正在尝试绑定到持有IEnumerable的类而不是IEnumerable中的实际项.我很困惑一个简单的方法来填充一个组合框而不在xaml中添加一串线.
它只是在itemssource中为对象调用ToString().我有一个解决方法是:
<ComboBox Grid.Row="1" Grid.Column="2" ItemsSource="{Binding PromptList}" SelectedItem="{Binding Prompt}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
但在我看来,对于这么简单的任务来说太过分了.我可以使用relativesource绑定吗?
我正在与客户端证书身份验证进行斗争.当服务器需要凭证(在这种情况下是证书)时,从NSURLConnection委托调用此方法:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
Run Code Online (Sandbox Code Playgroud)
我想从文件加载证书,填写凭证并运行此方法:
[[challenge sender] useCredential:[self credential] forAuthenticationChallenge:challenge];
Run Code Online (Sandbox Code Playgroud)
但我不知道如何初始化(或填充)SecIdentityRef参数.这是我创建凭据的代码:
NSString *certPath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"cer"];
NSData *certData = [[NSData alloc] initWithContentsOfFile:certPath];
SecIdentityRef myIdentity; // ???
SecCertificateRef myCert = SecCertificateCreateWithData(NULL, (CFDataRef)certData);
[certData release];
SecCertificateRef certArray[1] = { myCert };
CFArrayRef myCerts = CFArrayCreate(NULL, (void *)certArray, 1, NULL);
CFRelease(myCert);
NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity
certificates:(NSArray *)myCerts
persistence:NSURLCredentialPersistencePermanent];
CFRelease(myCerts);
Run Code Online (Sandbox Code Playgroud)
有人知道怎么解决吗?谢谢.
我终于找到了解决方案,但是这里出现了一个新问题:
我的客户端不会将证书发送到服务器.服务器请求证书后,应用程序运行此方法:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
Run Code Online (Sandbox Code Playgroud)
并填写凭证(如上所述),但连接以错误结束:NSURLErrorDomain -1206.根据服务器日志,应用程序不会发送客户端证书.
有没有人有这种行为的经验?我是否需要以某种方式验证应用程序中的证书?或其他任何使其有效的方法?如果它有帮助,我可以提供我当前的代码.谢谢你的任何想法......
特别是
我知道如何管理线程等.我很想知道这是否是线程安全的做事方式.
class Program
{
// bogus object
class SomeObject
{
private int value1;
private int value2;
public SomeObject(int value1, int value2)
{
this.value1 = value1;
this.value2 = value2;
}
}
static void Main(string[] args)
{
var s = new SomeObject[10];
var threads = Environment.ProcessorCount - 1;
var stp = new SmartThreadPool(1000, threads, threads);
for (var i = 0; i < 10; i++)
{
stp.QueueWorkItem(CreateElement, s, i);
}
}
static void CreateElement(SomeObject[] s, int index)
{ …Run Code Online (Sandbox Code Playgroud) 我有许多资源(旅行,计划等),其行动应仅限于资源的所有者.
如何使用ApplicationController中定义的#require_owner方法实现代码来实现此目的?理想情况下,代码将查找所有者的继承链,因此before_filter将处理:belongs_to:travel that belongs_to:user的注释.
class TripsController < ApplicationController
belongs_to :member
before_filter :require_owner
...
end
Run Code Online (Sandbox Code Playgroud) 我习惯做这样的事情:
<a href="Javascript:void(0);" onclick="GetCommentForGeneralObservation(<%# Eval("ID") %>)">
Run Code Online (Sandbox Code Playgroud)
这将是一个转发器或类似顺便说一句.但是我现在试图使用不引人注目的JavaScript,因此摆脱了标记中的任何JS.我试图弄清楚这样的情况下最佳做法是什么?我已经使用了属性,然后使用JQuery将值传递给AJAX调用,但它看起来有点像黑客.
根据第一个回复编辑:
我在考虑更多
据我所知,这是不引人注目的JS的一部分.
这恰好适用于我不必担心Javascript在客户端被关闭的应用程序,它在我公司内部托管.我得到的是如果我通过JQuery将onclick事件附加到单独的.js文件中,我将如何从Eval("ID")获取值到JS调用中.
很抱歉没有更清楚.我很欣赏在面向公众的应用程序中逐步增强的需求.
我创建了一个jexcelApi类的包装器,可以轻松地将对象列表导出到Excel.为了最小化对象创建,单元格格式创建为静态字段,并在连续的导出调用中重用.但我的日期格式有问题 - 第一个调用工作正常,但在所有连续导出日期单元格中都有数字格式而不是日期格式.如果我为日期格式创建一个新对象而不是使用静态字段,一切都很好.有没有理由为不同的工作表或工作簿使用相同的格式对象失败?
这是代码,简化了异常处理,省略了其他数据类型,可能还缺少一些导入:
ExcelCellGenerator.java:
import jxl.write.WritableCell;
public interface ExcelCellGenerator<T> {
WritableCell getCell(int col, int row, T arg);
}
Run Code Online (Sandbox Code Playgroud)
ExcelCellGeneratorFactory.java:
import jxl.write.DateFormat;
import jxl.write.DateTime;
import jxl.write.Label;
import jxl.write.NumberFormat;
import jxl.write.NumberFormats;
import jxl.write.WritableCell;
import jxl.write.WritableCellFormat;
import ExcelExporter.DateTimeExtractor;
final class ExcelCellGeneratorFactory {
private ExcelCellGeneratorFactory() {}
private static final WritableCellFormat DATE_FORMAT = new WritableCellFormat ( new DateFormat ("dd MMM yyyy hh:mm:ss")); // reusing this field fails
static public <T> ExcelCellGenerator<T> createDateCellGenerator(final DateTimeExtractor<T> extractor) {
return new ExcelCellGenerator<T>() {
public WritableCell getCell(int col, int …Run Code Online (Sandbox Code Playgroud) asp.net ×2
c# ×2
iphone ×2
ajax ×1
arrays ×1
certificate ×1
cocoa-touch ×1
combobox ×1
compression ×1
datetime ×1
dds-format ×1
directdraw ×1
directx ×1
excel ×1
java ×1
jexcelapi ×1
jquery ×1
linq ×1
selector ×1
ssl ×1
textures ×1
wpf ×1
xml ×1