Exemplo n.º 1
0
#pragma warning restore 0649

        private void Awake()
        {
            BeatInputService beatInputService = new BeatInputService(this);
            UnitService      unitService      = new UnitService(this);

            services = new ServiceDictionary {
                { typeof(SongService), new SongService() },
                { typeof(BeatInputService), beatInputService },
                { typeof(AudioService), new AudioService(GetComponent <AudioSource>()) },
                { typeof(UnitService), unitService },
                { typeof(GameStateService), new GameStateService() },
                { typeof(PersistenceService), new PersistenceService() }
            };
            updateableServices = new IUpdateableService[] {
                beatInputService,
                unitService
            };
            VerifyBuildOrder();

            foreach (IService service in services.Values)
            {
                service.Initialize();
            }

            foreach (IService service in services.Values)
            {
                service.PostInitialize();
            }
        }
Exemplo n.º 2
0
        internal ModelContainer GetPackage(ModelContainer inputPackage)
        {
            if (ServiceDictionary.TryGetValue(inputPackage.TypePacket, out IGenerateResponseContainer generateResponseContainer))
            {
                Loger.Log("Server " + (Context.Player == null ? "     " : Context.Player.Public.Login.PadRight(5)) + " " + generateResponseContainer.GetType().Name);
                return(generateResponseContainer.GenerateModelContainer(inputPackage, Context));
            }

            Loger.Log("Server " + (Context.Player == null ? "     " : Context.Player.Public.Login.PadRight(5)) + $" Response for type {inputPackage.TypePacket} not found");

            return(new ModelContainer()
            {
                TypePacket = 0
            });
        }
