예제 #1
0
        /// <summary>
        /// Process the request.
        /// </summary>
        /// <remarks>
        /// Assumes that user context has already been set.
        /// </remarks>
        /// <param name="request"></param>
        /// <param name="endpoint"></param>
        /// <returns></returns>
        public ConnectorResponse HandleRequest(ConnectorRequest request, ApiSpreadsheetEndpoint endpoint)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }
            if (request.Verb != ConnectorVerb.Post)
            {
                return(new ConnectorResponse(HttpStatusCode.MethodNotAllowed));
            }

            long importConfigId;

            using (new SecurityBypassContext( ))
            {
                if (endpoint.EndpointImportConfig == null)
                {
                    throw new ConnectorConfigException("Endpoint does not point to an import configuration.");
                }
                importConfigId = endpoint.EndpointImportConfig.Id;
            }

            ImportSettings settings = new ImportSettings
            {
                FileToken      = request.FileUploadToken,
                ImportConfigId = importConfigId,
                TestRun        = false,
                TimeZoneName   = null, // Imports via WebAPI treat values as UTC  (but should they?)
                SuppressSecurityCheckOnImportConfig = true
            };

            // Start import
            try
            {
                _spreadsheetImporter.StartImport(settings);
                return(new ConnectorResponse(HttpStatusCode.OK));
            }
            catch
            {
                return(new ConnectorResponse(HttpStatusCode.InternalServerError));
            }
        }
예제 #2
0
        /// <summary>
        /// Main entry point.
        /// </summary>
        public ConnectorResponse HandleRequest(ConnectorRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            ApiEndpoint            endpoint;
            ApiResourceEndpoint    resourceEndpoint;
            ApiSpreadsheetEndpoint spreadsheetEndpoint = null;

            using (new SecurityBypassContext( ))
            {
                endpoint = GetEndpoint(request);
                if (endpoint == null)
                {
                    return(new ConnectorResponse(HttpStatusCode.NotFound));
                }

                // Check type of endpoint
                resourceEndpoint = endpoint.As <ApiResourceEndpoint>( );

                if (resourceEndpoint == null)
                {
                    spreadsheetEndpoint = endpoint.As <ApiSpreadsheetEndpoint>( );
                }
            }

            if (resourceEndpoint != null)
            {
                ResourceEndpoint resourceEndpointService = _componentContext.Resolve <ResourceEndpoint>( );
                return(resourceEndpointService.HandleRequest(request, resourceEndpoint));
            }
            if (spreadsheetEndpoint != null)
            {
                SpreadsheetEndpoint spreadsheetEndpointService = _componentContext.Resolve <SpreadsheetEndpoint>( );
                return(spreadsheetEndpointService.HandleRequest(request, spreadsheetEndpoint));
            }
            throw new NotImplementedException("Unknown ApiEndpoint type");
        }