/**
         *  Sends a SIF_Event
         *  @param zone The zone to send the sifEvent to
         */
        public SIF_Ack SifEvent(IZone zone, Event sifEvent, String destinationId, String sifMsgId)
        {
            if (sifEvent.Data == null || sifEvent.Data.Available == false)
            {
                throw new AdkException("The sifEvent has no SIFDataObjects", zone);
            }

            SIF_ObjectData od = new SIF_ObjectData();

            //  Fill out the SIF_ObjectData
            IDataObjectInputStream inStr = sifEvent.Data;
            SifDataObject          data  = inStr.ReadDataObject();

            SifVersion msgVersion = data.EffectiveSIFVersion;

            SIF_EventObject eo = new SIF_EventObject();

            od.SIF_EventObject = eo;
            eo.Action          = sifEvent.ActionString;
            eo.ObjectName      = data.ElementDef.Tag(msgVersion);

            // Create the SIF_Event object
            SIF_Event msg = new SIF_Event(msgVersion);

            msg.SIF_ObjectData = od;

            SIF_Header msgHdr = msg.Header;

            //	Assign SIF_DestinationId if applicable
            if (destinationId != null)
            {
                msgHdr.SIF_DestinationId = destinationId;
            }

            while (data != null)
            {
                eo.Attach(data);
                data = inStr.ReadDataObject();
            }

            if (sifMsgId != null)
            {
                msgHdr.SIF_MsgId = sifMsgId;
            }

            SifContext[] contexts = sifEvent.Contexts;
            if (contexts == null)
            {
                contexts = new SifContext[] { SifContext.DEFAULT };
            }

            SIF_Contexts msgContexts = new SIF_Contexts();

            foreach (SifContext context in contexts)
            {
                msgContexts.AddSIF_Context(context.Name);
            }
            msgHdr.SIF_Contexts = msgContexts;
            return(((ZoneImpl)zone).Dispatcher.send(msg));
        }
Beispiel #2
0
        private void Log(string fileName,
                         IDataObjectInputStream input,
                         SifMessageInfo info,
                         bool logToConsole)
        {
            try
            {
                // Ensure that the directory is there
                FileInfo file = new FileInfo(fileName);
                file.Directory.Create();
                int numObjects = 0;

                using (Stream outStream = File.OpenWrite(fileName))
                {
                    using (TextWriter twriter = new StreamWriter(outStream, Encoding.UTF8))
                    {
                        twriter.WriteLine("<SIF_ObjectData>");
                        twriter.Flush();
                        SifWriter writer        = new SifWriter(twriter);
                        SifWriter consoleWriter = null;
                        if (logToConsole)
                        {
                            consoleWriter = new SifWriter(Console.Out);
                        }

                        SifDataObject o;
                        while ((o = input.ReadDataObject()) != null)
                        {
                            numObjects++;
                            Track(o);
                            writer.Write(o);
                            if (logToConsole)
                            {
                                consoleWriter.Write(o);
                                Console.WriteLine();
                            }
                        }
                        writer.Flush();
                        if (logToConsole)
                        {
                            consoleWriter.Flush();
                        }
                        twriter.WriteLine("</SIF_ObjectData>");
                    }

                    outStream.Close();

                    Console.WriteLine
                        ("Received {0} objects for {1}, Packet# {2}", numObjects,
                        input.ObjectType.Name, info.PacketNumber);
                }
            }
            catch (Exception ex)
            {
                Adk.Log.Error(ex.Message, ex);
            }
        }
        /// <summary>
        /// This method is called when a response is received to a request made by the Subscriber.
        /// </summary>
        /// <param name="data">The data stream containing the SIF Response.</param>
        /// <param name="error">Error details (if encountered).</param>
        /// <param name="zone">Zone that SIF Response was received.</param>
        /// <param name="info">Information on the received message.</param>
        void IQueryResults.OnQueryResults(IDataObjectInputStream data, SIF_Error error, IZone zone, IMessageInfo info)
        {
            int count = 0;

            // Before reading data from a SIF Response, first check to see if an error was returned.
            if (error != null)
            {
                // The provider returned an error message for this SIF Request.
                if (log.IsErrorEnabled)
                {
                    log.Error("An error was received from the provider of " + SifObjectType.Name + ".");
                }
                if (log.IsErrorEnabled)
                {
                    log.Error(error.SIF_Desc + "\r\n" + error.SIF_ExtendedDesc);
                }
                return;
            }

            // Now, read each object from the DataObjectInputStream until Available returns false.
            while (data.Available)
            {
                count++;
                T sifDataObject = (T)data.ReadDataObject();

                if (PreProcessResponse(sifDataObject, zone))
                {
                    ProcessResponse(sifDataObject, zone);
                }
            }

            // Print out the total number of objects recieved.
            if (log.IsInfoEnabled)
            {
                log.Info(count + " total objects received.");
            }

            // To determine if you have completed receiving all responses, check the
            // MorePackets property of the SIFMessageInfo object
            if (((SifMessageInfo)info).MorePackets)
            {
                if (log.IsInfoEnabled)
                {
                    log.Info("Waiting for more packets...");
                }
            }
            else
            {
                if (log.IsInfoEnabled)
                {
                    log.Info("All requested packets have been received.");
                }
            }
        }
