我有以下成员角色列举:
public enum RoleName
{
RegisteredUser,
Moderator,
Administrator,
Owner
}
Run Code Online (Sandbox Code Playgroud)
我希望能够获取大于或等于给定角色的所有角色.
例如,我输入管理员,我用RoleName.Administration和获得IEnumerableRoleName.Owner
这种东西:
public static void AddUserToRole(string username, RoleName level)
{
var roles = Enum.GetValues(typeof(RoleName)).Cast<R>().ToList().Where(role => level > role);
foreach (var role in roles)
{
Roles.AddUserToRole(username, role);
}
}
Run Code Online (Sandbox Code Playgroud) 我像这样使用剃须刀引擎:
public class EmailService : IService
{
private readonly ITemplateService templateService;
public EmailService(ITemplateService templateService)
{
if (templateService == null)
{
throw new ArgumentNullException("templateService");
}
this.templateService = templateService;
}
public string GetEmailTemplate(string templateName)
{
if (templateName == null)
{
throw new ArgumentNullException("templateName");
}
Assembly assembly = Assembly.GetAssembly(typeof(EmailTemplate));
Stream stream = assembly.GetManifestResourceStream(typeof(EmailTemplate), "{0}.cshtml".FormatWith(templateName));
string template = stream.ReadFully();
return template;
}
public string GetEmailBody(string templateName, object model = null)
{
if (templateName == null)
{
throw new ArgumentNullException("templateName");
}
string template = GetEmailTemplate(templateName); …Run Code Online (Sandbox Code Playgroud) 在早期版本中,我曾经测试过我是否应该popstate在页面加载时手动触发,因为Chrome会在加载后立即触发,而Firefox和IE则不会.
if ($.browser.mozilla || $.browser.msie) {
$(window).trigger('popstate');
}
Run Code Online (Sandbox Code Playgroud)
现在他们在1.9中删除了浏览器对象,我应该如何测试这些浏览器?或者我如何计算是否需要popstate页面加载?
代码是:
$(function(){
$(window).on('popstate', popState);
// manual trigger loads template by URL in FF/IE.
if ($.browser.mozilla || $.browser.msie) {
$(window).trigger('popstate');
}
});
Run Code Online (Sandbox Code Playgroud)
去了这个:
function popState(e){
var initial = e.originalEvent === undefined || e.originalEvent.state === null;
if(!initial){
activateRoute({
key: e.originalEvent.state.key,
settings: e.originalEvent.state.settings
},'replace');
}
}
function init(){
$(window).on('popstate', popState);
$(function(){
var route = getRoute(document.location.pathname);
activateRoute(route, 'replace');
});
}
Run Code Online (Sandbox Code Playgroud) javascript jquery browser-detection browser-feature-detection
说我有
$(":input[type=text]:first")
Run Code Online (Sandbox Code Playgroud)
如何得到
<input type="text" value="" size="28" maxlength="140" tabindex="1" placeholder="search" class="textbox" name="q" autocomplete="off">
Run Code Online (Sandbox Code Playgroud)
假设我在SO上运行它?
更新我不想打电话,.parent()因为我在父元素中有很多其他东西.
这个错误意味着什么,我该如何解决?
视觉工作室2010,
Windows 7,
万一重要.
我尝试关闭并打开解决方案,但它仍然不会删除.
谢谢!
这个:
const int a = 5;
Run Code Online (Sandbox Code Playgroud)
编译得很好,而
const var a = 5;
Run Code Online (Sandbox Code Playgroud)
没有......同时:
var a = 5;
Run Code Online (Sandbox Code Playgroud)
编译就像这样:
int a = 5;
Run Code Online (Sandbox Code Playgroud)
为什么?
我要刷新温斯顿记录仪前 process.exit.
process.on('uncaughtException', function(err){
logger.error('Fatal uncaught exception crashed cluster', err);
logger.flush(function(){ // <-
process.exit(1);
});
});
Run Code Online (Sandbox Code Playgroud)
有没有logger.flush可用的东西?除了人们抱怨温斯顿没有得到非常积极的维护之外,我找不到任何关于它的信息.
作为替代方案,是否有任何流行的(主动维护的)多传输日志框架提供刷新功能?
public interface IAutomatizableEvent
{
Event AutomatizableEventItem { get; }
bool CanBeAutomatic { get; }
bool IsAutomaticallyRunning { get; }
bool OnBeforeAutomaticCall();
bool OnAutomaticCheck();
void OnAutomaticStart();
void OnAutomaticCancel();
}
public abstract class AutomatizableEvent : IAutomatizableEvent
{
public AutomatizableEvent()
{
}
#region Implementation of IAutomatizableEvent
public abstract Event AutomatizableEventItem { get; }
public abstract bool CanBeAutomatic { get; }
public abstract bool IsAutomaticallyRunning { get; }
public abstract bool OnBeforeAutomaticCall();
public abstract bool OnAutomaticCheck();
public abstract void OnAutomaticStart();
public abstract void OnAutomaticCancel(); …Run Code Online (Sandbox Code Playgroud) 这是引发异常的代码:
public static class NHibernateSessionManager
{
private static ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
public static ISession GetSession(string clientId)
{
if (ContextSession == null)
ContextSession = sessionFactory.OpenSession(new OracleIntercerptor(clientId.ToUpper()));
else
((OracleConnection)ContextSession.Connection).ClientId = clientId;
return ContextSession;
}
// - snip -
}
Run Code Online (Sandbox Code Playgroud)
以及对引发异常的代码的调用:
private ISession NHibernateSession
{
get
{
return NHibernateSessionManager.GetSession(SessionWrapper.GetUser());
}
}
Run Code Online (Sandbox Code Playgroud)
我得到了 TypeInitializationException
{"'Sigaf.Presupuesto.EntidadesDAL.NHibernate.NHibernateSessionManager'的类型初始化程序引发了异常."}
有一个内在的例外
{"无法从NHibernate.Driver.OracleDataClientDriver创建驱动程序."}
还有一些内部异常使我成为一个NRE:
你调用的对象是空的.
在NHibernate.Driver.OracleDataClientDriver..ctor()
NHibernate v3.0 Target Framework v4.0此代码实现适用于其他类似的解决方案.
哦,Hibernate.config文件:
<?xml version="1.0"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="current_session_context_class">web</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property> …Run Code Online (Sandbox Code Playgroud) c# ×7
javascript ×2
jquery ×2
connection ×1
declaration ×1
driver ×1
enums ×1
generics ×1
interface ×1
nhibernate ×1
node.js ×1
oracle ×1
razorengine ×1
winston ×1