internal CodeFlow CreateCodeFlow(CodeFlowVersionOne v1CodeFlow)
        {
            CodeFlow codeFlow = null;

            if (v1CodeFlow != null)
            {
                codeFlow = new CodeFlow
                {
                    Message    = CreateMessage(v1CodeFlow.Message),
                    Properties = v1CodeFlow.Properties
                };

                if (v1CodeFlow.Locations != null && v1CodeFlow.Locations.Count > 0)
                {
                    _threadFlowLocationNestingLevel = 0;
                    int executionOrder       = 0;
                    var threadFlowDictionary = new Dictionary <int, ThreadFlow>();

                    foreach (AnnotatedCodeLocationVersionOne v1CodeLocation in v1CodeFlow.Locations)
                    {
                        ThreadFlow threadFlow;
                        int        threadId = v1CodeLocation.ThreadId;

                        if (!threadFlowDictionary.TryGetValue(threadId, out threadFlow))
                        {
                            threadFlow = new ThreadFlow
                            {
                                Id        = threadId.ToString(CultureInfo.InvariantCulture),
                                Locations = new List <ThreadFlowLocation>()
                            };
                            threadFlowDictionary.Add(threadId, threadFlow);
                        }

                        ThreadFlowLocation tfl = CreateThreadFlowLocation(v1CodeLocation);
                        tfl.Step           = threadFlow.Locations.Count + 1;
                        tfl.ExecutionOrder = ++executionOrder;
                        threadFlow.Locations.Add(tfl);
                    }

                    codeFlow.ThreadFlows = threadFlowDictionary.Values.ToList();
                }
            }

            return(codeFlow);
        }
        internal CodeFlow CreateCodeFlow(CodeFlowVersionOne v1CodeFlow)
        {
            CodeFlow codeFlow = null;

            if (v1CodeFlow != null)
            {
                codeFlow = new CodeFlow
                {
                    Message    = CreateMessage(v1CodeFlow.Message),
                    Properties = v1CodeFlow.Properties
                };

                if (v1CodeFlow.Locations != null && v1CodeFlow.Locations.Count > 0)
                {
                    _codeFlowLocationNestingLevel = 0;

                    if (v1CodeFlow.Locations[0].Step == 0)
                    {
                        // If the steps are zero-based, add 1 to comply with the v2 spec
                        _codeFlowLocationStepAdjustment = 1;
                    }

                    codeFlow.ThreadFlows = new List <ThreadFlow>
                    {
                        new ThreadFlow
                        {
                            Locations = v1CodeFlow.Locations.Select(CreateCodeFlowLocation).ToList()
                        }
                    };

                    _codeFlowLocationStepAdjustment = 0;
                }
            }

            return(codeFlow);
        }