private object AutoProcessIfApplicable(FormSubmission formSub, FormDefinition formDef)
        {
            string autoProc = formDef.AutoProcessor;

            if (autoProc != null)
            {
                var    type       = formDef.AutoProcessorType();
                var    processor  = (IFormAutoProcessor)Container.NewTransientInstance(type);
                bool   successful = false;
                string message    = null;
                object result     = null;
                processor.Process(formSub, out successful, out message, out result);
                if (successful)
                {
                    formSub.AutoProcessing = "Successful";
                    return(result);
                }
                else
                {
                    formSub.AutoProcessing = message;
                    return(null);
                }
            }
            return(null);
        }
        private void GenerateTaskIfApplicable(FormSubmission formSub, FormDefinition formDef)
        {
            IUser user = formDef.UponSubmissionGenerateTaskFor;

            if (user != null)
            {
                //TODO:  Should be assigned to specified user, not to 'me'
                throw new NotImplementedException();
                //var task = TaskService.CreateNewTask(Cluster.Forms.Api.Constants.NewFormSubmission, true, null, formSub);
                //Container.Persist(ref task);
            }
        }
        private object ProcessPdf(PdfReader pr)
        {
            AcroFields     flds    = pr.AcroFields;
            FormSubmission formSub = Container.NewTransientInstance <FormSubmission>();

            foreach (DictionaryEntry entry in flds.Fields)
            {
                string     fieldName = entry.Key.ToString();
                FieldTypes type      = (FieldTypes)flds.GetFieldType(fieldName);
                string     content   = flds.GetField(fieldName);
                formSub.AddFormField(type, fieldName, content);
            }

            //Following code will write the .pdf as a byte array
            var ims = new MemoryStream();
            var ps  = new PdfStamper(pr, ims);

            ps.Close();
            formSub.FormAsBytes = ims.ToArray();

            //TODO:  Guard against 1) the FormCode field not existing 2) There being no FormDefinition for that code

            string formCode = flds.GetField(AppSettings.FieldLabelForFormCode());

            formSub.FormCode = formCode;
            FormDefinition formDef = FormRepository.FindFormDefinitionByCode(formCode);

            Container.Persist(ref formSub);

            //GenerateTaskIfApplicable(formSub, formDef);
            object result = null;

            if (formDef != null)
            {
                result = AutoProcessIfApplicable(formSub, formDef);  //TODO:  Or maybe form submission? Or some standard thank you acknowledgement?
            }
            return(result ?? formSub);
        }