コード例 #1
0
ファイル: StrategyManager.cs プロジェクト: malain/candle
        /// <summary>
        /// Déchargement de toutes les stratégies de toutes les instances
        /// </summary>
        public static void ClearAll()
        {
            ICandleNotifier notifier = ServiceLocator.Instance.GetService <ICandleNotifier>();

            if (notifier != null)
            {
                notifier.OptionsChanged -= new EventHandler(ReloadOnChangeEvents);
                notifier.SolutionOpened -= new EventHandler(ReloadOnChangeEvents);
                notifier.SolutionClosed -= new EventHandler(ReloadOnChangeEvents);
            }

            if (s_fileSystemWatcher != null)
            {
                s_fileSystemWatcher.EnableRaisingEvents = false;
                s_fileSystemWatcher.Changed            -= new FileSystemEventHandler(fileSystemWatcher_Changed);
            }

            if (s_currentStrategyManager != null)
            {
                try { s_currentStrategyManager.UnloadStrategies(); }
                catch { }
            }

            s_currentModelId         = Guid.Empty;
            s_currentStrategyManager = null;
        }
コード例 #2
0
 public MappingEngine(ISectionProvider sectionProvider, ITypeFactory typeFactory, IMappingFactory mappingFactory, IStrategyManager strategyManager)
 {
     _sectionProvider = sectionProvider;
     _typeFactory     = typeFactory;
     _mappingFactory  = mappingFactory;
     _strategyManager = strategyManager;
 }
コード例 #3
0
 public StrategyProcessor(
     ILogger <StrategyProcessor> logger,
     IOptions <AppSettings> settings,
     IStrategyManager strategyManager) : base(settings, logger)
 {
     _settings        = settings;
     _strategyManager = strategyManager;
 }
コード例 #4
0
 public TradingContextBuilder(
     IOptions <AppSettings> settings,
     ILogger <TradingContextBuilder> logger,
     ICandleManager candlesManager,
     IStrategyManager strategyManager) : base(settings, logger)
 {
     _settings        = settings;
     _candlesManager  = candlesManager;
     _strategyManager = strategyManager;
 }
コード例 #5
0
 private readonly IStrategyManager _manager;     //code added
 public ProcessStepFactory(ITableCountTest table, ICompareTest compareTest, IStrategyManager manager)
 {
     _table       = table;
     _compareTest = compareTest;
     _manager     = manager;
 }
コード例 #6
0
ファイル: StrategyManager.cs プロジェクト: malain/candle
        /// <summary>
        /// Récupère les stratégies du modèle courant.
        /// </summary>
        /// <param name="store"></param>
        /// <remarks>
        /// Si un autre modèle est ouvert dans la solution, on retourne un manager ne contenant aucune strategie.
        /// </remarks>
        /// <returns></returns>
        public static IStrategyManager GetInstance(Store store)
        {
            // Modèle correspondant au store
            CandleModel model = CandleModel.GetInstance(store);

            if (model == null) // On a pas trouvé le modèle, on retourne un strategyManager vide
            {
                return(new StrategyManager());
            }

            // Si on a dèja chargé les stratégies, on les retourne
            if (s_currentModelId != Guid.Empty && s_currentModelId == model.Id)
            {
                return(s_currentStrategyManager);
            }

            // Est ce que c'est le modèle courant
            CandleModel currentModel = CandleModel.GetModelFromCurrentSolution();

            if (currentModel == null || currentModel.Id != model.Id)
            {
                return(new StrategyManager());
            }

            // Sinon on va créer les stratégies
            SuspendWatcher(false);

            // Flag indiquant si on peut persister les stratégies ou seulement les initialiser.
            // On ne peut pas persister si on est dans le cas d'une initialisation du modèle puisqu'on ne connait pas
            // encore le nom du modèle
            bool   canPersist       = true;
            string strategyFileName = null;

            try
            {
                // Création d'un nouveau fichier de strategies ayant le même nom que le modèle mais avec
                // l'extension .strategies
                string modelFileName = model.FileName;

                // Dans le cas d'une création d'un modèle, on ne peut pas récupérer le filepath du modèle car
                // il n'y a pas encore de vue active. Dans ce cas, on essaye de le déduire.
                if (modelFileName == null)
                {
                    string name = model.Name;

                    // On est dans le cas d'une initialisation de modèle, on ne va crèer le fichier des stratégies tout de suite
                    // on attend que le modèle soit initialisé
                    if (name.Contains("?"))
                    {
                        canPersist       = false;
                        strategyFileName = Path.GetTempFileName();  // Fichier temporaire pour récupèrer les stratégies pré-initialisées
                        Utils.DeleteFile(strategyFileName);         // Obligé car GetTempFileName crée le fichier
                    }
                    else
                    {
                        IShellHelper shell = ServiceLocator.Instance.GetService <IShellHelper>();
                        if (shell != null)
                        {
                            string tmp = Path.GetFileNameWithoutExtension(shell.GetSolutionAssociatedModelName());
                            if (!String.IsNullOrEmpty(tmp))
                            {
                                name = tmp;
                            }
                            else
                            {
                                tmp = shell.Solution.FullName;
                                if (!String.IsNullOrEmpty(tmp))
                                {
                                    name = Path.GetFileNameWithoutExtension(tmp);
                                }
                            }
                        }

                        strategyFileName = String.Concat(Path.Combine(ServiceLocator.Instance.ShellHelper.SolutionFolder, name), DefaultStrategiesFileNameExtension);
                    }
                }
                else
                {
                    strategyFileName = Path.ChangeExtension(modelFileName, DefaultStrategiesFileNameExtension);
                }

                // Initialisation du fichier de stratégies à partir d'un modèle
                if (!String.IsNullOrEmpty(model.StrategyTemplate))
                {
                    EnsureStrategiesFileExists(strategyFileName, model.StrategyTemplate, canPersist);
                }

                StrategyManager manager = null;
                if (File.Exists(strategyFileName))
                {
                    manager = Load(store, strategyFileName);
                }
                else
                {
                    manager = new StrategyManager();
                }

                if (canPersist)
                {
                    manager.FileName = strategyFileName;
                    // Cache pour éviter de le relire
                    s_currentModelId         = model.Id;
                    s_currentStrategyManager = manager;
                }

                return(manager);
            }
            finally
            {
                SuspendWatcher(true);

                // Suppression du fichier temporaire
                if (!canPersist)
                {
                    Utils.DeleteFile(strategyFileName);
                }
            }
        }
