public MemoryStream WriteStream <T>(T source, bool includeProcessingInformation = true) where T : DocProcessingInstructions { DocBaseInterpreter _DocBaseInterpreter = InstanceLocatorByName <DocBaseInterpreter>(source.DocTypeName, source.solutionVersion); MemoryStream _MemoryStream = new MemoryStream(); if (_DocBaseInterpreter is DocByteInterpreter) { byte[] Docx = ((DocByteInterpreter)_DocBaseInterpreter).WriteByte(source, includeProcessingInformation); _MemoryStream.Write(Docx, 0, Docx.Length); _MemoryStream.Position = 0; return(_MemoryStream); } return(((DocTextInterpreter)_DocBaseInterpreter).WriteText(source, includeProcessingInformation) .AsMemoryStream()); }
public virtual void ProcessRequest(HttpContext context) { // ensure the latest content has been processed & imported ImporterController.TryDocRevImporting(); TemplateFileInfo _TemplateFileInfo = TemplateController.ParseTemplateFileInfo(context); if (!string.IsNullOrWhiteSpace(_TemplateFileInfo.DocTypeName) && !string.IsNullOrWhiteSpace(_TemplateFileInfo.solutionVersion) && !string.IsNullOrWhiteSpace(_TemplateFileInfo.FileName)) { // serve a supporting template file up (the the target Interpreter may need to alter it in some way, qazi-dynamic) InstanceLocatorByName <DocBaseInterpreter>(_TemplateFileInfo.DocTypeName, _TemplateFileInfo.solutionVersion) .ProcessRequest(context); } else { // serve a filled & stored document rendered previously context.Response.DisableKernelCache(); context.Response.Clear(); context.Response.ClearContent(); context.Response.ClearHeaders(); object docData; if (context.Request.Params.AllKeys.Any(m => m == Parm.DocId.ToString())) { docData = DocExchange.LuceneController.GetDocData( context.Request.Params[Parm.DocTypeName], context.Request.Params[Parm.DocId], HttpUtility.UrlDecode(context.Request.Params[Parm.RelayUrl]), long.Parse(context.Request.Params[Parm.LogSequenceNumber] ?? "0")); } else { docData = ((BaseDoc)(context.Request.Params.AllKeys.Any(m => m == Parm.DocCache) ? HttpRuntime.Cache[context.Request.Params[Parm.DocCache]] : Compressor.DecompressFromBase64String(HttpUtility.UrlDecode(context.Request.Params[Parm.DocBin])) .FromBytes <BaseDoc>())); } DocBaseInterpreter _DocBaseInterpreter = null; DocProcessingInstructions _DocProcessingInstructions; //TODO:need to tidy up this code block as its really hard to follow.. In the end, that docData may be a POCO, raw bytes or text... Need to rewrites it's PI here before it's shoved over the repsonse.stream if (docData is BaseDoc) { // get the interpreter & convert docData from poco to its raw form _DocBaseInterpreter = InstanceLocatorByName <DocBaseInterpreter>(((BaseDoc)docData).DocTypeName, ((BaseDoc)docData).solutionVersion); if (_DocBaseInterpreter is DocByteInterpreter) { docData = ((DocByteInterpreter)_DocBaseInterpreter).WriteByte((BaseDoc)docData); } else { docData = ((DocTextInterpreter)_DocBaseInterpreter).WriteText((BaseDoc)docData); } } if (docData is byte[]) { _DocBaseInterpreter = _DocBaseInterpreter ?? LocateInstance((byte[])docData); _DocProcessingInstructions = Instance.ReadDocPI((byte[])docData); docData = Instance.ModPI((byte[])docData, href: DocBaseInterpreter.BuildHref(context, _DocProcessingInstructions.DocTypeName, _DocProcessingInstructions.solutionVersion)); context.Response.BinaryWrite((byte[])docData); } else { _DocBaseInterpreter = _DocBaseInterpreter ?? LocateInstance((string)docData); _DocProcessingInstructions = Instance.ReadDocPI((string)docData); docData = Instance.ModPI((string)docData, href: DocBaseInterpreter.BuildHref(context, _DocProcessingInstructions.DocTypeName, _DocProcessingInstructions.solutionVersion)); context.Response.Write((string)docData); } context.Response.ContentType = _DocBaseInterpreter.ContentInfo.ContentType; context.Response.AddHeader( "content-disposition", string.Format( "attachment; filename=\"{0}\";", DocBaseInterpreter.GetFilename(_DocProcessingInstructions, context.Request.Params["ContentFileExtension"]))); } }