我在序列化包含派生对象列表的Dictionary时遇到问题.序列化输出包含
<BaseAttributes xsi:type="Turbine" Id="1975fe1f-7aa8-4f1d-b768-93ad262800cd">
Run Code Online (Sandbox Code Playgroud)
我想将BaseAttributes替换为Turbine并且xsi:type不存在.
<Turbine Id="1975fe1f-7aa8-4f1d-b768-93ad262800cd">
Run Code Online (Sandbox Code Playgroud)
我的整体代码如下所示.我有一个类BaseAttributes,我从中派生出一些类,例如Turbine类.这些类存储在带有BaseAttributes列表的字典中.字典是实现的可序列化字典.以下是一般的代码.
[XmlInclude(typeof(Turbine)), XmlInclude(typeof(Station)), XmlInclude(typeof(Substation))]
public class BaseAttributes {
[XmlAttribute("Id")]
public Guid Id;
}
public class Turbine : BaseAttributes {
private Element windSpeed;
public Element WindSpeed {
get { return windSpeed; }
set { windSpeed = value; }
}
public Turbine(float windSpeed){
this.windSpeed= new Element(windSpeed.ToString(),"ms");
}
//used for xmlserilization
private Turbine(){}
}
public class CollectionOfBaseAttributes {
public SerilizableUnitsDictionary<DateTime, List<BaseAttributes>> units;
}
[XmlRoot("dictionary")]
public class SerilizableUnitsDictionary<TKey, TValue>
: Dictionary<TKey, TValue>, IXmlSerializable {
public System.Xml.Schema.XmlSchema GetSchema() …Run Code Online (Sandbox Code Playgroud) 我在 Windows 服务中有一个线程 (STAThread),它执行大量工作。当 Windows 服务重新启动时,我想优雅地停止这个线程。
我知道几种方法
据我发现 Thread.Abort 是不行的......
最佳做法是什么?这项工作是在另一个类中执行的,而不是线程启动的类,因此有必要在构造函数中引入一个 cancelToken 参数,或者例如有一个 volatile 变量。但我就是不知道什么是最聪明的。
更新
只是为了澄清一点,我已经总结了我正在谈论的一个非常简单的例子。如前所述,这是在 Windows 服务中完成的。现在我正在考虑一个在循环中检查的可变布尔值或一个取消令牌......我不能等待循环完成,如下所述,它可能需要几分钟,使服务器的系统管理员相信当他们需要重新启动服务时,服务出了点问题......我可以毫无问题地将循环中的所有工作都毫无问题地删除,但是我不能用 Thread.Abort 来做到这一点,它是“邪恶的”,而且是一个 COM接口被调用,所以需要一个小的清理。
Class Scheduler{
private Thread apartmentThread;
private Worker worker;
void Scheduling(){
worker = new Worker();
apartmentThread = new Thread(Run);
apartmentThread.SetApartmentState(ApartmentState.STA);
apartmentThread.Start();
}
private void Run() {
while (!token.IsCancellationRequested) {
Thread.Sleep(pollInterval * MillisecondsToSeconds);
if (!token.IsCancellationRequested) {
worker.DoWork();
}
}
}
}
Class Worker{
//This will take several minutes....
public void DoWork(){
for(int i = 0; i < …Run Code Online (Sandbox Code Playgroud) 关于将用户定义的表类型作为参数的存储过程,我有一个问题.我知道我只需要在SQL DB中用户定义的表类型对应的c#代码中创建一个DataTable.就像这里 如何在C#中将用户定义的表类型作为存储过程参数传递
但是,我想避免的是在代码中手动创建DataTable,而是自动创建DataTable.是否有可能通过查询从数据库中获取此信息?
如果这是不可能的,那么另一种可能性是获取用户定义的表类型的定义,然后使用它来自动生成DataTable.但问题是我如何得到类型的定义?
任何人都可以解决这个问题,我发现的所有例子都是在代码中手动生成用户定义的数据类型作为DataTable.
我目前正在尝试更新版本号.在TeamCity中使用包含版本号的Nant构建文件.如果我只是用
<property name="versionNo" value="2.16.3."/>
.
.
<echo message="##teamcity[buildNumber '${versionNo}']"></echo>
Run Code Online (Sandbox Code Playgroud)
在脚本中buildNumber更新到2.16.3但我也希望在这个版本号上有计数器.意思是我想要的
<echo message="##teamcity[buildNumber '${versionNo}.{0}']"></echo>
Run Code Online (Sandbox Code Playgroud)
但这不起作用.有没有人知道如何做到这一点,在这个解决方案中尝试了很多东西http://binary-notes.blogspot.com/2011/05/controlling-application-version-number.html但是,$ {Version}参数是一个线索为了我 ?
通过在Teamcity中使用{0}作为buildnumber并将该内部版本号附加到文件中我自己的内部版本号来实现实现
<property name="versionNo" value="2.16.3."/>
.
.
<echo message="##teamcity[buildNumber '${versionNo}.${environment::get-variable('BUILD_NUMBER')}']"></echo>
Run Code Online (Sandbox Code Playgroud)