Exemplo n.º 3
0
        internal static Tuple <Type, Type, Type> GetServiceTypes(Type entityType)
        {
            var attributes = entityType.GetCustomAttributes().Where(a => typeof(EntityAttribute).IsAssignableFrom(a.GetType()));
            Tuple <Type, Type, Type> ret = null;

            foreach (var att in attributes)
            {
                ServiceDictionary.TryGetValue(att.GetType(), out ret);
                if (ret != null)
                {
                    return(ret);
                }
            }
            return(ServiceDictionary.DefaultValue);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes the GlobalSettings class.  Also reads the stored cache mode setting.
        /// </summary>
        public static void Initialize()
        {
            // Create objects for the objects that we need. 
            PairedDevices = new List<BeDeviceModel>();

            ParserLookupTable = new CharacteristicParserLookupTable();
            ServiceDictionaryUnknown = new ServiceDictionary();
            ServiceDictionaryConstant = new ServiceDictionary();
            CharacteristicDictionaryUnknown = new CharacteristicDictionary();
            CharacteristicDictionaryConstant = new CharacteristicDictionary();
            ServiceDictionaryConstant.InitAsConstant();
            CharacteristicDictionaryConstant.InitAsConstant();
            DictionariesCleared = false;
            CharacteristicsWithActiveToast = new List<BeCharacteristicModel>();

            _useCachedMode = ApplicationData.Current.LocalSettings.Values.ContainsKey(USE_CACHED_MODE);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes the GlobalSettings class.  Also reads the stored cache mode setting.
        /// </summary>
        public static void Initialize()
        {
            // Create objects for the objects that we need.
            PairedDevices = new List <BEDeviceModel>();

            ParserLookupTable                = new Dictionary.DataParser.CharacteristicParserLookupTable();
            ServiceDictionaryUnknown         = new ServiceDictionary();
            ServiceDictionaryConstant        = new ServiceDictionary();
            CharacteristicDictionaryUnknown  = new CharacteristicDictionary();
            CharacteristicDictionaryConstant = new CharacteristicDictionary();
            ServiceDictionaryConstant.InitAsConstant();
            CharacteristicDictionaryConstant.InitAsConstant();
            DictionariesCleared            = false;
            CharacteristicsWithActiveToast = new List <BECharacteristicModel>();

            _useCachedMode = ApplicationData.Current.LocalSettings.Values.ContainsKey(USE_CACHED_MODE);
        }
Exemplo n.º 6
0
        public async Task SendInteractiveAsync(IEmbedMessage message,
                                               IDiscordContext context,
                                               CancellationToken cancellationToken = default,
                                               bool forceStateful = true)
        {
            // create dependency scope to initialize the interactive within
            using (var scope = _services.CreateScope())
            {
                var services = new ServiceDictionary(scope.ServiceProvider)
                {
                    { typeof(IDiscordContext), context }
                };

                // initialize interactive
                if (!await message.UpdateViewAsync(services, cancellationToken))
                {
                    return;
                }
            }

            var id = message.Message.Id;

            if (message is IInteractiveMessage interactiveMessage)
            {
                if (forceStateful || interactiveMessage.Triggers.Values.Any(t => !t.CanRunStateless))
                {
                    InteractiveMessages[id] = interactiveMessage;
                }
            }

            // forget interactives in an hour
            _ = Task.Run(async() =>
            {
                try
                {
                    await Task.Delay(TimeSpan.FromHours(1), cancellationToken);
                }
                catch (TaskCanceledException) { }
                finally
                {
                    InteractiveMessages.TryRemove(id, out _);
                }
            },
                         cancellationToken);
        }
Exemplo n.º 7
0
        public async Task <bool> TryHandleAsync(IMessageContext context,
                                                CancellationToken cancellationToken = default)
        {
            switch (context.Event)
            {
            case MessageEvent.Create: break;

            default: return(false);
            }

            var content = context.Message.Content;

            // message has command prefix
            if (!content.StartsWith(_settings.Discord.Prefix))
            {
                return(false);
            }

            content = content.Substring(_settings.Discord.Prefix.Length);

            // parse command
            if (!TryParseCommand(content, out var command, out var args))
            {
                return(false);
            }

            using (var scope = _services.CreateScope())
            {
                var services = new ServiceDictionary(scope.ServiceProvider)
                {
                    { typeof(IDiscordContext), context },
                    { typeof(IMessageContext), context }
                };

                // invoke command
                using (context.BeginTyping())
                    await command.InvokeAsync(services, args);
            }

            return(true);
        }
Exemplo n.º 8
0
        private IServiceDictionary GetServiceDictionary(Type serviceType, bool create)
        {
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }

            var unwrappedServiceType = UnwrapServiceType(serviceType);
            IServiceDictionary result;

            if (_services.TryGetValue(unwrappedServiceType, out result))
            {
                return(result);
            }

            if (create)
            {
                return(_services[unwrappedServiceType] = ServiceDictionary.Create(this, serviceType));
            }

            return(null);
        }
Exemplo n.º 9
0
        internal ModelContainer GetPackage(ModelContainer inputPackage)
        {
            if (ServiceDictionary.TryGetValue(inputPackage.TypePacket, out IGenerateResponseContainer generateResponseContainer))
            {
                var name = generateResponseContainer.GetType().Name;
                Loger.Log("Server " + (Context.Player == null ? "     " : Context.Player.Public.Login.PadRight(5))
                          + " " + name
                          + (name == "PlayInfo"
                        ? $" dMS={(Context.Player.LastUpdateTime - Context.Player.WLastUpdateTime).TotalMilliseconds} "
                             + $"dTicks={Context.Player.Public.LastTick - Context.Player.WLastTick} "
                             + $"dValue={Context.Player.DeltaMarketValue} "
                             + $"dPawn={Context.Player.DeltaMarketValuePawn} "
                        : ""));
                return(generateResponseContainer.GenerateModelContainer(inputPackage, Context));
            }

            Loger.Log("Server " + (Context.Player == null ? "     " : Context.Player.Public.Login.PadRight(5)) + $" Response for type {inputPackage.TypePacket} not found");

            return(new ModelContainer()
            {
                TypePacket = 0
            });
        }