Beispiel #4
0
        public void OnQueryResults(IDataObjectInputStream data,
                                   SIF_Error error,
                                   IZone zone,
                                   IMessageInfo info)
        {
            SifMessageInfo smi = (SifMessageInfo)info;

            if (!(fRequestState.Equals(smi.SIFRequestInfo.UserData)))
            {
                // This is a SIF_ZoneStatus response from a previous invocation of the agent
                return;
            }
            if (data.Available)
            {
                SIF_ZoneStatus zoneStatus = data.ReadDataObject() as SIF_ZoneStatus;
                AsyncUtils.QueueTaskToThreadPool(new zsDelegate(_processSIF_ZoneStatus), zoneStatus, zone);
            }
        }
Beispiel #5
0
        public void OnQueryResults(IDataObjectInputStream data,
                                   SIF_Error error,
                                   IZone zone,
                                   IMessageInfo info)
        {
            // Demonstrates basic handling of a SIF_Query response

            // 1)   To read data from a SIF_Response, first check to see if an error was returned
            if (error != null)
            {
                // The provider returned an error message for this SIF_Request
                Console.WriteLine("An error was received from the provider of LearnerPersonal.");
                Console.WriteLine(error.SIF_Desc + "\r\n" + error.SIF_ExtendedDesc);
                return;
            }

            // 2)   Now, read each object from the DataObjectInputStream until available() returns false
            while (data.Available)
            {
                StudentPersonal sp = (StudentPersonal)data.ReadDataObject();
                fObjectCount++;
                Name stuName = sp.Name;
                Console.WriteLine
                    (fObjectCount + ") Refid:{" + sp.RefId +
                    "} Name: " + stuName.FirstName + " " + stuName.LastName);
            }

            // Demonstration purposes only: print out the total number of objects recieved
            Console.WriteLine(fObjectCount + " total objects received.");


            // 3)	To determine if you have completed receiving all responses, check the
            //      MorePackets property of the SIFMessageInfo object
            if (((SifMessageInfo)info).MorePackets)
            {
                Console.WriteLine("Waiting for more packets...");
            }
            else
            {
                Console.WriteLine("All requested packets have been received");
            }
        }
        public void OnQueryResults( IDataObjectInputStream data,
                                    SIF_Error error,
                                    IZone zone,
                                    IMessageInfo info )
        {
            // Demonstrates basic handling of a SIF_Query response

            // 1) 	To read data from a SIF_Response, first check to see if an error was returned
            if ( error != null )
            {
                // The provider returned an error message for this SIF_Request
                Console.WriteLine( "An error was received from the provider of LearnerPersonal." );
                Console.WriteLine( error.SIF_Desc + "\r\n" + error.SIF_ExtendedDesc );
                return;
            }

            // 2) 	Now, read each object from the DataObjectInputStream until available() returns false
            while ( data.Available )
            {
                StudentPersonal sp = (StudentPersonal) data.ReadDataObject();
                fObjectCount++;
                Name stuName = sp.PersonInfo.Name;
                Console.WriteLine
                    ( fObjectCount + ") Refid:{" + sp.RefId +
                      "} Name: " + stuName.GivenName + " " + stuName.FamilyName );
            }

            // Demonstration purposes only: print out the total number of objects recieved
            Console.WriteLine( fObjectCount + " total objects received." );

            // 3)	To determine if you have completed receiving all responses, check the
            // 		MorePackets property of the SIFMessageInfo object
            if ( ((SifMessageInfo) info).MorePackets )
            {
                Console.WriteLine( "Waiting for more packets..." );
            }
            else
            {
                Console.WriteLine( "All requested packets have been received" );
            }
        }
