是否可以将Loggin行为注入标记的类或/和方法,如下所示:
Log("Method {0} started",GetMethodNameTroughReflection)
Call method body
Log("Method {0} Finished",GetMethodNameTroughReflection)
Run Code Online (Sandbox Code Playgroud)
我想创建自己的Attribute类,它将实现方法调用的记录行为.
我想描述app.config文件中的登录行为,可以通过config中的设置禁用它.
怎么做对了?也许为这样的任务创建了解决方案?
如何编写这行代码以允许它编译
MoveMemory(poleFileDescriptorW
, (oleDataPointer + SizeOf(oleFileDescriptorW) *Index + 4)^
, SizeOf(oleFileDescriptorW));
Run Code Online (Sandbox Code Playgroud)
特别是这一部分
(oleDataPointer + SizeOf(oleFileDescriptorW)*Index + 4)^
我只是想按SizeOf(oleFileDescriptorW)*Index + 4字节移动指针
变量定义为:
pOLEFileDescriptorW : ^FILEDESCRIPTORW;
oleDataPointer : Pointer;
Run Code Online (Sandbox Code Playgroud) 所以问题非常简单.这在Silverlight 4中是否可行?
更新:
这是我在尝试更新edventuro.us文本块的解决方案时获得的代码
namespace EmpresaHR.Controls
{
using System.Windows;
using System.Windows.Controls;
/// <summary>
/// A simple text control that shrinks or expands the font of the text to
/// display all of the text in the preferred size of the textblock.
/// Dependency Properties:
/// - MinFontSize: This is the smallest size the font will be reduced to. Defaults to 8pt.
/// - MaxFontSize: This is the largest size the font will be increased to. Defaults to 20. …Run Code Online (Sandbox Code Playgroud) 我们正在使用ChanellFacotry通过创建代理来使用Silverlight应用程序上的wcf服务.
操作和数据合同暴露于silverlight槽组件,该组件由来自服务器端数据和操作合同库的共享文件组成.(omg我希望你明白我在说什么).
因此服务器和客户端使用相同的操作和数据协定.
如您所知,Silverlight wcf客户端lib具有无法同步调用wcf方法的限制,因此共享操作契约文件必须公开每个操作的asyn版本.
如果它们不包含阻塞操作,编写异步WCF服务会有所帮助,但是当我们使用EF时,通过将阻塞工作委托给线程池来实现asyncrhony.无论如何,这就是WCF为同步方法所做的事情.这个事实让我想要睁开眼睛(#@%!^%!@%).
我们的项目顾问有权不允许在客户端生成动态代理来调用同步操作合同方法(谷歌Yevhen Bobrov Servelat Pieces,如果你感兴趣的话).因此,我们必须在服务器端编写异步方法的senseles实现,而不会产生任何性能提升(在您记忆时阻止调用).
是否可以使用其数据协定从silverlight调用wcf web服务同步方法?
您以前遇到过这个问题,如果是这样,您是如何解决的?
在此,我期待仅使用服务器端合同作为转换源为客户端生成异步合同.也许有一些t4模板可以很好地为我做到这一点?
对于文本墙感到抱歉,只是为了将一些代码混合到我的问题中,这就是异步合同实现如何看待这个问题:
/// <summary>
/// Subscribes to users of the specified organization.
/// </summary>
/// <param name="organizationId">The organization id.</param>
public void Unsubscribe(int organizationId)
{
var clientId = this.OperationContext.GetClientId();
if (string.IsNullOrEmpty(clientId))
{
return;
}
this.InternalUnsubscribe(organizationId, clientId);
}
/// <summary>
/// Begins an asynchronous operation to Unsubscribe.
/// </summary>
/// <param name="organizationId">The organization id.</param>
/// <param name="callback">The callback.</param>
/// <param name="passThroughData">The pass through data.</param>
/// <returns>
/// An implementation …Run Code Online (Sandbox Code Playgroud) 所以这就是令我难过的代码:
private static void AssignId(object entity, string id)
{
var idFieldInfo = entity.GetType().GetProperties().SingleOrDefault(it => it.GetCustomAttributes(typeof(KeyAttribute), false).Any());
if (idFieldInfo != null)
{
var type = idFieldInfo.PropertyType;
if (type == typeof(byte))
{
idFieldInfo.SetValue(entity, Convert.ToByte(id), null);
}
else if (type == typeof(short))
{
idFieldInfo.SetValue(entity, Convert.ToInt16(id), null);
}
else if (type == typeof(int))
{
idFieldInfo.SetValue(entity, Convert.ToInt32(id), null);
}
else if (type == typeof(long))
{
idFieldInfo.SetValue(entity, Convert.ToInt64(id), null);
}
else if (type == typeof(sbyte))
{
idFieldInfo.SetValue(entity, Convert.ToSByte(id), null);
}
else if (type == typeof(ushort))
{ …Run Code Online (Sandbox Code Playgroud) 我刚开始使用ActiveMQ并得到了几个问题.
我应该使用ActiveMQ发送消息
我现在做了什么:
public class ActiveMQSender
{
private readonly Uri connectionUri;
private readonly IConnectionFactory connectionFactory;
private readonly string destinationName;
public ActiveMQSender()
{
this.connectionUri = new Uri("activemq:tcp://localhost:61616");
this.connectionFactory = new NMSConnectionFactory(this.connectionUri);
this.destinationName = "queue://testQ";
}
public void Send(string msg)
{
using (var connection = this.connectionFactory.CreateConnection())
using (var session = connection.CreateSession())
{
var destination = SessionUtil.GetDestination(session, this.destinationName);
using (var producer = session.CreateProducer(destination))
{
connection.Start();
var message = session.CreateTextMessage(msg);
producer.Send(message);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个类中只有一个实例将作为构造函数参数注入.
我担心连接,会话和生成器创建的开销,因为消息将被频繁发送(通常每10秒发送一条消息)我应该重用连接,会话或生成器实例,以及我应该如何应对连接失败?这种情况下的常见模式是什么?
以下是c ++和c#中的两个代码部分,完全相同:
#include <stdio.h>
int main(int argc, char *argv[]) {
char p[1000000];
unsigned int i,j;
unsigned long long s=0;
for(i=2;i<1000000;i++) p[i]=1;
for(i=2;i<500000;) {
for(j=2*i;j<1000000;j+=i) p[j]=0;
for(i++;!p[i];i++);
}
for(i=3,s=2;i<1000000;i+=2) if(p[i]) s+=i;
printf ("%lld\n",s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
时间:0.01s memmory:2576 kB
using System;
namespace ConsoleApplication4
{
internal class Program
{
private static void Main(string[] args)
{
var p = new byte[1000000];
ulong i, j;
double s = 0;
for(i=2;i<1000000;i++)
p[i]=1;
for(i=2;i<500000;)
{
for(j=2*i;j<1000000;j+=i)
p[j]=0;
for(i++;p[i]==0;i++);
}
for(i=3,s=2;i<1000000;i+=2)
if(p[i]!=0) s+=i; …Run Code Online (Sandbox Code Playgroud) 我正在为我们的Web服务器编写功能,它应该从其他服务器下载多个文件,并将它们作为zip存档返回而不进行压缩.
如果我知道所有下载文件的大小,如何确定ZIP存档的最终大小?
这是我目前正在处理的代码.注释行导致ZIP存档损坏.
public void Download()
{
var urls = Request.Headers["URLS"].Split(';');
Task<WebResponse>[] responseTasks = urls
.Select(it =>
{
var request = WebRequest.Create(it);
return Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse(null, null), request.EndGetResponse);
})
.ToArray();
Task.WaitAll(responseTasks);
var webResponses = responseTasks.Where(it => it.Exception == null).Select(it => it.Result);
var totalSize = webResponses.Sum(it => it.ContentLength + 32);
Response.ContentType = "application/zip";
Response.CacheControl = "Private";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
// Response.AddHeader("Content-Length", totalSize.ToString(CultureInfo.InvariantCulture));
var sortedResponses = webResponses.OrderBy(it => it.ContentLength);
var buffer = new byte[32 * 1024];
using (var zipOutput = new ZipOutputStream(Response.OutputStream))
{
zipOutput.SetLevel(0);
foreach (var …Run Code Online (Sandbox Code Playgroud) 我需要对用户拖动我的表单上的放置操作做出反应.从资源管理器接受文件并不困难,但是加载OLE对象(Outlook电子邮件)丢失对我来说很难处理.
到目前为止,我有一个带有IDropTarget接口的Delphi表单.
IDropTarget = interface(IUnknown)
['{00000122-0000-0000-C000-000000000046}']
function DragEnter(const dataObj: IDataObject; grfKeyState: Longint;
pt: TPoint; var dwEffect: Longint): HResult; stdcall;
function DragOver(grfKeyState: Longint; pt: TPoint;
var dwEffect: Longint): HResult; stdcall;
function DragLeave: HResult; stdcall;
function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint;
var dwEffect: Longint): HResult; stdcall;
end;
Run Code Online (Sandbox Code Playgroud)
这是Drop方法实现:
function TForm1.Drop(const dataObj: IDataObject; grfKeyState: Integer;
pt: TPoint; var dwEffect: Integer): HResult;
var
aFmtEtc: TFORMATETC;
aStgMed: TSTGMEDIUM;
pData: PChar;
begin
if (dataObj = nil) then
raise Exception.Create('IDataObject-Pointer is not valid!');
with aFmtEtc …Run Code Online (Sandbox Code Playgroud) 我花了两天时间试图解决这个问题.
我已经实现了两种使用mvvm弹出窗口的方法
第一个aproach用法示例:
_childWindowController
.ShowDialogWithResult<AddNationalityPopup,AddNationalityPopupModel, AddNationalityResult>(
(result, a) =>
{
if (a.DialogResult.HasValue && a.DialogResult.Value)
{
if (result.NationalityCountryId.HasValue)
{
Background.NationalityCountryId = result.NationalityCountryId.Value;
Background.NationalityDescription = result.NationalityDescription;
}
}
});
Run Code Online (Sandbox Code Playgroud)
第二种方法:
var window = _childWindowController.CreateDialog<AddNationalityPopup>();
window.Closed += (sender, args) =>
{
if (args.DialogResult.HasValue && args.DialogResult.Value)
{
var result = (AddNationalityResult)window.Result;
if (result.NationalityCountryId.HasValue)
{
Background.NationalityCountryId = result.NationalityCountryId.Value;
Background.NationalityDescription = result.NationalityDescription;
}
}
};
window.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
在第一种方法中,服务的用户应该知道视图的类型,视图模型和结果,以便能够显示对话框
在第二个接口简化了一点,但我仍然必须知道在使用之前将结果转换为什么类型.
你有没有遇到过与视图模型对话的问题?
如何改进窗口服务的设计?
您能举例说明对话服务的良好实现吗?
c# ×6
silverlight ×3
.net ×2
delphi ×2
apache-nms ×1
asynchronous ×1
c++ ×1
com ×1
mvvm ×1
ole ×1
optimization ×1
outlook ×1
performance ×1
wcf ×1
wpf ×1
wpf-controls ×1
zip ×1