public static bool UpdateData(CardContext db, List <ForecastCard> forecastCards) { foreach (var card in forecastCards) { if (DataValidation.AllValidation(card)) { ForecastCard forecastCard = db.ForecastCards.FirstOrDefault(x => x.DateTime == card.DateTime); if (forecastCard == null) { db.ForecastCards.Add(card); } else { forecastCard.Description = card.Description; forecastCard.Humidity = card.Humidity; forecastCard.Temperature = card.Temperature; forecastCard.WindDirection = card.WindDirection; db.Entry(forecastCard).State = EntityState.Modified; } } } try { db.SaveChanges(); return(true); } catch (Exception ex) { return(false); }; }
public CardContext[] DrawCards(int n) { var ret = new CardContext[n]; var pool = new List<CardContext>(cardContexts); for (int i = 0; i < n; i++) { var privilegedOne = PopOne(pool, CardContext.MAGIC_NUMBER); if (privilegedOne != null) { ret[i] = privilegedOne; continue; } var theOne = PopOne(pool, 0); if (theOne == null) { throw new System.Exception("Logical Exception!"); } ret[i] = theOne; } return ret; }
private void TypeEditor_Delete_Button_Click(object sender, RoutedEventArgs e) { ConfirmDelete confirmDelete = new ConfirmDelete(currentType.Name); confirmDelete.WindowStartupLocation = WindowStartupLocation.CenterScreen; bool?confirmedDelete = confirmDelete.ShowDialog(); if (confirmedDelete == false) { return; } using (CardContext context = new CardContext()) { foreach (Attack attack in attacks) { if (attack.CardTypeID == currentType.ID) { context.Attacks.Remove(attack); } } context.CardTypes.Remove(context.CardTypes.Find(currentType.ID)); context.SaveChanges(); } Close(); }
public virtual byte[] processCommand(Apdu apdu) { CardContext context = handler.Context; ushort bsoId = Util.ToUShort(apdu.P1, (byte)(apdu.P2 & 0x7f)); bool backTrack = (apdu.P2 & 0x80) != 0; BSO bso = null; if (backTrack) { bso = context.CurDF.GetChildBSO(bsoId, backTrack); } else { bso = context.CurDF.Owner.MasterFile.GetChildBSO(bsoId, false); } if (bso == null) { return(Error.FileNotFound); } if (!handler.IsVerifiedAC(bso, BSO_AC.AC_CHANGE)) { return(Error.SecurityStatusNotSatisfied); } if (bso.Data.Length != apdu.Data.Length) { return(Error.DataFieldNotValid); } bso.Data = apdu.Data; handler.UnblockBSO(bso); return(Error.Ok); }
public async Task <Card> AddProductToCardAsync(Guid customerID, Guid productID, int quantity) { using (var db = new CardContext()) { var card = db.Cards .Where(c => c.IsActive == true && c.CustomerID == customerID) .Include(m => m.CardItems) .Include(m => m.CardItems) .FirstOrDefault(); if (card != null) { if (card.CardItems.Any(ci => ci.ProductID != productID)) { card.CardItems.Add(new CardItem(customerID, productID, quantity)); } else { card.CardItems.Where(ci => ci.ProductID == productID).FirstOrDefault().Quantity += quantity; } } else { db.Add(new Card(customerID, new List <CardItem>() { new CardItem(customerID, productID, quantity) }, true)); } db.SaveChanges(); return(db.Cards.Where(c => c.CustomerID == customerID && c.IsActive).FirstOrDefault()); } }
public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut) { CardContext context = handler.Context; sigOut = null; encOut = null; ushort bsoId = Util.ToUShort(apdu.P1, (byte)(apdu.P2 & 0x7f)); bool backTrack = (apdu.P2 & 0x80) != 0; BSO bso = null; if (backTrack) { bso = context.CurDF.GetChildBSO(bsoId, backTrack); } else { bso = context.CurDF.Owner.MasterFile.GetChildBSO(bsoId, false); } if (bso == null) { throw new ISO7816Exception(Error.FileNotFound); } encIn = handler.getSMKey(bso, BSO_SM.SM_ENC_CHANGE); sigIn = handler.getSMKey(bso, BSO_SM.SM_SIG_CHANGE); }
internal CardLabelCollection(CardContext context, TrelloAuthorization auth) : base(() => context.Data.Id, auth) { _context = context; EventAggregator.Subscribe(this); }
public virtual byte[] processCommand(Apdu apdu) { CardContext context = handler.Context; if (apdu.P1 != 0 || apdu.P2 != 0) { return(Error.P1OrP2NotValid); } if (apdu.Data != null && apdu.Data.Length != 0) { return(Error.DataFieldNotValid); } var ef = context.CurFile; if (ef == null) { return(Error.NoCurrentEFSelected); } if (!ef.Active) { return(Error.InsNotValid); } ef.Active = false; return(Error.Ok); }
/// <summary> /// Creates a new instance of the <see cref="Card"/> object. /// </summary> /// <param name="id">The card's ID.</param> /// <param name="auth">(Optional) Custom authorization parameters. When not provided, <see cref="TrelloAuthorization.Default"/> will be used.</param> /// <remarks> /// The supplied ID can be either the full or short ID. /// </remarks> public Card(string id, TrelloAuthorization auth = null) { Id = id; _context = new CardContext(id, auth); _context.Synchronized.Add(this); Badges = new Badges(_context.BadgesContext); _board = new Field <Board>(_context, nameof(Board)); _board.AddRule(NotNullRule <Board> .Instance); _description = new Field <string>(_context, nameof(Description)); _dueDate = new Field <DateTime?>(_context, nameof(DueDate)); _isComplete = new Field <bool?>(_context, nameof(IsComplete)); _isArchived = new Field <bool?>(_context, nameof(IsArchived)); _isArchived.AddRule(NullableHasValueRule <bool> .Instance); _isSubscribed = new Field <bool?>(_context, nameof(IsSubscribed)); _isSubscribed.AddRule(NullableHasValueRule <bool> .Instance); _lastActivity = new Field <DateTime?>(_context, nameof(LastActivity)); _list = new Field <List>(_context, nameof(List)); _list.AddRule(NotNullRule <IList> .Instance); _name = new Field <string>(_context, nameof(Name)); _name.AddRule(NotNullOrWhiteSpaceRule.Instance); _position = new Field <Position>(_context, nameof(Position)); _position.AddRule(PositionRule.Instance); _shortId = new Field <int?>(_context, nameof(ShortId)); _shortUrl = new Field <string>(_context, nameof(ShortUrl)); _url = new Field <string>(_context, nameof(Url)); if (_context.HasValidId && auth != TrelloAuthorization.Null) { TrelloConfiguration.Cache.Add(this); } }
public string GetHistory(string user, int toShow, ulong serverId) { string message = $"History for {user}:\n"; using (var db = new CardContext()) { var history = db.CardGivings.AsQueryable() .Where(g => g.Degenerate.Id == db.Users.AsQueryable() .Where(u => u.Name == user).Select(u => u.Id).FirstOrDefault()) .Where(c => c.ServerId == serverId) .OrderByDescending(x => x.TimeStamp).ToList(); if (history.Count > 0) { for (int count = 0; count <= toShow && count < history.Count; ++count) { var i = history[count]; var color = db.Cards.AsQueryable().Where(c => c.Id == i.CardId).Select(c => c.Name).FirstOrDefault(); var giver = db.Users.AsQueryable().Where(u => u.Id == i.GiverId).Select(u => u.Name).FirstOrDefault(); message += $"**{color}** card given by **{giver}**: {i.CardReason}\n"; } } else { message = $"{user} does not have any cards. smile :)"; } } return(message); }
// // GET: /Archive/ public ActionResult Index() { CardContext db = new CardContext(); var cards = db.Cards.Where <Card>(c => c.archived == true); return(View(cards.ToList())); }
public static CardEntity CreateDeckCard(this CardContext context, DeckCard type) { var entity = context.CreateEntity(); entity.AddDeckCard(type); return(entity); }
private void AttackEditor_CreateAttack_Button_Click(object sender, RoutedEventArgs e) { if (!CheckValidInput()) { MessageBox.Show("Some values are not valid!", "Invalid Input!"); return; } using (CardContext context = new CardContext()) { if (editAttack) { Attack updatedAttack = context.Attacks.Find(currentAttack.ID); updatedAttack.Name = AttackEditor_Name_Textbox.Text; updatedAttack.CardTypeID = ((CardType)AttackEditor_Type_Combobox.SelectedItem).ID; updatedAttack.Damage = int.Parse(AttackEditor_Damage_Textbox.Text); context.SaveChanges(); } else { Attack newAttack = new Attack() { Name = AttackEditor_Name_Textbox.Text, CardTypeID = ((CardType)AttackEditor_Type_Combobox.SelectedItem).ID, Damage = int.Parse(AttackEditor_Damage_Textbox.Text) }; context.Attacks.Add(newAttack); context.SaveChanges(); } } Close(); }
public void Disconnect() { if (CardMonitor != null) { try { CardMonitor.Cancel(); CardMonitor.CardInserted -= CardInserted; CardMonitor.CardInserted -= CardRemoved; } catch (Exception) { } finally { CardMonitor = null; } } if (CardContext != null) { try { CardContext.Release(); } catch (Exception) { } finally { CardContext = null; } } }
private void MainWindow_ImportFromJSON(object sender, RoutedEventArgs e) { OpenFileDialog openJSON = new OpenFileDialog { Filter = "Json files (*.json)|*.json" }; openJSON.CheckFileExists = true; if (openJSON.ShowDialog() == true) { if (openJSON.FileName.Trim() != string.Empty) { using (StreamReader sr = new StreamReader(openJSON.FileName)) { string json = sr.ReadToEnd(); List <Card> importedCards = JsonConvert.DeserializeObject <List <Card> >(json); using (CardContext context = new CardContext()) { foreach (Card newCard in importedCards) { newCard.ID = 0; context.Cards.Add(newCard); context.SaveChanges(); } } } RefreshListView(); } } }
public StartDeckCardDrawingSystem(Contexts contexts, DeckSetting setting) : base(contexts) { _gameContext = contexts.game; _cardContext = contexts.card; _setting = setting; _eventContext = contexts.gameEvent; }
public static CardEntity[] GetPlayerBoxCards <T>(this CardContext context, GameEntity playerEntity) { return(context.GetBoxCards() .Where(c => c.owner.Entity == playerEntity) .Where(boxCard => boxCard.ability.Ability is T) .ToArray()); }
/// <summary> /// Установить выбранную карту в окно /// </summary> /// <param name="primaryKey"></param> private void InitialCard(object primaryKey) { using (CardContext db = new CardContext()) { card = db.Cards.Find(primaryKey); } OutputData(card); }
public void Add(Card c) { if (c == null) { throw new Exception("card cannot be null"); } CardContext.AddCard(c); }
public static void SetData(DependencyObject d, DependencyPropertyChangedEventArgs e) { CardControl cardControl = d as CardControl; if (cardControl != null) { cardControl.Name.Content = (e.NewValue as Card).Name; cardControl.HP.Content = (e.NewValue as Card).HP + " HP"; using (CardContext context = new CardContext()) { if (context.CardTypes.Find((e.NewValue as Card).CardTypeID) != null) { cardControl.Type.Content = context.CardTypes.Find((e.NewValue as Card).CardTypeID).Name; string color = context.CardTypes.Find((e.NewValue as Card).CardTypeID).Cardcolor; cardControl.BorderColor.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color)); } else { cardControl.Type.Content = "No Type"; cardControl.UC_IsValid_Label.Content = "Not Valid for play"; } if (context.Attacks.Find((e.NewValue as Card).Attack1ID) != null) { cardControl.Attack1.Content = context.Attacks.Find((e.NewValue as Card).Attack1ID).Name; cardControl.Attack1_Damage.Content = context.Attacks.Find((e.NewValue as Card).Attack1ID).Damage; } else { cardControl.Attack1.Content = ""; cardControl.Attack1_Damage.Content = ""; } if (context.Attacks.Find((e.NewValue as Card).Attack2ID) != null) { cardControl.Attack2.Content = context.Attacks.Find((e.NewValue as Card).Attack2ID).Name; cardControl.Attack2_Damage.Content = context.Attacks.Find((e.NewValue as Card).Attack2ID).Damage; } else { cardControl.Attack2.Content = ""; cardControl.Attack2_Damage.Content = ""; } if (context.Attacks.Find((e.NewValue as Card).Attack1ID) == null && context.Attacks.Find((e.NewValue as Card).Attack2ID) == null) { cardControl.UC_IsValid_Label.Content = "Not Valid for play"; cardControl.UC_IsValid_Label.Foreground = Brushes.Red; } } ImageSourceConverter converter = new ImageSourceConverter(); cardControl.Image.Source = (ImageSource)converter.ConvertFromString((e.NewValue as Card).ImagePath); } }
public BossActiveSkillUsingSystem(Contexts contexts, TurnNotification noti, SystemController syscon) : base(contexts) { _cardContext = contexts.card; _unitContext = contexts.unit; _eventContext = contexts.gameEvent; _noti = noti; _syscon = syscon; }
private void AttackEditor_Delete_Button_Click(object sender, RoutedEventArgs e) { using (CardContext context = new CardContext()) { context.Attacks.Remove(context.Attacks.Find(currentAttack.ID)); context.SaveChanges(); } Close(); }
static void Main(string[] args) { Func <ICardContext, ICardChannel> createCardChannel; Action processCommands; if (args.Length == 2) { switch (args[1]) { case "applet": createCardChannel = (context) => new CardChannel(context, context.Readers.Last(), new JavaCardApplet()); processCommands = ProcessTb100FakeCardCommands; break; case "javacard": default: createCardChannel = (context) => new CardChannel(context, context.Readers.Last(), new JavaCardT0ForTB100Adapter(new JavaCardApplet())); processCommands = ProcessJavaCardTb100FakeCardCommands; break; } } else { createCardChannel = (context) => new CardChannel(context, context.Readers.Last(), new JavaCardT0ForTB100Adapter(new JavaCardApplet())); processCommands = ProcessJavaCardTb100FakeCardCommands; } // Connect to Fake PC/SC var context = new CardContext(); context.Establish(); // Get installed readers context.ListReaderGroups(); context.ListReaders(""); PrintReadersAndReaderGroups(context); // Connect to an ISO7816-4 card in the last reader found var rawChannel = createCardChannel(context); channel = new CardChannelIso7816(rawChannel); channel.Connect(ShareMode.Exclusive, Protocol.Any); PrintAttribute(Attrib.AtrString); PrintAttribute(Attrib.DeviceFriendlyName); processCommands(); // Unpower the card channel.Disconnect(Disposition.UnpowerCard); // Disconnect from Fake PC/SC context.Release(); }
public async Task GetCards() { List <Cards> cards; using (var db = new CardContext()) { cards = db.Cards.AsQueryable() .Where(c => c.ServerId == Context.Guild.Id) .OrderByDescending(c => c.Value) .ToList(); } if (null == cards || cards.Count == 0) { await ReplyAsync("There are no cards for this server. Create one with !create."); return; } var message = new StringBuilder(); string segment, line, header; string cardHeader = "Card"; string valueHeader = "Value"; int longestCard = cards.OrderByDescending(c => c.Name.Length).First().Name.Length; int longestValue = cards.OrderByDescending(c => c.Value.ToString().Length).First().Value.ToString().Length; if (longestCard < cardHeader.Length) { longestCard = cardHeader.Length; } if (longestValue < valueHeader.Length) { longestValue = valueHeader.Length; } segment = $"| {cardHeader.CenterString(longestCard)} |"; line = $"|{new string('-', segment.Length-2)}+"; header = segment; segment = $" {valueHeader.CenterString(longestValue)} |"; line += $"{new string('-', segment.Length-1)}|"; header += segment; message.AppendLine(header).AppendLine(line); foreach (var c in cards) { message.AppendLine( $"| {c.Name.CenterString(longestCard)} | {c.Value.ToString().CenterString(longestValue)} |"); } await ReplyAsync($"The following cards are available:\n```{message}```"); }
public void Evaluate(CardContext ctx, out CardContext res) { res = new CardContext(); MonsterCard mc = ctx.Card as MonsterCard; MonsterCard resMc = new MonsterCard(mc.Name, mc.AttackPower, mc.DefensePower + 2, mc.MonsterType, mc.Description); res.Card = resMc; res.Player = ctx.Player; }
public CardRepository(CardContext context, CardActionContext cardActionContext, BoardContext boardContext, ColumnContext columnContext, TodolistContext todolistContext) { _db = context; _dbBoard = boardContext; _dbColumn = columnContext; _todolistContext = todolistContext; _cardActionContext = cardActionContext; }
public virtual byte[] processCommand(Apdu apdu) { context = handler.Context; if (apdu.P1 == 0x01 && apdu.P2 == 0x6E) return PutDataOCI(apdu); if (apdu.P1 == 0x01 && apdu.P2 == 0x6F) return PutDataFCI(apdu); if (apdu.P1 == 0x01 && apdu.P2 == 0x6D) return PutDataSE(apdu); return Error.P1OrP2NotValid; }
public void getSMKeys(Apdu apdu, out BSO sigIn, out BSO encIn, out BSO sigOut, out BSO encOut) { context = handler.Context; if (apdu.P1 == 0x01 && apdu.P2 == 0x6E) PutDataOCIKeys(apdu, out sigIn, out encIn, out sigOut, out encOut); else if (apdu.P1 == 0x01 && apdu.P2 == 0x6F) PutDataFCIKeys(apdu, out sigIn, out encIn, out sigOut, out encOut); else if (apdu.P1 == 0x01 && apdu.P2 == 0x6D) PutDataSEKeys(apdu, out sigIn, out encIn, out sigOut, out encOut); else throw new ISO7816Exception(Error.P1OrP2NotValid); }
private void MainWindow_Delete_Button_Click(object sender, RoutedEventArgs e) { using (CardContext context = new CardContext()) { foreach (Card c in MainWindow_Cards_ListView.SelectedItems) { context.Cards.Remove(context.Cards.Find(c.ID)); } context.SaveChanges(); context.SaveChanges(); } RefreshListView(); }
public void Update(Model.Match M, string current) { if (M.Guess != current) { M.Guess = current; using (var context = new CardContext()) { context.Entry(M).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } } }
public virtual byte[] processCommand(Apdu apdu) { CardContext context = handler.Context; if (context.CurEF == null) { return(Error.NoCurrentEFSelected); } if (apdu.Data != null && apdu.Data.Length > 0) { return(Error.DataFieldNotValid); } if (!(context.CurEF is EFBinary)) { return(Error.CommandIncompatibleWithFileStructure); } var efBin = context.CurEF as EFBinary; if (!handler.IsVerifiedAC(efBin, EF_AC.AC_READ)) { return(Error.SecurityStatusNotSatisfied); } var offset = (apdu.P1 << 8) | apdu.P2; int len = 0; if (apdu.UseLE) { if (apdu.LE == 0) { len = 256; } else { len = apdu.LE; } } if (efBin.Data.Length < offset) { return(Error.P1OrP2NotValid); } if (efBin.Data.Length < offset + len) { len = efBin.Data.Length - offset; } return(Util.Response(efBin.Data, offset, len, Error.Ok)); }
public void Evaluate(CardContext ctx, out CardContext res) { res = new CardContext(); var player = ctx.Player; ItemCard fort = ctx.Card as ItemCard; ItemCard ic = new ItemCard(fort.Name, fort.ItemType, fort.Description); var updatedPlayer = new Player(player.Name, player.HitPoints + 1); res.Card = ic; res.Player = updatedPlayer; }
private static void SaveImageUris(CardContext context, List <ImageUri> storedUris, List <ImageUri> incomingUris) { var itemsToAdd = incomingUris.ToArray().Where(d => !storedUris.Any(c => c.Id == d.Id)); var itemsToUpdate = storedUris.Where(d => incomingUris.ToArray().Any(c => c.Id == d.Id)); var itemsToRemove = storedUris.Where(d => !incomingUris.ToArray().Any(c => c.Id == d.Id)); foreach (var update in itemsToUpdate) { context.Entry(update).CurrentValues.SetValues(incomingUris.ToArray().Where(d => d.Id == update.Id).SingleOrDefault()); } context.ImageUris.RemoveRange(itemsToRemove); context.ImageUris.AddRange(itemsToAdd); }
public CardsRepository(CardContext context) { _context = context; }