BExIS.IO.Transform.Input.AsciiFileReaderInfo.GetSeperator C# (CSharp) Метод

GetSeperator() публичный статический Метод

Get TextSeperator based on string as name
public static GetSeperator ( string seperator ) : TextSeperator
seperator string Name of TextSeperator
Результат TextSeperator
        public static TextSeperator GetSeperator(string seperator)
        {
            switch (seperator)
            {
                case "comma":
                    return TextSeperator.comma;
                case "semicolon":
                    return TextSeperator.semicolon;
                case "space":
                    return TextSeperator.space;
                case "tab":
                    return TextSeperator.tab;
                default: return TextSeperator.tab;
            }
        }

Same methods

AsciiFileReaderInfo::GetSeperator ( TextSeperator sep ) : char

Usage Example

Пример #1
0
        /// <summary>
        /// Validate the whole FileStream line by line until no more come.
        /// Convert the lines into a datatuple based on the datastructure.
        /// Return value is a list of datatuples
        /// </summary>
        /// <remarks>A list of errorMessages is filled when the fil is not valid </remarks>
        /// <seealso cref="AsciiFileReaderInfo"/>
        /// <seealso cref="DataTuple"/>
        /// <seealso cref="StructuredDataStructure"/>
        /// <param name="FileStream">Stream of the FileStream</param>
        /// <param name="fileName">name of the FileStream</param>
        /// <param name="fri">AsciiFileReaderInfo needed</param>
        /// <param name="sds">StructuredDataStructure</param>
        /// <param name="datasetId">Id of the dataset</param>
        public void ValidateFile(Stream file, string fileName, long datasetId)
        {
            this.FileStream = file;
            this.FileName   = fileName;
            this.DatasetId  = datasetId;
            AsciiFileReaderInfo fri = (AsciiFileReaderInfo)Info;

            // Check params
            if (this.FileStream == null)
            {
                this.ErrorMessages.Add(new Error(ErrorType.Other, "File not exist"));
            }
            if (!this.FileStream.CanRead)
            {
                this.ErrorMessages.Add(new Error(ErrorType.Other, "File is not readable"));
            }
            if (this.Info.Variables <= 0)
            {
                this.ErrorMessages.Add(new Error(ErrorType.Other, "Startrow of Variable can´t be 0"));
            }
            if (this.Info.Data <= 0)
            {
                this.ErrorMessages.Add(new Error(ErrorType.Other, "Startrow of Data can´t be 0"));
            }

            if (this.ErrorMessages.Count == 0)
            {
                using (StreamReader streamReader = new StreamReader(file, encoding))
                {
                    string line;
                    int    index     = 1;
                    char   seperator = AsciiFileReaderInfo.GetSeperator(fri.Seperator);
                    bool   dsdIsOk   = false;

                    while ((line = streamReader.ReadLine()) != null)
                    {
                        if (index == this.Info.Variables)
                        {
                            dsdIsOk = ValidateDatastructure(line, seperator);

                            // if data is not in the correct order, create a dictionary with the new position
                        }

                        if (dsdIsOk && index >= this.Info.Data && !string.IsNullOrEmpty(line) && !isEmpty(line, seperator))
                        {
                            var r = rowToList(line, seperator);
                            var e = ValidateRow(r, index);
                            this.ErrorMessages = this.ErrorMessages.Union(e).ToList();

                            if (this.ErrorMessages.Count >= 1000)
                            {
                                break;
                            }
                        }

                        index++;
                    }
                }
            }
        }
All Usage Examples Of BExIS.IO.Transform.Input.AsciiFileReaderInfo::GetSeperator