示例#1
0
        /// <summary>
        /// Writes a set of <see cref="FtirData"/> formated to file
        /// </summary>
        /// <param name="items">Pass a set of <see cref="FtirData"/> that needs to be written to file</param>
        public override void Write(FtirData items)
        {
            EnsureFileExists(_fileInfo);

            if (_columns != null)
            {
                items = StripColumns(items, _columns);
            }

            using (FileStream fStm = _fileInfo.Create())
                using (StreamWriter sStm = new StreamWriter(fStm, Encoding.Default))
                {
                    var data = Stringify(items.Header.Tuple, items.SeparatorChar, items.DecimalChar, _toMyLocalesFormat);
                    sStm.WriteLine(data);

                    foreach (FtirItem item in items.Data)
                    {
                        var val = item.Tuple.LastOrDefault(i => i.ToLowerInvariant() == "value");
                        if (val == null)
                        {
                            continue;
                        }

                        data = Stringify(item.Tuple, items.SeparatorChar, items.DecimalChar, _toMyLocalesFormat);
                        sStm.WriteLine(data);
                    }
                }
        }
        /// <summary>
        /// Writes a set of <see cref="FtirData"/> to file considering local decimal settings
        /// or passed ones
        /// </summary>
        /// <param name="items">Pass a data ited that need needs to be written to file</param>
        public void Write(FtirData items)
        {
            FtirRawDataWriteBase writer = IsWineScanData(items)
                ? (FtirRawDataWriteBase) new FtirRawDataWineScanWriter(_fileInfo, _toMyLocalesFormat, _columns)
                : new FtirRawDataGrapeScanWriter(_fileInfo, _toMyLocalesFormat, _columns);

            writer.Write(items);
        }
示例#3
0
        private static void  Write(FtirData s, string name, bool toMylocales, string[] filteredColumns)
        {
            Console.Write($"Write output to file  output directory {name}");

            FtirRawDataWriterWrapper wrt = new FtirRawDataWriterWrapper(name, toMylocales, filteredColumns);

            wrt.Write(s);

            Console.WriteLine("...OK");
        }
        bool IsWineScanData(FtirData items)
        {
            if (items.Header.Tuple.Any(i => i.ToLowerInvariant() == "f-so2"))
            {
                return(true);
            }

            var idx = GetIndexOfColumn("produkt", items);

            return(items.Data.Select(i => i.Tuple[idx]).Any(i => i.ToLowerInvariant().Contains("wein")));
        }
        int GetIndexOfColumn(string name, FtirData items)
        {
            int idx = 0;

            for (int i = 0; i < items.Header.Tuple.Length; i++)
            {
                if (items.Header.Tuple[i].ToLowerInvariant() == name)
                {
                    return(i);
                }
            }

            throw new ArgumentException($"Invalid column name {name}");
        }
        /// <summary>
        /// Strips a set of <see cref="FtirData"/> accordingt to the passed columns
        /// </summary>
        /// <param name="data">Pass the data to be stripped</param>
        /// <param name="columns">Pass th ecolumsn to be selected for writing</param>
        /// <returns>returns a stripped set of <see cref="FtirData"/></returns>
        protected FtirData StripColumns(FtirData data, string[] columns)
        {
            List <string> headerFiltered = new List <string>();

            bool[] selectedColums = new bool[data.Header.Tuple.Length];

            for (int i = 0; i < data.Header.Tuple.Length; i++)
            {
                var col = data.Header.Tuple[i];

                if (columns.Any(t => t.ToLowerInvariant() == col.ToLowerInvariant()))
                {
                    headerFiltered.Add(col);
                    selectedColums[i] = true;
                }
                else
                {
                    selectedColums[i] = false;
                }
            }

            List <FtirItem> selectedItems = new List <FtirItem>();

            foreach (FtirItem item in data.Data)
            {
                List <string> items = new List <string>();
                for (int i = 0; i < item.Tuple.Length; i++)
                {
                    if (selectedColums[i])
                    {
                        items.Add(item.Tuple[i]);
                    }
                }

                selectedItems.Add(new FtirItem {
                    Tuple = items.ToArray()
                });
            }

            return(new FtirData
            {
                Header = new FtirItem {
                    Tuple = headerFiltered.ToArray()
                },
                Data = selectedItems.ToArray(),
                DecimalChar = data.DecimalChar,
                SeparatorChar = data.SeparatorChar,
            });
        }
 /// <summary>
 /// Writes a set of <see cref="FtirData"/> to target
 /// </summary>
 /// <param name="items">Pass the <see cref="FtirData"/> that needs to be written to target</param>
 /// <exception cref="FileNotFoundException"></exception>
 public abstract void Write(FtirData items);