本文整理汇总了C#中ISessionProvider.GetSession方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionProvider.GetSession方法的具体用法?C# ISessionProvider.GetSession怎么用?C# ISessionProvider.GetSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISessionProvider
的用法示例。
在下文中一共展示了ISessionProvider.GetSession方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MonitorModule
public MonitorModule(ISessionProvider sessionProvider)
: base("/monitor")
{
_sessionProvider = sessionProvider;
Get["/live"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
return session.Load<MonitorSite>("MonitorSites/1").Text;
}
};
Get["/createlive"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
if (session.Load<MonitorSite>("MonitorSites/1") == null)
{
session.Store(new MonitorSite
{
Id = "MonitorSites/1",
Text = "I was fetched from the database",
});
session.SaveChanges();
return "Message was stored to the database.";
}
else
{
return Response.AsRedirect("/monitor/live");
}
}
};
}
示例2: WebLoginModule
public WebLoginModule(ISessionProvider sessionProvider)
{
_sessionProvider = sessionProvider;
Get["/weblogin"] = parameters => View["web/login.html"];
Get["/weblogout"] = parameters => this.Logout("/");
Post["/weblogin"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
string username = Request.Form["UserName"];
string password = Request.Form["Password"];
var login = session.Query<Login>()
.SingleOrDefault(
x => x.Username == username && x.Password == password);
if (login == null)
return Response.AsRedirect("/weblogin", RedirectResponse.RedirectType.SeeOther);
if(login.Roles.Contains(Roles.SuperAdmin))
return this.Login(login.AuthenticationKey, DateTime.Now.AddDays(1), "/admin");
if (login.Roles.Contains(Roles.ClientAdmin))
return this.Login(login.AuthenticationKey, DateTime.Now.AddDays(1), "/web/views/livedetails.html?" + login.ClientId);
if (login.Roles.Contains(Roles.ClientUser))
return this.Login(login.AuthenticationKey, DateTime.Now.AddDays(1), "/mobile/views/startup.html");
return this.Login(login.AuthenticationKey, fallbackRedirectUrl: "/");
}
};
}
示例3: UnitOfWorkBase
/// <summary>
/// Initializes the unit of work.
/// </summary>
protected UnitOfWorkBase(bool createTransaction, ISessionProvider sessionProvider)
{
_session = sessionProvider.GetSession();
if (createTransaction)
{
Session.BeginTransaction();
_transactionStarted = true;
}
}
示例4: RavenModule
protected RavenModule(ISessionProvider sessionProvider, IDispatchEvents eventDispatcher, string modulePath)
: base(modulePath)
{
_eventDispatcher = eventDispatcher;
this.RequiresAuthentication();
this.RequiresAnyClaim(new[] { "SuperAdmin", "ClientAdmin", "ClientUser" });
Before += ctx =>
{
ClientId = string.Format("clients/{0}", ctx.Parameters["id"]);
UncommitedEvents = new List<EventBase>();
if (ctx.CurrentUser.Claims.Any(x => x == "ClientAdmin"))
{
var seerefineIdentity = ctx.CurrentUser as SeerefineIdentity;
if (seerefineIdentity == null)
return HttpStatusCode.Unauthorized;
if (seerefineIdentity.ClientId != ClientId)
return HttpStatusCode.Unauthorized;
}
RavenSession = sessionProvider.GetSession();
return null;
};
After += ctx =>
{
if (RavenSession != null)
{
if(RavenSession.Advanced.HasChanges)
RavenSession.SaveChanges();
RavenSession.Dispose();
if (UncommitedEvents.Any())
_eventDispatcher.Dispatch(UncommitedEvents.ToArray());
}
};
OnError += (ctx, ex) =>
{
Trace.TraceError(ex.ToString());
if (ex is ConcurrencyException)
{
return Response.Conflict(ex.Message);
}
return HttpStatusCode.InternalServerError;
};
}
示例5: DefinitionCreatorFactory
public DefinitionCreatorFactory(ISessionProvider sessionProvider)
{
if (sessionProvider == null) throw new ArgumentNullException(nameof(sessionProvider));
_session = sessionProvider.GetSession();
_transaction = _session.BeginTransaction();
var definitionCreator = new DefinitionCreator(_session);
var productDefinitionCreator = new ProductDefinitionCreator(_session);
var dataTypeCreator = new DataTypeCreator(_session);
_definitionCreators = new Dictionary<BuiltInDefinitionType, ICreator>
{
{ BuiltInDefinitionType.CampaignItem, definitionCreator },
{ BuiltInDefinitionType.Category, definitionCreator },
{ BuiltInDefinitionType.PaymentMethod, definitionCreator },
{ BuiltInDefinitionType.Product, productDefinitionCreator },
{ BuiltInDefinitionType.DataType, dataTypeCreator }
};
}
示例6: NcsCriptBuilder
/// <summary>
/// Initializes a new instance of the <see cref="NcsCriptBuilder"/> class.
/// </summary>
/// <param name="configProvider">The config provider.</param>
/// <param name="sessionProvider">The session provider.</param>
public NcsCriptBuilder( IConfigurationPropertiesProvider configProvider, ISessionProvider sessionProvider )
{
_configProvider = configProvider;
_session = sessionProvider.GetSession ();
}
示例7: DefaultSession
public DefaultSession(ISessionProvider sessionProvider, ISessionIdProvider sessionIdProvider)
{
sessionId = sessionIdProvider.Get();
entries = sessionProvider.GetSession(sessionId);
}
示例8: AdminClientModule
public AdminClientModule(ISessionProvider sessionProvider)
: base("/admin/clients")
{
this.RequiresAuthentication();
this.RequiresClaims(new[] { "SuperAdmin" });
_sessionProvider = sessionProvider;
Get["/create"] = parameters => View["views/admin/_createClient.html"];
Get["/{id}"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
var client = session.Load<Client>(int.Parse(parameters.id));
if (client == null)
return HttpStatusCode.NotFound;
return View["views/admin/showclient.html", client];
}
};
Get["/{id}/admins/list"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
string clientId = string.Format("clients/{0}", parameters.id);
var logins = session.Query<Login>()
.Where(x => x.Roles.Contains(Roles.ClientAdmin) && x.ClientId == clientId)
.ToList();
return Response.AsJson(logins);
}
};
Get["/{id}/createadmin"] = parameters => View["views/admin/_createClientAdmin.html", new {ClientId = parameters.id}];
Post["/{id}/createadmin"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
session.Advanced.UseOptimisticConcurrency = true;
var command = this.Bind<CreateLoginCommand>();
if (command.AuthenticationKey == Guid.Empty)
command.AuthenticationKey = Guid.NewGuid();
session.Store(new Login
{
AuthenticationKey = command.AuthenticationKey,
ClientId = string.Format("clients/{0}", parameters.id),
Username = command.UserName,
Password = command.Password,
Roles = new List<Roles> {Roles.ClientAdmin},
});
session.Store(new UserNameAndPasswordIsUnique
{
Id = command.ToUniqueString(),
AuthenticationKey = command.AuthenticationKey,
});
session.SaveChanges();
}
return HttpStatusCode.NoContent;
};
Get["/list"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
var clients = session.Query<Client>().ToArray();
return Response.AsJson(clients);
}
};
Post["/create"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
session.Store(new Client
{
Name = Request.Form["ClientName"],
});
session.SaveChanges();
}
return HttpStatusCode.NoContent;
};
}
示例9: LoginsModule
public LoginsModule(ISessionProvider sessionProvider)
: base("/admin/logins")
{
_sessionProvider = sessionProvider;
this.RequiresAuthentication();
this.RequiresClaims(new[] { "SuperAdmin" });
Get["/create"] = parameters => View["views/admin/_createLogin.html"];
Get["/list"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
var accounts = session.Query<Login>()
.Where(x => x.Roles.Contains(Roles.SuperAdmin))
.ToList();
return Response.AsJson(accounts);
}
};
Post["/create"] = parameters =>
{
using (var session = _sessionProvider.GetSession())
{
session.Advanced.UseOptimisticConcurrency = true;
var command = this.Bind<CreateLoginCommand>();
if (command.AuthenticationKey == Guid.Empty)
command.AuthenticationKey = Guid.NewGuid();
session.Store(new Login
{
AuthenticationKey = command.AuthenticationKey,
Username = command.UserName,
Password = command.Password,
Roles = new List<Roles> {Roles.SuperAdmin},
});
session.Store(new UserNameAndPasswordIsUnique
{
Id = command.ToUniqueString(),
AuthenticationKey = command.AuthenticationKey,
});
session.SaveChanges();
}
return HttpStatusCode.NoContent;
};
}