Exemple #1
0
        /*
         * (non-Javadoc)
         *
         * @see
         * org.javarosa.core.model.utils.ITreeVisitor#visit(org.javarosa.core.model
         * .DataModelTree)
         */
        public void visit(FormInstance tree)
        {
            nodeSet = "";

            //TreeElement root = tree.getRoot();
            TreeElement root = tree.resolveReference(rootRef);

            xmlns     = root.getAttributeValue("", "xmlns");
            delimeter = root.getAttributeValue("", "delimeter");
            prefix    = root.getAttributeValue("", "prefix");

            xmlns     = (xmlns != null) ? xmlns : " ";
            delimeter = (delimeter != null) ? delimeter : " ";
            prefix    = (prefix != null) ? prefix : " ";

            //Don't bother adding any delimiters, yet. Delimiters are
            //added before tags/data
            theSmsStr = prefix;

            // serialize each node to get it's answers
            for (int j = 0; j < root.getNumChildren(); j++)
            {
                TreeElement tee = root.getChildAt(j);
                String      e   = serializeNode(tee);
                if (e != null)
                {
                    theSmsStr += e;
                }
            }
            theSmsStr = theSmsStr.Trim();
        }
Exemple #2
0
        /// <summary>
        /// Informs any Form that is registered in TFormsList about a specific 'Forms Message'
        /// that is being 'broadcasted'.
        /// </summary>
        /// <remarks>The individual Form can choose to 'listen' to such 'Forms Message' broadcasts
        /// by implementing the Method 'ProcessFormsMessage'. Once this is done, the Forms'
        /// 'ProcessFormsMessage' Method will be called each time a 'Forms Message' broadcast occurs.
        /// </remarks>
        /// <param name="AFormsMessage">An instance of a 'Forms Message'. This can be inspected
        /// for parameters in the Method Body of a Forms' 'ProcessFormsMessage' Method and
        /// the Form can use those to choose whether to react on the Message, or not.</param>
        /// <returns>The Number of Forms that reacted on the 'Forms Message'.</returns>
        public int BroadcastFormMessage(TFormsMessage AFormsMessage)
        {
            System.Windows.Forms.Form FormInstance;
            IDictionaryEnumerator     DictEnum;
            int FormsThatReacted = 0;

            DictEnum = this.GetEnumerator();

            while (DictEnum.MoveNext())
            {
                FormInstance = (System.Windows.Forms.Form)DictEnum.Value;

                var        Type   = FormInstance.GetType();
                MethodInfo Method = Type.GetMethod("ProcessFormsMessage");

                // Does form contain the method "ProcessFormsMessage"?
                // If so, call it.
                if ((Method != null) && ((bool)Method.Invoke(FormInstance, new object[] { AFormsMessage }) == true))
                {
//                    MessageBox.Show("BroadcastFormMessage: FormInstance = " + FormInstance.Name);
                    FormsThatReacted++;
                }
            }

//            MessageBox.Show("FormsThatListened: " + FormsThatListened.ToString());
            return(FormsThatReacted);
        }
Exemple #3
0
        public void init(EvaluationContext c, IConditionExpr conditional, FormInstance instance)
        {
            List <Object> pivots = conditional.pivot(instance, c);

            List <CmpPivot> internalPivots = new List <CmpPivot>();

            foreach (Object p in pivots)
            {
                if (!(p is CmpPivot))
                {
                    throw new UnpivotableExpressionException();
                }
                internalPivots.Add((CmpPivot)p);
            }

            if (internalPivots.Count > 2)
            {
                //For now.
                throw new UnpivotableExpressionException();
            }

            foreach (CmpPivot pivot in internalPivots)
            {
                evaluatePivot(pivot, conditional, c, instance);
            }
        }
