Esempio n. 1
0
        /// <summary>
        /// The method that handle the processing of the sdmx query and orchestrate the
        ///     calls to different building blocks.
        /// </summary>
        /// <param name="input">
        /// The xml containing the SDMX Query
        /// </param>
        /// <param name="controller">
        /// The Controller of the request
        /// </param>
        /// <param name="xmlQualifiedName">
        /// Name of the XML qualified.
        /// </param>
        /// <param name="operation">
        /// The operation.
        /// </param>
        /// <returns>
        /// The queried data in specified format
        /// </returns>
        /// <exception cref="System.ServiceModel.Web.WebFaultException">
        /// Internal server error.
        /// </exception>
        private static Message HandleRequest(Message input, IController <Message, XmlWriter> controller, XmlQualifiedName xmlQualifiedName, SoapOperation operation)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat(CultureInfo.InvariantCulture, "Request: {0}\n", input);
            }

            try
            {
                IStreamController <XmlWriter> streamController = controller.ParseRequest(input);
                WebOperationContext           ctx = WebOperationContext.Current;
                if (ctx == null)
                {
                    _log.Error("Current WebOperationContext is null. Please check service configuration.");
                    throw new WebFaultException(HttpStatusCode.InternalServerError);
                }

                Message message = new SdmxMessageSoap(
                    streamController,
                    xmlQualifiedName: xmlQualifiedName,
                    exceptionHandler: exception => _messageFaultBuilder.BuildException(exception, operation.ToString()));

                return(message);
            }
            catch (Exception e)
            {
                _log.Error(operation.ToString(), e);
                throw _messageFaultBuilder.BuildException(e, operation.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The method that handle the processing of the SDMX query and orchestrate the
        /// calls to different building blocks.
        /// </summary>
        /// <param name="input">The xml containing the query bean</param>
        /// <param name="controller">The Controller of the request</param>
        /// <param name="soapOperation">The SOAP operation.</param>
        /// <returns>
        /// The queried data in specified format
        /// </returns>
        private XmlStreamWrapper HandleRequest(XmlNode input, IController <XmlNode, XmlWriter> controller, SoapOperation soapOperation)
        {
            _logger.DebugFormat(CultureInfo.InvariantCulture, "Received request for {0} for endpoint {1}", soapOperation, this.Endpoint);
            IStreamController <XmlWriter> streamController = controller.ParseRequest(input);

            return(new XmlStreamWrapper(streamController, soapOperation));
        }
 public FilePresentationController(
     IGetDirectoryDelegate getDirectoryDelegate,
     IGetFilenameDelegate getFilenameDelegate,
     IStreamController streamController)
 {
     this.getDirectoryDelegate = getDirectoryDelegate;
     this.getFilenameDelegate  = getFilenameDelegate;
     this.streamController     = streamController;
 }
Esempio n. 4
0
 public StorageController(
     IStreamController streamController,
     IFileController fileController,
     ITraceDelegate traceDelegate = null)
 {
     this.streamController = streamController;
     this.fileController   = fileController;
     this.traceDelegate    = traceDelegate;
 }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SdmxMessageSoap"/> class.
        /// </summary>
        /// <param name="controller">The controller.</param>
        /// <param name="exceptionHandler">The exception handler.</param>
        /// <param name="xmlQualifiedName">Name of the XML qualified.</param>
        public SdmxMessageSoap(IStreamController <XmlWriter> controller, Func <Exception, FaultException> exceptionHandler, XmlQualifiedName xmlQualifiedName)
            : base(controller, exceptionHandler, OperationContext.Current.IncomingMessageVersion)
        {
            if (xmlQualifiedName == null)
            {
                throw new ArgumentNullException("xmlQualifiedName");
            }

            this._xmlQualifiedName = xmlQualifiedName;
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlStreamWrapper"/> class.
        /// </summary>
        /// <param name="controller">
        /// The <see cref="IStreamController{XmlWriter}"/> which will be used at <see cref="WriteXml"/>
        /// </param>
        /// <param name="soapOperation">
        /// The soap Operation.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="controller"/>
        ///   is null
        /// </exception>
        internal XmlStreamWrapper(IStreamController <XmlWriter> controller, SoapOperation soapOperation) : this()
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            this._controller    = controller;
            this._soapOperation = soapOperation;
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlStreamWrapper"/> class.
        /// </summary>
        /// <param name="controller">
        /// The <see cref="IStreamController{XmlWriter}"/> which will be used at <see cref="WriteXml"/> 
        /// </param>
        /// <param name="soapOperation">
        /// The soap Operation.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="controller"/>
        ///   is null
        /// </exception>
        internal XmlStreamWrapper(IStreamController<XmlWriter> controller, SoapOperation soapOperation) : this()
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            this._controller = controller;
            this._soapOperation = soapOperation;
        }
Esempio n. 8
0
        public ProtoBufSerializedStorageController(
            IFileController fileController,
            IStreamController streamController,
            IStatusController statusController,
            ITraceDelegate traceDelegate = null)
        {
            this.fileController   = fileController;
            this.streamController = streamController;
            this.statusController = statusController;

            this.traceDelegate = traceDelegate;
        }
        public DownloadFromResponseAsyncDelegate(
            INetworkController networkController,
            IStreamController streamController,
            IFileController fileController,
            IStatusController statusController)
        {
            this.networkController = networkController;
            this.streamController = streamController;
            this.fileController = fileController;

            this.statusController = statusController;
        }
        public FileValidationController(
            IConfirmDelegate <string> confirmValidationExpectedDelegate,
            IFileController fileController,
            IStreamController streamController,
            IGetHashAsyncDelegate <byte[]> getBytesHashAsyncDelegate,
            IValidationResultController validationResultController,
            IStatusController statusController)
        {
            this.confirmValidationExpectedDelegate = confirmValidationExpectedDelegate;
            this.fileController             = fileController;
            this.streamController           = streamController;
            this.getBytesHashAsyncDelegate  = getBytesHashAsyncDelegate;
            this.validationResultController = validationResultController;
            this.statusController           = statusController;

            validationXml = new XmlDocument {
                PreserveWhitespace = false
            };
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SdmxMessageBase"/> class.
        /// </summary>
        /// <param name="controller">
        /// The controller.
        /// </param>
        /// <param name="exceptionHandler">
        /// The exception handler.
        /// </param>
        /// <param name="messageVersion">
        /// The message version.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// controller
        ///     or
        ///     exceptionHandler
        ///     or
        ///     messageVersion
        /// </exception>
        protected SdmxMessageBase(IStreamController<XmlWriter> controller, Func<Exception, FaultException> exceptionHandler, MessageVersion messageVersion)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException("exceptionHandler");
            }

            if (messageVersion == null)
            {
                throw new ArgumentNullException("messageVersion");
            }

            this._controller = controller;
            this._exceptionHandler = exceptionHandler;
            this._messageVersion = messageVersion;
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SdmxMessageBase"/> class.
        /// </summary>
        /// <param name="controller">
        /// The controller.
        /// </param>
        /// <param name="exceptionHandler">
        /// The exception handler.
        /// </param>
        /// <param name="messageVersion">
        /// The message version.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// controller
        ///     or
        ///     exceptionHandler
        ///     or
        ///     messageVersion
        /// </exception>
        protected SdmxMessageBase(IStreamController <XmlWriter> controller, Func <Exception, FaultException> exceptionHandler, MessageVersion messageVersion)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException("exceptionHandler");
            }

            if (messageVersion == null)
            {
                throw new ArgumentNullException("messageVersion");
            }

            this._controller       = controller;
            this._exceptionHandler = exceptionHandler;
            this._messageVersion   = messageVersion;
        }
