コード例 #1
0
        private void ValidateReadyToRead()
        {
            if (this.m_NeedPropertyCheck | this.ArrayHasChanged())
            {
                switch (this.m_TextFieldType)
                {
                case FieldType.Delimited:
                    this.ValidateAndEscapeDelimiters();
                    break;

                case FieldType.FixedWidth:
                    this.ValidateFieldWidths();
                    break;
                }
                if (this.m_CommentTokens != null)
                {
                    foreach (string str in this.m_CommentTokens)
                    {
                        if (((str != "") && (this.m_HasFieldsEnclosedInQuotes & (this.m_TextFieldType == FieldType.Delimited))) && (string.Compare(str.Trim(), "\"", StringComparison.Ordinal) == 0))
                        {
                            throw ExceptionUtils.GetInvalidOperationException("TextFieldParser_InvalidComment", new string[0]);
                        }
                    }
                }
                this.m_NeedPropertyCheck = false;
            }
        }
コード例 #2
0
        private int IncreaseBufferSize()
        {
            this.m_PeekPosition = this.m_CharsRead;
            int num = this.m_Buffer.Length + 0x1000;

            if (num > this.m_MaxBufferSize)
            {
                throw ExceptionUtils.GetInvalidOperationException("TextFieldParser_BufferExceededMaxSize", new string[0]);
            }
            char[] destinationArray = new char[(num - 1) + 1];
            Array.Copy(this.m_Buffer, destinationArray, this.m_Buffer.Length);
            int num2 = this.m_Reader.Read(destinationArray, this.m_Buffer.Length, 0x1000);

            this.m_Buffer     = destinationArray;
            this.m_CharsRead += num2;
            return(num2);
        }
コード例 #3
0
        private void ValidateFieldWidths()
        {
            if (this.m_FieldWidths == null)
            {
                throw ExceptionUtils.GetInvalidOperationException("TextFieldParser_FieldWidthsNothing", new string[0]);
            }
            if (this.m_FieldWidths.Length == 0)
            {
                throw ExceptionUtils.GetInvalidOperationException("TextFieldParser_FieldWidthsNothing", new string[0]);
            }
            int index = this.m_FieldWidths.Length - 1;

            this.m_LineLength = 0;
            int num3 = index - 1;

            for (int i = 0; i <= num3; i++)
            {
                this.m_LineLength += this.m_FieldWidths[i];
            }
            if (this.m_FieldWidths[index] > 0)
            {
                this.m_LineLength += this.m_FieldWidths[index];
            }
        }
コード例 #4
0
        private void ValidateAndEscapeDelimiters()
        {
            if (this.m_Delimiters == null)
            {
                throw ExceptionUtils.GetArgumentExceptionWithArgName("Delimiters", "TextFieldParser_DelimitersNothing", new string[] { "Delimiters" });
            }
            if (this.m_Delimiters.Length == 0)
            {
                throw ExceptionUtils.GetArgumentExceptionWithArgName("Delimiters", "TextFieldParser_DelimitersNothing", new string[] { "Delimiters" });
            }
            int           length   = this.m_Delimiters.Length;
            StringBuilder builder  = new StringBuilder();
            StringBuilder builder2 = new StringBuilder();

            builder2.Append(this.EndQuotePattern + "(");
            int num3 = length - 1;

            for (int i = 0; i <= num3; i++)
            {
                if (this.m_Delimiters[i] != null)
                {
                    if (this.m_HasFieldsEnclosedInQuotes && (this.m_Delimiters[i].IndexOf('"') > -1))
                    {
                        throw ExceptionUtils.GetInvalidOperationException("TextFieldParser_IllegalDelimiter", new string[0]);
                    }
                    string str = Regex.Escape(this.m_Delimiters[i]);
                    builder.Append(str + "|");
                    builder2.Append(str + "|");
                }
            }
            this.m_SpaceChars     = this.WhitespaceCharacters;
            this.m_DelimiterRegex = new Regex(builder.ToString(0, builder.Length - 1), RegexOptions.CultureInvariant);
            builder.Append("\r|\n");
            this.m_DelimiterWithEndCharsRegex = new Regex(builder.ToString(), RegexOptions.CultureInvariant);
            builder2.Append("\r|\n)|\"$");
        }
コード例 #5
0
 private ReferencedStream GetStream()
 {
     int num = 0;
     ReferencedStream stream2 = null;
     string fullPath = Path.GetFullPath(this.LogFileName + ".log");
     while ((stream2 == null) && (num < 0x7fffffff))
     {
         string str3;
         if (num == 0)
         {
             str3 = Path.GetFullPath(this.LogFileName + ".log");
         }
         else
         {
             str3 = Path.GetFullPath(this.LogFileName + "-" + num.ToString(CultureInfo.InvariantCulture) + ".log");
         }
         string key = str3.ToUpper(CultureInfo.InvariantCulture);
         Dictionary<string, ReferencedStream> streams = m_Streams;
         lock (streams)
         {
             if (m_Streams.ContainsKey(key))
             {
                 stream2 = m_Streams[key];
                 if (!stream2.IsInUse)
                 {
                     m_Streams.Remove(key);
                     stream2 = null;
                 }
                 else
                 {
                     if (this.Append)
                     {
                         new FileIOPermission(FileIOPermissionAccess.Write, str3).Demand();
                         stream2.AddReference();
                         this.m_FullFileName = str3;
                         return stream2;
                     }
                     num++;
                     stream2 = null;
                     continue;
                 }
             }
             System.Text.Encoding fileEncoding = this.Encoding;
             try
             {
                 if (this.Append)
                 {
                     fileEncoding = this.GetFileEncoding(str3);
                     if (fileEncoding == null)
                     {
                         fileEncoding = this.Encoding;
                     }
                 }
                 StreamWriter stream = new StreamWriter(str3, this.Append, fileEncoding);
                 stream2 = new ReferencedStream(stream);
                 stream2.AddReference();
                 m_Streams.Add(key, stream2);
                 this.m_FullFileName = str3;
                 return stream2;
             }
             catch (IOException)
             {
             }
             num++;
             continue;
         }
     }
     throw ExceptionUtils.GetInvalidOperationException("ApplicationLog_ExhaustedPossibleStreamNames", new string[] { fullPath });
 }