Beispiel #7
0
        public void OnQueryResults(IDataObjectInputStream data, SIF_Error error, IZone zone, IMessageInfo info)
        {
            SifMessageInfo smi   = (SifMessageInfo)info;
            DateTime       start = DateTime.Now;

            if (smi.Timestamp.HasValue)
            {
                start = smi.Timestamp.Value;
            }

            Console.WriteLine();
            Console.WriteLine("********************************************* ");
            Console.WriteLine("Received SIF_Response packet from zone" + zone.ZoneId);
            Console.WriteLine("Details... ");
            Console.WriteLine("Request MsgId: " + smi.SIFRequestMsgId);
            Console.WriteLine("Packet Number: " + smi.PacketNumber);
            Console.WriteLine();

            if (error != null)
            {
                Console.WriteLine("The publisher returned an error: ");
                Console.WriteLine("Category: " + error.SIF_Category + " Code: " + error.SIF_Code);
                Console.WriteLine("Description " + error.SIF_Desc);
                if (error.SIF_ExtendedDesc != null)
                {
                    Console.WriteLine("Details: " + error.SIF_ExtendedDesc);
                }
                return;
            }

            try
            {
                int objectCount = 0;
                while (data.Available)
                {
                    SifDataObject next = data.ReadDataObject();
                    objectCount++;
                    Console.WriteLine();
                    Console.WriteLine("Text Values for " + next.ElementDef.Name + " " + objectCount + " {" + next.Key + "}");

                    SifXPathContext context = SifXPathContext.NewSIFContext(next);

                    //	Print out all attributes
                    Console.WriteLine("Attributes:");
                    XPathNodeIterator textNodes = context.Select("//@*");
                    while (textNodes.MoveNext())
                    {
                        XPathNavigator navigator = textNodes.Current;
                        Element        value     = (Element)navigator.UnderlyingObject;
                        IElementDef    valueDef  = value.ElementDef;
                        Console.WriteLine(valueDef.Parent.Tag(SifVersion.LATEST) + "/@" + valueDef.Tag(SifVersion.LATEST) + "=" + value.TextValue + ", ");
                    }
                    Console.WriteLine();
                    // Print out all  elements that have a text value
                    Console.WriteLine("Element:");
                    textNodes = context.Select("//*");
                    while (textNodes.MoveNext())
                    {
                        XPathNavigator navigator = textNodes.Current;
                        Element        value     = (Element)navigator.UnderlyingObject;
                        String         textValue = value.TextValue;
                        if (textValue != null)
                        {
                            IElementDef valueDef = value.ElementDef;
                            Console.WriteLine(valueDef.Tag(SifVersion.LATEST) + "=" + textValue + ", ");
                        }
                    }
                }
                Console.WriteLine();
                Console.WriteLine("Total Objects in Packet: " + objectCount);
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            if (!smi.MorePackets)
            {
                // This is the final packet. Print stats
                Console.WriteLine("Final Packet has been received.");
                IRequestInfo ri = smi.SIFRequestInfo;
                if (ri != null)
                {
                    Console.WriteLine("Source Query: ");
                    Console.WriteLine(ri.UserData);
                    TimeSpan difference = start.Subtract(ri.RequestTime);
                    Console.WriteLine("Query execution time: " + difference.Milliseconds + " ms");
                }
            }
            else
            {
                Console.WriteLine("This is not the final packet for this SIF_Response");
            }

            Console.WriteLine("********************************************* ");
            Console.WriteLine( );
            PrintPrompt();
        }
Beispiel #8
0
        public void OnQueryResults(IDataObjectInputStream data, SIF_Error error, IZone zone, IMessageInfo info)
        {
            SifMessageInfo smi = (SifMessageInfo)info;
            DateTime start = DateTime.Now;
            if (smi.Timestamp.HasValue) {
            start = smi.Timestamp.Value;
            }

            Console.WriteLine();
            Console.WriteLine( "********************************************* " );
            Console.WriteLine( "Received SIF_Response packet from zone" + zone.ZoneId );
            Console.WriteLine( "Details... " );
            Console.WriteLine( "Request MsgId: " + smi.SIFRequestMsgId );
            Console.WriteLine( "Packet Number: " + smi.PacketNumber );
            Console.WriteLine();

            if( error != null ){

            Console.WriteLine( "The publisher returned an error: " );
            Console.WriteLine( "Category: " + error.SIF_Category + " Code: " + error.SIF_Code  );
            Console.WriteLine( "Description " + error.SIF_Desc );
            if( error.SIF_ExtendedDesc != null )
            {
                Console.WriteLine( "Details: " + error.SIF_ExtendedDesc );
            }
            return;
            }

            try
            {
            int objectCount = 0;
            while( data.Available ){
                SifDataObject next = data.ReadDataObject();
                objectCount++;
                Console.WriteLine();
                Console.WriteLine( "Text Values for " + next.ElementDef.Name + " " + objectCount + " {" + next.Key + "}" );

                SifXPathContext context = SifXPathContext.NewSIFContext(next);

                //	Print out all attributes
                Console.WriteLine("Attributes:");
                XPathNodeIterator textNodes = context.Select("//@*");
                while( textNodes.MoveNext() ) {
                    XPathNavigator navigator = textNodes.Current;
                    Element value = (Element)navigator.UnderlyingObject;
                    IElementDef valueDef = value.ElementDef;
                    Console.WriteLine( valueDef.Parent.Tag( SifVersion.LATEST ) + "/@" + valueDef.Tag( SifVersion.LATEST ) + "=" + value.TextValue + ", " );
                }
                Console.WriteLine();
                // Print out all  elements that have a text value
                Console.WriteLine("Element:");
                textNodes = context.Select("//*");
                while( textNodes.MoveNext() ) {
                    XPathNavigator navigator = textNodes.Current;
                    Element value = (Element)navigator.UnderlyingObject;
                    String textValue = value.TextValue;
                    if( textValue != null ){
                        IElementDef valueDef = value.ElementDef;
                        Console.WriteLine( valueDef.Tag( SifVersion.LATEST ) + "=" + textValue + ", " );
                    }
                }

            }
            Console.WriteLine();
            Console.WriteLine( "Total Objects in Packet: " + objectCount );

            } catch( Exception ex ){
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.StackTrace);
            }

            if (!smi.MorePackets) {
            // This is the final packet. Print stats
            Console.WriteLine( "Final Packet has been received." );
            IRequestInfo ri = smi.SIFRequestInfo;
            if( ri != null ){
                Console.WriteLine( "Source Query: " );
                Console.WriteLine( ri.UserData );
                TimeSpan difference = start.Subtract(ri.RequestTime);
                Console.WriteLine( "Query execution time: " + difference.Milliseconds + " ms" );
            }

            } else {
            Console.WriteLine( "This is not the final packet for this SIF_Response" );
            }

            Console.WriteLine( "********************************************* " );
            Console.WriteLine( );
            PrintPrompt();
        }
    /// <summary>  Handles SIF_Responses
    /// </summary>
    public virtual void OnQueryResults( IDataObjectInputStream inStream,
                                        SIF_Error error,
                                        IZone zone,
                                        IMessageInfo inf )
    {
        SifMessageInfo info = (SifMessageInfo) inf;

        Console.WriteLine
            ( "\nReceived a query response from agent \"" + info.SourceId + "\" in zone " +
              zone.ZoneId );
        IRequestInfo reqInfo = info.SIFRequestInfo;
        if ( reqInfo != null )
        {
            Console.WriteLine
                ( "\nResponse was received in {0}. Object State is '{1}'",
                  DateTime.Now.Subtract( reqInfo.RequestTime ), reqInfo.UserData );
        }

        //
        //  Use the Mappings class to translate the LearnerPersonal objects received
        //  from the zone into a HashMap of field/value pairs, then dump the table
        //  to System.out
        //

        //  Always check for an error response
        if ( error != null )
        {
            Console.WriteLine
                ( "The request for LearnerPersonal failed with an error from the provider:" );
            Console.WriteLine
                ( "  [Category=" + error.SIF_Category + "; Code=" + error.SIF_Code + "]: " +
                  error.SIF_Desc +
                  ". " + error.SIF_ExtendedDesc );
            return;
        }

        //  Get the root Mappings object from the configuration file
        Mappings m = fCfg.Mappings.GetMappings( "Default" );

        //  Ask the root Mappings instance to select a Mappings from its
        //  hierarchy. For example, you might have customized the agent.cfg
        //  file with mappings specific to zones, versions of SIF, or
        //  requesting agents. The Mappings.select() method will select
        //  the most appropriate instance from the hierarchy given the
        //  three parameters passed to it.
        MappingsContext mappings = m.SelectInbound( StudentDTD.STUDENTPERSONAL, info );
        Hashtable data = new Hashtable();
        StringMapAdaptor sma = new StringMapAdaptor( data, Adk.Dtd.GetFormatter( SifVersion.LATEST ) );

        int count = 0;
        while ( inStream.Available )
        {
            Console.WriteLine( "Object Number {0}", count++ );
            StudentPersonal sp = (StudentPersonal) inStream.ReadDataObject();
            //  Ask the Mappings object to populate the dictionary with field/value pairs
            //  by using the mapping rules in the configuration file to decompose
            //  the LearnerPersonal object into field values.
            mappings.Map( sp, sma );
            //  Now dump the field/value pairs to System.out
            DumpDictionaryToConsole( data );
            Console.WriteLine();
            data.Clear();
        }
    }
