本文整理汇总了C#中ZkData.ZkDataContext类的典型用法代码示例。如果您正苦于以下问题:C# ZkDataContext类的具体用法?C# ZkDataContext怎么用?C# ZkDataContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZkDataContext类属于ZkData命名空间,在下文中一共展示了ZkDataContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SubmitSpringBattleResult
public static string SubmitSpringBattleResult(Spring.SpringBattleContext result, ZkLobbyServer.ZkLobbyServer server)
{
try
{
if (!result.GameEndedOk) return "Game didn't end properly";
if (result.IsCheating) return "Cheats were enabled during this game";
var db = new ZkDataContext();
var text = new StringBuilder();
var sb = SaveSpringBattle(result, db);
ProcessExtras(result.OutputExtras, sb, db);
if (result.LobbyStartContext.Mode == AutohostMode.Planetwars) ProcessPlanetWars(result, server, sb, db, text);
ProcessElos(result, server, db, sb);
text.AppendLine(string.Format("BATTLE DETAILS AND REPLAY ----> {1}/Battles/Detail/{0} <-----", sb.SpringBattleID, GlobalConst.BaseSiteUrl));
return text.ToString();
}
catch (Exception ex)
{
var data = JsonConvert.SerializeObject(result);
Trace.TraceError($"{ex}\nData:\n{data}");
return $"{ex}\nData:\n{data}";
}
}
示例2: CopyExtraImages
private void CopyExtraImages() {
var db = new ZkDataContext();
var configs = Path.Combine(targetFolder, "LuaUI", "Configs");
Utils.CheckPath(configs);
var tpath = Path.Combine(configs, "Avatars");
Utils.CheckPath(tpath);
Trace.TraceInformation("Copying avatars");
var spath = Path.Combine(siteBase, "img", "Avatars");
foreach (var file in Directory.GetFiles(spath)) File.Copy(file, Path.Combine(tpath, Path.GetFileName(file)), true);
Trace.TraceInformation("Copying clan icons");
tpath = Path.Combine(configs, "Clans");
Utils.CheckPath(tpath);
spath = Path.Combine(siteBase, "img", "clans");
foreach (var clan in db.Clans.Where(x => !x.IsDeleted))
{
var fileName = $"{clan.Shortcut}.png";
var src = Path.Combine(spath, fileName);
if (File.Exists(src)) File.Copy(src, Path.Combine(tpath, fileName), true);
}
Trace.TraceInformation("Copying faction icons");
tpath = Path.Combine(configs, "Factions");
Utils.CheckPath(tpath);
spath = Path.Combine(siteBase, "img", "factions");
foreach (var fac in db.Factions.Where(x => !x.IsDeleted))
{
var fileName = $"{fac.Shortcut}.png";
var src = Path.Combine(spath, fileName);
if (File.Exists(src)) File.Copy(src, Path.Combine(tpath, fileName), true);
}
}
示例3: AddContribution
public ActionResult AddContribution(int accountID,int kudos, string item, string currency, double gross, double grossEur, double netEur, string email, string comment, bool isSpring, DateTime date) {
using (var db = new ZkDataContext()) {
var acc = db.Accounts.Find(accountID);
var contrib = new Contribution()
{
AccountID = accountID,
ManuallyAddedAccountID = Global.AccountID,
KudosValue = kudos,
ItemName = item,
IsSpringContribution = isSpring,
Comment = comment,
OriginalCurrency = currency,
OriginalAmount = gross,
Euros = grossEur,
EurosNet = netEur,
Time = date,
Name = acc.Name,
Email = email
};
db.Contributions.InsertOnSubmit(contrib);
db.SubmitAndMergeChanges();
acc.Kudos = acc.KudosGained - acc.KudosSpent;
db.SubmitAndMergeChanges();
}
return RedirectToAction("Index");
}
示例4: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
var db = new ZkDataContext();
if (!int.TryParse(Request["resourceID"], out resourceID)) {
resourceID = db.Resources.Single(x => x.InternalName == Request["name"]).ResourceID;
}
if (!IsPostBack) {
var res = db.Resources.Where(x => x.ResourceID == resourceID).Single();
lbDetails.Text = string.Format("Download count: {0}<br/>\nFailed downloads (no links): {1}<br/>\n", res.DownloadCount, res.NoLinkDownloadCount);
lbName.Text = res.InternalName;
litLinks.Text = string.Join("<br/>", res.ResourceDependencies.Select(x => x.NeedsInternalName).ToArray());
string name = res.InternalName.EscapePath();
var sb = new StringBuilder();
if (res.TypeID == ZkData.ResourceType.Map) {
sb.AppendFormat("<img src='Resources/{0}.minimap.jpg'><br/>", name);
sb.AppendFormat("<img src='Resources/{0}.heightmap.jpg'><br/>", name);
sb.AppendFormat("<img src='Resources/{0}.metalmap.jpg'><br/>", name);
}
sb.AppendFormat("<a href='Resources/{0}.metadata.xml.gz'>metadata</a><br/>", name);
litBasics.Text = sb.ToString();
}
}
示例5: CanJoin
public async Task<bool> CanJoin(int accountID, string channel)
{
using (var db = new ZkDataContext()) {
var acc = await db.Accounts.FindAsync(accountID);
return CanJoin(acc, channel);
}
}
示例6: DeleteAllPostsByUser
public ActionResult DeleteAllPostsByUser(int accountID, string accountName) {
var db = new ZkDataContext();
var acc = db.Accounts.FirstOrDefault(x => x.AccountID == accountID);
if (acc.Name != accountName) return Content("Invalid safety code");
foreach (var p in acc.ForumPosts) DeletePost(p.ForumPostID);
return RedirectToAction("Index");
}
示例7: ConvertPage
public static void ConvertPage(string pageName, string newName, bool overwrite = false)
{
var db = new ZkDataContext();
ForumThread thread = db.ForumThreads.FirstOrDefault(x=> x.WikiKey == pageName);
if (thread == null)
{
Console.WriteLine("No ZK wiki page with name {0} found", pageName);
return;
}
string text = thread.ForumPosts.First().Text;
text = BBCodeToMediaWiki(text);
Page page = new Page(newWiki, newName);
page.Load();
bool update = false;
if (!page.IsEmpty())
{
if (!overwrite)
{
Console.WriteLine("Page already exists, exiting");
return;
}
else update = true;
}
if (newName.StartsWith("Mission Editor", true, System.Globalization.CultureInfo.CurrentCulture))
page.AddToCategory("Mission Editor");
page.Save(text, update ? "" : "Ported from ZK wiki by DotNetWikiBot", update);
}
示例8: BattleBalanceData
public BattleBalanceData(int battleID)
{
ZkDataContext db = new ZkDataContext();
SpringBattle game = db.SpringBattles.FirstOrDefault(x => x.SpringBattleID == battleID);
this.battleID = battleID;
this.t1Elo = new List<double>();
this.t2Elo = new List<double>();
this.t1Names = new List<string>();
this.t2Names = new List<string>();
double t1Sum = 0;
double t2Sum = 0;
int t1Count = 0;
int t2Count = 0;
foreach (SpringBattlePlayer player in game.SpringBattlePlayers.Where(x=> !x.IsSpectator))
{
if (player.IsInVictoryTeam)
{
t1Sum += player.Account.EffectiveElo;
this.t1Elo.Add(Math.Floor(player.Account.EffectiveElo+0.5));
this.t1Names.Add(player.Account.Name);
t1Count++;
}
else
{
t2Sum += player.Account.EffectiveElo;
this.t2Elo.Add(Math.Floor(player.Account.EffectiveElo + 0.5));
this.t2Names.Add(player.Account.Name);
t2Count++;
}
}
this.t1Avg = Math.Floor(t1Sum / t1Count + 0.5);
this.t2Avg = Math.Floor(t2Sum / t2Count + 0.5);
this.t1Variance = Math.Floor(Variance(this.t1Elo, this.t1Avg) + 0.5);
this.t2Variance = Math.Floor(Variance(this.t2Elo, this.t2Avg) + 0.5);
}
示例9: client_ChannelUserAdded
void client_ChannelUserAdded(object sender, ChannelUserInfo e)
{
Task.Run(async () =>
{
try
{
var chan = e.Channel.Name;
List<LobbyMessage> messages;
foreach (var user in e.Users) {
using (var db = new ZkDataContext()) {
messages = db.LobbyMessages.Where(x => x.TargetName == user.Name && x.Channel == chan).OrderBy(x => x.Created).ToList();
db.LobbyMessages.DeleteAllOnSubmit(messages);
db.SubmitChanges();
}
foreach (var m in messages) {
var text = string.Format("!pm|{0}|{1}|{2}|{3}", m.Channel, m.SourceName, m.Created.ToString(CultureInfo.InvariantCulture), m.Message);
await client.Say(SayPlace.User, user.Name, text, false);
await Task.Delay(MessageDelay);
}
}
}
catch (Exception ex)
{
Trace.TraceError("Error adding user: {0}", ex);
}
});
}
示例10: Index
//
// GET: /Poll/
public ActionResult Index(int pollID)
{
var db = new ZkDataContext();
var poll = db.Polls.FirstOrDefault(x => x.PollID == pollID);
if (poll != null) return PartialView("PollView", poll);
return null;
}
示例11: GetMissionByID
public Mission GetMissionByID(int missionID)
{
var db = new ZkDataContext();
db.Configuration.ProxyCreationEnabled = false;
var prev = db.Missions.Where(x => x.MissionID == missionID).Include(x=>x.Mutator).SingleOrDefault();
return prev;
}
示例12: Index
//
// GET: /News/
public ActionResult Index()
{
Response.ClearContent();
Response.ContentType = "application/rss+xml";
var db = new ZkDataContext();
return View(db.News.Where(x=>x.Created < DateTime.UtcNow).OrderByDescending(x=>x.Created));
}
示例13: CachePunishments
private static void CachePunishments()
{
lock (punishmentsLock)
{
using (var db = new ZkDataContext()) punishments = db.Punishments.Where(x => x.BanExpires > DateTime.UtcNow).Include(x=>x.AccountByAccountID).Include(x=>x.AccountByCreatedAccountID).ToList();
}
}
示例14: VerifyAccountHashed
public static Account VerifyAccountHashed(string login, string passwordHash)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(passwordHash)) return null;
var db = new ZkDataContext();
var acc = Account.AccountVerify(db, login, passwordHash);
return acc;
}
示例15: Delete
public ActionResult Delete(int id)
{
var db = new ZkDataContext();
db.Missions.First(x => x.MissionID == id).IsDeleted = true;
db.SubmitChanges();
return RedirectToAction("Index");
}