Ejemplo n.º 1
0
        public void Run()
        {
            Debugger.Break();

            int speakerId   = 10;
            int techeventId = 11;

            // Welche Strategie darf es sein?
            Strategy strategy = Strategy.EagerLoading;

            switch (strategy)
            {
            case Strategy.LazyLoadingAutomatic:
                #region LazyLoadingAutomatic
                Console.Clear();
                // Wird nicht unterstützt
                break;

                #endregion
            case Strategy.LazyLoadingExplicit:
                #region LazyLoadingExplicit
                Console.Clear();

                Speaker speaker2 = _efContext.Speakers.Find(speakerId);
                _efContext.Entry(speaker2).Collection(e => e.SpeakerSessions).Load();

                TechEvent techEvent = _efContext.TechEvents.Find(techeventId);
                _efContext.Entry(techEvent).Reference(e => e.VenueSetup).Load();

                break;

                #endregion
            case Strategy.Preloading:
                #region Preloading
                Console.Clear();

                // Alle Sprecher laden
                _efContext.Speakers.ToList();

                // Zugriff aus dem Speicher
                Speaker speaker3 = _efContext.Speakers.Find(speakerId);

                break;

                #endregion
            case Strategy.EagerLoading:
                #region EagerLoading

                TechEvent techEvent4 = _efContext.TechEvents
                                       .Include(i => i.Sessions).ThenInclude(i => i.SpeakerSessions)
                                       .Include(i => i.VenueSetup)
                                       .SingleOrDefault(t => t.Id == techeventId);
                Console.WriteLine(techEvent4);
                break;

                #endregion
            default:
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     技術ツリーに発明イベントを追加する
        /// </summary>
        /// <param name="item">追加対象の項目</param>
        /// <param name="position">追加対象の位置</param>
        private void AddEventItem(TechEvent item, TechPosition position)
        {
            Label label = new Label
            {
                Location  = new Point(DeviceCaps.GetScaledWidth(position.X), DeviceCaps.GetScaledHeight(position.Y)),
                BackColor = Color.Transparent,
                Tag       = new TechLabelInfo {
                    Item = item, Position = position
                },
                Size   = new Size(_eventLabelBitmap.Width, _eventLabelBitmap.Height),
                Region = _eventLabelRegion
            };

            // ラベル画像を設定する
            if (ApplyItemStatus && (QueryItemStatus != null))
            {
                QueryItemStatusEventArgs e = new QueryItemStatusEventArgs(item);
                QueryItemStatus(this, e);
                label.Image = e.Done ? _doneEventLabelBitmap : _eventLabelBitmap;
            }
            else
            {
                label.Image = _doneEventLabelBitmap;
            }

            label.Click        += OnItemLabelClick;
            label.MouseClick   += OnItemLabelMouseClick;
            label.MouseDown    += OnItemLabelMouseDown;
            label.MouseUp      += OnItemLabelMouseUp;
            label.MouseMove    += OnItemLabelMouseMove;
            label.GiveFeedback += OnItemLabelGiveFeedback;

            _pictureBox.Controls.Add(label);
        }
Ejemplo n.º 3
0
        public void Run()
        {
            Debugger.Break();

            int techeventId = 11;

            #region Abfragen mit Shadow Property
            Console.Clear();

            TechEvent techEvent1 = _efContext.TechEvents.Find(techeventId);

            // Wert lesen
            string code = (string)_efContext.Entry(techEvent1).Property("Code").CurrentValue;

            // Wert setzen
            _efContext.Entry(techEvent1).Property("Code").CurrentValue = "123456";

            // Änderungen erkannt?
            bool hasChanges = _efContext.ChangeTracker.HasChanges();

            _efContext.SaveChanges();
            #endregion

            #region Abfrage via Shadow Property
            Console.Clear();
            int techEventsCount1 = _efContext.TechEvents
                                   .Where(w => EF.Property <string>(w, "Code") == "123456")
                                   .Count();

            var techEventsCount2 = _efContext.TechEvents
                                   .OrderBy(o => EF.Property <string>(o, "Code"))
                                   .Count();
            #endregion
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     技術ツリーに項目ラベルを追加する
        /// </summary>
        /// <param name="item">追加対象の項目</param>
        /// <param name="position">追加対象の位置</param>
        public void AddItem(ITechItem item, TechPosition position)
        {
            TechItem tech = item as TechItem;

            if (tech != null)
            {
                AddTechItem(tech, position);
                return;
            }

            TechLabel label = item as TechLabel;

            if (label != null)
            {
                AddLabelItem(label, position);
                return;
            }

            TechEvent ev = item as TechEvent;

            if (ev != null)
            {
                AddEventItem(ev, position);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     項目を書き出す
        /// </summary>
        /// <param name="item">項目</param>
        /// <param name="writer">ファイル書き込み用</param>
        private static void WriteTechItem(ITechItem item, StreamWriter writer)
        {
            TechItem techItem = item as TechItem;

            if (techItem != null)
            {
                WriteApplication(techItem, writer);
                return;
            }

            TechLabel labelItem = item as TechLabel;

            if (labelItem != null)
            {
                WriteLabel(labelItem, writer);
                return;
            }

            TechEvent eventItem = item as TechEvent;

            if (eventItem != null)
            {
                WriteEvent(eventItem, writer);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 ///     eventセクションを書き出す
 /// </summary>
 /// <param name="item">技術イベント項目</param>
 /// <param name="writer">ファイル書き込み用</param>
 private static void WriteEvent(TechEvent item, StreamWriter writer)
 {
     writer.WriteLine("  event =");
     writer.WriteLine("  {{ id         = {0}", item.Id);
     foreach (TechPosition position in item.Positions)
     {
         writer.WriteLine("    position   = {{ x = {0} y = {1} }}", position.X, position.Y);
     }
     writer.WriteLine("    technology = {0}", item.TechId);
     writer.WriteLine("  }");
 }
Ejemplo n.º 7
0
        public void Run()
        {
            Debugger.Break();

            // Die die eingebttete Ressource ein JSON-Dokument erzeugen
            // string techEventJson = constructTechEventJson();

            // Entität aus Json konstrieren
            TechEvent techEvent = getTechEventFromJson();

            // Verbessert seit EF Core 2.0
            // _efContext.Attach(techEvent);

            // oder

            // Entität durchlaufen rekursive
            _efContext.ChangeTracker.TrackGraph(techEvent, node =>
            {
                // node: EntityEntryGraphNode
                EntityEntry entry = node.Entry;
                Console.WriteLine(entry.Entity.GetType().ToString());

                PropertyEntry propertyEntry = entry.Property("Id");

                // Entscheiden, was neu, was gelöscht und was modifiziert ist
                if ((int)propertyEntry.CurrentValue == 0)
                {
                    // Anlegen
                    entry.State = EntityState.Added;
                    propertyEntry.IsTemporary = true;
                }
                else if ((int)propertyEntry.CurrentValue < 0)
                {
                    // Löschen
                    entry.State = EntityState.Unchanged;
                    _efContext.Entry(cloneObjectWithId(entry.Entity, -((int)propertyEntry.CurrentValue))).State
                        = EntityState.Deleted;
                }
                else
                {
                    // Änderng
                    entry.State = EntityState.Modified;
                }
            });

            // Speichern
            _efContext.SaveChanges();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Zu Testzwecken ein Object erstellen.
        /// </summary>
        /// <returns></returns>
        private string constructTechEventJson()
        {
            int id = -1;

            // Ereigbnis an sich
            TechEvent techEvent = new TechEvent()
            {
                Id       = id--,
                Name     = "Happy Event",
                Begin    = DateTime.Now,
                End      = DateTime.Now.AddDays(3),
                ImageUrl = "http://www.dotnetconsulting.eu",
                Created  = DateTime.Now,
                Updated  = null
            };

            // Veranstaltungsort
            techEvent.VenueSetup.Id          = id--;
            techEvent.VenueSetup.Description = "Bayerisches Thema";
            techEvent.Created = DateTime.Now;

            // Und die Session
            for (int i = 0; i < 3; i++)
            {
                Session session = new Session()
                {
                    Id       = id--,
                    Title    = $"Session {i}",
                    Abstract = "Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.",
                    Begin    = DateTime.Now,
                    End      = DateTime.Now.AddHours(1),
                    Created  = DateTime.Now,
                    Updated  = null
                };

                techEvent.Sessions.Add(session);
            }

            return(JsonConvert.SerializeObject(techEvent, Formatting.Indented));
        }
Ejemplo n.º 9
0
        public static void SeedDemoData(this SamplesContext1 context)
        {
            // Daten hinzufügen, wenn es noch keine gibt
            if (!context.Speakers.Any())
            {
                for (int i = 1; i <= 10; i++)
                {
                    Speaker speaker = new Speaker()
                    {
                        Name     = $"Speaker {i}",
                        Infos    = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam!",
                        Homepage = "http://www.dotnetconsulting.eu"
                    };

                    context.Speakers.Add(speaker);
                }

                context.SaveChanges();
            }

            if (!context.TechEvents.Any())
            {
                for (int i = 1; i <= 10; i++)
                {
                    TechEvent techEvent = new TechEvent()
                    {
                        Name  = $"Event {i}",
                        Begin = DateTime.Now,
                        End   = DateTime.Now.AddDays(3),

                        ImageUrl = "http://www.dotnetconsulting.eu"
                    };

                    context.TechEvents.Add(techEvent);
                }

                context.SaveChanges();
            }
        }
Ejemplo n.º 10
0
        public void Run()
        {
            Debugger.Break();

            #region Einzelne Entität
            // Instanz erzeugen
            Speaker speaker = new Speaker();

            speaker.Name     = "Thorsten Kansy";
            speaker.Homepage = "http://www.dotnetcore.eu";

            // An den Context anfügen
            _efContext.Speakers.Add(speaker);
            // oder
            // _efContext.Entry(speaker).State = EntityState.Added;
            // oder
            // _efContext.Add(speaker);
            // oder
            // _efContext.Attach(speaker);

            try
            {
                // Änderungen speichern (Keine Validierung!)
                _logger.LogInformation($"speaker.Id={speaker.Id}");
                _efContext.SaveChanges();
                _logger.LogInformation($"speaker.Id={speaker.Id}");
            }
            catch (DbUpdateConcurrencyException ex)
            {
                // Concurrency
                Console.WriteLine(ex);
                Debugger.Break();
            }
            catch (DbUpdateException ex)
            {
                // Datenbank kann nicht aktualisiert werden
                Console.WriteLine(ex);
                Debugger.Break();
            }
            catch (Exception ex)
            {
                // Etwas anderes ist schief gelaufen. Panik!
                Console.WriteLine(ex);
                Debugger.Break();
            }
            #endregion

            #region  Mehere Entitäten
            for (int i = 0; i < 10; i++)
            {
                // Instanz erzeugen und an den Context anfügen
                Speaker speaker2 = new Speaker();

                speaker2.Name     = $"Speaker {i}";
                speaker2.Homepage = "http://www.homepage.eu";

                _efContext.Speakers.Add(speaker2);
            }
            _efContext.SaveChanges();
            #endregion

            #region Parent-Child
            TechEvent te = new TechEvent();
            te.Name    = "Demo TechEvent";
            te.Begin   = DateTime.Today.AddDays(10);
            te.End     = DateTime.Today.AddDays(10);
            te.Price   = 99.9m;
            te.Created = DateTime.Now;

            _efContext.Add(te);

            for (int i = 0; i < 10; i++)
            {
                Session session = new Session();
                session.Title      = $"Session: {i}";
                session.Difficulty = DifficultyLevel.Level3;
                session.Duration   = 60;
                session.SpeakerId  = 1;
                session.Begin      = DateTime.Now;
                session.End        = DateTime.Now.AddMinutes(60);
                session.Abstract   = "Abstract";

                te.Sessions.Add(session);
            }
            _efContext.SaveChanges();

            #endregion
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     eventセクションを構文解析する
        /// </summary>
        /// <param name="lexer">字句解析器</param>
        /// <returns>技術イベントデータ</returns>
        private static TechEvent ParseEvent(TextLexer lexer)
        {
            // =
            Token token = lexer.GetToken();

            if (token.Type != TokenType.Equal)
            {
                Log.InvalidToken(LogCategory, token, lexer);
                return(null);
            }

            // {
            token = lexer.GetToken();
            if (token.Type != TokenType.OpenBrace)
            {
                Log.InvalidToken(LogCategory, token, lexer);
                return(null);
            }

            TechEvent ev = new TechEvent();

            while (true)
            {
                token = lexer.GetToken();

                // ファイルの終端
                if (token == null)
                {
                    break;
                }

                // } (セクション終端)
                if (token.Type == TokenType.CloseBrace)
                {
                    break;
                }

                // 無効なトークン
                if (token.Type != TokenType.Identifier)
                {
                    Log.InvalidToken(LogCategory, token, lexer);
                    lexer.SkipLine();
                    continue;
                }

                string keyword = token.Value as string;
                if (string.IsNullOrEmpty(keyword))
                {
                    continue;
                }
                keyword = keyword.ToLower();

                // id
                if (keyword.Equals("id"))
                {
                    // =
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Equal)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 無効なトークン
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Number)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 技術イベントID
                    ev.Id = (int)(double)token.Value;
                    continue;
                }

                // position
                if (keyword.Equals("position"))
                {
                    TechPosition position = ParsePosition(lexer);
                    if (position == null)
                    {
                        Log.InvalidSection(LogCategory, "position", lexer);
                        continue;
                    }

                    // 座標リスト
                    ev.Positions.Add(position);
                    continue;
                }

                // technology
                if (keyword.Equals("technology"))
                {
                    // =
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Equal)
                    {
                        Log.InvalidSection(LogCategory, "technology", lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 無効なトークン
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Number)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 技術ID
                    ev.TechId = (int)(double)token.Value;
                    continue;
                }

                // 無効なトークン
                Log.InvalidToken(LogCategory, token, lexer);
                lexer.SkipLine();
            }

            return(ev);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     technologyセクションを構文解析する
        /// </summary>
        /// <param name="lexer">字句解析器</param>
        /// <returns>技術グループデータ</returns>
        private static TechGroup ParseTechnology(TextLexer lexer)
        {
            // =
            Token token = lexer.GetToken();

            if (token.Type != TokenType.Equal)
            {
                Log.InvalidToken(LogCategory, token, lexer);
                return(null);
            }

            // {
            token = lexer.GetToken();
            if (token.Type != TokenType.OpenBrace)
            {
                Log.InvalidToken(LogCategory, token, lexer);
                return(null);
            }

            TechGroup group = new TechGroup();

            while (true)
            {
                token = lexer.GetToken();

                // ファイルの終端
                if (token == null)
                {
                    break;
                }

                // } (セクション終端)
                if (token.Type == TokenType.CloseBrace)
                {
                    break;
                }

                // 無効なトークン
                if (token.Type != TokenType.Identifier)
                {
                    Log.InvalidToken(LogCategory, token, lexer);
                    lexer.SkipLine();
                    continue;
                }

                string keyword = token.Value as string;
                if (string.IsNullOrEmpty(keyword))
                {
                    continue;
                }
                keyword = keyword.ToLower();

                // id
                if (keyword.Equals("id"))
                {
                    // =
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Equal)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 無効なトークン
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Number)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 技術グループID
                    group.Id = (int)(double)token.Value;
                    continue;
                }

                // category
                if (keyword.Equals("category"))
                {
                    // =
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Equal)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 無効なトークン
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Identifier)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 無効なカテゴリ文字列
                    string s = token.Value as string;
                    if (string.IsNullOrEmpty(s))
                    {
                        continue;
                    }
                    if (!Techs.CategoryMap.ContainsKey(s))
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 技術カテゴリ
                    group.Category = Techs.CategoryMap[s];
                    continue;
                }

                // name
                if (keyword.Equals("name"))
                {
                    // =
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Equal)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 無効なトークン
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Identifier && token.Type != TokenType.String)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 技術グループ名
                    group.Name = token.Value as string;
                    continue;
                }

                // desc
                if (keyword.Equals("desc"))
                {
                    // =
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Equal)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 無効なトークン
                    token = lexer.GetToken();
                    if (token.Type != TokenType.Identifier && token.Type != TokenType.String)
                    {
                        Log.InvalidToken(LogCategory, token, lexer);
                        lexer.SkipLine();
                        continue;
                    }

                    // 技術グループ説明
                    group.Desc = token.Value as string;
                    continue;
                }

                // label
                if (keyword.Equals("label"))
                {
                    TechLabel label = ParseLabel(lexer);
                    if (label == null)
                    {
                        Log.InvalidSection(LogCategory, "label", lexer);
                        continue;
                    }

                    // ラベル
                    group.Items.Add(label);
                    continue;
                }

                // event
                if (keyword.Equals("event"))
                {
                    TechEvent ev = ParseEvent(lexer);
                    if (ev == null)
                    {
                        Log.InvalidSection(LogCategory, "event", lexer);
                        continue;
                    }

                    // 技術イベント
                    group.Items.Add(ev);
                    continue;
                }

                // application
                if (keyword.Equals("application"))
                {
                    TechItem application = ParseApplication(lexer);
                    if (application == null)
                    {
                        Log.InvalidSection(LogCategory, "application", lexer);
                        continue;
                    }

                    // 技術
                    group.Items.Add(application);
                    continue;
                }

                // 無効なトークン
                Log.InvalidToken(LogCategory, token, lexer);
                lexer.SkipLine();
            }

            return(group);
        }