예제 #1
0
    public void WriteAllLines(GxSimpleCollection <string> svalue, String encoding, bool append)
    {
        _lastError            = 0;
        _lastErrorDescription = "";
        if (validSource() && svalue != null)
        {
            try
            {
                if (append)
                {
                    foreach (string s in svalue)
                    {
                        File.AppendAllText(_file.FullName, s + StringUtil.NewLine(), GXUtil.GxIanaToNetEncoding(encoding, false));
                    }
                }
                else
                {
                    string[] strArray = new string[svalue.Count];
                    svalue.CopyTo(strArray, 0);
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                    File.WriteAllLines(_file.FullName, strArray, GXUtil.GxIanaToNetEncoding(encoding, false));
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                }
            }
            catch (Exception e)
            {
                setError(e);
            }
        }
    }
예제 #2
0
    public GxSimpleCollection <string> ReadAllLines(String encoding)
    {
        GxSimpleCollection <string> strColl = new GxSimpleCollection <string>();

        _lastError            = 0;
        _lastErrorDescription = "";
        if (!validSource())
        {
            return(strColl);
        }
        try
        {
            if (!Exists())
            {
                _lastError            = 2;
                _lastErrorDescription = "File does not exist";
                return(strColl);
            }
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
            strColl.AddRange(File.ReadAllLines(_file.FullName, GXUtil.GxIanaToNetEncoding(encoding, false)));
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
            return(strColl);
        }
        catch (Exception e)
        {
            setError(e);
            return(strColl);
        }
    }
예제 #3
0
    public void WriteAllText(String value, String encoding, bool append)
    {
        _lastError            = 0;
        _lastErrorDescription = "";
        if (validSource())
        {
            try
            {
                if (append)
                {
                    File.AppendAllText(_file.FullName, value, GXUtil.GxIanaToNetEncoding(encoding, false));
                }
                else
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                {
                    File.WriteAllText(_file.FullName, value, GXUtil.GxIanaToNetEncoding(encoding, false));
                }
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
            }
            catch (Exception e)
            {
                setError(e);
            }
        }
    }
예제 #4
0
    public String ReadAllText(String encoding)
    {
        _lastError            = 0;
        _lastErrorDescription = "";
        if (!validSource())
        {
            return(String.Empty);
        }
        try
        {
            if (!Exists())
            {
                _lastError            = 2;
                _lastErrorDescription = "File does not exist";
                return(String.Empty);
            }
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
            return(File.ReadAllText(_file.FullName, GXUtil.GxIanaToNetEncoding(encoding, false)));

#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
        }
        catch (Exception e)
        {
            setError(e);
            return(string.Empty);
        }
    }
예제 #5
0
        string substringByte(string sEnc, string s, int len)
        {
            string s1;
            int    len1;

            if (sEnc.Trim().Length == 0)
            {
                len1 = len == 0 ? s.Length : len;
                if (s.Length <= len1)
                {
                    s1 = s;
                }
                else
                {
                    s1 = s.Substring(0, len1);
                }
            }
            else
            {
                Encoding enc = GXUtil.GxIanaToNetEncoding(sEnc, false);
                byte[]   b1  = enc.GetBytes(s);
                len1 = len == 0 ? b1.Length : len;
                if (b1.Length <= len1)
                {
                    s1 = s;
                }
                else
                {
                    s1 = enc.GetString(b1, 0, len1);
                }
            }
            return(s1);
        }
예제 #6
0
        public short dfwopen(string fileName, string fldDelimiter, string strDelimiter, int append, string encoding)
        {
            if (_writeStatus != FileIOStatus.Closed)
            {
                GXLogging.Error(log, "Error ADF0005: open function in use");
                return(GX_ASCDEL_INVALIDSEQUENCE);
            }
            try
            {
                FileMode mode = FileMode.Create;
                if (append == 1)
                {
                    mode = FileMode.Append;
                }
                fileName = Path.Combine(GxContext.StaticPhysicalPath(), fileName);
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                _fsw = new FileStream(fileName, mode, FileAccess.Write, FileShare.ReadWrite, 1024);
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
            }
            catch (DirectoryNotFoundException e)
            {
                GXLogging.Error(log, "Error ADF0001", e);
                return(GX_ASCDEL_OPENERROR);
            }
            _fldDelimiterW = CleanDelimiter(fldDelimiter);
            _strDelimiterW = strDelimiter;
            _encodingW     = encoding;
            _sw            = new StreamWriter(_fsw, GXUtil.GxIanaToNetEncoding(encoding, false));
            _currentLineW  = null;
            _writeStatus   = FileIOStatus.Open;
            return(GX_ASCDEL_SUCCESS);
        }
