Ejemplo n.º 1
0
        /// <summary>
        /// 初始化策略
        /// </summary>
        /// <param name="contentType">输出文档类型</param>
        private void InitStrategy(string contentType)
        {
            //输出Json格式
            if (ContentType.JSON.Equals(contentType, StringComparison.OrdinalIgnoreCase))
            {
                this._strategy = ResponseJson.GetInstance();
                return;
            }

            //输出Xml格式
            if (ContentType.XML.Equals(contentType, StringComparison.OrdinalIgnoreCase))
            {
                this._strategy = ResponseXml.GetInstance();
                return;
            }

            //表示输出图片或者文件格式的
            if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) || contentType.IndexOf("octet-stream", StringComparison.OrdinalIgnoreCase) > 0)
            {
                this._strategy = ResponseFile.GetInstance();
                return;
            }

            //其余 只需直接输出文本均可
            this._strategy = ResponseString.GetInstance();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化策略
        /// </summary>
        /// <param name="contentType">输出文档类型</param>
        private void InitStrategy(string contentType)
        {
            //输出Json格式
            if (ContentType.JSON.Equals(contentType, StringComparison.OrdinalIgnoreCase))
            {
                this._strategy = ResponseJson.GetInstance();
                return;
            }

            //输出Xml格式
            if (ContentType.XML.Equals(contentType, StringComparison.OrdinalIgnoreCase))
            {
                this._strategy = ResponseXml.GetInstance();
                return;
            }

            //表示输出图片或者文件格式的
            if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase) || contentType.IndexOf("octet-stream", StringComparison.OrdinalIgnoreCase) > 0)
            {
                this._strategy = ResponseFile.GetInstance();
                return;
            }

            //其余 只需直接输出文本均可
            this._strategy = ResponseString.GetInstance();
        }