Esempio n. 13
0
        /// <summary>
        /// The method that handle the processing of the sdmx query and orchestrate the
        ///     calls to different building blocks.
        /// </summary>
        /// <param name="input">
        /// The xml containing the SDMX Query
        /// </param>
        /// <param name="controller">
        /// The Controller of the request
        /// </param>
        /// <param name="xmlQualifiedName">
        /// Name of the XML qualified.
        /// </param>
        /// <param name="getSoapOperation">
        /// The get SOAP operation.
        /// </param>
        /// <returns>
        /// The queried data in specified format
        /// </returns>
        /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxInternalServerException">
        /// Not initialized correctly
        /// </exception>
        private static Message HandleRequest(Message input, IController <Message, XmlWriter> controller, XmlQualifiedName xmlQualifiedName, SoapOperation getSoapOperation)
        {
            try
            {
                IStreamController <XmlWriter> streamController = controller.ParseRequest(input);
                WebOperationContext           ctx = WebOperationContext.Current;
                if (ctx == null)
                {
                    _log.Error("Current WebOperationContext is null. Please check service configuration.");
                    throw new SdmxInternalServerException("Not initialized correctly");
                }

                Message message = new SdmxMessageSoap(streamController, exception => _messageFaultBuilder.BuildException(exception, getSoapOperation.ToString()), xmlQualifiedName);

                return(message);
            }
            catch (Exception e)
            {
                _log.Error(xmlQualifiedName, e);

                ////return Message.CreateMessage(MessageVersion.Soap11, _messageFaultBuilder.Build(e, xmlQualifiedName.Name), string.Empty);
                throw _messageFaultBuilder.BuildException(e, getSoapOperation.ToString());
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Streams the structural metadata.
        /// </summary>
        /// <param name="schemaVersion">The schema version.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="streamController">The stream controller.</param>
        /// <param name="encoding">The response encoding.</param>
        public static void StreamXml(SdmxSchema schemaVersion, Stream stream, IStreamController<XmlWriter> streamController, Encoding encoding)
        {
            try
            {
                if (schemaVersion.IsXmlFormat())
                {
                    using (var writer = XmlWriter.Create(stream, new XmlWriterSettings { Indent = true, Encoding = encoding }))
                    {
                        var actions = new Queue<Action>();
                        streamController.StreamTo(writer, actions);
                        writer.Flush();
                    }
                }
                else
                {
                    throw new SdmxNotImplementedException(string.Format(CultureInfo.InvariantCulture,"Not supported {0}", schemaVersion.ToEnglishString()));
                }
            }
            catch (SdmxResponseSizeExceedsLimitException e)
            {
                // error is on payload.
                _logger.Warn(e.Message, e);
            }
            catch (SdmxResponseTooLargeException e)
            {
                // error is on payload.
                _logger.Warn(e.Message, e);
            }
            catch (Exception e)
            {
                _logger.Error(e.Message, e);

                // HACK.
                // The following is needed because for some reason WebOperationContext.CreateStreamResponse closes the connection and does not return a
                // status code and/or error message to the user.
                var normalizedException = _builder.Build(e);

                //// Setting the WebOperationContext does not seem to work....
                //// WebOperationContext.Current.OutgoingResponse.StatusCode = normalizedException.StatusCode;
                try
                {
                    HttpContext.Current.Response.StatusCode = (int)normalizedException.StatusCode;
                }
                catch (HttpException ex)
                {
                    _logger.Error(e.Message, ex);

                    // Not much we can do. We already sent the header Throw the original exception.
                    throw e;
                }

                HttpContext.Current.Response.ContentType = "text/html;";
                using (var streamWriter = new StreamWriter(stream))
                {
                    streamWriter.WriteLine("{0} - {1}", normalizedException.Message, normalizedException.Detail);
                    streamWriter.Flush();
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Streams the structural metadata.
        /// </summary>
        /// <param name="schemaVersion">The schema version.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="streamController">The stream controller.</param>
        /// <param name="encoding">The response encoding.</param>
        public static void StreamXml(SdmxSchema schemaVersion, Stream stream, IStreamController <XmlWriter> streamController, Encoding encoding)
        {
            try
            {
                if (schemaVersion.IsXmlFormat())
                {
                    using (var writer = XmlWriter.Create(stream, new XmlWriterSettings {
                        Indent = true, Encoding = encoding
                    }))
                    {
                        var actions = new Queue <Action>();
                        streamController.StreamTo(writer, actions);
                        writer.Flush();
                    }
                }
                else
                {
                    throw new SdmxNotImplementedException(string.Format(CultureInfo.InvariantCulture, "Not supported {0}", schemaVersion.ToEnglishString()));
                }
            }
            catch (SdmxResponseSizeExceedsLimitException e)
            {
                // error is on payload.
                _logger.Warn(e.Message, e);
            }
            catch (SdmxResponseTooLargeException e)
            {
                // error is on payload.
                _logger.Warn(e.Message, e);
            }
            catch (Exception e)
            {
                _logger.Error(e.Message, e);

                // HACK.
                // The following is needed because for some reason WebOperationContext.CreateStreamResponse closes the connection and does not return a
                // status code and/or error message to the user.
                var normalizedException = _builder.Build(e);

                //// Setting the WebOperationContext does not seem to work....
                //// WebOperationContext.Current.OutgoingResponse.StatusCode = normalizedException.StatusCode;
                try
                {
                    HttpContext.Current.Response.StatusCode = (int)normalizedException.StatusCode;
                }
                catch (HttpException ex)
                {
                    _logger.Error(e.Message, ex);

                    // Not much we can do. We already sent the header Throw the original exception.
                    throw e;
                }

                HttpContext.Current.Response.ContentType = "text/html;";
                using (var streamWriter = new StreamWriter(stream))
                {
                    streamWriter.WriteLine("{0} - {1}", normalizedException.Message, normalizedException.Detail);
                    streamWriter.Flush();
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Streams the structural metadata.
        /// </summary>
        /// <param name="schemaVersion">The schema version.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="streamController">The stream controller.</param>
        /// <param name="encoding">The response encoding.</param>
        public static void StreamXml(SdmxSchema schemaVersion, Stream stream, IStreamController<XmlWriter> streamController, Encoding encoding)
        {
            try
            {
                if (schemaVersion.IsXmlFormat())
                {
                    using (var writer = XmlWriter.Create(stream, new XmlWriterSettings { Indent = true, Encoding = encoding }))
                    {
                        var actions = new Queue<Action>();
                        streamController.StreamTo(writer, actions);
                        writer.Flush();
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error(e.Message, e);

                // HACK. 
                // The following is needed because for some reason WebOperationContext.CreateStreamResponse closes the connection and does not return a 
                // status code and/or error message to the user.
                var normalizedException = _builder.Build(e);

                //// Setting the WebOperationContext does not seem to work.... 
                //// WebOperationContext.Current.OutgoingResponse.StatusCode = normalizedException.StatusCode; 
                
                HttpContext.Current.Response.StatusCode = (int)normalizedException.StatusCode;
                HttpContext.Current.Response.ContentType = "text/html;";
                using (var streamWriter = new StreamWriter(stream))
                {
                    streamWriter.WriteLine("{0} - {1}", normalizedException.Message, normalizedException.Detail);
                    streamWriter.Flush();
                }
            }
        }
 /// <summary>
 /// Writes the response.
 /// </summary>
 /// <param name="soapOperation">The SOAP operation.</param>
 /// <param name="controller">The controller.</param>
 /// <returns>The <see cref="Message"/>.</returns>
 private Message WriteResponse(SoapOperation soapOperation, IStreamController<XmlWriter> controller)
 {
     var format = new SoapFormatMessage(soapOperation, _messageFaultBuilder, SoapNamespaces.SdmxV21);
     return this._messageBuilderManager.GetResponse<SdmxMessageSoap, XmlWriter>(format, controller);
 }
Esempio n. 18
0
 /// <summary>
 /// Streams the DSPL structural metadata.
 /// </summary>
 /// <param name="schemaVersion">The schema version.</param>
 /// <param name="stream">The stream.</param>
 /// <param name="streamController">The stream controller.</param>
 /// <param name="encoding">The response encoding.</param>
 /// 
 public static void StreamDspl(Stream stream, IStreamController<DsplDataFormat.Engine.DsplTextWriter> streamController, Encoding encoding)
 {
     try
     {
         using (var writer = new DsplDataFormat.Engine.DsplTextWriter(new StreamWriter(stream, encoding)))
         {
             streamController.StreamTo(writer, new Queue<Action>());
         }
     }
     catch (Exception e)
     {
         _logger.Error(e.Message, e);
         throw _builder.Build(e);
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Streams the CSV  .
        /// </summary>
        /// <param name="schemaVersion">The schema version.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="streamController">The stream controller.</param>
        /// <param name="encoding">The response encoding.</param>
        /// 


        public static void StreamCSV(Stream stream, IStreamController<CSVZip.Engine.CsvZipTextWriter> streamController, Encoding encoding)
        {
            try
            {
                using (var writer = new CSVZip.Engine.CsvZipTextWriter(new StreamWriter(stream, encoding)))
                {
                    streamController.StreamTo(writer, new Queue<Action>());
                    //writer.Flush();
                }
            }
            catch (Exception e)
            {
                _logger.Error(e.Message, e);
                throw _builder.Build(e);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Streams the structural metadata.
        /// </summary>
        /// <param name="schemaVersion">The schema version.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="streamController">The stream controller.</param>
        /// <param name="encoding">The response encoding.</param>
        public static void StreamJson(Stream stream,
                                      IStreamController<Newtonsoft.Json.JsonTextWriter> streamController,
                                      Encoding encoding)
        {
            try
            {
                using (var writer = new Newtonsoft.Json.JsonTextWriter(new StreamWriter(stream, encoding)))
                {
                    streamController.StreamTo(writer, new Queue<Action>());
                    writer.Flush();

                }
            }
            catch (Exception e)
            {
                _logger.Error(e.Message, e);
                throw _builder.Build(e);
            }
        }
Esempio n. 21
0
        public static void StreamJsonZip(Stream stream, IStreamController<Newtonsoft.Json.JsonTextWriter> streamController, Encoding encoding)
        {
            try
            {
                Stream zipStream = new System.IO.Compression.GZipStream(stream,
                                                System.IO.Compression.CompressionMode.Compress);

                using (var writer = new Newtonsoft.Json.JsonTextWriter(new StreamWriter(zipStream, encoding)))
                {
                    streamController.StreamTo(writer, new Queue<Action>());
                    writer.Flush();
                }
            }
            catch (Exception e)
            {
                _logger.Error(e.Message, e);
                throw _builder.Build(e);
            }
        }
Esempio n. 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SdmxMessageRest"/> class.
 /// </summary>
 /// <param name="controller">
 /// The controller.
 /// </param>
 /// <param name="exceptionHandler">
 /// The exception handler.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// controller
 ///     or
 ///     exceptionHandler
 ///     or
 ///     messageVersion
 /// </exception>
 public SdmxMessageRest(IStreamController <XmlWriter> controller, Func <Exception, FaultException> exceptionHandler)
     : base(controller, exceptionHandler, MessageVersion.None)
 {
 }
Esempio n. 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SdmxMessageRest"/> class.
 /// </summary>
 /// <param name="controller">
 /// The controller.
 /// </param>
 /// <param name="exceptionHandler">
 /// The exception handler.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// controller
 ///     or
 ///     exceptionHandler
 ///     or
 ///     messageVersion
 /// </exception>
 public SdmxMessageRest(IStreamController<XmlWriter> controller, Func<Exception, FaultException> exceptionHandler)
     : base(controller, exceptionHandler, MessageVersion.None)
 {
 }
 /// <summary>
 /// Writes the response.
 /// </summary>
 /// <param name="soapOperation">The SOAP operation.</param>
 /// <param name="streamController">The stream controller.</param>
 /// <returns>The <see cref="Message"/>.</returns>
 private Message WriteResponse(SoapOperation soapOperation, IStreamController<XmlWriter> streamController)
 {
     IMessageFormat format = new SoapFormatMessage(soapOperation, this._faultSoapBuilderFactory.GetMessageFaultSoapBuilder(SdmxSchemaEnumType.VersionTwo), this.Ns);
     return this._messageBuilderManager.GetResponse<SdmxMessageSoap, XmlWriter>(format, streamController);
 }