Esempio n. 1
0
        private TemplateInfo DecodeTemplate()
        {
            var template = new TemplateInfo();

            bool flag = true;
            while (flag)
            {
                if (_currentIndex >= _runningDna.Length)
                {
                    lock (_runningMutex)
                    {
                        _state = RunningState.Stoped;
                        return null;
                    }
                }

                if (_runningDna.HasPatternAtPosition(
                    new[]
                        {
                            "C"
                        },
                    _currentIndex))
                {
                    ++_currentIndex;
                    template.AppendBack('I');
                    continue;
                }

                if (_runningDna.HasPatternAtPosition(
                    new[]
                        {
                            "F"
                        },
                    _currentIndex))
                {
                    ++_currentIndex;
                    template.AppendBack('C');
                    continue;
                }

                if (_runningDna.HasPatternAtPosition(
                    new[]
                        {
                            "P"
                        },
                    _currentIndex))
                {
                    ++_currentIndex;
                    template.AppendBack('F');
                    continue;
                }

                if (_runningDna.HasPatternAtPosition(
                    new[]
                        {
                            "IC"
                        },
                    _currentIndex))
                {
                    _currentIndex += 2;
                    template.AppendBack('P');
                    continue;
                }

                if (_runningDna.HasPatternAtPosition(
                    new[]
                        {
                            "IF", "IP"
                        },
                    _currentIndex))
                {
                    _currentIndex += 2;
                    int level = DecodeNumber();
                    int reference = DecodeNumber();
                    template.AddReference(reference, level);
                    continue;
                }

                if (_runningDna.HasPatternAtPosition(
                    new[]
                        {
                            "IIC", "IIF"
                        },
                    _currentIndex))
                {
                    _currentIndex += 3;
                    flag = false;
                    continue;
                }

                if (_runningDna.HasPatternAtPosition(
                    new[]
                        {
                            "IIP"
                        },
                    _currentIndex))
                {
                    _currentIndex += 3;
                    int reference = DecodeNumber();
                    template.AddLengthOfReference(reference);
                    continue;
                }

                if (_runningDna.HasPatternAtPosition(
                    new[]
                        {
                            "III"
                        },
                    _currentIndex))
                {
                    string toRna = _runningDna.Substring(_currentIndex + 3, 7).ToString();
                    OutputToRna(toRna);
                    _currentIndex += 10;
                    continue;
                }

                // Else stop.
                lock (_runningMutex)
                {
                    _state = RunningState.Stoped;
                    return null;
                }
            }

            return template;
        }