/// <summary>
        /// When overridden runs the activity's simulation logic
        /// </summary>
        /// <param name="context">The context to be used.</param>
        // ReSharper disable VirtualMemberNeverOverriden.Global
        protected virtual void OnExecuteSimulation(NativeActivityContext context)
        // ReSharper restore VirtualMemberNeverOverriden.Global
        {
            var rootInfo = context.GetExtension <WorkflowInstanceInfo>();

            var key = new SimulationKey
            {
                WorkflowID = rootInfo.ProxyName,
                ActivityID = UniqueID,
                ScenarioID = ScenarioID
            };
            var result = SimulationRepository.Instance.Get(key);

            if (result != null && result.Value != null)
            {
                var dataObject = context.GetExtension <IDSFDataObject>();

                if (dataObject != null)
                {
                    var allErrors = new ErrorResultTO();
                    allErrors.MergeErrors(errorsTo);

                    allErrors.MergeErrors(errorsTo);

                    allErrors.MergeErrors(errorsTo);

                    if (allErrors.HasErrors())
                    {
                        DisplayAndWriteError(rootInfo.ProxyName, allErrors);
                        dataObject.Environment.AddError(allErrors.MakeDataListReady());
                    }
                }
            }
        }
        /// <summary>
        /// When overridden runs the activity's simulation logic
        /// </summary>
        /// <param name="context">The context to be used.</param>
        protected virtual void OnExecuteSimulation(NativeActivityContext context)
        {
            var rootInfo = context.GetExtension <WorkflowInstanceInfo>();

            var key = new SimulationKey
            {
                WorkflowID = rootInfo.ProxyName,
                ActivityID = UniqueID,
                ScenarioID = ScenarioID
            };
            var result = SimulationRepository.Instance.Get(key);

            if (result != null && result.Value != null)
            {
                var dataListExecutionID    = context.GetValue(DataListExecutionID);
                IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

                var dataObject = context.GetExtension <IDSFDataObject>();

                if (compiler != null && dataObject != null)
                {
                    var allErrors = new ErrorResultTO();
                    var dataList  = compiler.FetchBinaryDataList(dataObject.DataListID, out errorsTo);
                    allErrors.MergeErrors(errorsTo);

                    compiler.Merge(dataList, result.Value, enDataListMergeTypes.Union, enTranslationDepth.Data, false, out errorsTo);
                    allErrors.MergeErrors(errorsTo);

                    compiler.Shape(dataListExecutionID, enDev2ArgumentType.Output, OutputMapping, out errorsTo);
                    allErrors.MergeErrors(errorsTo);

                    if (allErrors.HasErrors())
                    {
                        DisplayAndWriteError(rootInfo.ProxyName, allErrors);
                        dataObject.Environment.AddError(allErrors.MakeDataListReady());
                    }
                }
            }
        }
        public void ExecuteSimulation_NoValidSimulationKeyInRepository_Expected_NoDataInjectedIntoDataList()
        {
            var dataObject = CreateDataObject(false, true);
            var compiler   = DataListFactory.CreateDataListCompiler();

            ErrorResultTO errors;

            dataObject.DataListID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), string.Empty, _simulationShape.ToStringBuilder(), out errors);

            var simulationDataID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), _simulationData, _simulationShape.ToStringBuilder(), out errors);

            compiler.FetchBinaryDataList(simulationDataID, out errors);

            #region Setup simulation repository

            var random        = new Random();
            var simulationKey = new SimulationKey
            {
                WorkflowID = "TestActivity", // class name of activity used below
                ActivityID = string.Format("AID-{0}", random.Next()),
                ScenarioID = string.Format("SID-{0}", random.Next())
            };
            //var simulationResult = new SimulationResult {
            //    Key = simulationKey,
            //    Value = simulationDataList
            //};
            //SimulationRepository.Instance.Save(simulationResult);

            #endregion

            var activity = new TestActivity(DebugDispatcher.Instance)
            {
                SimulationMode = SimulationMode.Always,
                UniqueID       = simulationKey.ActivityID,
                ScenarioID     = simulationKey.ScenarioID
            };

            Run(activity, dataObject,
                () =>
            {
                //SimulationRepository.Instance.Delete(simulationResult);

                ErrorResultTO resultErrors;
                var resultDataList = compiler.FetchBinaryDataList(dataObject.DataListID, out resultErrors);
                if (errors.HasErrors())
                {
                    Assert.Fail("Errors fetching Binary DataList result");
                }

                // See SimulationData.xml in XML folder
                try
                {
                    ValidateRecordSet(resultDataList, "Golfer", new[]
                    {
                        new KeyValuePair <string, string[]>("FirstName", new[]
                        {
                            "Tiger", "Ernie"
                        }),
                        new KeyValuePair <string, string[]>("LastName", new[]
                        {
                            "Woods", "Els"
                        })
                    });
                }
                catch (AssertFailedException)
                {
                    // we know that we could not find the value in the datalist
                    Assert.IsTrue(true);
                }


                try
                {
                    ValidateScalar(resultDataList, "A", "6");
                }
                catch (AssertFailedException)
                {
                    // we know that we could not find the value in the datalist
                    Assert.IsTrue(true);
                }
            });
        }