#pragma warning disable 1591 // Xml Commentsz
        public ISaga ToSaga(SagaHolder sagaHolder)
		{
			if (string.IsNullOrEmpty(sagaHolder.Type))
				return null;

			var type = Type.GetType(sagaHolder.Type);

			Type currentChapterType = null;
			if (!string.IsNullOrEmpty(sagaHolder.CurrentChapterType))
				currentChapterType = Type.GetType(sagaHolder.CurrentChapterType);

			ISaga saga;
			if (string.IsNullOrEmpty(sagaHolder.SerializedSaga))
				saga = _container.Get(type) as ISaga;
			else
				saga = (ISaga) _serializer.FromJson(type,sagaHolder.SerializedSaga, SerializationOptions);

			saga.Id = sagaHolder.Id;
			saga.Partition = sagaHolder.Partition;
			saga.Key = sagaHolder.Key;
		    saga.CurrentState = sagaHolder.State;

			if (!string.IsNullOrEmpty(sagaHolder.UncommittedEvents))
			{
				var uncommittedEvents = new List<EventHolder>();
				_serializer.FromJson(uncommittedEvents,sagaHolder.UncommittedEvents);
				var actualEvents = _eventConverter.ToEvents(uncommittedEvents);
				saga.SetUncommittedEvents(actualEvents);
			}

			DeserializeChapters(sagaHolder, saga, currentChapterType);
			

			return saga;
		}
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);
                    }
                }
            }
        }
Exemple #3
0
        public SagaHolder ToSagaHolder(ISaga saga)
        {
            var sagaHolder = new SagaHolder();

            Populate(sagaHolder, saga);
            return(sagaHolder);
        }
Exemple #4
0
#pragma warning disable 1591 // Xml Commentsz
        public ISaga ToSaga(SagaHolder sagaHolder)
        {
            if (string.IsNullOrEmpty(sagaHolder.Type))
            {
                return(null);
            }

            var type = Type.GetType(sagaHolder.Type);

            Type currentChapterType = null;

            if (!string.IsNullOrEmpty(sagaHolder.CurrentChapterType))
            {
                currentChapterType = Type.GetType(sagaHolder.CurrentChapterType);
            }

            ISaga saga;

            if (string.IsNullOrEmpty(sagaHolder.SerializedSaga))
            {
                saga = _container.Get(type) as ISaga;
            }
            else
            {
                saga = (ISaga)_serializer.FromJson(type, sagaHolder.SerializedSaga, SerializationOptions);
            }

            saga.Id           = sagaHolder.Id;
            saga.Partition    = sagaHolder.Partition;
            saga.Key          = sagaHolder.Key;
            saga.CurrentState = sagaHolder.State;

            if (!string.IsNullOrEmpty(sagaHolder.UncommittedEvents))
            {
                var uncommittedEvents = new List <IEvent>();
                _serializer.FromJson(uncommittedEvents, sagaHolder.UncommittedEvents);
                saga.SetUncommittedEvents(uncommittedEvents);
            }

            DeserializeChapters(sagaHolder, saga, currentChapterType);


            return(saga);
        }
Exemple #5
0
        public void Populate(SagaHolder sagaHolder, ISaga saga)
        {
            sagaHolder.Id                = saga.Id;
            sagaHolder.Name              = saga.GetType().Name;
            sagaHolder.Type              = saga.GetType().AssemblyQualifiedName;
            sagaHolder.Key               = saga.Key;
            sagaHolder.Partition         = saga.Partition;
            sagaHolder.State             = saga.CurrentState.ToString();
            sagaHolder.SerializedSaga    = _serializer.ToJson(saga, SerializationOptions);
            sagaHolder.UncommittedEvents = _serializer.ToJson(saga.GetUncommittedEvents());

            var chapterHolders = (from c in saga.Chapters
                                  select GetChapterHolderFromChapter(c)).ToArray();

            sagaHolder.SerializedChapters = _serializer.ToJson(chapterHolders);

            if (saga.CurrentChapter != null)
            {
                sagaHolder.CurrentChapterType = saga.CurrentChapter.GetType().AssemblyQualifiedName;
            }
        }
		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);
				}
			}
		}
		public void Populate(SagaHolder sagaHolder, ISaga saga)
		{
			sagaHolder.Id = saga.Id;
			sagaHolder.Name = saga.GetType().Name;
			sagaHolder.Type = saga.GetType().AssemblyQualifiedName;
			sagaHolder.Key = saga.Key;
			sagaHolder.Partition = saga.Partition;
		    sagaHolder.State = saga.CurrentState.ToString();
			sagaHolder.SerializedSaga = _serializer.ToJson(saga, SerializationOptions);
			sagaHolder.UncommittedEvents = _serializer.ToJson(_eventConverter.ToEventHolders(saga.GetUncommittedEvents()));

			var chapterHolders = (from c in saga.Chapters
			                      select GetChapterHolderFromChapter(c)).ToArray();

			sagaHolder.SerializedChapters = _serializer.ToJson(chapterHolders);

			if (saga.CurrentChapter != null)
				sagaHolder.CurrentChapterType = saga.CurrentChapter.GetType().AssemblyQualifiedName;
		}
		public SagaHolder ToSagaHolder(ISaga saga)
		{
			var sagaHolder = new SagaHolder();
			Populate(sagaHolder, saga);
			return sagaHolder;
		}