Beispiel #10
0
 public void OnQueryResults(IDataObjectInputStream data,
                             SIF_Error error,
                             IZone zone,
                             IMessageInfo info)
 {
     SifMessageInfo smi = (SifMessageInfo)info;
     if (!(fRequestState.Equals(smi.SIFRequestInfo.UserData)))
     {
         // This is a SIF_ZoneStatus response from a previous invocation of the agent
         return;
     }
     if (data.Available)
     {
         SIF_ZoneStatus zoneStatus = data.ReadDataObject() as SIF_ZoneStatus;
         AsyncUtils.QueueTaskToThreadPool(new zsDelegate(_processSIF_ZoneStatus), zoneStatus, zone);
     }
 }
Beispiel #11
0
    /// <summary>  Handles SIF_Responses
    /// </summary>
    public virtual void OnQueryResults(IDataObjectInputStream inStream,
                                       SIF_Error error,
                                       IZone zone,
                                       IMessageInfo inf)
    {
        SifMessageInfo info = (SifMessageInfo)inf;

        Console.WriteLine
            ("\nReceived a query response from agent \"" + info.SourceId + "\" in zone " +
            zone.ZoneId);
        IRequestInfo reqInfo = info.SIFRequestInfo;

        if (reqInfo != null)
        {
            Console.WriteLine
                ("\nResponse was received in {0}. Object State is '{1}'",
                DateTime.Now.Subtract(reqInfo.RequestTime), reqInfo.UserData);
        }

        //
        //  Use the Mappings class to translate the LearnerPersonal objects received
        //  from the zone into a HashMap of field/value pairs, then dump the table
        //  to System.out
        //

        //  Always check for an error response
        if (error != null)
        {
            Console.WriteLine
                ("The request for LearnerPersonal failed with an error from the provider:");
            Console.WriteLine
                ("  [Category=" + error.SIF_Category + "; Code=" + error.SIF_Code + "]: " +
                error.SIF_Desc +
                ". " + error.SIF_ExtendedDesc);
            return;
        }

        //  Get the root Mappings object from the configuration file
        Mappings m = fCfg.Mappings.GetMappings("Default");

        //  Ask the root Mappings instance to select a Mappings from its
        //  hierarchy. For example, you might have customized the agent.cfg
        //  file with mappings specific to zones, versions of SIF, or
        //  requesting agents. The Mappings.select() method will select
        //  the most appropriate instance from the hierarchy given the
        //  three parameters passed to it.
        MappingsContext  mappings = m.SelectInbound(StudentDTD.STUDENTPERSONAL, info);
        Hashtable        data     = new Hashtable();
        StringMapAdaptor sma      = new StringMapAdaptor(data, Adk.Dtd.GetFormatter(SifVersion.LATEST));

        int count = 0;

        while (inStream.Available)
        {
            Console.WriteLine("Object Number {0}", count++);
            StudentPersonal sp = (StudentPersonal)inStream.ReadDataObject();
            //  Ask the Mappings object to populate the dictionary with field/value pairs
            //  by using the mapping rules in the configuration file to decompose
            //  the LearnerPersonal object into field values.
            mappings.Map(sp, sma);
            //  Now dump the field/value pairs to System.out
            DumpDictionaryToConsole(data);
            Console.WriteLine();
            data.Clear();
        }
    }
