Пример #1
0
        public async Task <RouteResponse> GetRouteByIdentiferAsync(RouteIdentifier identifier)
        {
            var userId = User.GetUserId();
            var route  = await _routeRepository.GetRouteByIdentifierAsync(identifier, userId);

            return(RouteResponse.Map(route));
        }
Пример #2
0
        public async Task <RouteResponse> PatchRouteByIdentiferAsync(RouteIdentifier identifier, IDictionary <string, object> values)
        {
            // We'll get the intersection of known valid property names, to the incoming property
            // names, as this will get us a list of only valid incoming property keys.
            var userId = User.GetUserId();
            var route  = await _routeRepository.GetRouteByIdentifierAsync(identifier, userId);

            var validProperties = new List <string> {
                "owner", "uri", "title", "type", "code", "isOnline"
            };

            // Allow the IsDefault property to be set if the user is an admin.
            if (User.IsAdmin())
            {
                validProperties.Add("isDefault");
            }

            var selectedProperties = values.Keys.Intersect(validProperties);

            // Only set allowed properties using reflection and type coersion. We proper-case the
            // name because our serializer automatically camel-cases json property names.
            foreach (var property in selectedProperties)
            {
                route.SetProperty(property.ToProperCase(), values[property]);
            }

            // Update server properties.
            route.IsCurrent = false;
            route           = await _routeRepository.UpdateRouteAsync(route, userId);

            return(RouteResponse.Map(route));
        }
        public async Task <IHttpActionResult> PostPublishAsync(RouteIdentifier identifier)
        {
            // Load route to get source code.
            var route = await _routeRepository.GetRouteByIdentifierAsync(identifier);

            var code = route.Code;

            // Compile code and get assembly as byte array.
            var compilationResult = _compilationService.Compile(code);

            // We'll save the assembly and mark the route as published if the compilation was successful.
            if (compilationResult.Success)
            {
                route.Assembly    = compilationResult.Assembly;
                route.IsCurrent   = true;
                route.IsOnline    = true;
                route.PublishedOn = DateTimeOffset.UtcNow;

                route = await _routeRepository.UpdateRouteAsync(route);
            }

            var result = new PublishResponse
            {
                Compilation = compilationResult,
                Route       = RouteResponse.Map(route)
            };

            // Return an error response if compile was unsuccessful, otherwise the response was successful.
            return(Content(compilationResult.Success ? HttpStatusCode.OK : HttpStatusCode.InternalServerError, result));
        }
Пример #4
0
        public async Task <RouteResponse> PostCreateRouteAsync(RouteRequest routeRequest)
        {
            // We'll use the patch method to set the properties values from the request to a new internal Route class.
            var userId = User.GetUserId();
            var route  = new Route();

            routeRequest.Patch(route);

            route = await _routeRepository.CreateRouteAsync(route, userId);

            return(RouteResponse.Map(route));
        }