Exemple #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);
        }
Exemple #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);
                    }
                }
            }
        }
		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);
				}
			}
		}