ATMLWorkBench.servers.DocumentServer.processDocument C# (CSharp) Method

processDocument() private method

private processDocument ( HttpProcessor p ) : void
p ATMLUtilitiesLibrary.HttpProcessor
return void
        private void processDocument( HttpProcessor p )
        {
            const string key = "uuid";
            const string name = "name";
            Document document;
            string uuid = "";
            string fileName = "";
            Dictionary<String, String> properties = p.Properties;
            if (!properties.ContainsKey( key ) && !properties.ContainsKey( name ))
                throw new Exception( "Missing uuid or name" );
            if (properties.ContainsKey( key ))
                uuid = properties[key];
            if (properties.ContainsKey( name ))
                fileName = properties[name];
            if (!string.IsNullOrWhiteSpace( uuid ))
                document = DocumentManager.GetDocument( uuid );
            else
                document = DocumentManager.GetDocumentByName( fileName );

            if (document == null)
                throw new Exception( String.Format( "Document \"{0}\" was not found.", uuid ) );
            p.httpHeaders.Add( "Content-Type", document.ContentType );
            p.httpHeaders.Add( "Content-Disposition", "Attachment; filename=" + document.name );
            var writer = new BinaryWriter( p.outputStream.BaseStream, Encoding.UTF8 );
            writer.Write( document.DocumentContent );
        }