Exemplo n.º 1
0
            internal int GetMatchingParts(HttpProcessUtility.MediaType candidate)
            {
                int num = -1;

                if (candidate != null)
                {
                    if (this.type == "*")
                    {
                        return(0);
                    }
                    if (candidate.subType == null)
                    {
                        return(num);
                    }
                    string type = candidate.type;
                    if (!WebUtil.CompareMimeType(this.type, type))
                    {
                        return(num);
                    }
                    if (this.subType == "*")
                    {
                        return(1);
                    }
                    string subType = candidate.subType;
                    if (WebUtil.CompareMimeType(this.subType, subType) && string.Equals(this.GetParameterValue("odata"), candidate.GetParameterValue("odata"), StringComparison.OrdinalIgnoreCase))
                    {
                        num = 2;
                    }
                }
                return(num);
            }
Exemplo n.º 2
0
        /// <summary>Creates a delegate that can serialize an error for the specified arguments.</summary>
        /// <param name="args">Arguments for the exception being handled.</param>
        /// <param name="encoding">Encoding to created over stream.</param>
        /// <returns>A delegate that can serialize an error for the specified arguments.</returns>
        private static Action <Stream> CreateErrorSerializer(HandleExceptionArgs args, Encoding encoding)
        {
            Debug.Assert(args != null, "args != null");
            Debug.Assert(encoding != null, "encoding != null");
            ErrorHandler handler = new ErrorHandler(args, encoding);

            if (WebUtil.CompareMimeType(args.ResponseContentType, XmlConstants.MimeApplicationJson))
            {
                return(handler.SerializeJsonErrorToStream);
            }
            else
            {
                return(handler.SerializeXmlErrorToStream);
            }
        }
Exemplo n.º 3
0
        internal static void SerializeODataError(HandleExceptionArgs args, ODataMessageWriter writer, Stream outputStream, Encoding encoding)
        {
            ODataError error = CreateODataErrorFromExceptionArgs(args);

            try
            {
                writer.WriteError(error, args.UseVerboseErrors);
            }
            catch (InvalidOperationException)
            {
                if (!WebUtil.CompareMimeType(args.ResponseContentType, "application/json;odata=verbose"))
                {
                    WebUtil.Dispose(writer);
                    using (XmlWriter writer2 = XmlWriter.Create(outputStream, XmlUtil.CreateXmlWriterSettings(encoding)))
                    {
                        ErrorUtils.WriteXmlError(writer2, error, args.UseVerboseErrors, 100);
                    }
                }
            }
        }
Exemplo n.º 4
0
        internal static string SelectRequiredMimeType(string acceptTypesText, string[] exactContentType, string inexactContentType)
        {
            string str   = null;
            int    num   = -1;
            int    num2  = 0;
            bool   flag  = false;
            bool   flag2 = true;
            bool   flag3 = false;

            if (!string.IsNullOrEmpty(acceptTypesText))
            {
                foreach (MediaType type in MimeTypesFromAcceptHeader(acceptTypesText))
                {
                    flag2 = false;
                    for (int i = 0; i < exactContentType.Length; i++)
                    {
                        if (WebUtil.CompareMimeType(type.MimeType, exactContentType[i]))
                        {
                            str   = exactContentType[i];
                            num2  = type.SelectQualityValue();
                            flag  = num2 != 0;
                            flag3 = true;
                            break;
                        }
                    }
                    if (flag3)
                    {
                        break;
                    }
                    int matchingParts = type.GetMatchingParts(inexactContentType);
                    if (matchingParts >= 0)
                    {
                        if (matchingParts > num)
                        {
                            str  = inexactContentType;
                            num  = matchingParts;
                            num2 = type.SelectQualityValue();
                            flag = num2 != 0;
                        }
                        else if (matchingParts == num)
                        {
                            int num5 = type.SelectQualityValue();
                            if (num5 > num2)
                            {
                                str  = inexactContentType;
                                num2 = num5;
                                flag = num2 != 0;
                            }
                        }
                    }
                }
            }
            if (!flag && !flag2)
            {
                throw System.Data.Services.Error.HttpHeaderFailure(0x19f, System.Data.Services.Strings.DataServiceException_UnsupportedMediaType);
            }
            if (flag2)
            {
                str = inexactContentType;
            }
            return(str);
        }