Example #1
0
 public void MoveIndexes(PyFileSection startFrom, int count)
 {
     for (int i = (int)startFrom; i<_sec_count; i++)
     {
         _py_sections[i].MoveBeginIndex(count);
     }
 }
Example #2
0
 public void MoveSectionSize(PyFileSection startFrom, int count)
 {
     _py_sections[(int)startFrom].MoveSizeIndex(count);
     for (int i = (int)startFrom + 1; i<_sec_count; i++)
     {
         _py_sections[i].MoveBeginIndex(count);
     }
 }
Example #3
0
 public void InsertLines(int pos, PyFileSection section, string str)
 {
     // pos : relative to section, -1 mean end of section
     string[] arr = Regex.Split(str, "\r\n");
     int count = arr.Length;
     int row = SeekToSection(section, pos);
     for (int i=0; i<count; i++)
     {
         if (row + i >= _py_mem.Count)
         {
             _py_mem.Add(arr[i]);
         } else {
             _py_mem.Insert(row + i, arr[i]);
         }
     }
     MoveSectionSize(section, count);
 }
Example #4
0
 public void InsertSingleLine(int pos, PyFileSection section, string str)
 {
     // pos : relative to section, -1 mean end of section
     int row = SeekToSection(section, pos);
     if (row >= _py_mem.Count)
     {
         _py_mem.Add(str);
     } else {
         _py_mem.Insert(row, str);
     }
     MoveSectionSize(section, 1);
 }
Example #5
0
 public void InsertAfterSection(PyFileSection section, string str)
 {
     // pos : relative to section, -1 mean end of section
     int row = SeekToSection(section, -1);
     row++;
     if (row >= _py_mem.Count)
     {
         _py_mem.Add(str);
     } else {
         _py_mem.Insert(row, str);
     }
     MoveIndexes((PyFileSection)(section+1), 1);
 }
Example #6
0
 public void InsertBeforeSection(PyFileSection section, string str)
 {
     // pos : relative to section, -1 mean end of section
     int row = SeekToSection(section, 0);
     if (row - 1 < 0)  row = 0; else row--;
     _py_mem.Insert(row, str);
     MoveIndexes(section, 1);
 }
Example #7
0
        private void SeekToSection(PyFileSection section)
        {
            switch (startFrom)
            {
                case PyFileSection.PY_HEADER_SECTION :
                    if (count > 0)
                    {
                        _py_header_begin += count;
                        MoveIndexes(PyFileSection.PY_INIT_SECTION, count);
                    }
                    break;
                case PyFileSection.PY_INIT_SECTION :
                    _py_init_begin += count; // _py_header_size + _py_header_size + 1;
                    MoveIndexes(PyFileSection.PY_EVENTDECL_SECTION, count);
                    break;

                case PyFileSection.PY_EVENTDECL_SECTION :
                    _py_eventdecl_begin += count; // _py_init_begin + _py_init_size + 1;
                    MoveIndexes(PyFileSection.PY_EVENTIMPL_SECTION, count);
                    break;

                case PyFileSection.PY_EVENTIMPL_SECTION :
                    _py_eventimpl_begin += count; // _py_eventdecl_begin + _py_eventdecl_size + 1;
                    MoveIndexes(PyFileSection.PY_APP_SECTION, count);
                    break;

                case PyFileSection.PY_APP_SECTION :
                    _py_app_begin += count; // _py_eventimpl_begin + _py_eventimpl_size + 2;
                    break;

                case PyFileSection.PYBASE_INIT_SECTION :
                    if (count > 0)
                    {
                        _pybase_init_begin += count;
                        MoveIndexes(PyFileSection.PYBASE_PROPS_SECTION, count);
                    }
                    break;

                case PyFileSection.PYBASE_PROPS_SECTION :
                    _pybase_props_begin += count; // _py_eventimpl_begin + _py_eventimpl_size + 2;
                    break;

                case PyFileSection.PYBASE_LAYOUT_SECTION :
                    _pybase_layout_begin += count; // _py_eventimpl_begin + _py_eventimpl_size + 2;
                    break;
            }
        }
Example #8
0
 private long ConvertSectionToPosition(PyFileSection section, int pos)
 {
     int row = 0;
     long posf = 0;
     while (row < pos)
     {
         if ((int)section < 5)
         {
             posf += _py_mem.Reader.ReadLine().Length;
         } else {
             posf += _py_base_mem.Reader.ReadLine().Length;
         }
         row++;
     }
     return posf;
 }
