public override string ToString()
    {
        StringBuilder sb = new StringBuilder();

        sb.AppendLine(Title);
        sb.AppendLine(Description);
        sb.AppendLine(CreationDateTime.ToString("G"));
        sb.AppendLine(ModifiedDateTime.ToString("G"));
        sb.AppendLine(NumberOfRobots + "");
        sb.AppendLine(FieldHeight + "");
        sb.AppendLine(FieldWidth + "");
        return(sb.ToString());
    }
示例#2
0
        /// <summary>
        /// Saves the Routable Message to a file
        /// </summary>
        /// <param name="fileName">The file where the message is being saved</param>
        public void SaveToFile(string fileName)
        {
            try
            {
                // Ensure all variables are informed
                if (CreationDateTime == DateTime.MinValue)
                {
                    CreationDateTime = DateTime.Now;
                }

                // Defines the format of the file
                FormatOptions dosLineFormat = new FormatOptions()
                {
                    NewLineFormat = NewLineFormat.Dos,
                };

                // Prepare File Output
                using (var fileStream = File.Create(fileName))
                {
                    // Creates a stream for the header
                    using (MemoryStream streamHeader = new MemoryStream())
                    {
                        using (StreamWriter streamHeaderWriter = new StreamWriter(streamHeader, Encoding.GetEncoding(28592)))
                        {
                            // Ensure to not Automatically Flush
                            streamHeaderWriter.AutoFlush = false;

                            // Writes the SmtpRouter Header
                            streamHeaderWriter.WriteLine(SMTPROUTER_HEADER_BEGIN);
                            streamHeaderWriter.WriteLine($"{SMTPROUTER_HEADER_VERSION}: {SMTPROUTER_VERSION}");
                            streamHeaderWriter.WriteLine($"{SMTPROUTER_HEADER_CREATIONTIME}: {CreationDateTime.ToString(SMTPROUTER_HEADER_CREATIONTIME_FORMAT)}");
                            streamHeaderWriter.WriteLine($"{SMTPROUTER_HEADER_FROM}: {MailFrom.Address.ToString()}");
                            streamHeaderWriter.WriteLine($"{SMTPROUTER_HEADER_IPADDRESS}: {IPAddress}");

                            foreach (var mailTo in Recipients)
                            {
                                streamHeaderWriter.WriteLine($"{SMTPROUTER_HEADER_TO}: {mailTo.Address.ToString()}");
                            }

                            streamHeaderWriter.WriteLine(SMTPROUTER_HEADER_END);

                            // Flushes to the file
                            streamHeaderWriter.Flush();

                            // Copy Header to file
                            streamHeader.Seek(0, SeekOrigin.Begin);
                            streamHeader.CopyTo(fileStream);
                        }
                    }

                    // Creates a stream for the Message
                    using (MemoryStream streamMessage = new MemoryStream())
                    {
                        Message.WriteTo(dosLineFormat, streamMessage);

                        streamMessage.Seek(0, SeekOrigin.Begin);
                        streamMessage.CopyTo(fileStream);
                    }

                    // Flush it to the file
                    fileStream.Flush();
                }
            }
            catch (Exception e)
            {
                throw new MessageNotQueuedException(this, e);
            }
        }