/// <summary>
        /// Initialize the reader with a Triple-S survey and the full path to the data file.
        /// </summary>
        /// <param name="root">Triple-S survey with the variables specifying fixed field positions</param>
        /// <param name="filepath"></param>
        public S3FixedFormatReader(S3Root root, string filepath)
        {
            if (root.Survey.Record.DataFormat != S3Format.Fixed)
            {
                throw new ArgumentException("Triple-S survey data format must be fixed field");
            }
            if (!File.Exists(filepath))
            {
                throw new ArgumentException($"Specified file {filepath} does not exist");
            }

            s3Root     = root;
            filename   = filepath;
            fileReader = new StreamReader(filepath);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Serialize a Triple-S survey to XML and return that as a string
 /// </summary>
 /// <param name="metaData">S3Root object to serialize</param>
 /// <returns>String of XML</returns>
 public static string ToString(S3Root metaData)
 {
     using var writer = new StringWriter();
     ToWriter(writer, metaData);
     return(writer.ToString());
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Serialize a Triple-S survey to XML and save it to a stream.
        /// </summary>
        /// <param name="stream">Open stream to save the XML to.
        /// Caller is responsible for closing the stream.</param>
        /// <param name="metaData">S3Root object to serialize</param>
        public static void ToWriter(TextWriter stream, S3Root metaData)
        {
            var xs = new XmlSerializer(typeof(S3Root));

            xs.Serialize(stream, metaData);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Serialize a Triple-S survey to XML and save it to a file.
 /// </summary>
 /// <param name="filename">Fully qualified file to save the XML to</param>
 /// <param name="metaData">S3Root object to serialize</param>
 public static void ToFile(string filename, S3Root metaData)
 {
     using var writer = new StreamWriter(filename);
     ToWriter(writer, metaData);
 }