Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiagramViewModel"/> class.
        /// </summary>
        /// <param name="diagram">The <see cref="Diagram"/> for which to create this viewmodel.</param>
        /// <param name="getIdForModelFunc">A function returning the Id for the provided model.</param>
        public DiagramViewModel(RedYarn.Diagram diagram,
                                Func <object, Guid> getIdForModelFunc = null,
                                Func <Relationship, Guid, Guid, Guid> getIdForRelationshipFunc               = null,
                                Dictionary <RedYarn.Character, CharacterViewModel> characterDictionary       = null,
                                Dictionary <RedYarn.Storyline, StorylineViewModel> storylineDictionary       = null,
                                Dictionary <RedYarn.PlotElement, PlotElementViewModel> plotElementDictionary = null)
        {
            if (getIdForModelFunc != null)
            {
                Id = getIdForModelFunc(diagram);
            }
            Name = diagram.Name;

            characterDictionary   = characterDictionary ?? diagram.Characters.ToDictionary(c => c, c => new CharacterViewModel(c, getIdForModelFunc));
            storylineDictionary   = storylineDictionary ?? diagram.Storylines.ToDictionary(s => s, s => new StorylineViewModel(s, getIdForModelFunc));
            plotElementDictionary = plotElementDictionary ?? diagram.PlotElements.ToDictionary(p => p, p => new PlotElementViewModel(p, getIdForModelFunc));

            AddStorylines(storylineDictionary);
            AddCharacters(characterDictionary);
            AddPlotElements(plotElementDictionary);

            GenerateStorylineCharacterConnections(storylineDictionary, characterDictionary);
            GenerateRelationships(characterDictionary, getIdForRelationshipFunc);
            GenerateStorylinePlotElementConnections(plotElementDictionary, storylineDictionary);
            GeneratePlotElementConnections(plotElementDictionary, characterDictionary);
        }
Пример #2
0
 /// <summary>
 /// Update the provided model with the values in this viewmodel.
 /// </summary>
 /// <param name="model">The model to update.</param>
 public void UpdateModel(RedYarn.Diagram model)
 {
     // Only set the properties we can set, so don't set shadow properties like the Id.
     model.Name = Name;
 }