本文整理汇总了C#中Session.Load方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Load方法的具体用法?C# Session.Load怎么用?C# Session.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session.Load方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateName
/// <summary>
/// 用户更新用户名
/// </summary>
/// <param name="session"></param>
/// <param name="userName"></param>
/// <param name="newName"></param>
/// <param name="currentAccountNo"></param>
/// <returns></returns>
public static bool UpdateName(Session session, string userName, string newName, string currentAccountNo)
{
if(string.IsNullOrEmpty(userName)) throw new ArgumentNullException("userName");
var user = session.Load<User>(m => m.Name.Equals(userName));
if(user == null) throw new ArgumentException(string.Format("用户{0}不存在", userName));
return UpdateName(session, user, newName, currentAccountNo);
}
示例2: btnMergeNext_Click
private void btnMergeNext_Click(object sender, System.EventArgs e)
{
var sessionName = string.Format("Merge {0:yyyy-MM-dd HH.mm.ss}", DateTime.Now);
var session = new Session(sessionName);
var sessionsList = new List<Session>();
sessionsList.Add(_leftSession);
sessionsList.Add(_rightSession);
if (session.Load(sessionsList))
{
if (PartFinished != null)
PartFinished(_leftSession, _rightSession, session);
}
else
{
btnCancel.PerformClick();
}
}
示例3: SaveNavigationCategory
/// <summary>
/// 保存模块的功能分类
/// </summary>
/// <param name="session"></param>
/// <param name="categories"></param>
/// <returns></returns>
private long SaveNavigationCategory(Session session, IList<CategoryAttribute> categories)
{
if (categories == null || categories.Count == 0) return DefaultParentId;
var id = DefaultParentId;
var orderedCategories = categories.OrderBy(m => m.Position).ToArray();
for (var i = 0; i < orderedCategories.Length; i++)
{
var category = orderedCategories[i];
if (i == 0)
{
var nav = session.Load<Navigation>(m => m.Name.Equals(category.Name) && m.Type.Equals(NavigationType.Category));
if (nav == null)
{
id = DefaultParentId;
}
else
{
id = nav.Id;
continue;
}
}
id = SaveNavigation(session, category, id);
}
return id;
}
示例4: SaveNavigationContainer
/// <summary>
/// 存储分类
/// </summary>
/// <param name="session">数据库会话</param>
/// <param name="category">导航分类</param>
/// <param name="parentId">导航分类的上级序号</param>
private void SaveNavigationContainer(Session session, NavigationCategory category, long parentId)
{
if (string.IsNullOrEmpty(category.Name))
throw new Exception("Category的Name属性不能为空,请检查nav_container.xml文件");
var nav = session.Load<Navigation>(m => m.Name.Equals(category.Name));
if (nav != null) throw new Exception("Category的Name属性已被使用,请检查nav_container.xml文件");
nav = new Navigation { Id = GetNavIdByName(session, category.Name), Name = category.Name, Type = NavigationType.Category, ParentId = parentId, OrderId = category.OrderId, CreatedAt = DateTime.Now, CreatedBy = "SYSTEM", AuthCode = Navigation.NotCheck };
if (!session.Create(nav))
{
throw new Exception(string.Format("保存导航分类失败:Name - {0}, ParentId - {1}", category.Name, parentId));
}
// 如果是叶子分类,放入导航分类字典备查
if (category.Categories.Count == 0) _navCagotryDict.Add(nav.Name, nav.Id);
foreach (var subCategory in category.Categories)
{
SaveNavigationContainer(session, subCategory, nav.Id);
}
}
示例5: SaveNavigation
private long SaveNavigation(Session session, ModuleAttribute module, long parentId, long moduleOrderId, string minorIcon = null)
{
if (module == null || string.IsNullOrEmpty(module.Name)) return parentId;
var nav = session.Load<Navigation>(m => m.Name.Equals(module.Name) && m.ParentId.Equals(parentId));
if (nav != null) return nav.Id;
nav = new Navigation
{
Id = GetNavIdByName(session, module.Name),
Name = module.Name,
Type = module.IsHideMenu ? NavigationType.Action : NavigationType.Module,
ParentId = parentId,
OrderId = moduleOrderId > 0 ? moduleOrderId : module.Position,
CreatedAt = DateTime.Now,
CreatedBy = "SYSTEM",
AuthCode = module.NotCheck ? Navigation.NotCheck : Navigation.ShouldCheck,
Icon = module.Icon ?? minorIcon
};
if (session.Create(nav)) { return nav.Id; }
throw new Exception(string.Format("保存导航失败:Name - {0}, ParentId - {1}", module.Name, parentId));
}
示例6: RegisterNavigation
/// <summary>
/// 注册导航
/// </summary>
/// <param name="session"></param>
/// <param name="container">导航分类容器</param>
internal void RegisterNavigation(Session session, NavigationContainer container)
{
var moduleOrderDict = new Dictionary<string, int>();
AddModuleOrder(container.Categories, moduleOrderDict);
var assembly = typeof(SystemActivity).Assembly;
foreach (var type in assembly.GetExportedTypes())
{
if (type == null) continue;
if (!type.FullName.EndsWith("Controller")) continue;
var categoryAttrs = GetCategoryAttributes(type);
if (categoryAttrs == null)
{
_logger.Warn("{0}没有CategoryAttribute标记", type.FullName);
continue;
}
var moduleAttr = GetModuleAttribute(type);
if (moduleAttr == null)
{
_logger.Warn("{0}没有ModuleAttribute标记", type.FullName);
continue;
}
_logger.Info("处理控制器 {0}", type.FullName);
var area = GetArea(type);
// 隐藏
if (categoryAttrs.Any(m => m.HideMenu)) continue;
var categoryId = SaveNavigationCategory(session, categoryAttrs);
var moduleOrderId = string.IsNullOrEmpty(moduleAttr.Name) ? 0 :
moduleOrderDict.ContainsKey(moduleAttr.Name) ? moduleOrderDict[moduleAttr.Name] : 0;
var moduleId = SaveNavigation(session, moduleAttr, categoryId , moduleOrderId, type.Name.Replace("Controller", ""));
var hasNormalMoudle = !string.IsNullOrEmpty(moduleAttr.Name);
var foundDefaultModuleAction = false;
var controller = type.Name.Replace("Controller", String.Empty);
var validMethodsCount = 0;
foreach (var mi in type.GetMethods())
{
var action = mi.Name;
_logger.Debug("process Controller {0} Actioon {1}", controller, action);
// 更新模块的URL
if (hasNormalMoudle && !foundDefaultModuleAction && moduleAttr.DefaultAction != null && action.Equals(moduleAttr.DefaultAction))
{
foundDefaultModuleAction = true;
SaveNavigation(session, moduleId, GetUrl(area, controller, action));
continue;
}
var attr = GetPriviledgeAttribute(mi);
if (attr == null) continue;
if (!attr.NotCheck) validMethodsCount++;
SaveNavigation(session, attr, moduleId, area, controller, action);
}
if (validMethodsCount == 0)
{
var count = session.Count<Navigation>(m => m.ParentId.Equals(categoryId));
if (count == 0)
{
if (!session.Delete<Navigation>(m => m.Id.Equals(categoryId))) throw new Exception("删除数据分类失败");
}
}
else
{
var nav = session.Load<Navigation>(moduleId);
nav.AuthCode = Navigation.ShouldCheck;
if (!session.Update(nav)) throw new Exception("更新数据模块[NotCheck]失败");
if (moduleId != categoryId)
{
nav = session.Load<Navigation>(categoryId);
nav.AuthCode = Navigation.ShouldCheck;
if (!session.Update(nav)) throw new Exception("更新数据分类[NotCheck]失败");
}
}
}
}
示例7: ResetAccount
public string ResetAccount(Session session, string currentAccountNo, string flag)
{
flag = string.IsNullOrEmpty(flag) ? Account.GetFlag() : flag;
var account = session.Load<Account>(m => m.Name.Equals(Name));
if (account == null)
{
// 发生账户丢失异常时,修复账户
InitAccount(session, currentAccountNo);
account = session.Load<Account>(m => m.Name.Equals(Name));
}
account.Flag = flag;
account.Status = Account.Inactive;
account.UpdatedAt = DateTime.Now;
account.UpdatedBy = currentAccountNo;
if (session.Update(account)) return flag;
return null;
}
示例8: Delete
public bool Delete(Session session)
{
var account = session.Load<Account>(m => m.Name.Equals(Name));
if (account == null)
{
return true;
}
if (!session.Delete<AccountNavigationRef>(m => m.Type.Equals(AccountNavigationRef.AccountType) && m.OwnerId.Equals(account.Id)))
{
return false;
}
if (!session.Delete<AccountRoleRef>(m => m.AccountId.Equals(account.Id)))
{
return false;
}
if (!session.Delete<User>(m => m.Id.Equals(Id)))
{
return false;
}
return true;
}
示例9: DeactiveAccount
public bool DeactiveAccount(Session session, string currentAccountNo)
{
var account = session.Load<Account>(m => m.Name.Equals(Name));
if (account == null)
{
account = new Account();
account.Name = Name;
account.Password = Guid.NewGuid().ToString();
account.Status = Account.Inactive;
account.CreatedAt = DateTime.Now;
account.CreatedBy = currentAccountNo;
return session.Create(account);
}
account.Status = Account.Inactive;
account.UpdatedAt = DateTime.Now;
account.UpdatedBy = currentAccountNo;
return session.Update(account);
}
示例10: DeactiveAccount
private bool DeactiveAccount(Session session, string currentAccountNo)
{
var account = session.Load<Account>(m => m.Name.Equals(Code));
if (account == null)
{
account = new Account
{
Name = Code,
Password = Guid.NewGuid().ToString(),
Status = Account.Inactive,
CreatedAt = DateTime.Now,
CreatedBy = currentAccountNo
};
return session.Create(account);
}
account.Flag = null;
account.Status = Account.Inactive;
account.UpdatedAt = DateTime.Now;
account.UpdatedBy = currentAccountNo;
return session.Update(account);
}