Exemple #4
0
 public IDataPayload createSerializedPayload(FormInstance model, IDataReference ref_)
 {
     init();
     rootRef = model.unpackReference2(ref_);
     if (this.serializer == null)
     {
         this.setAnswerDataSerializer(new XFormAnswerDataSerializer());
     }
     model.accept(this);
     if (theXmlDoc != null)
     {
         byte[] form = Encoding.UTF8.GetBytes(XFormSerializer.getString(theXmlDoc));
         if (dataPointers.Count == 0)
         {
             return(new ByteArrayPayload(form, null, IDataPayload_Fields.PAYLOAD_TYPE_XML));
         }
         MultiMessagePayload payload = new MultiMessagePayload();
         payload.addPayload(new ByteArrayPayload(form, null, IDataPayload_Fields.PAYLOAD_TYPE_XML));
         IEnumerator en = dataPointers.GetEnumerator();
         while (en.MoveNext())
         {
             IDataPointer pointer = (IDataPointer)en.Current;
             payload.addPayload(new DataPointerPayload(pointer));
         }
         return(payload);
     }
     else
     {
         return(null);
     }
 }
Exemple #5
0
        public Object eval(FormInstance model, EvaluationContext evalContext)
        {
            Object  aval   = a.eval(model, evalContext);
            Object  bval   = b.eval(model, evalContext);
            Boolean result = false;

            //xpath spec says comparisons only defined for numbers (not defined for strings)
            aval = XPathFuncExpr.toNumeric(aval);
            bval = XPathFuncExpr.toNumeric(bval);

            double fa = ((Double)aval);
            double fb = ((Double)bval);

            switch (op)
            {
            case LT: result = fa < fb; break;

            case GT: result = fa > fb; break;

            case LTE: result = fa <= fb; break;

            case GTE: result = fa >= fb; break;
            }

            return(result);
        }
Exemple #6
0
        public JsonResult SaveFormValue(int instId, List <NormValue> list)
        {
            FormInstance instance = new FormInstance();

            instance.InstId = instId;

            _context.FormInstance.Add(instance);
            _context.SaveChanges();

            foreach (var item in list)
            {
                if (string.IsNullOrWhiteSpace(item.Value))
                {
                    continue;
                }

                FormValue fvalue = new FormValue();
                fvalue.InstId      = instance.Id;
                fvalue.NormId      = item.Id;
                fvalue.ValueString = item.Value;

                _context.FormValue.Add(fvalue);
                _context.SaveChanges();
            }


            return(Json(new { code = 0 }));
        }
Exemple #7
0
 public virtual byte[] serializeInstance(FormInstance model, FormDef formDef)
 {
     //LEGACY: Should remove
     init();
     this.schema = formDef;
     return(serializeInstance(model));
 }
Exemple #8
0
        private void createInstance()
        {
            FormInstance i = new FormInstance();

            i.FormCommencementDate = DateTime.Now;
            i.FormTemplate         = ((Form)SelectedForm).FormTemplates.OrderBy(x => x.VersionDate).Last();
            SelectedFormInstance   = i;
        }
Exemple #9
0
 public void setDestRef(QuestionDef q)
 {
     destRef = FormInstance.unpackReference(q.Bind).clone();
     if (copyMode)
     {
         destRef.add(copyRef.getNameLast(), TreeReference.INDEX_UNBOUND);
     }
 }
Exemple #10
0
        public ActionResult FormInstanceData(int id)
        {
            FormInstance         Instance = _Forms.FormInstances.Where(e => e.FormInstanceID == id).SingleOrDefault();
            List <FieldInstance> Fields   = _Forms.FieldInstances.Where(e => e.FormInstanceID == id).OrderBy(e => e.FieldName).ToList();

            ViewBag.Instance = Instance;
            ViewBag.Fields   = Fields;
            return(View());
        }
Exemple #11
0
 public List <TreeReference> evalNodeset(FormInstance model, EvaluationContext evalContext)
 {
     if (expr is XPathPathExpr)
     {
         return((List <TreeReference>)(((XPathPathExpr)expr).eval(model, evalContext)));
     }
     else
     {
         throw new FatalException("evalNodeset: must be path expression");
     }
 }
Exemple #12
0
 public IDataPayload serializeInstance(FormInstance dm)
 {
     try
     {
         return((new XFormSerializingVisitor()).createSerializedPayload(dm));
     }
     catch (IOException e)
     {
         return(null);
     }
 }
