Exemple #1
0
        protected override void Context()
        {
            base.Context();
            _templateStartValues = new ParameterStartValuesBuildingBlock();

            _containerPath = new ObjectPath("the", "container", "path");

            _parameterStartValueBuildingBlock.Add(
                new ParameterStartValue {
                StartValue = 0.1, ContainerPath = _containerPath.Clone <IObjectPath>(), Name = "ConstantStartValue"
            });

            _parameterStartValue = new ParameterStartValue {
                ContainerPath = _containerPath.Clone <IObjectPath>(), Name = "FormulaStartValue", StartValue = 4
            };
            _clonedStartValue = new ParameterStartValue {
                ContainerPath = _containerPath.Clone <IObjectPath>(), Name = "FormulaStartValue", StartValue = 4
            };

            _templateStartValues.Add(_parameterStartValue);
            _templateStartValues.Add(new ParameterStartValue {
                StartValue = 0.4, ContainerPath = _containerPath.Clone <IObjectPath>(), Name = "ConstantStartValue"
            });

            A.CallTo(() => _cloneManagerForBuildingBlock.Clone(_parameterStartValue, A <IFormulaCache> .Ignored)).Returns(_clonedStartValue);
        }
 protected override void Context()
 {
     base.Context();
     _objectPath             = new ObjectPath("root2", "B");
     _pathWithModelNameFirst = _objectPath.Clone <IObjectPath>();
     _pathWithModelNameFirst.AddAtFront(_modelName);
 }
        public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler callback)
        {
            if (this.Activity == null)
            {
                throw new Exception("You must define one of Text or Activity properties");
            }

            var activity = ObjectPath.Clone(this.Activity);

            activity.ApplyConversationReference(adapter.Conversation, isIncoming: true);

            if (!string.IsNullOrEmpty(this.User))
            {
                activity.From      = ObjectPath.Clone(activity.From);
                activity.From.Id   = this.User;
                activity.From.Name = this.User;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            await adapter.ProcessActivityAsync(this.Activity, callback, default(CancellationToken)).ConfigureAwait(false);

            sw.Stop();
            Trace.TraceInformation($"[Turn Ended => {sw.ElapsedMilliseconds} ms processing UserActivity: {this.Activity.Text} ]");
        }
Exemple #4
0
        // Helper method to create the activity to be sent to the DialogSkillBot using selected type and values.
        private Activity CreateDialogSkillBotActivity(string selectedOption, ITurnContext turnContext)
        {
            // Note: in a real bot, the dialogArgs will be created dynamically based on the conversation
            // and what each action requires; here we hardcode the values to make things simpler.

            Activity activity = null;

            // Just forward the message activity to the skill with whatever the user said.
            if (selectedOption.Equals(SkillActionMessage, StringComparison.CurrentCultureIgnoreCase))
            {
                // Note message activities also support input parameters but we are not using them in this example.
                // Return a deep clone of the activity so we don't risk altering the original one
                activity = ObjectPath.Clone(turnContext.Activity);
            }

            // Send an event activity to the skill with "BookFlight" in the name.
            if (selectedOption.Equals(SkillActionBookFlight, StringComparison.CurrentCultureIgnoreCase))
            {
                activity      = (Activity)Activity.CreateEventActivity();
                activity.Name = SkillActionBookFlight;
            }

            // Send an event activity to the skill with "BookFlight" in the name and some testing values.
            if (selectedOption.Equals(SkillActionBookFlightWithInputParameters, StringComparison.CurrentCultureIgnoreCase))
            {
                activity       = (Activity)Activity.CreateEventActivity();
                activity.Name  = SkillActionBookFlight;
                activity.Value = JObject.Parse("{ \"origin\": \"New York\", \"destination\": \"Seattle\"}");
            }

            // Send an event activity to the skill with "GetWeather" in the name and some testing values.
            if (selectedOption.Equals(SkillActionGetWeather, StringComparison.CurrentCultureIgnoreCase))
            {
                activity       = (Activity)Activity.CreateEventActivity();
                activity.Name  = SkillActionGetWeather;
                activity.Value = JObject.Parse("{ \"latitude\": 47.614891, \"longitude\": -122.195801}");
            }

            if (activity == null)
            {
                throw new Exception($"Unable to create a skill activity for \"{selectedOption}\".");
            }

            // We are manually creating the activity to send to the skill; ensure we add the ChannelData and Properties
            // from the original activity so the skill gets them.
            // Note: this is not necessary if we are just forwarding the current activity from context.
            activity.ChannelData = turnContext.Activity.ChannelData;
            activity.Properties  = turnContext.Activity.Properties;

            return(activity);
        }
Exemple #5
0
        public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler callback)
        {
            var typing = adapter.MakeActivity();

            typing.Type = ActivityTypes.Typing;

            if (!string.IsNullOrEmpty(this.User))
            {
                typing.From      = ObjectPath.Clone(typing.From);
                typing.From.Id   = this.User;
                typing.From.Name = this.User;
            }

            await adapter.ProcessActivityAsync((Activity)typing, callback, default(CancellationToken)).ConfigureAwait(false);
        }
