Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameBase" /> class.
        /// </summary>
        protected GameBase()
        {
            // Internals
            Log                      = GlobalLogger.GetLogger(GetType().GetTypeInfo().Name);
            updateTime               = new GameTime();
            drawTime                 = new GameTime();
            playTimer                = new TimerTick();
            updateTimer              = new TimerTick();
            totalUpdateTime          = new TimeSpan();
            timer                    = new TimerTick();
            IsFixedTimeStep          = false;
            maximumElapsedTime       = TimeSpan.FromMilliseconds(500.0);
            lastUpdateCount          = new int[4];
            nextLastUpdateCountIndex = 0;
            TargetElapsedTime        = defaultTimeSpan; // default empty timespan, will be set on window create if not set elsewhere

            TreatNotFocusedLikeMinimized = true;
            DrawEvenMinimized            = false;
            WindowMinimumUpdateRate      = new ThreadThrottler(defaultTimeSpan);                                  // will be set when window gets created with window's refresh rate
            MinimizedMinimumUpdateRate   = new ThreadThrottler(TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 15)); // by default 15 updates per second while minimized

            // Calculate the updateCountAverageSlowLimit (assuming moving average is >=3 )
            // Example for a moving average of 4:
            // updateCountAverageSlowLimit = (2 * 2 + (4 - 2)) / 4 = 1.5f
            const int BadUpdateCountTime = 2; // number of bad frame (a bad frame is a frame that has at least 2 updates)
            var       maxLastCount       = 2 * Math.Min(BadUpdateCountTime, lastUpdateCount.Length);

            updateCountAverageSlowLimit = (float)(maxLastCount + (lastUpdateCount.Length - maxLastCount)) / lastUpdateCount.Length;

            // Externals
            Services = new ServiceRegistry(true);

            // Database file provider
            Services.AddService <IDatabaseFileProviderService>(new DatabaseFileProviderService(null));

            LaunchParameters = new LaunchParameters();
            GameSystems      = new GameSystemCollection(Services);
            Services.AddService <IGameSystemCollection>(GameSystems);

            // Create Platform
            gamePlatform                = GamePlatform.Create(this);
            gamePlatform.Activated     += GamePlatform_Activated;
            gamePlatform.Deactivated   += GamePlatform_Deactivated;
            gamePlatform.Exiting       += GamePlatform_Exiting;
            gamePlatform.WindowCreated += GamePlatformOnWindowCreated;

            // Setup registry
            Services.AddService <IGame>(this);
            Services.AddService <IGraphicsDeviceFactory>(gamePlatform);
            Services.AddService <IGamePlatform>(gamePlatform);

            IsActive = true;
        }
        public async Task <IActionResult> UploadAsync(
            IFormFile file,
            int chunkNumber,
            int totalSize,
            string uid,
            string filename,
            string relativePath,
            int totalChunks)
        {
            try
            {
                if (!Guid.TryParse(uid, out Guid parsedUid))
                {
                    throw new ArgumentException("The provided unique identifier is not valid.");
                }

                ThreadThrottler throttler = new ThreadThrottler();

                CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(
                    HttpContext?.RequestAborted ?? default(CancellationToken));

                var chunkResult = await uploader.UploadAsync(totalChunks, chunkNumber, uid, file.OpenReadStream(), cts.Token);

                if (ApiConfiguration?.Options?.EnableRateLimiting ?? false)
                {
                    // Ensure current request lasts at least 500 milliseconds
                    throttler.Throttle(500);
                }

                if (chunkResult != null && chunkResult.IsCompleted)
                {
                    var result = await uploader.CommitAsync(filename, relativePath, uid, cts.Token);

                    return(CreatedAtAction(nameof(GetById), new { id = result.Id }, result));
                }
                else
                {
                    return(Content(string.Empty));
                }
            }
            catch (ArgumentException e)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Content(e.Message));
            }
            catch (Exception e)
            {
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(Content(e.Message));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameBase" /> class.
        /// </summary>
        protected GameBase()
        {
            // Internals
            Log                = GlobalLogger.GetLogger(GetType().GetTypeInfo().Name);
            UpdateTime         = new GameTime();
            DrawTime           = new GameTime();
            autoTickTimer      = new TimerTick();
            IsFixedTimeStep    = false;
            maximumElapsedTime = TimeSpan.FromMilliseconds(500.0);
            TargetElapsedTime  = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 60); // target elapsed time is by default 60Hz

            TreatNotFocusedLikeMinimized = true;
            WindowMinimumUpdateRate      = new ThreadThrottler(TimeSpan.FromSeconds(0d));
            MinimizedMinimumUpdateRate   = new ThreadThrottler(TimeSpan.FromTicks(TimeSpan.TicksPerSecond / 15)); // by default 15 updates per second while minimized

            isMouseVisible = true;

            // Externals
            Services = new ServiceRegistry();

            // Database file provider
            Services.AddService <IDatabaseFileProviderService>(new DatabaseFileProviderService(null));

            LaunchParameters = new LaunchParameters();
            GameSystems      = new GameSystemCollection(Services);
            Services.AddService <IGameSystemCollection>(GameSystems);

            // Create Platform
            gamePlatform                = GamePlatform.Create(this);
            gamePlatform.Activated     += GamePlatform_Activated;
            gamePlatform.Deactivated   += GamePlatform_Deactivated;
            gamePlatform.Exiting       += GamePlatform_Exiting;
            gamePlatform.WindowCreated += GamePlatformOnWindowCreated;

            // Setup registry
            Services.AddService <IGame>(this);
            Services.AddService <IGraphicsDeviceFactory>(gamePlatform);
            Services.AddService <IGamePlatform>(gamePlatform);

            IsActive = true;
        }