/**
  * Construct the AckDistributionEnvelope as an acknowledgment to the given
  * DistributionEnvelope.
  */
 public AckDistributionEnvelope(DistributionEnvelope d)
     : base()
 {
     Address[] a = new Address[1];
     a[0] = d.getSender();
     setTo(a);
     String id = null;
     String snd = null;
     try
     {
         Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         id = config.AppSettings.Settings[AUDIT_ID_PROPERTY].Value;
         snd = config.AppSettings.Settings[SENDER_PROPERTY].Value;
     }
     catch (Exception e)
     {
         throw new DistributionEnvelopeException("SYST-0000", "Configuration manager exception", e.ToString());
     }
     Address sndr = new Address(snd);
     Identity[] auditId = new Identity[1];
     auditId[0] = new Identity(id);
     setAudit(auditId);
     setSender(sndr);
     setService(SERVICE);
     setTrackingId(d.getTrackingId());
     serviceRef = d.getService();
 }
        /**
         * Implementation of the interface' "handle()" method. Determines the
         * file name and tries to write it. Note that this doesn't return any
         * ITK response because formally such a response requires a router. Providing
         * an ITK router here would put a dependency on the ITK code, in the TMS
         * adapter. An implementation that does do ITK responses will be found in
         * the router package.
         */
        public void handle(DistributionEnvelope d)
        {
            StringBuilder sb = new StringBuilder(spoolDirectory);
            sb.Append("\\");
            sb.Append(getLastServiceURIElement(d.getService()));
            sb.Append("_");
            sb.Append(getFileSafeMessageID(d.getTrackingId()));
            sb.Append(".message");
            string filename = sb.ToString();

            try
            {
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        d.parsePayloads();
                        sw.Write(d.getEnvelope());
                        sw.Flush();
                        sw.Close();
                    }
                }
            }
            catch (Exception e)
            {
                EventLog ev = new EventLog("Application");
                ev.Source = LOGSOURCE;
                StringBuilder sbe = new StringBuilder("Failed to save DistributionEnvelope ");
                sbe.Append(d.getTrackingId());
                sbe.Append(" service ");
                sbe.Append(d.getService());
                sbe.Append(" from ");
                sbe.Append(d.getSender().getUri());
                sbe.Append(". Reason: ");
                sbe.Append(e.ToString());
                ev.WriteEntry(sbe.ToString(), EventLogEntryType.Error);
            }
        }