Пример #1
0
        /// <summary>
        /// Commits the writing of all objects and sends the objects
        /// </summary>
        public override void Commit()
        {
            try
            {
                if (fDeferResponses)
                {
                    Abort();
                }
                else
                {
                    //  If no objects or SIF_Errors have been written to the stream, we still
                    //  need to return an empty SIF_Response to the ZIS.
                    if (fCurrentOutputStream == null)
                    {
                        try
                        {
                            NewPacket();
                            Close();
                        }
                        catch (IOException ioe)
                        {
                            throw new AdkException
                                  (
                                      "Could not commit the stream because of an IO error writing an empty SIF_Response packet: " +
                                      ioe, fZone);
                        }
                    }

                    String responseFileName = ResponseDelivery.SerializeResponseHeaderFileName(fDestId, fReqId, fMorePackets);

                    //  Write out "destId.requestId." file to signal the Publisher has finished
                    //  writing all responses successfully. This file will hang around until
                    //  all "requestId.{packet}.pkt" files have been sent to the ZIS by the Adk,
                    //  a process that could occur over several agent sessions if the agent
                    //  is abruptly terminated.
                    //
                    String fileName = fWorkDir + Path.DirectorySeparatorChar + responseFileName;

                    try
                    {
                        FileInfo publisherFile = new FileInfo(fileName);
                        using (Stream publisherFileStream = publisherFile.Create())
                        {
                            publisherFileStream.Close();
                        }
                    }
                    catch (IOException ioe)
                    {
                        fZone.Log.Warn("Unable to create SIF_Response header file: " + fileName + ". " + ioe.Message, ioe);
                    }

                    OnCommitted();
                }
            }
            finally
            {
                fZone = null;
            }
        }
Пример #2
0
        /// <summary>  Create a File descriptor of the current output file</summary>
        private FileInfo CreateOutputFile()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(fWorkDir);
            builder.Append(Path.DirectorySeparatorChar);
            ResponseDelivery.SerializeResponsePacketFileName(builder, fDestId, fReqId, fCurPacket, fRenderAsVersion,
                                                             (fError != null));
            return(new FileInfo(builder.ToString()));
        }
Пример #3
0
        /// <summary>  Initialize the output stream. This method must be called after creating
        /// a new instance of this class and before writing any SIFDataObjects to
        /// the stream.
        /// </summary>
        /// <param name="zone">The Zone associated with messages that will be written to the stream
        /// </param>
        /// <param name="queryRestrictions">The fields that should be returned according to the Query
        /// that was specified in the SIF_Request message
        /// </param>
        /// <param name="requestSourceId">The SourceId of the associated SIF_Request message
        /// </param>
        /// <param name="requestMsgId">The MsgId of the associated SIF_Request message
        /// </param>
        /// <param name="requestSIFVersion">The version of the SIF_Message envelope of the
        /// SIF_Request message (if specified and different than the SIF_Message
        /// version, the SIF_Request/SIF_Version element takes precedence).
        /// SIF_Responses will be encapsulated in a message envelope matching
        /// this version and SifDataObject contents will be rendered in this
        /// version
        /// </param>
        /// <param name="maxSize">The maximum size of rendered SifDataObject that will be
        /// accepted by this stream. If a SifDataObject is written to the stream
        /// and its size exceeds this value after rendering the object to an XML
        /// stream, an ObjectTooLargeException will be thrown by the <i>write</i>
        /// method
        /// </param>
        public override void Initialize(
            IZone zone,
            IElementDef[] queryRestrictions,
            String requestSourceId,
            String requestMsgId,
            SifVersion requestSIFVersion,
            int maxSize)
        {
            fZone = (ZoneImpl)zone;
            fQueryRestrictions = queryRestrictions;
            fReqId             = requestMsgId;
            fDestId            = requestSourceId;
            fMaxSize           = maxSize;
            fCurPacket         = 0;
            fRenderAsVersion   = requestSIFVersion;

            //
            //  Messages written to this stream are stored in the directory
            //  "%adk.home%/work/%zoneId%_%zoneHost%/responses". One or more files
            //  are written to this directory, where each file has the name
            //  "destId.requestId.{packet}.pkt". As messages are written to the
            //  stream, the maxSize property is checked to determine if the size of
            //  the current file will be larger than the maxSize. If so, the file is
            //  closed and the packet number incremented. A new file is then created
            //  for the message and all subsequent messages until maxSize is again
            //  exceeded.

            //  Ensure work directory exists
            fWorkDir = ResponseDelivery.GetSourceDirectory(DeliveryType, zone);
            DirectoryInfo dir = new DirectoryInfo(fWorkDir);

            if (!dir.Exists)
            {
                dir.Create();
            }

            //  Get the size of the SIF_Message envelope to determine the actual
            //  packet size we're producing
            fEnvSize = CalcEnvelopeSize(fZone);
        }