Example #1
0
        public async Task <AntiCsrfNonce> Generate(Guid?sessionId = null)
        {
            if (!_configuration.Enabled)
            {
                return(null);
            }

            sessionId = sessionId ?? _guidFactory.Random();

            Guid     nonce            = _guidFactory.Random();
            DateTime currentTimestamp = _systemClock.UtcDateTime;

            await _nonceRepository.AddAsync(sessionId.Value, nonce, currentTimestamp, currentTimestamp + _configuration.NonceDuration);

            return(new AntiCsrfNonce(sessionId.Value, nonce));
        }
Example #2
0
        public Player(IGuidFactory guidFactory, Coordinate <int> coordinate)
        {
            guidFactory.ThrowIfNull(nameof(guidFactory));

            Id         = guidFactory.Random();
            Coordinate = coordinate;
        }
Example #3
0
        public Task <IdResult> MapAsync(Type type, MethodInfo method)
        {
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");

            return(IdResult.IdMapped(_guidFactory.Random()).AsCompletedTask());
        }
Example #4
0
        protected Route(string name, IGuidFactory guidFactory)
        {
            name.ThrowIfNull("name");
            guidFactory.ThrowIfNull("guidFactory");

            _name = name;
            _id   = guidFactory.Random();
        }
Example #5
0
        public Board(IGuidFactory guidFactory, World world, Coordinate <int> coordinate, Size <int> size)
        {
            guidFactory.ThrowIfNull(nameof(guidFactory));
            _world = world.EnsureNotNull(nameof(world));

            Id           = guidFactory.Random();
            Coordinate   = coordinate;
            Size         = size;
            _boardLayers = new BoardLayerCollection <BoardLayer>(() => new BoardLayer(size));
        }
Example #6
0
        public Route(string name, IGuidFactory guidFactory, string resolvedRelativeUrl)
        {
            name.ThrowIfNull("name");
            guidFactory.ThrowIfNull("guidFactory");
            resolvedRelativeUrl.ThrowIfNull("resolvedRelativeUrl");

            _name = name;
            _id   = guidFactory.Random();
            _resolvedRelativeUrl = resolvedRelativeUrl;
        }
        public Routing.Route GetJavaScriptRoute(string name, IGuidFactory guidFactory, string resolvedRelativeUrl, string javaScript, IHttpRuntime httpRuntime)
        {
            guidFactory.ThrowIfNull("guidFactory");
            resolvedRelativeUrl.ThrowIfNull("resolvedRelativeUrl");
            javaScript.ThrowIfNull("javaScript");

            return(new Routing.Route(name, guidFactory.Random(), resolvedRelativeUrl)
                   .RestrictByMethods(HttpMethod.Get)
                   .RestrictByUrlRelativePath(resolvedRelativeUrl, CaseInsensitivePlainComparer.Instance, httpRuntime)
                   .RespondWith(context => new JavaScriptResponse(javaScript)));
        }
        public Routing.Route GetViewRoute <T>(string name, IGuidFactory guidFactory, string resolvedRelativeUrl, byte[] viewTemplate, IEnumerable <string> namespaces, IHttpRuntime httpRuntime, Action <T> populateView = null)
            where T : View
        {
            guidFactory.ThrowIfNull("guidFactory");
            resolvedRelativeUrl.ThrowIfNull("resolvedRelativeUrl");
            viewTemplate.ThrowIfNull("viewTemplate");
            namespaces.ThrowIfNull("namespaces");

            return(new Routing.Route(name, guidFactory.Random(), resolvedRelativeUrl)
                   .RestrictByMethods(HttpMethod.Get)
                   .RestrictByUrlRelativePath(resolvedRelativeUrl, CaseInsensitivePlainComparer.Instance, httpRuntime)
                   .RespondWith(context => GetViewResponse(viewTemplate, namespaces, populateView)));
        }
        public NewWorldController(INewWorldView view, IConfigFile <Config> configFile, IGuidFactory guidFactory, ISystemClock systemClock)
            : base(view)
        {
            _configFile  = configFile.EnsureNotNull(nameof(configFile));
            _guidFactory = guidFactory.EnsureNotNull(nameof(guidFactory));
            _systemClock = systemClock.EnsureNotNull(nameof(systemClock));
            _viewModel   = new NewWorldViewModel
            {
                Author   = _configFile.Config.Views.NewWorld.DefaultAuthor,
                IdAsGuid = _guidFactory.Random(),
                Version  = "1.0"
            };

            AddDisposables(View.IdGenerationRequested.Subscribe(x => _viewModel.IdAsGuid = _guidFactory.Random()));
        }
Example #10
0
        public Task ConfigureCookieAsync(HttpRequestBase request, HttpResponseBase response)
        {
            request.ThrowIfNull("request");
            response.ThrowIfNull("response");

            if (request.Cookies.AllKeys.Contains(_configuration.CookieName))
            {
                response.Cookies.Set(request.Cookies[_configuration.CookieName]);
                return(Task.Factory.Empty());
            }

            string sessionId = _guidFactory.Random().ToString("N");
            var    cookie    = new HttpCookie(_configuration.CookieName, sessionId)
            {
                HttpOnly = true
            };

            response.Cookies.Add(cookie);

            return(Task.Factory.Empty());
        }
        public async Task <string> GenerateHiddenInputHtmlAsync(HttpResponseBase response)
        {
            if (!_configuration.Enabled)
            {
                return("");
            }

            Guid?sessionId = await _cookieManager.GetSessionIdAsync(response);

            if (sessionId == null)
            {
                return("");
            }

            Guid     nonce            = _guidFactory.Random();
            DateTime currentTimestamp = _systemClock.UtcDateTime;

            await _nonceRepository.AddAsync(sessionId.Value, nonce, currentTimestamp, currentTimestamp + _configuration.NonceDuration);

            return(String.Format(@"<input type=""hidden"" name=""{0}"" value=""{1}""/>", _configuration.FormFieldName, nonce.ToString("N")));
        }
        public WorldModel ShowView(IWin32Window owner)
        {
            owner.ThrowIfNull(nameof(owner));

            if (View.ShowView(owner, _viewModel) != DialogResult.OK)
            {
                return(null);
            }

            _configFile.Config.Views.NewWorld.DefaultAuthor = _viewModel.Author;
            _configFile.Save();

            return(new WorldModel
            {
                Author = _viewModel.Author,
                CreatedTimestamp = _systemClock.LocalDateTime,
                Id = _viewModel.IdAsGuid,
                Name = _viewModel.WorldName,
                Resources =
                {
                    Charactersets     =
                    {
                        new WorldResourceCharactersetModel
                        {
                            Id        = _guidFactory.Random(),
                            Name      = "standard",
                            PngBase64 = CharactersetResources.standard.AsBase64Png()
                        }
                    }
                },
                Versions =
                {
                    FileFormat = "1.0",
                    World      = _viewModel.Version
                }
            });
        }
 public string BuildFromRandomGuid()
 {
     return("_" + _guidFactory.Random().ToString("N"));
 }