我有一个用PowerShell和SMO恢复数据库的脚本.现在我知道我可以在恢复对象上将事件处理程序传递给PercentComplete,并在恢复时获得恢复的进度.问题是我不知道如何创建一个事件处理程序并在PowerShell中传递一个函数?我可以在C#中做到这一点
restore.PercentComplete += new PercentCompleteEventHandler(restore_PercentComplete);
static void restore_PercentComplete(object sender, PercentCompleteEventArgs e)
{
System.Console.WriteLine("{0}", e.Percent);
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
谢谢.
我正在寻找有关将Windows服务自动部署到多台计算机的工具的建议.该工具应该能够: - 停止/启动服务 - 复制文件 - 根据某些CSV/Excel文件修改每个目标服务器上的配置文件
优点:Web界面,通过电子邮件发送通知,压缩/解压缩
以下是我听到的工具,我开始评估,但我想听听那些在自动部署过程中实际应用其中一个(或其他一些工具)的人.
PS在SO上有一个类似的问题,但它没有回答我的问题: WCF服务部署 - 工具
回答问:您计划部署多少台服务器?答:目前有2个数据中心的20台服务器.这些数字可能会在未来增长
问:有多少用户参与设计和执行部署?答:一个人会设计部署,而另一个人(一个人)会执行它
问:您的部署是否需要跨层同步?答:我只需要部署一个Windows服务,没有数据库更改,没有IIS或任何其他Web层
问:审核和报告对您有多重要?答:我希望该工具能够报告其成功与否.看到所有部署的服务器的完整仪表板及其版本和最近的更改也会很高兴.
在尝试伪造简单的intefrace时,使用FakeItEasy的单元测试会随机失败.它偶尔会在不同的测试中出现并且不稳定.
这是我需要伪造的示例界面:
public interface IJobSuiteFilterApplier
{
JobSuiteDto FilterJobSuites(JobSuiteDto jobSuiteDto, JobSuiteFilter jobSuiteFilter);
}
Run Code Online (Sandbox Code Playgroud)
这是一段创建假的代码,有时会失败:
var jobSuiteFilterApplier = A.Fake<IJobSuiteFilterApplier>(x => x.Strict());
Run Code Online (Sandbox Code Playgroud)
这是例外细节:
FakeItEasy.Core.FakeCreationException:
Failed to create fake of type "QS.TestShell.Server.ExecutionPlanner.Queries.IExecutionPlannerQueryService".
Below is a list of reasons for failure per attempted constructor:
No constructor arguments failed:
No usable default constructor was found on the type QS.TestShell.Server.ExecutionPlanner.Queries.IExecutionPlannerQueryService.
An exception was caught during this call. Its message was:
Collection was modified; enumeration operation may not execute.
at FakeItEasy.Core.DefaultExceptionThrower.ThrowFailedToGenerateProxyWithResolvedConstructors(Type typeOfFake, String reasonForFailureOfUnspecifiedConstructor, IEnumerable`1 resolvedConstructors)
at FakeItEasy.Creation.FakeObjectCreator.TryCreateFakeWithDummyArgumentsForConstructor(Type …
Run Code Online (Sandbox Code Playgroud) 我使用以下代码为所有需要它的类注册log4net.
public class LogInjectionModule : Module
{
private readonly string _configPath;
public LogInjectionModule(string configPath)
{
_configPath = configPath;
}
protected override void AttachToComponentRegistration(IComponentRegistry registry,
IComponentRegistration registration)
{
XmlConfigurator.Configure(new FileInfo(_configPath));
registration.Preparing += OnComponentPreparing;
}
private static void OnComponentPreparing(object sender, PreparingEventArgs e)
{
var t = e.Component.Activator.LimitType;
e.Parameters = e.Parameters.Union(new[]
{
new ResolvedParameter((p, i) => p.ParameterType == typeof (ILog),
(p, i) => LogManager.GetLogger(t))
});
}
}
Run Code Online (Sandbox Code Playgroud)
使用autofac的类型扫描注册所有类:
builder.RegisterAssemblyTypes(typeof (IResourceFinder).Assembly)
.AsImplementedInterfaces();
Run Code Online (Sandbox Code Playgroud)
它工作正常!
需要明确注册一个类尝试解决ILog并失败
builder.Register(x => new ClassThatNeedsILog(x.Resolve<ILog>())).AsImplementedInterfaces();
Run Code Online (Sandbox Code Playgroud)
这是上课
public class ClassThatNeedsILog
{
public …
Run Code Online (Sandbox Code Playgroud) 是否可以标记的结果async Task<T>
可以为null?使用属性[CanBeNull]不起作用,因为异步Task的返回值永远不会为null。
[CanBeNull] // not working...
private async Task<T> doSomeFancyAsyncStuff([NotNull] object icantbenull) { ...
Run Code Online (Sandbox Code Playgroud) c# ×3
.net ×2
annotations ×1
async-await ×1
autofac ×1
chocolatey ×1
deployment ×1
fakeiteasy ×1
log4net ×1
mocking ×1
powershell ×1
resharper ×1
service ×1
smo ×1
sql-server ×1
unit-testing ×1
wcf ×1
windows ×1