Exemple #13
0
        public Object pivot(FormInstance model, EvaluationContext evalContext, List <Object> pivots, Object sentinal)
        {
            Object aval = a.pivot(model, evalContext, pivots, sentinal);
            Object bval = b.pivot(model, evalContext, pivots, sentinal);

            if (handled(aval, bval, sentinal, pivots) || handled(bval, aval, sentinal, pivots))
            {
                return(null);
            }

            return(this.eval(model, evalContext));
        }
Exemple #14
0
 public JsonResult SaveMetaDescriptions(FormInstance obj)
 {
     if (obj.Form.FormID > 0)
     {
         obj = new FormBll().EditFormMetaDescriptions(obj);
     }
     else
     {
         obj = new FormBll().AddFormMetaDescriptions(obj);
     }
     return(Json(this.CreateResponsePackage <FormInstance>(obj), JsonRequestBehavior.AllowGet));
 }
 public Action <IFieldObject> GetOnFieldChangeDelegate()
 {
     return(f =>
     {
         AddChangedField(f);
         foreach (var action in FormService.GetOnChanges(f.FieldName))
         {
             action(this);
         }
         FormInstance.OnChange(f.FieldName);
     });
 }
Exemple #16
0
 public override System.Object eval(FormInstance model, EvaluationContext evalContext)
 {
     try
     {
         return(expr.eval(model, evalContext));
     }
     catch (XPathException e)
     {
         Console.WriteLine("Relevant expression for " + contextRef.toString(true));
         throw e;
     }
 }
        public override void Run(IPERunArgs args)
        {
            if (args.IsBootup)
            {
                FormInstance = new MainForm(args.Host);
                FormInstance.Show();
                FormInstance.Visible = false;
                return;
            }

            FormInstance.Visible = true;
            FormInstance.BringToFront();
        }
        public AssessmentButtonPage(string selectedItem)
        {
            _friendlyName = selectedItem;

            CreateToolBar();
            CreateErrorLabel();


            _formService = new FormService();

            //Get Form Instance
            _formInstance     = _formService.GetFormInstance(AppDataWallet.SelectedAssessmentMetadata.AssessmentTrackingNumber.ToString(), selectedItem);
            _validationSchema = _formInstance.ValidationSchema;
            //generate Layout Dynamically

            //Set the bar naviagtion
            _pageLayout = new StackLayout();
            StackLayout questionNavigationButtonBarLayout = new StackLayout();

            questionNavigationButtonBarLayout.Orientation = StackOrientation.Horizontal;
            _pageLayout.Children.Add(questionNavigationButtonBarLayout);

            //Create Button list for Navigation
            Button questionButton;

            foreach (FormGroup formGroup in _formInstance.FormModelView.formgroups)
            {
                questionButton                  = new Button();
                questionButton.Text             = formGroup.text;
                questionButton.Clicked         += QuestionButton_Clicked;
                questionButton.CommandParameter = formGroup;
                questionNavigationButtonBarLayout.Children.Add(questionButton);
            }

            //Add Error Message
            _pageLayout.Children.Add(lblErrorMessage);

            //Load First Question
            _formGroup = _formInstance.FormModelView.formgroups[0];
            LoadFirstQuestionByDefault(_formGroup);

            //Final Page Content
            //Content = _pageLayout;
            //scrollView = new ScrollView();
            Content = _pageLayout;

            /*Content = new ScrollView
             * {
             *  Content = _pageLayout
             * };*/
        }
Exemple #19
0
        /*public Layout GetFormLayout(string friendlyName)
         * {
         *  var sl = new StackLayout();
         *
         *  string FormModelJson = _formRepository.GetFormModel(friendlyName);
         *  FormModel view = JsonConvert.DeserializeObject<FormModel>(FormModelJson);
         *
         *  return _layoutGenerator.GenerateLayout(view);
         * }*/

        public FormInstance GetFormInstance(string friendlyName)
        {
            FormInstanceData formInstanceData = new FormInstanceData();

            formInstanceData = _formRepository.GetFormInstance(friendlyName);

            FormInstance formInstance = new FormInstance();

            formInstance.FormModelView    = JsonConvert.DeserializeObject <FormModel>(formInstanceData.FormModel);
            formInstance.FormData         = formInstanceData.FormData;
            formInstance.ValidationSchema = formInstanceData.ValidationSchema;
            //formInstance.FormModelLayout = _layoutGenerator.GenerateLayout(formInstance.FormModelView, formInstance.FormData);
            return(formInstance);
        }
        /**
         * deserialize a compact instance. note the retrieval of the template data instance
         */
        public void readExternal(BinaryReader in_renamed, PrototypeFactory pf)
        {
            int formID = ExtUtil.readInt(in_renamed);

            instance = getTemplateInstance(formID).clone();

            instance.ID = (ExtUtil.readInt(in_renamed));
            instance.setDateSaved((DateTime)ExtUtil.read(in_renamed, new ExtWrapNullable(typeof(DateTime))));
            //formID, name, schema, versions, and namespaces are all invariants of the template instance

            TreeElement root = instance.getRoot();

            readTreeElement(root, in_renamed, pf);
        }
