Exemplo n.º 1
0
        public List <Record> getElements(string[] elements, RecordFormat format)
        {
            List <Record> records = new List <Record>();

            for (int i = format.makeHeader ? 1 : 0; i < elements.Length; i++)
            {
                string[] row = elements[i].Split(format.dataSeparator.ToCharArray());
                row = Util.replaceAll(row, format.format.Values);
                records.Add(new Record(new List <string>(row)));
            }

            return(records);
        }
Exemplo n.º 2
0
        public string[] formatElements(List <Record> records, RecordFormat after, RecordFormat before)
        {
            int headerOffset = after.makeHeader ? 1 : 0;

            string[] formattedElements = new string[records.Count + headerOffset];
            for (int i = 0; i < formattedElements.Length; i++)
            {
                formattedElements[i] = "";
            }

            if (after.makeHeader)
            {
                string header = "";
                foreach (KeyValuePair <string, ColumnInfo> pair in after.format.ToList())
                {
                    if (pair.Value.start < header.Length)
                    {
                        continue;
                    }
                    header += fillBlank(after.dataSeparator, pair.Value.start - header.Length);
                    header += putToLength(after.dataSeparator, pair.Key, pair.Value.length);
                }
                formattedElements[0] = header;
            }

            int index = 0;

            foreach (KeyValuePair <string, ColumnInfo> pair in after.format)
            {
                bool contained = before.format.ContainsKey(pair.Key);
                if (pair.Value.start < index)
                {
                    continue;
                }
                for (int i = 0; i < records.Count; i++)
                {
                    formattedElements[i + headerOffset] += fillBlank(after.dataSeparator, pair.Value.start - formattedElements[i + headerOffset].Length);

                    string data = contained ? records[i].getData()[before.format[pair.Key].index] : after.notExistent;
                    data = data.Equals(before.notExistent) ? after.notExistent : data;
                    data = pair.Value.hasDefault() && data.Equals(after.notExistent) ? pair.Value.defaultValue : data;
                    data = Util.replace(data, pair.Value);

                    formattedElements[i + headerOffset] += putToLength(after.dataSeparator, data, pair.Value.length);
                    index = pair.Value.start + pair.Value.length;
                }
            }

            return(formattedElements);
        }
Exemplo n.º 3
0
        public List <Record> getElements(string[] elements, RecordFormat format)
        {
            List <Record> records = new List <Record>();

            for (int i = format.makeHeader ? 1 : 0; i < elements.Length; i++)
            {
                List <string> data = new List <string>();
                foreach (KeyValuePair <string, ColumnInfo> pair in format.format.ToList <KeyValuePair <string, ColumnInfo> >())
                {
                    data.Add(getElement(elements[i], format.dataSeparator, pair.Value));
                }
                data = Util.replaceAll(data, format.format.Values);
                records.Add(new Record(data));
            }

            return(records);
        }
Exemplo n.º 4
0
        public string[] formatElements(List <Record> records, RecordFormat after, RecordFormat before)
        {
            int headerOffset = after.makeHeader ? 1 : 0;

            string[] formattedElements = new string[records.Count + headerOffset];

            if (after.makeHeader)
            {
                string   header = "";
                string[] data   = after.format.Keys.ToArray();
                for (int i = 0; i < data.Length; i++)
                {
                    header += data[i];
                    if (i < data.Length - 1)
                    {
                        header += after.dataSeparator;
                    }
                }
                formattedElements[0] = header;
            }

            foreach (KeyValuePair <string, ColumnInfo> pair in after.format.ToList <KeyValuePair <string, ColumnInfo> >())
            {
                for (int i = 0; i < records.Count; i++)
                {
                    string data;
                    bool   contained = before.format.ContainsKey(pair.Key);

                    data = contained ? records[i].getData()[before.format[pair.Key].index] : after.notExistent;
                    data = data.Equals(before.notExistent) ? after.notExistent : data;
                    data = pair.Value.hasDefault() && data.Equals(after.notExistent) ? pair.Value.defaultValue : data;
                    data = Util.replace(data, pair.Value);
                    if (pair.Value.index < after.format.Count - 1)
                    {
                        data += after.dataSeparator;
                    }
                    formattedElements[i + headerOffset] += data;
                }
            }
            return(formattedElements);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Calls this format's formatter to turn the list of records into the output file
 /// </summary>
 /// <param name="records">List of records</param>
 /// <param name="before">The format of the input file</param>
 /// <returns>Content of the output file</returns>
 public string[] recordsToFileFormat(List <Record> records, RecordFormat before)
 {
     return(formatter.formatElements(records, this, before));
 }