Exemple #1
0
        protected override bool OnInitialize(Platform platform)
        {
            TracerHelper.TraceEntry();

            if (base.OnInitialize(platform) == false)
            {
                return(false);
            }

            string expertName = this.Name + ".expert";

            // Clean expertname since we might be sending it trough command line.
            expertName = expertName.Replace(" ", "_");
            expertName = expertName.Replace("\"", "");

            lock (this)
            {
                if (_expert == null)
                {// Create the expert.
                    SystemMonitor.CheckThrow(_expertType.IsSubclassOf(typeof(Expert)), "Invalid expert type passed in.");
                    ConstructorInfo constructor = _expertType.GetConstructor(new Type[] { typeof(ISourceAndExpertSessionManager), typeof(string) });

                    if (constructor == null)
                    {// Try the second option for construction.
                        constructor = _expertType.GetConstructor(new Type[] { typeof(ISourceAndExpertSessionManager) });
                    }

                    if (constructor == null)
                    {
                        SystemMonitor.Error("Failed to find corresponding constructor for expert type [" + _expertType.ToString() + "].");
                        return(false);
                    }

                    if (constructor.GetParameters().Length == 2)
                    {
                        _expert = (Expert)constructor.Invoke(new object[] { this, expertName });
                    }
                    else
                    {
                        _expert = (Expert)constructor.Invoke(new object[] { this });
                    }
                }

                if (_expert.Initialize() == false)
                {
                    SystemMonitor.Error("Expert host failed to connect to platform.");
                    return(false);
                }

                if (_expert != null)
                {
                    _expert.PersistenceDataUpdateEvent += new Expert.ExpertUpdateDelegate(_expert_PersistenceDataUpdateEvent);
                }
            }

            foreach (PlatformExpertSession session in SessionsArray)
            {
                if (session.Initialize(null) == false)
                {
                    SystemMonitor.OperationWarning("Failed to initialize session.");
                }
            }

            ChangeOperationalState(OperationalStateEnum.Operational);

            TracerHelper.TraceExit();
            return(true);
        }