コード例 #7
0
    void Start()
    {
        // Timers
        lifeTime        = new Stopwatch();
        takeHealthTimer = new Stopwatch();
        lifeTime.Start();
        takeHealthTimer.Start();

        // Setting up the startup state
        state = new AgentState
        {
            hydrationLevel = 35,
            foodSupply     = 50,
            happy          = false,
            isAtDisco      = false
        };

        // Creating the default strategy behaviours
        walkAround      = new WalkAroundBehaviour(GetComponent <NavMeshAgent>());
        eatFood         = new EatNearbyFoodBehaviour(GetComponent <NavMeshAgent>(), transform, state);
        findWater       = new GetWaterBehaviour(GetComponent <NavMeshAgent>(), transform, state);
        awayFromMonster = new RunAwayFromMonster(GetComponent <NavMeshAgent>(), transform);
        List <AgentBehaviour> behaviours = new List <AgentBehaviour>
        {
            walkAround,
            eatFood,
            findWater,
            awayFromMonster
        };

        homeAndRest = new GetHomeAndRestBehaviour(GetComponent <NavMeshAgent>(), restingPlace, state); // Added later to the default strategy

        defaultStrategy = new BehaviourStrategy(behaviours, (state) => { return(true); });

        ControlCenter = new ControlCenter(gameObject, defaultStrategy);
        ControlCenter.SetStateObject(state);

        // Making additional strategies
        IStrategyManager strategyManager = ControlCenter.StrategyManager;

        strategyManager.EnableMultipleStrategies = true;

        AgentBehaviour goToDisco      = new GoToDiscoBehaviour(GetComponent <NavMeshAgent>(), disco);
        AgentBehaviour dance          = new DanceBehaviour(ControlCenter.CommunicationManager, GetComponent <NavMeshAgent>(), gameObject, state);
        AgentBehaviour goHomeAndSleep = new GetHomeAndSleepBehaviour(GetComponent <NavMeshAgent>(), restingPlace, state);

        List <AgentBehaviour> nightTimeStrategy = new List <AgentBehaviour>
        {
            goToDisco,
            dance,
            goHomeAndSleep
        };
        BehaviourStrategy strategy = new BehaviourStrategy(nightTimeStrategy, (state) =>
        {
            if (GameManager.isNight)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        });

        strategyManager.AddAdditionalStrategy(strategy);

        // Setting up the communication manager
        ICommunicationManager communicationManager = ControlCenter.CommunicationManager;

        communicationManager.EnableBroadcasting = true;
        BroadcastSettings settings = new BroadcastSettings
        {
            AgentTag        = "Agent",
            BroadcastRadius = 20
        };

        settings.SetSuppressibleBehaviours(new List <AgentBehaviour> {
            dance, goToDisco
        });
        communicationManager.SetBroadcastSettings(settings);

        // Add arbitration rules
        ControlCenter.ArbitrationManager.EnableArbitrationRules = true;
        ControlCenter.ArbitrationManager.AddArbitrationRule((inputBehaviors) =>
        {
            if (inputBehaviors.Contains(findWater) && inputBehaviors.Contains(awayFromMonster))
            {
                List <AgentBehaviour> toExecute = new List <AgentBehaviour>
                {
                    findWater
                };
                return(new ArbitrationRule(toExecute, true));
            }
            return(default);
コード例 #8
0
ファイル: Service.cs プロジェクト: akramarev/AK.CCI
		public Service(IConfiguration configuration, IStrategyManager strategyManager)
		{
			_configuration = configuration;
			_strategyManager = strategyManager;
		}