Esempio n. 1
0
 public GameEnvironment(IDependencyContainer dependencies, TimeSpan gameLoopPeriod)
 {
     DependencyContainer = dependencies;
     Entities            = dependencies.Resolve <IEntityRepository>();
     Systems             = dependencies.ResolveAll <ISystem>();
     GameLoopPeriod      = gameLoopPeriod;
 }
Esempio n. 2
0
        public ISaveEntityDatabasePipeline CreateDefaultSavePipeline(IDependencyContainer container)
        {
            var mappingRegistry       = new MappingRegistry(container.Resolve <EverythingTypeMapper>());
            var primitiveTypeMappings = container.ResolveAll <IBinaryPrimitiveHandler>();
            var everythingSerializer  = new BinarySerializer(mappingRegistry, primitiveTypeMappings);

            return(CreateSavePipeline(container, everythingSerializer, DefaultEntityDatabaseFile));
        }
Esempio n. 3
0
        public ILoadEntityDatabasePipeline CreateDefaultLoadPipeline(IDependencyContainer container)
        {
            var mappingRegistry        = new MappingRegistry(container.Resolve <EverythingTypeMapper>());
            var typeCreator            = container.Resolve <ITypeCreator>();
            var primitiveTypeMappings  = container.ResolveAll <IBinaryPrimitiveHandler>();
            var everythingDeserializer = new BinaryDeserializer(mappingRegistry, typeCreator, primitiveTypeMappings);

            return(CreateLoadPipeline(container, everythingDeserializer, DefaultEntityDatabaseFile));
        }
Esempio n. 4
0
        public ILoadEntityDatabasePipeline CreateJsonLoadPipeline(IDependencyContainer container)
        {
            // Manually build deserializer as we want to load everything
            var mappingRegistry       = new MappingRegistry(container.Resolve <EverythingTypeMapper>());
            var typeCreator           = container.Resolve <ITypeCreator>();
            var primitiveTypeMappings = container.ResolveAll <IJsonPrimitiveHandler>();

            // Create deserializer for everything
            var everythingDeserializer = new JsonDeserializer(mappingRegistry, typeCreator, primitiveTypeMappings);

            // Use existing load pipeline helper to customize format and filename
            return(PersistityModule.CreateLoadPipeline(container, everythingDeserializer, CustomEntityDatabaseFile));
        }
Esempio n. 5
0
        public ISaveEntityDatabasePipeline CreateJsonSavePipeline(IDependencyContainer container)
        {
            // We manually create our serializer here as we dont want the default behaviour which
            // which would be to only persist things with `[Persist]` and `[PersistData]` attributes
            // we want to persist EVERYTHING
            var mappingRegistry       = new MappingRegistry(container.Resolve <EverythingTypeMapper>());
            var primitiveTypeMappings = container.ResolveAll <IJsonPrimitiveHandler>();

            // Create the serializer to serialize everything
            var everythingSerializer = new JsonSerializer(mappingRegistry, primitiveTypeMappings);

            // Piggyback off the existing save pipeline helper, which lets you set your format and filename
            return(PersistityModule.CreateSavePipeline(container, everythingSerializer, CustomEntityDatabaseFile));
        }
        public IScriptingProvider GetScriptingProvider(IDependencyContainer container, string providerName)
        {
            var providers = container.ResolveAll <IScriptingProvider>();

            foreach (var provider in providers)
            {
                if (provider.ScriptName.Equals(providerName, StringComparison.OrdinalIgnoreCase) ||
                    provider.FileTypes.Any(c => c.Equals(providerName, StringComparison.OrdinalIgnoreCase)))
                {
                    return(provider);
                }
            }

            return(null);
        }
Esempio n. 7
0
        /// <inheritdoc />
        public object Get(int index, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (Length <= index)
            {
                throw new CommandIndexOutOfRangeException(index, Length);
            }

            if (index < 0)
            {
                throw new IndexOutOfRangeException();
            }

            string arg = ToArray()[index];



            bool isUserInfo = typeof(IUserInfo).IsAssignableFrom(type);
            bool isUser     = typeof(IUser).IsAssignableFrom(type);


            //todo make type converters
            if (isUserInfo || isUser)
            {
                /*
                 * The logic for getting IUser and IUserInfo is as follows:
                 * If the name is supplied as usermanager:username, e.g. discord:Trojaner, it will search for valid "discord" user manager and return the "Trojaner" named user of it.
                 * Otherwise (if the user manager does not exist or the format was not supplied), it will use the player manager and return the user for the given input.
                 */
                IUserManager targetUserManager = container.Resolve <IPlayerManager>();

                string userName = arg;
                if (arg.Contains(":"))
                {
                    var    args = arg.Split(':');
                    string userManagerMapping = args.First();

                    foreach (var userMgr in container.ResolveAll <IUserManager>())
                    {
                        if (userMgr.ServiceName.Equals(userManagerMapping, StringComparison.OrdinalIgnoreCase))
                        {
                            userName          = string.Join(":", args.Skip(1).ToArray());
                            targetUserManager = userMgr;
                            break;
                        }
                    }
                }

                if (!isUserInfo)
                {
                    return(targetUserManager.OnlineUsers
                           .OrderBy(c => c.Name)
                           .First(c => c.Name.Equals(userName, StringComparison.OrdinalIgnoreCase)));
                }

                return(targetUserManager.GetUser(userName));
            }

            TypeConverter converter = TypeConverterExtensions.GetConverter(type);

            if (converter.CanConvertFrom(typeof(string)))
            {
                return(converter.ConvertFromWithContext(container, arg));
            }

            throw new CommandParameterParseException(arg, type);
        }
Esempio n. 8
0
        public ChubbyWarps(IDependencyContainer container) : base("ChubbyWarps", container)
        {
            var providers = container.ResolveAll <IDataProvider>();

            providers.ForEach(x => x.Initialize(this));
        }
Esempio n. 9
0
 /// <summary>
 /// Gets an enumerable of a given type from the underlying DI container
 /// </summary>
 /// <typeparam name="T">Type to resolve</typeparam>
 /// <returns>All matching instances of that type within the underlying container</returns>
 public static IEnumerable <T> ResolveAll <T>(this IDependencyContainer container)
 {
     return(container.ResolveAll(typeof(T)).Cast <T>());
 }
Esempio n. 10
0
 public static IEnumerable <TType> ResolveAll <TType>(this IDependencyContainer container) =>
 container.ResolveAll(typeof(TType)).Cast <TType>();
Esempio n. 11
0
 public static IEnumerable <T> ResolveAll <T>()
 {
     return(resolver.ResolveAll <T>());
 }