Exemplo n.º 1
0
        /**
         *  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));
        }
Exemplo n.º 2
0
        public void OnQueryResults(IDataObjectInputStream data,
                                   SIF_Error error,
                                   IZone zone,
                                   IMessageInfo info)
        {
            SifMessageInfo smi = (SifMessageInfo)info;

            if (error != null)
            {
                Adk.Log.Warn("Received Error Response: " + error.SIF_Desc);
            }
            else
            {
                string debug =
                    string.Format
                        ("Received Response for {0} from zone: {1}. Packet {2} of {3}",
                        data.ObjectType, zone.ZoneId, smi.PacketNumber,
                        smi.MorePackets ? smi.PacketNumber + "+" : smi.PacketNumber + " (FINAL)");
                zone.Log.Info(debug);
                zone.ServerLog.Log
                    (LogLevel.INFO, debug, null, "1003", LogEntryCodes.CATEGORY_SUCCESS,
                    LogEntryCodes.CODE_SUCCESS, smi, null);
                bool logToconsole = fAgent.getChameleonProperty(zone, "logConsole", false);
                if (fAgent.getChameleonProperty(zone, "logResponses", true))
                {
                    Log
                        (fDir + Path.DirectorySeparatorChar + zone.ZoneId +
                        Path.DirectorySeparatorChar + "Responses\\" + data.ObjectType.Name + "\\" +
                        data.ObjectType.Name + DateTime.Now.ToFileTime().ToString() + ".xml", data,
                        smi, logToconsole);
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>  Constructs an Event object to encapsulate
 /// an inbound SIF Event. This form of the constructor is called internally by the
 /// ADK when it receives a SIF Event message and is not intended to be used by ADK developers.
 /// </summary>
 /// <param name="data">An IDataObjectInputStream that returns SifDataObjects, all of
 /// which must be of the same class type
 /// </param>
 /// <param name="action">Describes how the data has changed
 /// </param>
 /// <param name="objectType">An ElementDef constant from the SifDtd class that
 /// identifies the type of SIF Data Object contained in the event
 /// </param>
 public Event(IDataObjectInputStream data,
              string action,
              IElementDef objectType)
 {
     fData    = data;
     fObjType = objectType;
     SetAction(action);
 }
Exemplo n.º 4
0
 /// <summary>  Constructs an Event object to encapsulate in inbound SIF Event.
 /// This form of the contructor is called internally by the ADK when it receives
 /// a SIF Event Message and is not intended to be used by ADK developers.
 /// 
 /// </summary>
 /// <param name="data">An IDataObjectInputStream that returns SifDataObjects, all of
 /// which must be of the same class type
 /// </param>
 /// <param name="action">One of the EventAction enum values</c>
 /// </param>
 /// <param name="objectType">An ElementDef constant from the <see cref="OpenADK.Library.SifDtd"/> class that
 /// identifies the type of SIF Data Object contained in the event
 /// </param>
 public Event(IDataObjectInputStream data,
             EventAction action,
             IElementDef objectType)
 {
     fData = data;
      fObjType = objectType;
      SetAction(action);
 }
Exemplo n.º 5
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.");
                }
            }
        }
Exemplo n.º 7
0
        public void OnQueryResults(IDataObjectInputStream data, SIF_Error error, IZone zone, IMessageInfo info)
        {
            SifMessageInfo smi = (SifMessageInfo)info;

            fResultsRequestInfo = smi.SIFRequestInfo;
            doBehavior(zone);

            Assert.IsNotNull(fResultsRequestInfo, "RequestInfo should not be null in onQueryResults()");
            if (RequestStateObject != null)
            {
                Assert.AreEqual(RequestStateObject, fResultsRequestInfo.UserData, "Custom State in onQueryResults()");
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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" );
            }
        }
Exemplo n.º 11
0
        /// <summary>  Constructs an Event object to encapsulate
        /// an outbound SIF Event, which describes
        /// one or more SifDataObjects that have been added, changed,
        /// or deleted by the local application. This form of the constructor is called
        /// by agents when reporting a SIF_Event message to a zone
        /// </summary>
        /// <param name="data">An array of SifDataObjects, all of which must be of the same class type
        /// </param>
        /// <param name="action">Describes how the data has changed.</param>
        /// <remarks>
        /// <seealso cref="OpenADK.Library.IZone.ReportEvent"/>
        /// </remarks>
        public Event(SifDataObject[] data,
                     EventAction action)
        {
            try
            {
                fData = DataObjectInputStreamImpl.newInstance();
                if (data != null)
                {
                    ((DataObjectInputStreamImpl)fData).Data = data;
                }
            }
            catch (AdkException adke)
            {
                throw new SystemException(adke.ToString());
            }

            fObjType = data != null && data.Length > 0 && data[0] != null
                        ? data[0].ElementDef
                        : null;
            SetAction(action);
        }
Exemplo n.º 12
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();
        }
    }
Exemplo n.º 13
0
 public void OnQueryResults(IDataObjectInputStream data,
                             SIF_Error error,
                             IZone zone,
                             IMessageInfo info)
 {
     SifMessageInfo smi = (SifMessageInfo)info;
     if (error != null)
     {
         Adk.Log.Warn("Received Error Response: " + error.SIF_Desc);
     }
     else
     {
         string debug =
             string.Format
                 ("Received Response for {0} from zone: {1}. Packet {2} of {3}",
                   data.ObjectType, zone.ZoneId, smi.PacketNumber,
                   smi.MorePackets ? smi.PacketNumber + "+" : smi.PacketNumber + " (FINAL)");
         zone.Log.Info(debug);
         zone.ServerLog.Log
             (LogLevel.INFO, debug, null, "1003", LogEntryCodes.CATEGORY_SUCCESS,
               LogEntryCodes.CODE_SUCCESS, smi, null);
         bool logToconsole = fAgent.getChameleonProperty(zone, "logConsole", false);
         if (fAgent.getChameleonProperty(zone, "logResponses", true))
         {
             Log
                 (fDir + Path.DirectorySeparatorChar + zone.ZoneId +
                   Path.DirectorySeparatorChar + "Responses\\" + data.ObjectType.Name + "\\" +
                   data.ObjectType.Name + DateTime.Now.ToFileTime().ToString() + ".xml", data,
                   smi, logToconsole);
         }
     }
 }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
0
        /// <summary>  Constructs an Event object to encapsulate
        /// an outbound SIF Event, which describes
        /// one or more SifDataObjects that have been added, changed,
        /// or deleted by the local application. This form of the constructor is called
        /// by agents when reporting a SIF_Event message to a zone
        /// </summary>
        /// <param name="data">An array of SIFDataObjects, all of which must be of the same class
        /// </param>
        /// <param name="action">Describes how the data has changed: in SIF, this string
        /// must be "Add", "Change", or "Delete"
        /// </param>
        /// <remarks>
        /// <seealso cref="OpenADK.Library.IZone.ReportEvent"/>
        /// </remarks>
        public Event(SifDataObject[] data,
                    string action)
        {
            try
             {
            fData = DataObjectInputStreamImpl.newInstance();
            if (data != null)
            {
               ((DataObjectInputStreamImpl)fData).Data = data;
            }
             }
             catch (AdkException adke)
             {
            throw new SystemException(adke.ToString());
             }

             fObjType = data != null && data.Length > 0 && data[0] != null
                        ? data[0].ElementDef
                        : null;

             SetAction(action);
        }
Exemplo n.º 16
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();
        }
Exemplo n.º 17
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();
        }
Exemplo n.º 18
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();
        }
    }
Exemplo n.º 19
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);
     }
 }