Ejemplo n.º 1
0
        /// <summary>
        /// Apply the ActorConfigs by instantiating the corresponding actors.
        /// </summary>
        public void ApplyConfig()
        {
            // set the results subdirectory name - fixed location is "resultsfiles"
            Config.CommonConfig.ResultsSubdirectory = "resultsfiles";
            if (Config.CommonConfig.OverwriteResults == false)
            {
                // create a date/time stamp as the results subdirectory name so that the results are overwritten each time the framework is re-started
                Config.CommonConfig.ResultsSubdirectory = System.DateTime.Now.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
            }
            _resultsDirectory = RootedBaseDirectory.GetFullPathname(Config.CommonConfig.RootedBaseDirectory, Config.CommonConfig.ResultsDirectory + "\\" + Config.CommonConfig.ResultsSubdirectory);

            // create the results directory
            System.IO.DirectoryInfo directoryInfo = Directory.CreateDirectory(_resultsDirectory);

            // iterate over all the actors in the configuration
            foreach (ActorConfig actorConfig in Config.ActorConfig)
            {
                // only instantiate those that need to be emulated
                if (actorConfig.ConfigState == ActorConfigStateEnum.ActorBeingEmulated)
                {
                    BaseActor actor = CreateActor(actorConfig.ActorName);
                    actor.ConfigActor(Config.CommonConfig, Config.PeerToPeerConfig);
                    _actors.Add(actor);
                }
            }


            // By inspecting which actors are emulated, build a CompareCondition in such a way that
            // for two "inversed" transactions (transaction that have the same actor but a different Direction)
            // only one of the transactions will be compared to other transactions.

            this._actorsTransactionLog.CompareCondition = new ConditionFalse();

            for (int index1 = 0; index1 < Config.ActorConfig.Count; index1++)
            {
                for (int index2 = index1 + 1; index2 < Config.ActorConfig.Count; index2++)
                {
                    if ((Config.ActorConfig[index1].ConfigState == ActorConfigStateEnum.ActorBeingEmulated) && (Config.ActorConfig[index2].ConfigState == ActorConfigStateEnum.ActorBeingEmulated))
                    {
                        ActorName actorName1 = Config.ActorConfig[index1].ActorName;
                        ActorName actorName2 = Config.ActorConfig[index2].ActorName;

                        Condition actorPairCondition1 = Condition.And(
                            new ActorsTransactionConditionFromActor(actorName1),
                            new ActorsTransactionConditionToActor(actorName2));

                        Condition actorPairCondition2 = Condition.And(
                            new ActorsTransactionConditionFromActor(actorName2),
                            new ActorsTransactionConditionToActor(actorName1));

                        Condition combinedactorPairCondition = Condition.Or(actorPairCondition1, actorPairCondition2);

                        Condition completeCondition = Condition.And(combinedactorPairCondition, new ActorsTransactionConditionDirection(TransactionDirectionEnum.TransactionSent));

                        this._actorsTransactionLog.CompareCondition = Condition.Or(this._actorsTransactionLog.CompareCondition, completeCondition);
                    }
                }
            }

            this._actorsTransactionLog.CompareCondition = Condition.Not(this._actorsTransactionLog.CompareCondition);
        }