Пример #1
0
        /// <summary>  Create a SIF_Ack for this message.</summary>
        /// <param name="code">The SIF_Status/SIF_Code value
        /// </param>
        /// <returns> A new SIF_Ack instance where the SIF_Status/SIF_Code value is
        /// set to the specified value and SIF_Ack header values are derived
        /// from this message's header values
        /// </returns>
        public virtual SIF_Ack ackStatus(int code)
        {
            SIF_Ack    ack    = new SIF_Ack();
            SIF_Status status = new SIF_Status(code);

            ack.SIF_Status           = status;
            ack.SIF_OriginalMsgId    = MsgId;
            ack.SIF_OriginalSourceId = SourceId;


            SifVersion msgVersion = this.SifVersion;

            if (code == 8 /* Receiver is sleeping */)
            {
                if (msgVersion.Major == 1)
                {
                    // SIF 1.x used SIF_Data for text
                    SIF_Data d = new SIF_Data();
                    d.TextValue     = "Receiver is sleeping";
                    status.SIF_Data = d;
                }
                else
                {
                    status.SIF_Desc = "Receiver is sleeping";
                }
            }

            ack.message = this;

            //  Ack using the same version of SIF as this message
            ack.SifVersion = msgVersion;

            return(ack);
        }
Пример #2
0
        public void TestWriteXSINillMultiple()
        {
            SIF_Data data = new SIF_Data();

            for (int a = 0; a < 3; a++)
            {
                StudentPersonal sp = new StudentPersonal();
                sp.RefId           = Adk.MakeGuid();
                sp.StateProvinceId = "\u06DE55889";
                sp.LocalId         = "987987987987987";
                Name name = new Name(NameType.LEGAL, "Johnson", "Steve");
                sp.Name = name;
                name.SetField(CommonDTD.NAME_TYPE, new SifString(null));
                name.SetField(CommonDTD.NAME_MIDDLENAME, new SifString(null));

                SIF_ExtendedElement see = new SIF_ExtendedElement("FOO", null);
                see.SetField(GlobalDTD.SIF_EXTENDEDELEMENT, new SifString(null));
                see.XsiType = "Integer";
                sp.SIFExtendedElementsContainer.Add(see);

                sp.SetField(StudentDTD.STUDENTPERSONAL_LOCALID, new SifString(null));
                data.AddChild(sp);
            }



            SIF_Data data2 = (SIF_Data)AdkObjectParseHelper.WriteParseAndReturn(data, SifVersion.LATEST, null, true);

            foreach (SifElement child in data2.GetChildList())
            {
                StudentPersonal copy = (StudentPersonal)child;
                Name            name = copy.Name;
                Assert.IsNull(name.Type);
                Assert.IsNull(name.MiddleName);
                Assert.IsNotNull(name.FirstName);
                Assert.IsNotNull(name.LastName);

                // Attributes cannot be represented using xs nil
                SimpleField field = name.GetField(CommonDTD.NAME_TYPE);
                Assert.IsNull(field);


                field = name.GetField(CommonDTD.NAME_MIDDLENAME);
                Assert.IsNotNull(field);
                Assert.IsNull(field.Value);

                SIF_ExtendedElement see = copy.GetSIFExtendedElement("FOO");
                field = see.GetField(GlobalDTD.SIF_EXTENDEDELEMENT);
                Assert.IsNotNull(field);
                Assert.IsNull(field.Value);

                field = copy.GetField(StudentDTD.STUDENTPERSONAL_LOCALID);
                Assert.IsNotNull(field);
                Assert.IsNull(field.Value);
            }
        }
Пример #3
0
        public void TestXsiNill_AllChildrenNilMultiple()
        {
            SIF_Data data = new SIF_Data();

            for (int a = 0; a < 3; a++)
            {
                SchoolInfo            si   = new SchoolInfo();
                AddressableObjectName paon = new AddressableObjectName();
                paon.Description = "The little white school house";
                paon.StartNumber = "321";
                Address      addr = new Address(AddressType.CURRENT, paon);
                GridLocation gl   = new GridLocation();
                gl.SetField(CommonDTD.GRIDLOCATION_PROPERTYEASTING, new SifDecimal(null));
                gl.SetField(CommonDTD.GRIDLOCATION_PROPERTYNORTHING, new SifDecimal(null));
                addr.GridLocation = gl;
                si.AddressList    = new AddressList(addr);

                data.AddChild(si);
            }



            //  Write the object to a file
            Console.WriteLine("Writing to file...");
            using (Stream fos = File.Open("SifWriterTest.Temp.xml", FileMode.Create, FileAccess.Write))
            {
                SifWriter writer = new SifWriter(fos);
                data.SetChanged(true);
                writer.Write(data);
                writer.Flush();
                fos.Close();
            }

            //  Parse the object from the file
            Console.WriteLine("Parsing from file...");
            SifParser p = SifParser.NewInstance();

            using (Stream fis = File.OpenRead("SifWriterTest.Temp.xml"))
            {
                data = (SIF_Data)p.Parse(fis, null);
            }

            foreach (SchoolInfo si in data.GetChildList())
            {
                AddressList al = si.AddressList;
                Assert.IsNotNull(al);

                Address addr = al.ItemAt(0);
                Assert.IsNotNull(addr);

                GridLocation gl = addr.GridLocation;
                Assert.IsNotNull(gl);

                Assert.IsNull(gl.PropertyEasting);
                Assert.IsNull(gl.PropertyNorthing);

                SimpleField sf = gl.GetField(CommonDTD.GRIDLOCATION_PROPERTYEASTING);
                Assert.IsNotNull(sf);
                Assert.IsNull(sf.Value);

                sf = gl.GetField(CommonDTD.GRIDLOCATION_PROPERTYNORTHING);
                Assert.IsNotNull(sf);
                Assert.IsNull(sf.Value);
            }
        }