Example #9
0
        public void MoveSectionSize(PyFileSection startFrom, int count)
        {
            // move the indexes of 'count', starting from 'startFrom'
            switch (startFrom)
            {
                case PyFileSection.PY_HEADER_SECTION :
                    if (count > 0)
                    {
                        _py_header_size += count;
                        MoveIndexes(PyFileSection.PY_INIT_SECTION, count);
                    }
                    break;
                case PyFileSection.PY_INIT_SECTION :
                    _py_init_size += count; // _py_header_size + _py_header_size + 1;
                    MoveIndexes(PyFileSection.PY_EVENTDECL_SECTION, count);
                    break;

                case PyFileSection.PY_EVENTDECL_SECTION :
                    _py_eventdecl_size += count; // _py_init_begin + _py_init_size + 1;
                    MoveIndexes(PyFileSection.PY_EVENTIMPL_SECTION, count);
                    break;

                case PyFileSection.PY_EVENTIMPL_SECTION :
                    _py_eventimpl_size += count; // _py_eventdecl_begin + _py_eventdecl_size + 1;
                    MoveIndexes(PyFileSection.PY_APP_SECTION, count);
                    break;

                case PyFileSection.PY_APP_SECTION :
                    _py_app_size += count; // _py_eventimpl_begin + _py_eventimpl_size + 2;
                    break;

                case PyFileSection.PYBASE_INIT_SECTION :
                    if (count > 0)
                    {
                        _pybase_init_size += count;
                        MoveIndexes(PyFileSection.PYBASE_PROPS_SECTION, count);
                    }
                    break;

                case PyFileSection.PYBASE_PROPS_SECTION :
                    _pybase_props_size += count; // _py_eventimpl_begin + _py_eventimpl_size + 2;
                    break;

                case PyFileSection.PYBASE_LAYOUT_SECTION :
                    _pybase_layout_size += count; // _py_eventimpl_begin + _py_eventimpl_size + 2;
                    break;
            }
        }
Example #10
0
 public void WriteLineToSection(PyFileSection section, string str, bool multiline)
 {
     string[] arr = Regex.Split(str, "\r\n");
     int count = arr.Length;
 }
Example #11
0
 public void InsertLinesToSection(int pos, PyFileSection section, string str)
 {
     // pos : relative to section, -1 mean end of section
     string[] arr = Regex.Split(str, "\r\n");
     int count = arr.Length;
     SeekToSection(section, pos);
     for (int i=0; i<count; i++)
     {
         _py_mem.Writer.WriteLine(arr[i]);
     }
 }
Example #12
0
 public void DeleteLineToSection(PyFileSection section, int rowcount)
 {
     // MemoryStream temp = new MemoryStream();
     MoveSectionSize(section, rowcount);
 }
Example #13
0
        private void SeekToSection(PyFileSection section, int pos)
        {
            // Seek to position
            // First : get position as row
            int ps = _py_sections[(int)section].Begin + pos + 1;
            if (pos == -1) ps = _py_sections[(int)section].End;
            if (ps > _py_sections[(int)section].End)
                ps = _py_sections[(int)section].End;

            if ((int)section < 5)
                _py_mem.Memory.Seek(0, SeekOrigin.Begin);
            else
                _py_base_mem.Memory.Seek(0, SeekOrigin.Begin);
            long posf = ConvertSectionToPosition(section, ps);
            if ((int)section < 5)
                _py_mem.Memory.Seek(posf, SeekOrigin.Begin);
            else
                _py_base_mem.Memory.Seek(posf, SeekOrigin.Begin);
        }
Example #14
0
 public void ReplaceEntireLine(int pos, PyFileSection section, string str)
 {
     // pos : relative to section, -1 mean end of section
     int row = SeekToSection(section, pos);
     if (row < _py_mem.Count)
     {
         _py_mem[row] = str;
     }
 }
Example #15
0
 public void DeleteLine(PyFileSection section, int pos, int rowcount)
 {
     // MemoryStream temp = new MemoryStream();
     int row = SeekToSection(section, pos);
     for (int i=0; i<rowcount; i++)
     {
         _py_mem.RemoveAt(row + i);
     }
     MoveSectionSize(section, -rowcount);
 }
Example #16
0
        private int SeekToSection(PyFileSection section, int pos)
        {
            /*
             		* B = 0, S = 0, E = B + S + 1
             		* Insert PS = B + 1 + Pos, If (Pos = -1) PS = E;
             		*/
             		int B = _py_sections[(int)section].Begin;
             		int E = _py_sections[(int)section].End;

            int ps = B + pos + 1;
            if (pos == -1) 	ps = E;
            if (ps < 0) 	ps = B + 1;
            if (ps > E) 	ps = E;

            return ps;
        }
Example #17
0
 public void InsertSingleLineToSection(int pos, PyFileSection section, string str)
 {
     // pos : relative to section, -1 mean end of section
     SeekToSection(section, pos);
     _py_mem.Writer.WriteLine(str);
 }