Exemple #6
0
        public void Visit(IModelCoreSimulation simulation)
        {
            simulation.BuildConfiguration.AllBuildingBlocks.Each(this.Visit);

            var root     = simulation.Model.Root;
            var organism = root.GetSingleChildByName <IContainer>(Constants.ORGANISM);

            if (organism == null)
            {
                return;
            }
            //Add new parameter gall bladder emptying active
            var parameter = addGallBladderEmptyingActiveParameter(organism);

            if (parameter == null)
            {
                return;
            }

            // Genearate EHC_Event assingment path in simulaton
            var gallbladderEmptyingRatePathSimulation = GallbladderEmptyingRatePath.Clone <IObjectPath>();

            gallbladderEmptyingRatePathSimulation.AddAtFront(root.Name);

            // change  ehc events
            var startEvents = root.GetAllChildren <IEvent>(eb => eb.Name.Equals(EHCStartEvent));

            startEvents.Each(se => changeAssignments(se, false, 1, gallbladderEmptyingRatePathSimulation));
            startEvents.Each(se => (se.Assignments).Each(a => ((EventAssignment)a).ChangedEntity = null));

            var stopEvents = root.GetAllChildren <IEvent>(eb => eb.Name.Equals(EHCStopEvent));

            stopEvents.Each(se => changeAssignments(se, true, 0, gallbladderEmptyingRatePathSimulation));
            stopEvents.Each(se => se.Assignments.Each(a => ((EventAssignment)a).ChangedEntity = null));

            // Update gall bladder emptying kinetics
            var tranports = simulation.Model.Neighborhoods.GetAllChildren <ITransport>(isOldGallbladderEmptyingTransport);

            tranports.Each(t => updateGallBladderEmptyingInSimulation(t, root.Name));

            updateTotalDrugMassHandling(simulation, root);

            updateAllParameters(root.GetAllChildren <IParameter>());
            _formulaTask.ExpandDynamicFormulaIn(simulation.Model);
            _converted = true;
        }
Exemple #7
0
        public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler callback)
        {
            if (this.Text == null)
            {
                throw new Exception("You must define the Text property");
            }

            var activity = adapter.MakeActivity(this.Text);

            if (!string.IsNullOrEmpty(this.User))
            {
                activity.From      = ObjectPath.Clone(activity.From);
                activity.From.Id   = this.User;
                activity.From.Name = this.User;
            }

            await adapter.ProcessActivityAsync(activity, callback, default(CancellationToken)).ConfigureAwait(false);
        }