Exemple #21
0
        public Object pivot(FormInstance model, EvaluationContext evalContext, List <Object> pivots, Object sentinal)
        {
            TreeReference out_ = this.getReference();

            //Either concretely the sentinal, or "."
            if (out_.Equals(sentinal) || (out_.getRefLevel() == 0))
            {
                return(sentinal);
            }
            else
            {
                return(this.eval(model, evalContext));
            }
        }
Exemple #22
0
        public void apply(FormInstance instance, EvaluationContext evalContext, FormDef f)
        {
            Object result = eval(instance, evalContext);

            for (int i = 0; i < targets.Count; i++)
            {
                TreeReference        targetRef = ((TreeReference)targets[i]).contextualize(evalContext.ContextRef);
                List <TreeReference> v         = instance.expandReference(targetRef);
                for (int j = 0; j < v.Count; j++)
                {
                    TreeReference affectedRef = (TreeReference)v[j];
                    apply(affectedRef, result, instance, f);
                }
            }
        }
Exemple #23
0
        private void generateInstance()
        {
            if (_template == null)
            {
                return;
            }
            RaisePropertyChanged("FormWidth");
            RaisePropertyChanged("FormHeight");
            _template.Rows    = RowString;
            _template.Columns = ColumnString;
            FormInstance i = new FormInstance();

            i.FormCommencementDate = DateTime.Now;
            i.FormTemplate         = _template;
            FormInstance           = i;
        }
 private FormInstance getTemplateInstance(int formID)
 {
     if (templateMgr != null)
     {
         return(templateMgr.getTemplateInstance(formID));
     }
     else
     {
         FormInstance template = loadTemplateInstance(formID);
         if (template == null)
         {
             throw new SystemException("no formdef found for form id [" + formID + "]");
         }
         return(template);
     }
 }
Exemple #25
0
        public FormInstance ConvertToFormInstance(TaxYearDefinition taxYear)
        {
            var formDef      = taxYear.Forms["1099-INT"];
            var numberValues = new Dictionary <string, decimal>()
            {
                { nameof(InterestIncome), InterestIncome },
                { nameof(TaxExemptInterest), TaxExemptInterest },
            };
            var stringValues = new Dictionary <string, string>()
            {
                { nameof(PayerNameAndAddress), PayerNameAndAddress },
            };
            var formInst = new FormInstance(formDef, numberValues, stringValues);

            return(formInst);
        }
        public void LoadFormSections()
        {
            DoWhileLoading(() =>
            {
                //forcing enumeration up front
                var sections          = FormService.GetFormMetadata(RecordType).FormSections.ToArray();
                var sectionViewModels = new List <SectionViewModelBase>();
                //Create the section view models

                foreach (var section in sections)
                {
                    if (section is FormFieldSection)
                    {
                        sectionViewModels.Add(new FieldSectionViewModel(
                                                  FormController,
                                                  (FormFieldSection)section,
                                                  this
                                                  ));
                    }
                    else if (section is SubGridSection)
                    {
                        sectionViewModels.Add(new GridSectionViewModel(
                                                  FormController,
                                                  (SubGridSection)section,
                                                  this
                                                  ));
                    }
                }
                //we need to populate the RecordFields property with the generated field view models
                _recordFields = new List <FieldViewModelBase>();
                foreach (var formSection in sectionViewModels.Where(fs => fs is FieldSectionViewModel).Cast <FieldSectionViewModel>()
                         )
                {
                    _recordFields.AddRange(formSection.Fields);
                }
                //now set the section view model property in the ui thread which will notify the ui with the sections
                SendToDispatcher(
                    () => { FormSectionsAsync = new ObservableCollection <SectionViewModelBase>(sectionViewModels); });
                RefreshVisibility();

                FormInstance.OnLoad(this);
                SaveButtonViewModel.IsVisible   = true;
                CancelButtonViewModel.IsVisible = true;
            });
        }
