Esempio n. 1
0
        public void CustomSIFElementEncoding()
        {
            SIF_Query q = new SIF_Query();

            q.SIF_QueryObject = new SIF_QueryObject(StudentDTD.STUDENTPERSONAL.Name);
            SIF_Conditions conditions = new SIF_Conditions(ConditionType.NONE);

            conditions.AddSIF_Condition("Name[@Type=\"05\"]/LastName", Operators.EQ, "Cookie");
            q.SetSIF_ConditionGroup(ConditionType.NONE, conditions);

            string xml;

            using (StringWriter w = new StringWriter())
            {
                SifWriter writer = new SifWriter(w);
                writer.Write(q);
                writer.Flush();
                writer.Close();
                xml = w.ToString();
            }

            Console.WriteLine(xml);
            // Mainly, just check to make sure that the single quotes didn't get encoded
            int index = xml.IndexOf(""");

            Assert.AreEqual(-1, index, "Single quotes should not be encoded");
        }
Esempio n. 2
0
        public void testSubjectAreaSIF15r1()
        {
            Adk.SifVersion = SifVersion.SIF15r1;
            SchoolCourseInfo sci = new SchoolCourseInfo();
            SubjectAreaList  lst = new SubjectAreaList();

            sci.SubjectAreaList = lst;

            SubjectArea sa = new SubjectArea("13");

            sa.TextValue = "Graphic Arts"; // for SIF 1.x ???
            OtherCodeList ocl = new OtherCodeList();

            ocl.Add(new OtherCode(Codeset.TEXT, "Graphic Arts"));
            sa.OtherCodeList = ocl;
            lst.Add(sa);

            StringWriter sw   = new StringWriter();
            SifWriter    sifw = new SifWriter(sw);

            sifw.Write(sci);
            sifw.Flush();
            sifw.Close();

            String xml = sw.ToString();

            Console.WriteLine(xml);

            int found = xml.IndexOf(">Graphic Arts</SubjectArea>");

            Assertion.Assert(found > -1);
        }
Esempio n. 3
0
        public static T WriteParseAndReturn<T>(T o, SifVersion version, SchemaValidator validator, bool echoOut)
            where T : SifElement
        {
            T returnVal;

            if ( o is SifMessagePayload )
            {
                o.SifVersion = version;
            }


            SifWriter echo = null;
            if ( echoOut )
            {
                //   Write the object to System.out
                Console.WriteLine( "Writing object : " + o.ElementDef.Name + " using SIFVersion: " + version.ToString() );

                echo = new SifWriter( Console.Out );
                echo.Write( o, version );
            }

            //  Write the object to a file
            Console.WriteLine( "Writing to file... test.xml" );

            using ( Stream fos = File.Open( "test.xml", FileMode.Create, FileAccess.Write ) )
            {
                SifWriter writer = new SifWriter( fos );
                writer.Write( o, version  );
                writer.Flush();
                writer.Close();
                fos.Close();
            }


            if ( validator != null )
            {
                Validate( "test.xml", validator );
            }

            //  Parse the object from the file
            Console.WriteLine( "Parsing from file..." );
            SifParser p = SifParser.NewInstance();
            using ( Stream fis = File.OpenRead( "test.xml" ) )
            {
                returnVal = (T) p.Parse( fis, null );
                fis.Close();
            }


            //  Write the parsed object to System.out
            returnVal.SetChanged( true );
            Console.WriteLine( "Read object : " + returnVal.ElementDef.Name );
            if ( echoOut )
            {
                echo.Write( returnVal, version );
                echo.Flush();
            }
             
            return returnVal;
        }
Esempio n. 4
0
        /**
         * @param sp
         * @param mappings
         * @param map
         * @throws AdkMappingException
         */

        private void MapOutbound(StudentPersonal sp, Mappings mappings, IDictionary map)
        {
            StringMapAdaptor adaptor = new StringMapAdaptor(map);

            mappings.MapOutbound(adaptor, sp);

            SifWriter writer = new SifWriter(Console.Out);

            writer.Write(sp);
            writer.Flush();
            writer.Close();
        }
Esempio n. 5
0
 public static void WriteObject(SifVersion writeVersion, string fileName, SifMessagePayload smp)
 {
     using (FileStream outputStream = new FileStream(fileName, FileMode.Create))
     {
         SifWriter writer = new SifWriter(outputStream);
         smp.SetChanged(true);
         smp.SifVersion = writeVersion;
         writer.Write(smp);
         writer.Flush();
         writer.Close();
         outputStream.Close();
     }
 }
        //public string Send(string msg)
        //{
        //   lock (this)
        //   {
        //      fMessages.AddLast(msg);
        //   }
        //   return makeAck();
        //}

        public IMessageInputStream Send( IMessageOutputStream msg )
        {
            lock ( this )
            {
                try
                {
                    MemoryStream stream = new MemoryStream();
                    msg.CopyTo( stream );
                    stream.Seek( 0, SeekOrigin.Begin );
                    SifParser parser = SifParser.NewInstance();
                    SifMessagePayload smp = (SifMessagePayload) parser.Parse( stream, fZone );

                    fMessages.Add( smp );
                    parser = null;

                    SIF_Ack ack = smp.ackStatus( 0 );
                    SIF_Header hdr = ack.Header;
                    hdr.SIF_Timestamp = DateTime.Now;
                    hdr.SIF_MsgId = Adk.MakeGuid();
                    hdr.SIF_SourceId = fZone.Agent.Id;

                    StringWriter str = new StringWriter();
                    SifWriter writer = new SifWriter( str );
                    writer.Write( ack );
                    writer.Flush();
                    writer.Close();
                    writer = null;
                    return new MessageStreamImpl( str.ToString() );
                }
                catch( Exception ex )
                {
                    // Possible error parsing. Write the message to console out
                    Console.Out.WriteLine(msg.Decode());
                    throw new AdkMessagingException(ex.Message, fZone, ex);
                }
            }
        }
Esempio n. 7
0
        /// <summary>  Calculate the size of a SIF_Response minus the SIF_ObjectData content.</summary>
        protected virtual long CalcEnvelopeSize(ZoneImpl zone)
        {
            long size = 400;

            try {
                SIF_Response rsp = new SIF_Response();
                rsp.SIF_MorePackets  = "Yes";
                rsp.SIF_RequestMsgId = fReqId;
                rsp.SIF_PacketNumber = 100000000;
                SIF_ObjectData data = new SIF_ObjectData();
                data.TextValue     = " ";
                rsp.SIF_ObjectData = data;

                SIF_Header hdr = rsp.Header;

                hdr.SIF_Timestamp     = DateTime.Now;
                hdr.SIF_MsgId         = "012345678901234567890123456789012";
                hdr.SIF_SourceId      = zone.Agent.Id;
                hdr.SIF_Security      = zone.Dispatcher.secureChannel();
                hdr.SIF_DestinationId = fDestId;

                using (MemoryStream buffer = new MemoryStream()) {
                    SifWriter writer = new SifWriter(buffer);
                    writer.Write(rsp);
                    writer.Flush();
                    size = buffer.Length + 10;
                    writer.Close();
                    buffer.Close();
                }
            }
            catch (Exception ex) {
                zone.Log.Warn("Error calculating packet size: " + ex, ex);
            }

            return(size);
        }
Esempio n. 8
0
        /// <summary>  Called when the Publisher.OnQuery method has thrown a SifException,
        /// indicating an error should be returned in the SIF_Response body
        /// </summary>
        public override void SetError(SIF_Error error)
        {
            fError = error;

            //
            //  Write a SIF_Response packet that contains only this SIF_Error
            //
            try
            {
                NewPacket();
                SifWriter writer = new SifWriter(fCurrentOutputStream);
                writer.SuppressNamespace(true);
                writer.Write(error, fRenderAsVersion);
                writer.Close();
            }
            catch (IOException ioe)
            {
                throw new AdkException
                      (
                          "Failed to write Publisher SIF_Error data (packet " + fCurPacket + ") to " +
                          fFile.FullName + ": " +
                          ioe, fZone);
            }
        }
Esempio n. 9
0
        public static SifElement WriteParseAndReturn( 
            SifElement o,
            SifVersion version,
            SchemaValidator validator, 
            Boolean echoOut )
        {
            SifElement returnVal;

            if ( o is SifMessagePayload )
            {
                o.SifVersion = version;
            }

            SifWriter echo = null;

            if ( echoOut )
            {
                //   Write the object to System.out
                Console.WriteLine( "Writing object : " + o.ElementDef.Name
                                   + " using SIFVersion: " + version.ToString() );

                echo = new SifWriter( Console.Out );
                echo.Write( o, version );
                echo.Flush();
                Console.Out.Flush();
                
            }

            //  Write the object to a file
            Console.WriteLine( "Writing to file... test.xml" );
            using (Stream fos = new FileStream("test.xml", FileMode.Create))
            {
                SifWriter writer = new SifWriter( new StreamWriter( fos, Encoding.UTF8 ) );
                o.SetChanged( true );
                writer.Write( o, version );
                writer.Flush();
                writer.Close();
                fos.Close();
            }

            if ( validator != null )
            {
                Validate( "test.xml", validator );
            }

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

            FileStream fr = new FileStream( "test.xml", FileMode.Open );

            StreamReader inStream = new StreamReader( fr, Encoding.UTF8 );


            returnVal = p.Parse( inStream, null, 0, version );

            inStream.Close();
            fr.Close();
            //  Write the parsed object to System.out
            returnVal.SetChanged( true );
            Console.WriteLine( "Read object : " + returnVal.ElementDef.Name );
            if ( echoOut )
            {
                echo.Write( returnVal, version );
                echo.Flush();
            }


            return returnVal;
        }
        /// <summary>  Called when the Publisher.OnQuery method has thrown a SifException,
        /// indicating an error should be returned in the SIF_Response body
        /// </summary>
        public override void SetError( SIF_Error error )
        {
            fError = error;

            //
            //  Write a SIF_Response packet that contains only this SIF_Error
            //
            try
            {
                NewPacket();
                SifWriter writer = new SifWriter( fCurrentOutputStream );
                writer.SuppressNamespace( true );
                writer.Write( error, fRenderAsVersion );
                writer.Close();
            }
            catch ( IOException ioe )
            {
                throw new AdkException
                    (
                    "Failed to write Publisher SIF_Error data (packet " + fCurPacket + ") to " +
                    fFile.FullName + ": " +
                    ioe, fZone );
            }
        }
        /// <summary>  Calculate the size of a SIF_Response minus the SIF_ObjectData content.</summary>
        protected virtual long CalcEnvelopeSize( ZoneImpl zone )
        {
            long size = 400;

            try {
                SIF_Response rsp = new SIF_Response();
                rsp.SIF_MorePackets = "Yes";
                rsp.SIF_RequestMsgId = fReqId;
                rsp.SIF_PacketNumber = 100000000;
                SIF_ObjectData data = new SIF_ObjectData();
                data.TextValue = " ";
                rsp.SIF_ObjectData = data;

                SIF_Header hdr = rsp.Header;

                hdr.SIF_Timestamp = DateTime.Now;
                hdr.SIF_MsgId = "012345678901234567890123456789012";
                hdr.SIF_SourceId = zone.Agent.Id;
                hdr.SIF_Security = zone.Dispatcher.secureChannel();
                hdr.SIF_DestinationId = fDestId;

                using ( MemoryStream buffer = new MemoryStream() ) {
                    SifWriter writer = new SifWriter( buffer );
                    writer.Write( rsp );
                    writer.Flush();
                    size = buffer.Length + 10;
                    writer.Close();
                    buffer.Close();
                }
            }
            catch( Exception ex ) {
                zone.Log.Warn( "Error calculating packet size: " + ex, ex );
            }

            return size;
        }