Esempio n. 1
0
        private void verfiyValueList(SIEEFieldlist fieldlist, string fieldname, string value, int count)
        {
            SIEEField field = fieldlist.GetFieldByName(fieldname);

            Assert.AreEqual(value, field.Value);
            Assert.AreEqual(count, field.ValueList.Count);
        }
        private void setFieldValue(SIEEFieldlist fieldlist, Field dataPoolField)
        {
            // Get field mapping. Normally the field is mapped by OCC.
            // For unit test it may also be set by FieldMapping4UnitTest
            CustomExportDestinationField edf = null;

            if (FieldMapping4UnitTest_Contains(dataPoolField.Name))
            {
                edf = new CustomExportDestinationField()
                {
                    Name = dataPoolField.Name
                }
            }
            ;
            else
            {
                edf = this.writerSettings.FieldsMapper.GetExternalField(dataPoolField);
            }

            if (edf == null)
            {
                return;
            }

            SIEEField field = fieldlist.GetFieldByName(edf.Name);

            if (field == null)
            {
                return;
            }
            field.Value = dataPoolField.Value;
            if (field.Cardinality != 0)
            {
                int cnt = 0;
                foreach (IField f in dataPoolField.Fields)
                {
                    if (field.Cardinality < 0 || cnt++ < field.Cardinality) // Cardinality < 0: infinite
                    {
                        field.ValueList.Add(f.Value);
                    }
                }

                if (field.Cardinality > 0 && dataPoolField.Fields.Count > field.Cardinality)
                {
                    SIEEExport.Trace.WriteError(
                        "Value list truncated. Field=" + edf.Name +
                        " Cardinality=" + field.Cardinality +
                        " FieldCcount=" + dataPoolField.Fields.Count
                        );
                }
            }
        }
Esempio n. 3
0
        public void t03_WorkWithSchema()
        {
            SIEEFieldlist schema = new SIEEFieldlist();

            Assert.IsNotNull(schema);

            schema.Add(new SIEEField("1", "ex1", "value1"));
            schema.Add(new SIEEField("2", "ex2", "value2"));
            schema.Add(new SIEEField("3", "ex3", "value3"));

            bool b = schema.Exists("2");

            Assert.IsTrue(b);

            SIEEField f = schema.GetFieldByName("2");

            Assert.AreEqual("2", f.Name);

            f = schema.GetFieldByName("x");
            Assert.IsNull(f);

            schema.MakeFieldnamesOCCCompliant();
        }
Esempio n. 4
0
        public void t02_SerializeSchemaToXML()
        {
            SIEEFieldlist s1 = new SIEEFieldlist();

            s1.Add(new SIEEField("1", "ex1", "value1"));
            s1.Add(new SIEEField("2", "ex2", "value2"));
            s1.Add(new SIEEField("3", "ex3", "value3"));

            SIEEFieldlist s2 = new SIEEFieldlist();

            s2.Add(new SIEEField("1.1", "ex1.1", "value1.1"));
            s2.Add(new SIEEField("1.2", "ex1.2", "value1.2"));

            s1.Add(new SIEETableField("4", "ex4", "value4", s2));

            string ser = Serializer.SerializeToXmlString(s1, System.Text.Encoding.Unicode);

            SIEEFieldlist deser = (SIEEFieldlist)Serializer.DeserializeFromXmlString(ser, typeof(SIEEFieldlist), System.Text.Encoding.Unicode);

            SIEEField f1 = deser.GetFieldByName("1");

            Assert.AreEqual("value1", f1.Value);
            SIEEField f2 = deser.GetFieldByName("2");

            Assert.AreEqual("2", f2.Name);
            SIEEField f3 = deser.GetFieldByName("3");

            Assert.AreEqual("ex3", f3.ExternalId);

            SIEETableField f4 = deser.GetFieldByName("4") as SIEETableField;

            Assert.AreEqual("ex4", f4.ExternalId);

            SIEEField f5 = f4.Columns[0];

            Assert.AreEqual("value1.1", f5.Value);
        }
        /// This is the core function that copies the field values from an OCC datapool document into an SIEEFieldlist.
        /// Input is a fieldlist as derived from the Schema. This means it contains all Schema fields. In the document
        /// there may (a) be additional fields and (b) the might be no field connected to a given Schema field.
        /// Additional fields are simply ingnored. Fields in the fieldlist that have no correspondence in the document
        /// are left unchanged. That means, if the field has a value that that is passed to the export. Normally schema
        /// fields should have "null" assigned to the Value property of a fields. The SIEEExport function needs to
        /// handle this case.
        private SIEEDocument documentToFieldlist(SIEEFieldlist fieldlist, Document doc, string batchId, string profile)
        {
            CustomExportDestinationField edf;
            CustomExportDestinationTable edt;

            foreach (Field dataPoolField in doc.Fields)
            {
                if (dataPoolField is LookupList)
                {
                    foreach (Field dataPoolSubfield in dataPoolField.Fields)
                    {
                        setFieldValue(fieldlist, dataPoolSubfield);
                    }
                    continue;
                }
                if (dataPoolField is Table)
                {
                    edt = this.writerSettings.FieldsMapper.GetExternalTable((Table)dataPoolField);
                    if (edt == null)
                    {
                        continue;
                    }
                    SIEETableField tf = (SIEETableField)fieldlist.GetFieldByName(edt.Name);
                    if (tf == null)
                    {
                        continue;
                    }
                    FieldCollection rows = ((Table)dataPoolField).Rows;
                    for (int i = 0; i != rows.Count; i++)
                    {
                        TableRow          r      = (TableRow)rows[i];
                        SIEETableFieldRow tf_row = new SIEETableFieldRow();
                        foreach (Field col in r.Columns)
                        {
                            edf = this.writerSettings.FieldsMapper.GetExternalTableCell(((Table)dataPoolField), col);
                            if (edf == null)
                            {
                                continue;
                            }

                            if (tf.ColumnExists(edf.Name))
                            {
                                tf_row.Add(edf.Name, col.Value);
                            }
                        }
                        tf.AddRow(tf_row);
                    }
                    continue;
                }
                // regular field
                setFieldValue(fieldlist, dataPoolField);
            }

            SIEEFieldlist auxFields = new SIEEFieldlist();

            foreach (Field dataPoolField in doc.Fields)
            {
                if (!(dataPoolField is LookupList) && !(dataPoolField is Table))
                {
                    auxFields.Add(new SIEEField(dataPoolField.Name, null, dataPoolField.Value));
                }
            }

            SourceInstance[] si = doc.GetInputSourceInstances();
            Annotation       a  = doc.Annotations["exportName"];

            SIEEDocument document = new SIEEDocument()
            {
                Fieldlist     = fieldlist,
                AuxFields     = auxFields,
                PDFFileName   = doc.GetExportPdfSource().Url,
                InputFileName = si.Length > 0 ? doc.GetInputSourceInstances()[0].Id : "",
                BatchId       = batchId,
                ScriptingName = a?.Value,
                Profile       = profile,
            };

            return(document);
        }