Esempio n. 1
0
        public ChapterTransition TransitionTo <T>(ISaga saga) where T : IChapter
        {
            var chapterTransition = new ChapterTransition();

            if (saga.CurrentChapter != null && saga.CurrentChapter.GetType().Equals(typeof(T)))
            {
                saga.CurrentChapter.OnTransitionedTo();
                chapterTransition.TransitionedTo = (T)saga.CurrentChapter;
                return(chapterTransition);
            }

            chapterTransition.ValidationResults = _chapterValidationService.Validate(saga.CurrentChapter);

            if (chapterTransition.Invalid)
            {
                return(chapterTransition);
            }

            ThrowIfTransitionNotAllowed(saga, typeof(T));
            var chapter = GetExistingChapterIfAnyFrom(saga, typeof(T));

            if (chapter == null)
            {
                chapter = _container.Get <T>();
                saga.AddChapter(chapter);
            }

            saga.SetCurrentChapter(chapter);
            chapter.OnTransitionedTo();
            _librarian.Catalogue(saga);

            chapterTransition.TransitionedTo = (T)chapter;
            return(chapterTransition);
        }
Esempio n. 2
0
        void DeserializeChapters(SagaHolder sagaHolder, ISaga saga, Type currentChapterType)
        {
            if (!string.IsNullOrEmpty(sagaHolder.SerializedChapters))
            {
                var chapterHolders = new List <ChapterHolder>();
                _serializer.FromJson(chapterHolders, sagaHolder.SerializedChapters);
                foreach (var chapterHolder in chapterHolders)
                {
                    var chapterType = Type.GetType(chapterHolder.Type);
                    var chapter     = _container.Get(chapterType) as IChapter;

                    if (!string.IsNullOrEmpty(chapterHolder.SerializedChapter))
                    {
                        _serializer.FromJson(chapter, chapterHolder.SerializedChapter);
                    }

                    saga.AddChapter(chapter);

                    if (currentChapterType != null &&
                        chapterType == currentChapterType)
                    {
                        saga.SetCurrentChapter(chapter);
                    }
                }
            }
        }
Esempio n. 3
0
#pragma warning restore 1591 // Xml Comments

        void CreateChaptersFromPropertiesOnSaga(ISaga saga)
        {
            foreach (var chapterProperty in saga.ChapterProperties)
            {
                var chapter = _container.Get(chapterProperty.PropertyType) as IChapter;
                chapter.OnCreated();
                saga.AddChapter(chapter);
            }
        }
Esempio n. 4
0
		void DeserializeChapters(SagaHolder sagaHolder, ISaga saga, Type currentChapterType)
		{
			if (!string.IsNullOrEmpty(sagaHolder.SerializedChapters))
			{
				var chapterHolders = new List<ChapterHolder>();
				_serializer.FromJson(chapterHolders,sagaHolder.SerializedChapters);
				foreach (var chapterHolder in chapterHolders)
				{
					var chapterType = Type.GetType(chapterHolder.Type);
					var chapter = _container.Get(chapterType) as IChapter;

					if (!string.IsNullOrEmpty(chapterHolder.SerializedChapter))
						_serializer.FromJson(chapter, chapterHolder.SerializedChapter);

					saga.AddChapter(chapter);

					if (currentChapterType != null &&
						chapterType == currentChapterType)
						saga.SetCurrentChapter(chapter);
				}
			}
		}