Exemple #8
0
        /// <inheritdoc/>
        public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler callback, Inspector inspector = null)
        {
            var typing = adapter.MakeActivity();

            typing.Type = ActivityTypes.Typing;

            if (!string.IsNullOrEmpty(User))
            {
                typing.From      = ObjectPath.Clone(typing.From);
                typing.From.Id   = User;
                typing.From.Name = User;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            await adapter.ProcessActivityAsync((Activity)typing, callback, default).ConfigureAwait(false);
        /// <summary>
        /// Called when the dialog is started and pushed onto the dialog stack.
        /// </summary>
        /// <param name="dc">The <see cref="DialogContext"/> for the current turn of conversation.</param>
        /// <param name="options">Optional, initial information to pass to the dialog.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects
        /// or threads to receive notice of cancellation.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public override async Task <DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
        {
            var dialogArgs = ValidateBeginDialogArgs(options);

            // Create deep clone of the original activity to avoid altering it before forwarding it.
            var skillActivity = ObjectPath.Clone(dialogArgs.Activity);

            if (Disabled != null && Disabled.GetValue(dc.State))
            {
                return(await dc.EndDialogAsync(cancellationToken : cancellationToken).ConfigureAwait(false));
            }

            // Update the dialog options with the runtime settings.
            DialogOptions.BotId                 = BotId.GetValue(dc.State);
            DialogOptions.SkillHostEndpoint     = new Uri(SkillHostEndpoint.GetValue(dc.State));
            DialogOptions.ConversationIdFactory = dc.Context.TurnState.Get <SkillConversationIdFactoryBase>() ?? throw new NullReferenceException("Unable to locate SkillConversationIdFactoryBase in HostContext");
            DialogOptions.SkillClient           = dc.Context.TurnState.Get <BotFrameworkClient>() ?? throw new NullReferenceException("Unable to locate BotFrameworkClient in HostContext");
            DialogOptions.ConversationState     = dc.Context.TurnState.Get <ConversationState>() ?? throw new NullReferenceException($"Unable to get an instance of {nameof(ConversationState)} from TurnState.");
            DialogOptions.ConnectionName        = ConnectionName.GetValue(dc.State);

            // Set the skill to call
            DialogOptions.Skill.Id            = DialogOptions.Skill.AppId = SkillAppId.GetValue(dc.State);
            DialogOptions.Skill.SkillEndpoint = new Uri(SkillEndpoint.GetValue(dc.State));

            // Store the initialized DialogOptions in state so we can restore these values when the dialog is resumed.
            dc.ActiveDialog.State[_dialogOptionsStateKey] = DialogOptions;

            // Get the activity to send to the skill.
            Activity activity = null;

            if (Activity != null && ActivityProcessed.GetValue(dc.State))
            {
                // The parent consumed the activity in context, use the Activity property to start the skill.
                activity = await Activity.BindAsync(dc, cancellationToken : cancellationToken).ConfigureAwait(false);
            }
            else if (skillActivity != null)
            {
                activity = skillActivity;
            }

            // Call the base to invoke the skill
            // (If the activity has not been processed, send the turn context activity to the skill (pass through)).
            return(await base.BeginDialogAsync(dc, new BeginSkillDialogOptions { Activity = activity ?? dc.Context.Activity }, cancellationToken).ConfigureAwait(false));
        }
        // Helper method to create the activity to be sent to the DialogSkillBot using selected type and values.
        private Activity CreateBeginActivity(ITurnContext turnContext, string skillId, string selectedOption)
        {
            if (selectedOption.Equals(JustForwardTheActivity, StringComparison.CurrentCultureIgnoreCase))
            {
                // Note message activities also support input parameters but we are not using them in this example.
                // Return a deep clone of the activity so we don't risk altering the original one
                return(ObjectPath.Clone(turnContext.Activity));
            }

            // Get the begin activity from the skill instance.
            var activity = _skillsConfig.Skills[skillId].CreateBeginActivity(selectedOption);

            // We are manually creating the activity to send to the skill; ensure we add the ChannelData and Properties
            // from the original activity so the skill gets them.
            // Note: this is not necessary if we are just forwarding the current activity from context.
            activity.ChannelData = turnContext.Activity.ChannelData;
            activity.Properties  = turnContext.Activity.Properties;

            return(activity);
        }
        public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler callback)
        {
            if (this.Activity == null)
            {
                throw new Exception("You must define one of Text or Activity properties");
            }

            var activity = ObjectPath.Clone(this.Activity);

            activity.ApplyConversationReference(adapter.Conversation, isIncoming: true);

            if (!string.IsNullOrEmpty(this.User))
            {
                activity.From      = ObjectPath.Clone(activity.From);
                activity.From.Id   = this.User;
                activity.From.Name = this.User;
            }

            await adapter.ProcessActivityAsync(this.Activity, callback, default(CancellationToken)).ConfigureAwait(false);
        }
Exemple #12
0
        /// <inheritdoc/>
        public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler callback)
        {
            var typing = adapter.MakeActivity();

            typing.Type = ActivityTypes.Typing;

            if (!string.IsNullOrEmpty(this.User))
            {
                typing.From      = ObjectPath.Clone(typing.From);
                typing.From.Id   = this.User;
                typing.From.Name = this.User;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            await adapter.ProcessActivityAsync((Activity)typing, callback, default(CancellationToken)).ConfigureAwait(false);

            sw.Stop();

            Trace.TraceInformation($"[Turn Ended => {sw.ElapsedMilliseconds} ms processing UserConversationUpdate[]");
        }
        /// <inheritdoc/>
        public async override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler callback, Inspector inspector = null)
        {
            if (Text == null)
            {
                throw new Exception("You must define the Text property");
            }

            var activity = adapter.MakeActivity(Text);

            if (!string.IsNullOrEmpty(User))
            {
                activity.From      = ObjectPath.Clone(activity.From);
                activity.From.Id   = User;
                activity.From.Name = User;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            await adapter.ProcessActivityAsync(activity, callback, default).ConfigureAwait(false);

            sw.Stop();
            Trace.TraceInformation($"[Turn Ended => {sw.ElapsedMilliseconds} ms processing UserSays: {Text} ]");
        }
        public async Task TestSkillAdapterApiCalls()
        {
            var activityId   = Guid.NewGuid().ToString("N");
            var botId        = Guid.NewGuid().ToString("N");
            var botAdapter   = CreateAdapter("TestSkillAdapterApiCalls");
            var skillAccount = ObjectPath.Clone(botAdapter.Conversation.Bot);
            var skillId      = "testSkill";

            skillAccount.Properties["SkillId"] = skillId;

            var middleware = new AssertInvokeMiddleware(botAdapter, activityId);

            botAdapter.Use(middleware);
            var bot          = new CallbackBot();
            var skillAdapter = new BotFrameworkSkillHostAdapter(botAdapter, new MicrosoftAppCredentials(string.Empty, string.Empty), new AuthenticationConfiguration(), configuration: new ConfigurationBuilder().Build());

            var sc = new SkillConversation()
            {
                ServiceUrl     = botAdapter.Conversation.ServiceUrl,
                ConversationId = botAdapter.Conversation.Conversation.Id
            };
            var skillConversationId = sc.GetSkillConversationId();
            var claimsIdentity      = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AudienceClaim, botId));
            claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AppIdClaim, botId));
            claimsIdentity.AddClaim(new Claim(AuthenticationConstants.ServiceUrlClaim, botAdapter.Conversation.ServiceUrl));

            object result = await skillAdapter.CreateConversationAsync(bot, claimsIdentity, skillConversationId, new ConversationParameters());

            Assert.IsType <ConversationResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ConversationResourceResponse)result).Id);

            await skillAdapter.DeleteActivityAsync(bot, claimsIdentity, skillConversationId, activityId);

            await skillAdapter.DeleteConversationMemberAsync(bot, claimsIdentity, skillConversationId, "user2");

            result = await skillAdapter.GetActivityMembersAsync(bot, claimsIdentity, skillConversationId, activityId);

            Assert.IsAssignableFrom <IList <ChannelAccount> >(result);

            result = await skillAdapter.GetConversationMembersAsync(bot, claimsIdentity, skillConversationId);

            Assert.IsAssignableFrom <IList <ChannelAccount> >(result);

            result = await skillAdapter.GetConversationPagedMembersAsync(bot, claimsIdentity, skillConversationId);

            Assert.IsType <PagedMembersResult>(result);

            result = await skillAdapter.GetConversationPagedMembersAsync(bot, claimsIdentity, skillConversationId, 10);

            Assert.IsType <PagedMembersResult>(result);

            var pagedMembersResult = (PagedMembersResult)result;

            result = await skillAdapter.GetConversationPagedMembersAsync(bot, claimsIdentity, skillConversationId, continuationToken : pagedMembersResult.ContinuationToken);

            Assert.IsType <PagedMembersResult>(result);

            result = await skillAdapter.GetConversationsAsync(bot, claimsIdentity, skillConversationId);

            Assert.IsType <ConversationsResult>(result);

            var conversationsResult = (ConversationsResult)result;

            result = await skillAdapter.GetConversationsAsync(bot, claimsIdentity, skillConversationId, continuationToken : conversationsResult.ContinuationToken);

            Assert.IsType <ConversationsResult>(result);

            var msgActivity = Activity.CreateMessageActivity();

            msgActivity.Conversation = botAdapter.Conversation.Conversation;
            msgActivity.From         = skillAccount;
            msgActivity.Recipient    = botAdapter.Conversation.User;
            msgActivity.Text         = "yo";

            result = await skillAdapter.SendToConversationAsync(bot, claimsIdentity, skillConversationId, (Activity)msgActivity);

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);
            msgActivity.Id = ((ResourceResponse)result).Id;

            result = await skillAdapter.ReplyToActivityAsync(bot, claimsIdentity, skillConversationId, activityId, (Activity)msgActivity);

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);

            result = await skillAdapter.SendConversationHistoryAsync(bot, claimsIdentity, skillConversationId, new Transcript());

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);

            result = await skillAdapter.UpdateActivityAsync(bot, claimsIdentity, skillConversationId, activityId, (Activity)msgActivity);

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);

            result = await skillAdapter.UploadAttachmentAsync(bot, claimsIdentity, skillConversationId, new AttachmentData());

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);
        }
        public async Task TestSkillAdapterApiCalls()
        {
            var activityId   = Guid.NewGuid().ToString("N");
            var botId        = Guid.NewGuid().ToString("N");
            var botAdapter   = CreateAdapter("TestSkillAdapterApiCalls");
            var skillAccount = ObjectPath.Clone(botAdapter.Conversation.Bot);
            var skillId      = "testSkill";

            skillAccount.Properties["SkillId"] = skillId;

            var middleware = new AssertInvokeMiddleware(botAdapter, activityId);

            botAdapter.Use(middleware);
            var bot         = new CallbackBot();
            var skillClient = new SkillHandlerInstanceForTests(botAdapter, bot, new Mock <ICredentialProvider>().Object, new AuthenticationConfiguration());

            var sc = new TestConversationIdFactory();

            var skillConversationId = sc.CreateSkillConversationId(botAdapter.Conversation.Conversation.Id, botAdapter.Conversation.ServiceUrl);
            var claimsIdentity      = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AudienceClaim, botId));
            claimsIdentity.AddClaim(new Claim(AuthenticationConstants.AppIdClaim, botId));
            claimsIdentity.AddClaim(new Claim(AuthenticationConstants.ServiceUrlClaim, botAdapter.Conversation.ServiceUrl));

            object result = await skillClient.TestOnCreateConversationAsync(claimsIdentity, new ConversationParameters());

            Assert.IsType <ConversationResourceResponse>(result);

            //Assert.Equal(middleware.NewResourceId, ((ConversationResourceResponse)result).Id);

            await skillClient.TestOnDeleteActivityAsync(claimsIdentity, skillConversationId, activityId);

            await skillClient.TestOnDeleteConversationMemberAsync(claimsIdentity, skillConversationId, "user2");

            result = await skillClient.TestOnGetActivityMembersAsync(claimsIdentity, skillConversationId, activityId);

            Assert.IsAssignableFrom <IList <ChannelAccount> >(result);

            result = await skillClient.TestOnGetConversationMembersAsync(claimsIdentity, skillConversationId);

            Assert.IsAssignableFrom <IList <ChannelAccount> >(result);

            result = await skillClient.TestOnGetConversationPagedMembersAsync(claimsIdentity, skillConversationId);

            Assert.IsType <PagedMembersResult>(result);

            result = await skillClient.TestOnGetConversationPagedMembersAsync(claimsIdentity, skillConversationId, 10);

            Assert.IsType <PagedMembersResult>(result);

            var pagedMembersResult = (PagedMembersResult)result;

            result = await skillClient.TestOnGetConversationPagedMembersAsync(claimsIdentity, skillConversationId, continuationToken : pagedMembersResult.ContinuationToken);

            Assert.IsType <PagedMembersResult>(result);

            result = await skillClient.TestOnGetConversationsAsync(claimsIdentity, skillConversationId);

            Assert.IsType <ConversationsResult>(result);

            var conversationsResult = (ConversationsResult)result;

            result = await skillClient.TestOnGetConversationsAsync(claimsIdentity, skillConversationId, continuationToken : conversationsResult.ContinuationToken);

            Assert.IsType <ConversationsResult>(result);

            var msgActivity = Activity.CreateMessageActivity();

            msgActivity.Conversation = botAdapter.Conversation.Conversation;
            msgActivity.Text         = "yo";

            result = await skillClient.TestOnSendToConversationAsync(claimsIdentity, skillConversationId, (Activity)msgActivity);

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);
            msgActivity.Id = ((ResourceResponse)result).Id;

            result = await skillClient.TestOnReplyToActivityAsync(claimsIdentity, skillConversationId, activityId, (Activity)msgActivity);

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);
            msgActivity.Id = ((ResourceResponse)result).Id;

            result = await skillClient.TestOnSendConversationHistoryAsync(claimsIdentity, skillConversationId, new Transcript());

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);

            result = await skillClient.TestOnUpdateActivityAsync(claimsIdentity, skillConversationId, activityId, (Activity)msgActivity);

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);

            result = await skillClient.TestOnUploadAttachmentAsync(claimsIdentity, skillConversationId, new AttachmentData());

            Assert.IsType <ResourceResponse>(result);
            Assert.Equal(middleware.NewResourceId, ((ResourceResponse)result).Id);
        }
        /// <inheritdoc/>
        public bool OnBeforeLoadToken <T>(JToken token, out T result)
            where T : class
        {
            // The deep hash code provides a pseudo-unique id for a given token
            var hashCode = Hash <T>(token);

            // Pass 1: We track the already visited objects' hash in the 'visited' collection
            // If we've already visited this hash code and we are still in pass 1, no need to revisit.
            if (visitedPassOne.Contains(hashCode) && CycleDetectionPass == CycleDetectionPasses.PassOne)
            {
                // If we already have a hydrated object for this hash code,
                // there is no cycle, just repetition of the object in different parts of the object tree.
                // We can get it from the cache but we don't necessarily want it to be the same reference.
                // In pass 2 when we connect cycles, we won't actually clone because at that point we do want
                // to conserve references.
                if (cache.ContainsKey(hashCode))
                {
                    result = ObjectPath.Clone <T>(cache[hashCode] as T);
                }

                // If we don't have a cached value for this hash code, we send null as the value.
                // Pass 2 will exist with the purpose of filling in these nulled values with the
                // references discovered and cached during pass 1
                else
                {
                    result = null;
                }

                return(true);
            }

            if (CycleDetectionPass == CycleDetectionPasses.PassTwo)
            {
                // If we already visited this item in pass 2 means we found a loop.
                // Since in pass 1 we should have filled the cache with the missing objects,
                // now we just bring the items from pass 1 to stitch the full object together
                if (visitedPassTwo.Contains(hashCode))
                {
                    // We found a loop and we have the final value in the cache. Return that value.
                    if (cache.ContainsKey(hashCode))
                    {
                        result = cache[hashCode] as T;
                    }

                    // Even if the value was no in the cache, we set as null since we don't want
                    // to have an infinite loop in pass 2 either.
                    else
                    {
                        result = null;
                    }

                    return(true);
                }

                visitedPassTwo.Add(hashCode);
            }

            visitedPassOne.Add(hashCode);
            result = null;
            return(false);
        }