Exemple #1
0
        private static IAdapterProvider GetConfiguredProviderInstance(LocalRecordsSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            IAdapterProvider provider = Instancer.GetInstanceOfInterface <IAdapterProvider>(settings.ProviderAssemblyLocation, settings.ProviderClass);

            provider.Init(settings.ProviderParameter);

            return(provider);
        }
Exemple #2
0
        public static IAdapterProvider GetAdapterProvider(LocalRecordsSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (_instance == null)
            {
                lock (_padlock)
                {
                    if (_instance == null)
                    {
                        _instance = GetConfiguredProviderInstance(settings);
                    }
                }
            }

            return(_instance);
        }
Exemple #3
0
        public static LocalRecordsSettings ReadFromFile(string xmlConfigurationFile)
        {
            LocalRecordsSettings result         = new LocalRecordsSettings();
            XDocument            configDocument = XDocument.Load(xmlConfigurationFile);

            if (configDocument.Root == null)
            {
                throw new ConfigurationErrorsException("Could not find root node in file: " + xmlConfigurationFile);
            }

            XElement providerSettingsElement = configDocument.Root.Element("ProviderSettings");

            if (providerSettingsElement == null)
            {
                throw new ConfigurationErrorsException("Could not find ProviderSettings node in file: " + xmlConfigurationFile);
            }

            XElement assemblyElement = providerSettingsElement.Element("Assembly");

            if (assemblyElement == null)
            {
                throw new ConfigurationErrorsException("Could not find Assembly node in file: " + xmlConfigurationFile);
            }

            if (assemblyElement.Value.IsNullOrTimmedEmpty())
            {
                throw new ConfigurationErrorsException("Assembly node is empty in file: " + xmlConfigurationFile);
            }

            result.ProviderAssemblyLocation = assemblyElement.Value.Trim();

            XElement providerElement = providerSettingsElement.Element("Provider");

            if (providerElement == null)
            {
                throw new ConfigurationErrorsException("Could not find Provider node in file: " + xmlConfigurationFile);
            }

            if (providerElement.Value.IsNullOrTimmedEmpty())
            {
                throw new ConfigurationErrorsException("Provider node is empty in file: " + xmlConfigurationFile);
            }

            result.ProviderClass = providerElement.Value.Trim();

            XElement parameterElement = providerSettingsElement.Element("Parameter");

            if (parameterElement == null)
            {
                throw new ConfigurationErrorsException("Could not find Parameter node in file: " + xmlConfigurationFile);
            }

            result.ProviderParameter            = parameterElement.Value.Trim();
            result.MaxRecordsToReport           = ReadConfigUInt(configDocument.Root, "MaxRecordsToReport", MAX_RECORDS_TO_REPORT, xmlConfigurationFile);
            result.CheaterDeletedMessage        = ReadConfigString(configDocument.Root, "CheaterDeletedMessage", CHEATER_DELETED_MSG, xmlConfigurationFile);
            result.CheaterDeletionFailedMessage = ReadConfigString(configDocument.Root, "CheaterDeletionFailedMessage", CHEATER_DELETION_FAILED_MSG, xmlConfigurationFile);
            result.CheaterBannedMessage         = ReadConfigString(configDocument.Root, "CheaterBannedMessage", CHEATER_BANNED_MSG, xmlConfigurationFile);
            result.Plugins = PluginConfigEntryCollection.ReadFromDirectory(Path.GetDirectoryName(xmlConfigurationFile));

            return(result);
        }
Exemple #4
0
        protected override void Init()
        {
            Settings = LocalRecordsSettings.ReadFromFile(PluginSettingsFilePath);

            try
            {
                AdapterProvider  = AdapterProviderFactory.GetAdapterProvider(Settings);
                ChallengeAdapter = AdapterProvider.GetChallengeAdapter();
                PlayerAdapter    = AdapterProvider.GetPlayerAdapter();
                PositionAdapter  = AdapterProvider.GetPositionAdapter();
                RecordAdapter    = AdapterProvider.GetRecordAdapter();
                RatingAdapter    = AdapterProvider.GetRatingAdapter();
                SessionAdapter   = AdapterProvider.GetSessionAdapter();
                RankingAdapter   = AdapterProvider.GetRankingAdapter();
            }
            catch (Exception ex)
            {
                Logger.Error("Error initializing AdapterProvider for local records.", ex);
                Logger.ErrorToUI(string.Format("An error occured. {0} not started!", Name));
                return;
            }

            List <ChallengeListSingleInfo> challenges = GetChallengeList();

            if (challenges == null)
            {
                return;
            }

            try
            {
                Logger.InfoToUI("Starting to delete data of missing tracks");
                int amountOfDeletedTracks = ChallengeAdapter.DeleteTracksNotInProvidedList(challenges.ConvertAll(c => c.UId));
                Logger.InfoToUI(string.Format("Data of {0} Track(s) has been deleted.", amountOfDeletedTracks));
            }
            catch (Exception ex)
            {
                Logger.ErrorToUI("Couldn't delete data of missing tracks.", ex);
            }


            foreach (PlayerSettings playerSettings in Context.PlayerSettings.GetAllAsList())
            {
                if (!playerSettings.NickName.IsNullOrTimmedEmpty())
                {
                    PlayerAdapter.CreateOrUpdate(new Player(playerSettings.Login, playerSettings.NickName));
                }
            }

            ChallengeInfo currentChallengeInfo = GetCurrentChallengeInfoCached();

            if (currentChallengeInfo == null)
            {
                Logger.ErrorToUI(string.Format("An error occured. {0} not started!", Name));
                return;
            }

            EnsureChallengeExistsInStorage(currentChallengeInfo);
            DetermineLocalRecords();

            InitializePlugins();
            OnLocalRecordsDetermined(new List <RankEntry>(LocalRecords));

            Context.RPCClient.Callbacks.BeginRace        += Callbacks_BeginRace;
            Context.RPCClient.Callbacks.EndRace          += Callbacks_EndRace;
            Context.RPCClient.Callbacks.PlayerConnect    += Callbacks_PlayerConnect;
            Context.RPCClient.Callbacks.PlayerDisconnect += Callbacks_PlayerDisconnect;
            Context.RPCClient.Callbacks.PlayerFinish     += Callbacks_PlayerFinish;
            Context.RPCClient.Callbacks.PlayerChat       += Callbacks_PlayerChat;
        }