问题: Micro Framework如何为结构数组分配内存?
BitBucket存储库,包含要复制的代码.
我正在使用固定大小的数组来排队,以便在处理来自USB键盘的击键时插入延迟.我用a struct代表键上下事件和延迟.
public struct QueuedEvent
{
public readonly EventType Type; // Byte
public readonly byte KeyPressed;
public readonly TinyTimeSpan Delay; // Int16
public readonly static QueuedEvent Empty = new QueuedEvent();
}
public enum EventType : byte
{
None = 0,
Delay = 1,
KeyDown = 2,
KeyUp = 3,
KeyPress = 4,
}
public class FixedSizeQueue
{
private readonly QueuedEvent[] _Array;
private int _Head = 0;
private int _Tail = 0;
public FixedSizeQueue(int …Run Code Online (Sandbox Code Playgroud) .net c# memory-management .net-micro-framework out-of-memory
我想知道是否有任何语言允许命名元组.即:具有不同类型和可配置名称的多个变量的对象.
例如:
public NamedTuple<double:Speed, int:Distance> CalculateStuff(int arg1, int arg2)
var result = CalculateStuffTuple(1,2);
Console.WriteLine("Speed is: " + result.Speed.ToString())
Console.WriteLine("Distance is: " + result.Distance.ToString())
Run Code Online (Sandbox Code Playgroud)
我可以设想动态如何支持这样的功能.我经常游泳的静态语言(如c#)可以做一个字典,但除非所有项目属于同一类型,否则这不是类型安全的.或者你可以使用元组类型,但这意味着你有成员的固定名称(Var1,Var2等).
你也可以写一个小的自定义类,但这是我想避免的情况.
我可以想象一个宏处理语言可以用静态语言为你编写类似的东西,但我不知道这样的语言.
这来自我关于回归类型的问题的答案.
我想关闭我的应用程序并写入任何挂起的日志消息.所以我LogManager.Flush()在关机过程中打电话.但是,我没有看到所有的消息写出来.相反,如果我等待几秒钟(使用Thread.Sleep()),我会看到消息.
检查后在GitHub上NLOG的代码,我找到AsyncTargetWrapper.FlushAsync()方法仅调度惰性写入器线程上写上下一批次的所有未决消息.它不是同步写日志消息.
这是预期的行为吗?我期望LogManager.Flush()是同步的,即:阻塞直到写入所有待处理的消息(或超过超时).
我在关机时使用的代码:
LogManager.Flush(ex => { }, TimeSpan.FromSeconds(15));
Run Code Online (Sandbox Code Playgroud)
然后是初始化Nlog的代码(这是一个Silverlight应用程序,所以我没有使用任何配置文件).
public static void InitialiseNLog(LogLevel forLevel)
{
var config = new LoggingConfiguration();
// Add targets.
// We need an async target wrapping a custom web service call back to the server.
var serverTarget = new RemoteServiceTarget();
var asyncWrapper = new AsyncTargetWrapper(serverTarget, 10000, AsyncTargetWrapperOverflowAction.Discard);
asyncWrapper.TimeToSleepBetweenBatches = (int)TimeSpan.FromSeconds(2).TotalMilliseconds;
asyncWrapper.BatchSize = 200;
// Add rules.
var rule = new LoggingRule("Company.Application.SilverlightApp.*", forLevel, asyncWrapper);
config.LoggingRules.Add(rule);
// …Run Code Online (Sandbox Code Playgroud) 我正在运行一个程序来测试查找和迭代包含大量文件的文件夹中的所有文件的速度.该过程中最慢的部分是创建100万个文件.我正在使用一种非常天真的方法来创建文件:
Console.Write("Creating {0:N0} file(s) of size {1:N0} bytes... ",
options.FileCount, options.FileSize);
var createTimer = Stopwatch.StartNew();
var fileNames = new List<string>();
for (long i = 0; i < options.FileCount; i++)
{
var filename = Path.Combine(options.Directory.FullName,
CreateFilename(i, options.FileCount));
using (var file = new FileStream(filename, FileMode.CreateNew,
FileAccess.Write, FileShare.None, 4096,
FileOptions.WriteThrough))
{
// I have an option to write some data to files, but it's not being used.
// That's why there's a using here.
}
fileNames.Add(filename);
}
createTimer.Stop();
Console.WriteLine("Done.");
// Other code appears …Run Code Online (Sandbox Code Playgroud) 我一直认为DbNull.value是一个单身人士.因此你可以做这样的事情:
VB.NET:
If someObject Is DbNull.Value Then
...
End if
Run Code Online (Sandbox Code Playgroud)
C#:
If (someObject == DbNull.Value)
{
...
}
Run Code Online (Sandbox Code Playgroud)
但是最近,我使用XmlSerialiser序列化了一个DbNull实例,突然间它不再是单例了.类型比较操作(如C#(obj是DBNull))工作正常.
代码如下:
[Serializable, System.Xml.Serialization.XmlInclude(typeof(DBNull))]
public class SerialiseMe
{
public SerialiseMe() { }
public SerialiseMe(object value)
{
this.ICanBeDbNull = value;
}
public Object ICanBeDbNull { get; set; }
}
public void Foo()
{
var serialiseDbNull = new SerialiseMe(DBNull.Value);
var serialiser = new System.Xml.Serialization.XmlSerializer(typeof(SerialiseMe));
var ms = new System.IO.MemoryStream();
serialiser.Serialize(ms, serialiseDbNull);
ms.Seek(0, System.IO.SeekOrigin.Begin);
var deSerialisedDbNull = (SerialiseMe)serialiser.Deserialize(ms);
// Is false, WTF!
var equalsDbNullDeserialised = …Run Code Online (Sandbox Code Playgroud) 如何将表值参数传递给具有计算列的存储过程?
我有一个表数据类型,我试图将其传递DataTable给存储过程.除了计算列之外,我的所有列都按顺序和数据类型匹配.
如果我将该列从我的列中删除,我DataTable会收到此错误:
System.Data.SqlClient.SqlException (0x80131904): Trying to pass a table-valued parameter with 3 column(s) where the corresponding user-defined table type requires 4 column(s).
如果我包含空值的列,我得到这个: System.Data.SqlClient.SqlException (0x80131904): The column "TransformationSum" cannot be modified because it is either a computed column or is the result of a UNION operator.
没有尝试摆弄特定的任何各种属性DataColumn.
表类型定义:
CREATE TYPE [dbo].[DataPoint] AS TABLE
(
[Id] [int] NOT NULL,
[RawDataPoint] [decimal](18, 9) NULL,
[TransformedDataPoint] [decimal](18, 9) NULL,
[TransformationSum] AS ([RawDataPoint]-[TransformedDataPoint]),
PRIMARY KEY ([Id])
) …Run Code Online (Sandbox Code Playgroud) 我正在使用Web API将大型文件流式传输到客户端,但我想记录下载是否成功.也就是说,如果服务器发送了文件的全部内容.
HttpResponseMessage完成发送数据后,是否有某种方法可以获得回调或事件?
也许是这样的:
var stream = GetMyStream();
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
// This doesn't exist, but it illustrates what I'm trying to do.
response.OnComplete(context =>
{
if (context.Success)
Log.Info("File downloaded successfully.");
else
Log.Warn("File download was terminated by client.");
});
Run Code Online (Sandbox Code Playgroud) 您可以在Crystal Reports图像" 图形位置"字段中输入URL,以允许Crystal在运行时动态加载它.例如:http://reports.server.com/logo.png或{?_pUrl} & "/logo.png"
您是否可以使用安全/ HTTPS URL?例如:https://reports.server.com/logo.png
我已使用Process Explorer的TCP/IP选项卡验证了传出的HTTP连接,但在使用HTTPS时无法看到任何传出连接.
我的实际报告是通过参数传递基本URL,并在仅HTTP环境中工作.还尝试使用硬编码的HTTPS URL,但无济于事.
我正在使用2012 R2服务器上的IIS中托管的版本14.0.2.364 RTM.
假设我有一个强大的.NET程序集.只有我可以访问私钥.然后我将程序集分发给某个客户端系统.
客户修改程序集有多难?即:他们需要做些什么才能修改我的装配?
我有一个大而复杂的SQL查询,带有一个在NHibernate中运行的DISTINCT子句(它是一个具有各种标准和连接的搜索查询).但是我在使用SQL Server 2008下的分页时遇到了问题.
我的问题是:我如何从NHibernate而不是我的手动解决方法(如下所述)这样做?
我正在使用的代码是这样的:
var searchQuery = BuildQuery(criteria);
.SetTimeout(240)
.SetFirstResult(pageIndex * pageSize)
.SetMaxResults(pageSize);
var resultRows = searchQuery.List<object[]>();
Run Code Online (Sandbox Code Playgroud)
我的SQL查询(来自BuildQuery(),没有DISTINCT)的结果看起来像这样(高度简化):
Id, Name, SortColumn
1 AA 1/1/2000
1 AA 1/1/2000
2 AB 3/1/2000
2 AB 3/1/2000
3 AC 10/1/2000
3 AC 10/1/2000
....
Run Code Online (Sandbox Code Playgroud)
由于查询的工作原理,我无法避免重复的行,所以我在SQL查询中粘贴DISTINCT以使它们消失.
为了进行分页,NHibernate生成一个这样的查询(这个例子来自第二页,每页有100个结果):
SELECT TOP 100 Id,
Name,
SortColumn,
FROM (select distinct Id, Name, SortColumn,
ROW_NUMBER() OVER (ORDER BY SortColumn) as __hibernate_sort_row
from ......
where ......) as query
WHERE query.__hibernate_sort_row > 100
ORDER BY query.__hibernate_sort_row
Run Code Online (Sandbox Code Playgroud)
这适用于第一页,但在后续页面上我只得到预期结果的一半.
我在NHibernate的子查询中运行SQL,发现NHibernate行插入来执行它的分页会返回一些意外的东西(即使使用DISTINCT):
Id, Name, SortColumn, …Run Code Online (Sandbox Code Playgroud) 我在后端对Magento的New Order交易电子邮件模板进行了一些模板更改.电子邮件顶部的文字更改(在"感谢您的订单......"部分)工作正常.但是,当我更改订单详细信息的模板时,它们不会出现在我的电子邮件中.
我在我的模板中创建了两个文件,我认为它会覆盖电子邮件:
app/design/frontend/default/mythemehere/template/email/order/items.phtmlapp/design/frontend/default/mythemehere/template/email/order/items/order/default.phtml这些在我的sales.xml文件中引用 app/design/frontend/default/mythemehere/layout
<sales_email_order_items>
<block type="sales/order_email_items" name="items" template="email/order/items.phtml">
<action method="addItemRender"><type>default</type><block>sales/order_email_items_order_default</block><template>email/order/items/order/default.phtml</template></action>
<action method="addItemRender"><type>grouped</type><block>sales/order_email_items_order_grouped</block><template>email/order/items/order/default.phtml</template></action>
<block type="sales/order_totals" name="order_totals" template="sales/order/totals.phtml">
<action method="setLabelProperties"><value>colspan="2" align="right" style="padding:3px 9px"</value></action>
<action method="setValueProperties"><value>align="right" style="padding:3px 9px"</value></action>
<block type="tax/sales_order_tax" name="tax" template="tax/order/tax.phtml">
<action method="setIsPlaneMode"><value>1</value></action>
</block>
</block>
</block>
<block type="core/text_list" name="additional.product.info" />
</sales_email_order_items>
Run Code Online (Sandbox Code Playgroud)
但是,当我下订单时,我会在电子邮件中获得基本模板.
如果我在Magento中提交红衣主教罪,覆盖基本模板文件(app/design/frontend/base/default/template/email/order ...),请看,我看到了我的变化!似乎Magento非常热衷于使用其基本模板.
我已经覆盖了销售部分中的其他模板(例如:sales/order/view.phtml,sales/order/print.phtml),Magento论坛上的各种帖子表明我在概念上做的正确.可惜!这对我不起作用.
c# ×8
.net ×3
ado.net ×1
asp.net ×1
dbnull ×1
distinct ×1
email ×1
file ×1
https ×1
image ×1
io ×1
magento ×1
nhibernate ×1
nlog ×1
performance ×1
return-value ×1
silverlight ×1
singleton ×1
sql ×1
strongname ×1
templates ×1
tuples ×1