예제 #7
0
 public short dfropen(string fileName, int recSize, string fldDelimiter, string strDelimiter, string encoding)
 {
     if (_readStatus != FileIOStatus.Closed)
     {
         GXLogging.Error(log, "Error ADF0005: open function in use");
         return(GX_ASCDEL_INVALIDSEQUENCE);
     }
     fileName = Path.Combine(GxContext.StaticPhysicalPath(), fileName);
     try
     {
         _fsr = new FileStream(Path.GetFullPath(fileName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 1024);
     }
     catch (FileNotFoundException fe)
     {
         GXLogging.Error(log, "Error ADF0001", fe);
         return(GX_ASCDEL_OPENERROR);
     }
     catch (DirectoryNotFoundException de)
     {
         GXLogging.Error(log, "Error ADF0001", de);
         return(GX_ASCDEL_OPENERROR);
     }
     _fldDelimiterR = CleanDelimiter(fldDelimiter);
     _strDelimiterR = strDelimiter;
     _encodingR     = encoding;
     _sr            = new StreamReader(_fsr, GXUtil.GxIanaToNetEncoding(encoding, false));
     _lastPos       = 0;
     _readStatus    = FileIOStatus.Open;
     return(GX_ASCDEL_SUCCESS);
 }
예제 #8
0
        string getNextFldByte(int length)
        {
            int      dlPos;
            Encoding enc = GXUtil.GxIanaToNetEncoding(_encodingR, false);

            byte[] currentLineBytes  = enc.GetBytes(_currentLineR);
            byte[] fldDelimiterBytes = enc.GetBytes(_fldDelimiterR);
            byte[] strDelimiterBytes = enc.GetBytes(_strDelimiterR);

            if (length == -1 && _fldDelimiterR.Length == 0)
            {
                return("");
            }

            if (_lastPos >= currentLineBytes.Length)
            {
                return("");
            }

            int oPos = _lastPos;

            if (_fldDelimiterR.Length == 0)
            {
                dlPos    = Math.Min(_lastPos + length, currentLineBytes.Length);
                _lastPos = dlPos;
            }
            else
            {
                if (_strDelimiterR.Length > 0 && IndexOfArray(currentLineBytes, strDelimiterBytes, _lastPos) == _lastPos)
                {
                    int strEndDelimiterPos = IndexOfArray(currentLineBytes, strDelimiterBytes, _lastPos + strDelimiterBytes.Length);
                    dlPos = IndexOfArray(currentLineBytes, fldDelimiterBytes, strEndDelimiterPos + strDelimiterBytes.Length);
                }
                else
                {
                    dlPos = IndexOfArray(currentLineBytes, fldDelimiterBytes, _lastPos);
                }

                if (dlPos == -1)
                {
                    dlPos = currentLineBytes.Length;
                }
                _lastPos = dlPos + fldDelimiterBytes.Length;
            }

            if (dlPos < oPos)
            {
                return("");
            }
            return(enc.GetString(currentLineBytes, oPos, dlPos - oPos));
        }
예제 #9
0
    public void OpenRead(String encoding)
    {
        _lastError            = 0;
        _lastErrorDescription = "";
        if (validSource())
        {
            try
            {
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                _fileStreamReader = new FileStream(_file.FullName, FileMode.Open, FileAccess.Read);
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                _fileReader = new StreamReader(_fileStreamReader, GXUtil.GxIanaToNetEncoding(encoding, false));
            }
            catch (Exception e)
            {
                setError(e);
            }
        }
    }