Пример #1
0
        /// <summary>
        /// This method prepares the HTTP body based on the browser content encoding settings.
        /// </summary>
        /// <param name="context">The current compile context.</param>
        /// <param name="blob">The UTF-8 formatted byte array.</param>
        /// <returns>Returns a ContentCompilerMessageFragmentBody object containing the prepared output binary data.</returns>
        protected virtual ContentCompilerMessageFragmentBody PrepareBody(ContentCompilerContext context, byte[] blob)
        {
            ContentCompilerMessageFragmentBody
                body = context.GetObjectPool<ContentCompilerMessageFragmentBody>().Get();

            switch (context.Request.Data.RequestPreferredCompression)
            {
                case "gzip":
                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (Stream gz = new GZipStream(ms, CompressionMode.Compress, true))
                        {
                            gz.Write(blob, 0, blob.Length);
                            gz.Close();
                        }
                        ms.Position = 0;
                        body.Load(ms);
                    }
                    body.ContentEncoding = "gzip";
                    break;
                case "deflate":
                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (Stream gz = new DeflateStream(ms, CompressionMode.Compress, true))
                        {
                            gz.Write(blob, 0, blob.Length);
                            gz.Close();
                        }
                        ms.Position = 0;
                        body.Load(ms);
                    }
                    body.ContentEncoding = "deflate";
                    break;
                default:
                    body.Load(blob, 0, blob.Length);
                    break;
            }

            blob = null;

            body.ContentType = context.Request.Data.ResponseOutputMIMEType;

            return body;
        }
        /// <summary>
        /// This method inserts incoming data in to the model.
        /// </summary>
        /// <param name="context">The current context.</param>
        public override void ModelDataLoadInserts(ContentCompilerContext context)
        {
            Insert insert = null;
            try
            {
                insert = context.GetObjectPool<Insert>().Get();
                foreach (XmlElement element in context.ModelData.DataNodes())
                {
                    insert.Reset(element);
                    string status;
                    if (insert.ReferenceValue != null && insert.ReferenceValue != "")
                    {
                        Content outData = null;
                        try
                        {
                            throw new NotImplementedException();
                            //status = context.CDSHelper.Execute(insert.EntityType,
                            //    CDSData.Get(CDSAction.Read, insert.ReferenceType, insert.ReferenceValue),
                            //    out outData);

                            if (status != CH.HTTPCodes.OK_200 && !insert.PermitError)
                                throw new ContentCompilerException(
                                    string.Format("Data load error: {0}/{1}", insert.ReferenceType, insert.ReferenceValue));

                            insert.ResponseStatus = status;

                            if (outData != null)
                            {
                                XmlDocumentFragment frag = element.OwnerDocument.CreateDocumentFragment();
                                frag.InnerXml = ((XmlDocumentContentBase)outData).Payload.LastChild.OuterXml;
                                element.AppendChild(frag);
                            }
                            else if (!insert.PermitError)
                                throw new ArgumentNullException("CDS data is null.");

                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            if (outData != null && outData.ObjectPoolCanReturn)
                                outData.ObjectPoolReturn();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (insert != null && insert.ObjectPoolCanReturn)
                    insert.ObjectPoolReturn();
            }
        }