Exemple #27
0
        public override Object eval(FormInstance model, EvaluationContext evalContext)
        {
            Object  aval = XPathFuncExpr.unpack(a.eval(model, evalContext));
            Object  bval = XPathFuncExpr.unpack(b.eval(model, evalContext));
            Boolean eq   = false;

            if (aval is Boolean || bval is Boolean)
            {
                if (!(aval is Boolean))
                {
                    aval = XPathFuncExpr.toBoolean(aval);
                }
                else if (!(bval is Boolean))
                {
                    bval = XPathFuncExpr.toBoolean(bval);
                }

                Boolean ba = ((Boolean)aval);
                Boolean bb = ((Boolean)bval);
                eq = (ba == bb);
            }
            else if (aval is Double || bval is Double)
            {
                if (!(aval is Double))
                {
                    aval = XPathFuncExpr.toNumeric(aval);
                }
                else if (!(bval is Double))
                {
                    bval = XPathFuncExpr.toNumeric(bval);
                }

                double fa = ((Double)aval);
                double fb = ((Double)bval);
                eq = Math.Abs(fa - fb) < 1.0e-12;
            }
            else
            {
                aval = XPathFuncExpr.ToString(aval);
                bval = XPathFuncExpr.ToString(bval);
                eq   = (aval.Equals(bval));
            }

            return((Boolean)(equal ? eq : !eq));
        }
        /*public Layout GetFormLayout(string FormModelJson)
         * {
         *  var sl = new StackLayout();
         *
         *  //string FormModelJson = _formRepository.GetFormModel(friendlyName);
         *  FormModel view = JsonConvert.DeserializeObject<FormModel>(FormModelJson);
         *
         *  return _layoutGenerator.GenerateLayout(view);
         * }*/


        public List <FormInstance> GetAllForms(string trackingNumber)
        {
            List <FormInstance>     formInstances    = new List <FormInstance>();
            List <FormInstanceData> allFormInstances = _formRepository.GetAllForms(trackingNumber);

            foreach (FormInstanceData formInstanceData in allFormInstances)
            {
                FormInstance formInstance = new FormInstance();
                formInstance.FriendlyName     = formInstanceData.FriendlyName;
                formInstance.FormModelView    = JsonConvert.DeserializeObject <FormModel>(formInstanceData.FormModel);
                formInstance.FormData         = formInstanceData.FormData;
                formInstance.ValidationSchema = formInstanceData.ValidationSchema;

                formInstances.Add(formInstance);
            }

            return(formInstances);
        }
        public FormInstance CreateFormInstance(string formId, string personId, string encounterId, string formContext, string formContextId)
        {
            FormInstance formInstance = new FormInstance()
            {
                FormInstanceId     = Guid.NewGuid().ToString(),
                FormId             = formId,
                PersonId           = personId,
                EncounterId        = encounterId,
                FormContext        = formContext,
                FormContextId      = formContextId,
                LastUpdateDateTime = DateTime.Now,
                Status             = "InProgress"
            };

            string formInstanceJSON = PostObject("dcs", "forminstance", formInstance);

            return(formInstance);
        }
 private void memoize()
 {
     if (payload == null)
     {
         IStorageUtility instances = StorageManager.getStorage(FormInstance.STORAGE_KEY);
         try
         {
             FormInstance tree = (FormInstance)instances.read(recordId);
             payload = serializer.createSerializedPayload(tree);
         }
         catch (IOException e)
         {
             //Assertion, do not catch!
             Console.WriteLine(e.StackTrace);
             throw new SystemException("ModelReferencePayload failed to retrieve its model from rms [" + e.Message + "]");
         }
     }
 }