我发现自己陷入了CacheItem没有正确清理的状态.在查看MSDN并纠正自己使用基于Utc的计算时,我发现了这个令人困惑的信息:
AbsolutExpiration用来设置一个"保持活着"的CacheItem,Priority.NotRemovable用来强制CacheItem永远存在.没有关于哪个属性覆盖另一个属性的通知.
下面的代码进行编译,SQL Profiler也确认只查询一次数据库,而其他每个请求都来自缓存.
CacheItemPolicy _cachePolicy = new CacheItemPolicy()
{
AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddHours(6)),
Priority = CacheItemPriority.NotRemovable
};
Run Code Online (Sandbox Code Playgroud)
我假设此代码强制缓存项目永久保留,但在创建12小时后清除,与MSDN关于该设置的注释一致.
"只有当缓存实现提供了从缓存中逐出条目并管理缓存条目数量的方法时,缓存实现才应为缓存条目设置NotRemovable优先级"
那么另一方面,为什么两个属性都可以一起工作?实现是否带来某种"更不可移动"?
我有两种方法:
public void ExecuteA()
{
Write();
// A specific work
Clear();
}
public void ExecuteB()
{
Write();
// B specific work
Clear();
}
Run Code Online (Sandbox Code Playgroud)
我想提取Write()和Clear()方法到一个新的方法(Action)有这样的东西:
public ASpecificWork()
{
// do A work
}
public BSpecificWork()
{
// do B work
}
Execute(BSpecificWork);
Execute(ASpecificWork);
Run Code Online (Sandbox Code Playgroud)
在Write()和Clear()会中定义Execute()只是一个时间.这样做的正确语法是什么?
与其他浏览器相比,Microsoft Edge不会始终如一地处理window.print().
在大多数浏览器中,从页面上的iframe内调用window.print()只会打印该iframe的内容.但是在边缘,它将始终打印整个文档.
这是故意的吗?有解决方法吗?
关于JSFiddle的例子.
Iframe.html的
...
<body>
<a href="#" onclick="window.print()">print iframe document</a>
</body>
...
Run Code Online (Sandbox Code Playgroud)
的index.html
...
<body>
<a href="#" onclick="window.print()">print outer document</a>
<iframe src="iframe.html"></iframe>
</body>
...
Run Code Online (Sandbox Code Playgroud) 我一直在努力让WCF数据服务服务器工作几天.我终于在今天退缩了,只是尝试完全按照快速启动的方式展示......没有其他......以及完全新鲜的项目.肯定会有用.
但它没有..它失败的方式与我的其他测试相同.
我只是跟着这个例子.使用Visual Studio 2013进行Web Express和托管正在使用IIS Express.我已安装WCF工具5.6版,以便Visual Studio具有WFC数据服务5.6模板.
它的要点是
创建ASP.Net应用程序选择MVC类型,不为MVC以外的任何内容添加任何文件夹,也不添加单元测试,个人帐户认证.
为NorthWind数据库添加ADO.Net实体数据模型,在web.config中称为NorthwindEntities,导入所有表.
添加WCF数据服务5.6项,将其命名为NorthWind.svc.
将NorthWind.svc.cs支持代码更改为以下内容.
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace StackOverflowApp
{
public class NorthWindService : DataService<NorthwindEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead | EntitySetRights.WriteMerge | EntitySetRights.WriteReplace );
config.SetEntitySetAccessRule("Order_Details", EntitySetRights.AllRead| EntitySetRights.AllWrite);
config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在它已准备好构建和运行..它应该工作..是吗?
我运行它,然后导航到服务..我受到以下投诉的欢迎.
<div id="content"> …Run Code Online (Sandbox Code Playgroud) 我发现这段代码生成一串随机字符.
但有没有更优雅/更快/更可靠的方式来做到这一点?这似乎依赖于在给定当前编码的情况下数字26-91是有效字符的事实.
/// <summary>
/// Generates a random string with the given length
/// </summary>
/// <param name="size">Size of the string</param>
/// <param name="lowerCase">If true, generate lowercase string</param>
/// <returns>Random string</returns>
private string RandomString(int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch;
for(int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
if(lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}
Run Code Online (Sandbox Code Playgroud) namespace Foo
{
public enum MyEnum
{
High, Low
}
public class Class1
{
public MyEnum MyProperty { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
MyEnum在外面宣布 Class1
我需要它在这里和其他类中
看起来不错,但如果我稍后决定删除包含的文件Class1怎么办?
MyEnum 宣言将丢失!!
在类之间编写共享枚举的最佳实践是什么?
由于某些原因,我的实体没有主键:
public partial class VehicleLocation
{
public virtual string UserCode { get; set; }
public virtual string DateTime { get; set; }
public virtual string Device { get; set; }
public virtual string Gps { get; set; }
public virtual string GpsDateTime { get; set; }
public virtual double Speed { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
映射:
class VehicleLoactionMap : ClassMap<VehicleLocation>
{
public VehicleLoactionMap()
{
Table("VEHICLE_LOCATION");
LazyLoad();
Map(x => x.UserCode).Column("USER_CODE");
Map(x => x.DateTime).Column("DATE_TIME");
Map(x => x.Device).Column("DEVICE");
Map(x => x.Gps).Column("GPS");
Map(x => …Run Code Online (Sandbox Code Playgroud) 我正在使用StringFormat来显示一些绑定数据并且工作正常.
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="Name {0} | Id ({1})">
<Binding Path="Name" />
<Binding Path="Id"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
我希望Id值(请参阅XAML)为粗体.这该怎么做?
我正在使用ItemsControl我的藏品.的ItemsPanel是Canvas,该ItemTemplate是块Border> StackPanel> TextBlocks
我要绑定在一个命令DataTemplate捕获在块上单击(我的收藏项目)
码:
<Grid Grid.Row="1" Grid.Column="1" >
<ItemsControl ItemsSource="{Binding Products}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<helpers:DragCanvas
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AllowDragging="True"
AllowDragOutOfView="False" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- The border and its content is what I see
on my canvas, I want to bind a command here (on click do something) -->
<Border BorderThickness="1" BorderBrush="Gold">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=Price}" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl> …Run Code Online (Sandbox Code Playgroud) 我不知道为什么我的边框在页面底部之前停止.我尝试了很多东西:清除浮动,100%,jQuery,vh,vmax +我已经从stackoverflow读取了其他问题,但总是在底部之前停止.
我有两个div section.left和section.middle.我试图让div 8 px上的边框section.left从页面顶部到底部.但如果页面变长,它就会停止.
见演示
HTML
<div class="wrapper">
<section class="left">
<header>
<a class="logo" href="#"><img src="images/smallImage1.jpg" alt="Logo"></a>
</header>
<div class="intro">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed posuere interdum sem. Quisque ligula eros ullamcorper quis,</p>
<a class="contact" href="#">Contact</a>
</div>
<div class="skills">
<h6>Skills</h6>
<ul>
<li>Skill 1</li>
<li>Skill 2</li>
</ul>
</div>
<footer>
<p>2016 - Site 1</p>
</footer>
</section>
<section class="midle">
<div class="post">
<h2>Headline</h2>
<img src="images/bigImage1.jpg" alt="Big image">
<p>Lorem ipsum dolor sit …Run Code Online (Sandbox Code Playgroud) c# ×5
html ×2
wpf ×2
caching ×1
css ×1
data-binding ×1
datatemplate ×1
enums ×1
iframe ×1
javascript ×1
mapping ×1
mvvm ×1
nhibernate ×1
printing ×1
random ×1
string ×1
viewport ×1
wcf ×1