Beispiel #12
0
        private void Log(string fileName,
                          IDataObjectInputStream input,
                          SifMessageInfo info,
                          bool logToConsole)
        {
            try
            {
                // Ensure that the directory is there
                FileInfo file = new FileInfo(fileName);
                file.Directory.Create();
                int numObjects = 0;

                using (Stream outStream = File.OpenWrite(fileName))
                {
                    using (TextWriter twriter = new StreamWriter(outStream, Encoding.UTF8))
                    {
                        twriter.WriteLine("<SIF_ObjectData>");
                        twriter.Flush();
                        SifWriter writer = new SifWriter(twriter);
                        SifWriter consoleWriter = null;
                        if (logToConsole)
                        {
                            consoleWriter = new SifWriter(Console.Out);
                        }

                        SifDataObject o;
                        while ((o = input.ReadDataObject()) != null)
                        {
                            numObjects++;
                            Track(o);
                            writer.Write(o);
                            if (logToConsole)
                            {
                                consoleWriter.Write(o);
                                Console.WriteLine();
                            }
                        }
                        writer.Flush();
                        if (logToConsole)
                        {
                            consoleWriter.Flush();
                        }
                        twriter.WriteLine("</SIF_ObjectData>");
                    }

                    outStream.Close();

                    Console.WriteLine
                        ("Received {0} objects for {1}, Packet# {2}", numObjects,
                          input.ObjectType.Name, info.PacketNumber);
                }
            }
            catch (Exception ex)
            {
                Adk.Log.Error(ex.Message, ex);
            }
        }