Пример #1
0
 static void Main(string[] args)
 {
     try
     {
         ContainerUtils.RegisterDependencies(Container);
         Application = Container.Get <IProgram>();
         var runSettings = Utils.ParseCommandLineArguments(args);
         Application.Run(runSettings);
     }
     catch (ArgumentException ex)
     {
         Console.WriteLine($"Application failed due to wrong arguments message : {ex.Message}");
     }
     catch (FormatException ex)
     {
         Console.WriteLine($"Application failed due to wrong format message : {ex.Message}");
     }
     catch (SocketException ex)
     {
         Console.WriteLine($"Application connection failed due to : {ex.Message}");
     }
     catch (Exception ex)
     {
         Console.WriteLine(
             $"Application failed with an unexpected exception message : {ex.Message} stack trace  : {ex.StackTrace} and inner exception : {ex.InnerException?.Message}");
     }
     finally
     {
         Console.ReadKey();
     }
 }
Пример #2
0
 /// <summary>
 ///     Applies the skin on all controls inside the form.
 /// </summary>
 private void ApplyAllControlsSkin()
 {
     foreach (Control c in Controls)
     {
         ContainerUtils.ApplySkinToControl(FormSkin, c);
     }
 }
Пример #3
0
        public ParametricEquation <F> Kernel()
        {
            var result = new List <Vector <F> >();
            var trap   = ToTrap();
            var rows   = new List <int>();
            int m      = 0;

            for (int n = 0; n < N; ++n)
            {
                if (trap.Column(n).IsNull())
                {
                    result.Add(Vector <F> .UnitVector(N, n));
                }
                else if (m < trap.M && trap[m][n].IsOne())
                {
                    rows.Add(n);
                    ++m;
                }
                else
                {
                    var vector = ContainerUtils.UniformArray(new F(), N);
                    vector[n] = new F().ONE;
                    for (int i = 0; i < rows.Count; ++i)
                    {
                        vector[rows[i]] = trap[i][n].AdditiveInverse();
                    }
                    result.Add(new Vector <F>(vector));
                }
            }
            return(new ParametricEquation <F>(Vector <F> .NullVector(N), result));
        }
Пример #4
0
            private void Rollback(ulong deliveryTag, Exception e)
            {
                if (_container.IsChannelTransacted)
                {
                    RabbitUtils.RollbackIfNecessary(Model);
                }

                if (AckRequired || ContainerUtils.IsRejectManual(e))
                {
                    try
                    {
                        if (MessagesPerAck > 1)
                        {
                            lock (_lock)
                            {
                                if (PendingAcks > 0)
                                {
                                    SendAck(DateTimeOffset.Now.ToUnixTimeMilliseconds());
                                }
                            }
                        }

                        Model.BasicNack(deliveryTag, true, ContainerUtils.ShouldRequeue(_container.DefaultRequeueRejected, e, _logger));
                    }
                    catch (IOException e1)
                    {
                        _logger?.LogError("Failed to nack message", e1);
                    }
                }

                if (_container.IsChannelTransacted)
                {
                    RabbitUtils.CommitIfNecessary(Model);
                }
            }
Пример #5
0
 protected virtual void PrepareHolderForRollback(RabbitResourceHolder resourceHolder, Exception exception)
 {
     if (resourceHolder != null)
     {
         resourceHolder.RequeueOnRollback = AlwaysRequeueWithTxManagerRollback ||
                                            ContainerUtils.ShouldRequeue(DefaultRequeueRejected, exception, _logger);
     }
 }
        private void tmiCentreImage_Click(object sender, EventArgs e)
        {
            var panPctBox = ContainerUtils.GetToolStripSourceControl(sender) as PannablePictureBox;

            if (panPctBox != null)
            {
                panPctBox.CenterImage();
            }
        }
        private void tmiChangeImage_Click(object sender, EventArgs e)
        {
            var panPctBox = ContainerUtils.GetToolStripSourceControl(sender);

            if (panPctBox != null)
            {
                IconSet(panPctBox);
            }
        }
Пример #8
0
        public Distributer(int inputs, int outputs)
        {
            Inputs  = new ConnectionsArray(inputs);
            Outputs = new ConnectionsArray(outputs);

            InputWeights = new Weights(ContainerUtils.UniformArray(1f, inputs));

            OutputWeights = new Weights(ContainerUtils.UniformArray(1f, outputs));
        }
Пример #9
0
        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);

            //Apply the skin to any control newly added to the form.
            if (FormSkin != null && !DesignMode)
            {
                ContainerUtils.ApplySkinToControl(FormSkin, e.Control);
            }
        }
 private void AsyncFailure(IMessage request, RC.IModel channel, Exception exception)
 {
     _logger?.LogError(exception, "Async method was completed with an exception for {request} ", request);
     try
     {
         channel.BasicNack(request.Headers.DeliveryTag().Value, false, ContainerUtils.ShouldRequeue(DefaultRequeueRejected, exception, _logger));
     }
     catch (Exception e)
     {
         _logger?.LogError(e, "Failed to nack message");
     }
 }
        public void ApplySkin(BaseSkin skin)
        {
            FlatStyle = skin.TabControlFlatStyle;
            FlatTabSelectedBackColor = skin.TabControlSelectedTabBackColor;
            FlatTabSelectedForeColor = skin.TabControlSelectedTabForeColor;
            FlatTabBorderColor       = skin.TabControlTabBorderColor;

            foreach (Control c in Controls)
            {
                ContainerUtils.ApplySkinToControl(skin, c);
            }
        }
Пример #12
0
        public static Matrix <F> DiagonalMatrix(IEnumerable <F> values)
        {
            var dim    = values.Count();
            var result = ContainerUtils.UniformArray(ContainerUtils.UniformArray(new F(), dim), dim);
            int i      = 0;

            foreach (var f in values)
            {
                result[i][i] = f;
                ++i;
            }
            return(new Matrix <F>(result));
        }
        /// <summary>
        /// Creates a <see cref="FileSystemXmlRepository"/> with keys stored at the given directory.
        /// </summary>
        /// <param name="directory">The directory in which to persist key material.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        public FileSystemXmlRepository(DirectoryInfo directory, ILoggerFactory loggerFactory)
        {
            Directory = directory ?? throw new ArgumentNullException(nameof(directory));

            _logger = loggerFactory.CreateLogger <FileSystemXmlRepository>();

            try
            {
                if (ContainerUtils.IsContainer && !ContainerUtils.IsVolumeMountedFolder(Directory))
                {
                    // warn users that keys may be lost when running in docker without a volume mounted folder
                    _logger.UsingEphemeralFileSystemLocationInContainer(Directory.FullName);
                }
            }
            catch (Exception ex)
            {
                // Treat exceptions as non-fatal when attempting to detect docker.
                // These might occur if fstab is an unrecognized format, or if there are other unusual
                // file IO errors.
                _logger.LogTrace(ex, "Failure occurred while attempting to detect docker.");
            }
        }
Пример #14
0
        internal VideoParams264(TrackEntry videoTrack)
        {
            // File.WriteAllBytes( @"C:\Temp\2remove\mkv\videoPrivateData.bin", videoTrack.codecPrivate );
            ReadOnlySpan <byte> codecPrivate = videoTrack.codecPrivate.AsSpan();
            int          cbHeader            = Marshal.SizeOf <NativeStruct>();
            NativeStruct ns = codecPrivate.Slice(0, cbHeader).cast <NativeStruct>()[0];

            profile = ns.profileCode;
            profileCompatibility = ns.profileCompatibility;
            levelCode            = ns.levelCode;

            int offset = cbHeader;

            sps = ContainerUtils.copyBlobs(ns.numOfSequenceParameterSets, codecPrivate, ref offset);

            // File.WriteAllBytes( @"C:\Temp\2remove\mkv\sps.bin", sps[ 0 ] );

            int ppsCount = codecPrivate[offset++];

            pps = ContainerUtils.copyBlobs(ppsCount, codecPrivate, ref offset);

            ReadOnlySpan <byte> spsBlob = sps[0].AsSpan();

            if (MiscUtils.getNaluType(spsBlob[0]) != eNaluType.SPS)
            {
                throw new ApplicationException("The SPS is invalid, wrong NALU type");
            }
            spsBlob = spsBlob.Slice(1);

            BitReader spsReader = new BitReader(spsBlob);

            parsedSps = new SequenceParameterSet(ref spsReader);

            chromaFormat   = parsedSps.chromaFormat;
            bitDepthLuma   = parsedSps.bitDepthLuma;
            bitDepthChroma = parsedSps.bitDepthChroma;
            m_decodedSize  = new sDecodedVideoSize(parsedSps.decodedSize, parsedSps.cropRectangle, chromaFormat);
        }
Пример #15
0
        public void RollbackOnExceptionIfNecessary(Exception ex)
        {
            bool ackRequired = !AcknowledgeMode.IsAutoAck() && (!AcknowledgeMode.IsManual() || ContainerUtils.IsRejectManual(ex));

            try
            {
                if (Transactional)
                {
                    Logger?.LogDebug(ex, "Initiating transaction rollback on application exception");
                    RabbitUtils.RollbackIfNecessary(Channel);
                }

                if (ackRequired)
                {
                    if (DeliveryTags.Count > 0)
                    {
                        ulong deliveryTag = DeliveryTags.Max();
                        Channel.BasicNack(deliveryTag, true, ContainerUtils.ShouldRequeue(DefaultRequeueRejected, ex, Logger));
                    }

                    if (Transactional)
                    {
                        // Need to commit the reject (=nack)
                        RabbitUtils.CommitIfNecessary(Channel);
                    }
                }
            }
            catch (Exception e)
            {
                Logger?.LogError(ex, "Application exception overridden by rollback exception");
                throw RabbitExceptionTranslator.ConvertRabbitAccessException(e); // NOSONAR stack trace loss
            }
            finally
            {
                DeliveryTags.Clear();
            }
        }
Пример #16
0
 public void TestMustNotRequeue()
 {
     Assert.False(ContainerUtils.ShouldRequeue(
                      true,
                      new ListenerExecutionFailedException(string.Empty, new RabbitRejectAndDontRequeueException("no requeue"))));
 }
Пример #17
0
 public void TestMustRequeue()
 {
     Assert.True(ContainerUtils.ShouldRequeue(
                     false,
                     new ListenerExecutionFailedException(string.Empty, new ImmediateRequeueException("requeue"))));
 }
Пример #18
0
 public void DeterminesFolderIsMounted(string directory)
 {
     Assert.True(ContainerUtils.IsDirectoryMounted(new DirectoryInfo(directory), fstab));
 }
Пример #19
0
 private void AsyncFailure(Message request, IModel channel, Exception exception)
 {
     _logger?.LogError("Future or Mono was completed with an exception for " + request, exception);
     try
     {
         channel.BasicNack(request.MessageProperties.DeliveryTag.Value, false, ContainerUtils.ShouldRequeue(DefaultRequeueRejected, exception, _logger));
     }
     catch (IOException e)
     {
         _logger?.LogError("Failed to nack message", e);
     }
 }
 public SerializableConcurrentContainer([NotNull][ItemNotNull] IEnumerable <TValue> values) : base(
         ContainerUtils.GetKeySelector <TValue, TKey>(), values,
         ContainerUtils.GetKeyEqualityComparer <TValue, TKey>())
 {
 }
 public SerializableConcurrentContainer() : base(ContainerUtils.GetKeySelector <TValue, TKey>(),
                                                 Array.Empty <TValue>(), ContainerUtils.GetKeyEqualityComparer <TValue, TKey>())
 {
 }
Пример #22
0
        private static void ApplySkinFromConfig()
        {
            var skin = Config.Instance.LastSkin;

            SkinHandler.SetCurrentSkin(ContainerUtils.SkinFromString(skin));
        }
Пример #23
0
        public AVC1SampleEntry(Mp4Reader reader, int bytesLeft) :
            base(reader, ref bytesLeft)
        {
            var avcc = reader.readStructure <Structures.AVCDecoderConfigurationRecord>();

            if (avcc.boxType != eAVC1BoxType.avcC)
            {
                throw new NotImplementedException();
            }
            bytesLeft -= decoderConfigSizeof;

            profile = avcc.profileCode;
            profileCompatibility = avcc.profileCompatibility;
            levelCode            = avcc.levelCode;
            naluLengthSize       = checked ((byte)(avcc.lengthSizeMinusOne + 1));

            Span <byte> remainingStuff = stackalloc byte[bytesLeft];

            reader.read(remainingStuff);

            int readOffset = 0;

            sps = ContainerUtils.copyBlobs(avcc.numOfSequenceParameterSets, remainingStuff, ref readOffset);

            if (null == sps)
            {
                throw new ArgumentException("The file doesn't have an SPS");
            }
            // SpsData spsData = new SpsData( sps[ 0 ] );
            // File.WriteAllBytes( @"C:\Temp\2remove\h264\sps.bin", sps[ 0 ] );

            int ppsCount = remainingStuff[readOffset++];

            pps = ContainerUtils.copyBlobs(ppsCount, remainingStuff, ref readOffset);

            if (null == sps || null == pps)
            {
                throw new NotImplementedException("Vrmac Video only supports mp4 files with out-of-band SPS and PPS blobs, in the `avcC` atom of the file.");
            }
            if (sps.Length > 1 || pps.Length > 1)
            {
                throw new NotImplementedException("Vrmac Video only supports mp4 files with a single out-of-band SPS and PPS for the complete video.");                     // The video payload may include other PPS-es, these are fine.
            }
            if (readOffset >= remainingStuff.Length)
            {
                return;
            }

            remainingStuff = remainingStuff.Slice(readOffset);

            if (readOffset + decoderConfigSizeof < avcc.length)
            {
                // The spec I have says the files with profile IDs 100, 110, 122, 144 have this.
                // The mp4 file I use to test this code has 100, but misses this data.
                chromaFormat   = (eChromaFormat)(remainingStuff[0] & 3);
                bitDepthLuma   = (byte)((remainingStuff[1] & 7) + 8);
                bitDepthChroma = (byte)((remainingStuff[2] & 7) + 8);
                int numPpsEx = remainingStuff[3];
                readOffset = 4;                 // Resetting because sliced the span
                ppsExt     = ContainerUtils.copyBlobs(numPpsEx, remainingStuff, ref readOffset);

                remainingStuff = remainingStuff.Slice(readOffset);
            }
            else
            {
                // https://en.wikipedia.org/wiki/Advanced_Video_Coding#Feature_support_in_particular_profiles
                chromaFormat   = eChromaFormat.c420;
                bitDepthLuma   = 8;
                bitDepthChroma = 8;
            }

            while (!remainingStuff.IsEmpty)
            {
                int          size = BitConverter.ToInt32(remainingStuff).endian();
                eAVC1BoxType code = (eAVC1BoxType)BitConverter.ToUInt32(remainingStuff.Slice(4));
                switch (code)
                {
                case eAVC1BoxType.btrt:
                    bitRate           = new MPEG4BitRateBox(remainingStuff);
                    m_maxBytesInFrame = bitRate.decodingBufferSize;
                    break;
                }
                remainingStuff = remainingStuff.Slice(size);
            }
        }
Пример #24
0
        private static Expression InternalCompile(LinkedListNode <Token> first, LinkedListNode <Token> last, int level = 0)
        {
            if (first.Value.Type == TokenType.SBracket && MatchingBracketForward(first) == last)
            {
                return(InternalCompile(first.Next, last.Previous, 0));
            }
            else if (first.Value.Type == TokenType.Negation && first.Next.Value.Type == TokenType.SBracket && MatchingBracketForward(first.Next) == last)
            {
                return(new Not(InternalCompile(first.Next.Next, last.Previous, 0)));
            }
            LinkedListNode <Token> token;
            int brackets = 0;

            switch (level)
            {
            case 0:
                Debug.Assert(level == 0);
                // Equality
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Value == "=")
                        {
                            if (token.Previous.Value.Type == TokenType.Negation)
                            {
                                return(new XOr(InternalCompile(first, token.Previous.Previous, level), InternalCompile(token.Next, last, level)));
                            }
                            else
                            {
                                return(new Iff(InternalCompile(first, token.Previous, level), InternalCompile(token.Next, last, level)));
                            }
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                Debug.Assert(brackets == 0, "Unbalanced brackets");
                level++;
                goto case 1;

            case 1:
                Debug.Assert(level == 1);
                // Implication
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Value == ">")
                        {
                            if (token.Previous.Value.Type == TokenType.Negation)
                            {
                                throw new Exception("Implication operator cannot be negated. Tokens: " + ContainerUtils.AsString(first, last));
                            }
                            return(new Implies(InternalCompile(first, token.Previous, level), InternalCompile(token.Next, last, level)));
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                level++;
                goto case 2;

            case 2:
                Debug.Assert(level == 2);
                // Or
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Value == "+" || token.Value.Value == "|")
                        {
                            if (token.Previous.Value.Type == TokenType.Negation)
                            {
                                return(new NOr(InternalCompile(first, token.Previous.Previous, level), InternalCompile(token.Next, last, level)));
                            }
                            else
                            {
                                return(new Or(InternalCompile(first, token.Previous, level), InternalCompile(token.Next, last, level)));
                            }
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                level++;
                goto case 3;

            case 3:
                Debug.Assert(level == 3);
                // And
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Value == "*" || token.Value.Value == "&")
                        {
                            if (token.Previous.Value.Type == TokenType.Negation)
                            {
                                return(new NAnd(InternalCompile(first, token.Previous.Previous, level), InternalCompile(token.Next, last, level)));
                            }
                            else
                            {
                                return(new And(InternalCompile(first, token.Previous, level), InternalCompile(token.Next, last, level)));
                            }
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                level++;
                goto case 4;

            case 4:
                Debug.Assert(level == 4);
                // Variables
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Type == TokenType.Identifier)
                        {
                            if (token != first && token.Previous.Value.Type == TokenType.Negation)
                            {
                                return(new Not(new Variable(token.Value.Value)));
                            }
                            else
                            {
                                return(new Variable(token.Value.Value));
                            }
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                level++;
                goto case 5;

            case 5:
                Debug.Assert(level == 5);
                // Literals
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Type == TokenType.Value)
                        {
                            return(new ValueExpression(token.Value.Value == "1"));
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                //level++;
                goto default;

            default:
                throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
            }
        }
Пример #25
0
 public static Vector <F> NullVector(int dim)
 {
     return(new Vector <F>(ContainerUtils.UniformArray(new F(), dim)));
 }
Пример #26
0
        private static Expression InternalCompile(LinkedListNode <Token> first, LinkedListNode <Token> last, FunctionManager functions, int level = 0)
        {
            if (first.Value.Type == TokenType.SBracket && MatchingBracketForward(first) == last)
            {
                return(InternalCompile(first.Next, last.Previous, functions, 0));
            }
            LinkedListNode <Token> token;
            int brackets = 0;

            switch (level)
            {
            case 0:
                Debug.Assert(level == 0);
                // Additions and subtractions
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Value == "+")
                        {
                            return(functions.Operator("+").Create(InternalCompile(first, token.Previous, functions, level), InternalCompile(token.Next, last, functions, level)));
                        }
                        if (token.Value.Value == "-")
                        {
                            return(functions.Operator("-").Create(InternalCompile(first, token.Previous, functions, level), InternalCompile(token.Next, last, functions, level)));
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                Debug.Assert(brackets == 0, "Unbalanced brackets");
                level++;
                goto case 1;

            case 1:
                Debug.Assert(level == 1);
                // Multiplications and divisions
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Value == "*")
                        {
                            return(functions.Operator("*").Create(InternalCompile(first, token.Previous, functions, level), InternalCompile(token.Next, last, functions, level)));
                        }
                        if (token.Value.Value == "/")
                        {
                            return(functions.Operator("/").Create(InternalCompile(first, token.Previous, functions, level), InternalCompile(token.Next, last, functions, level)));
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                level++;
                goto case 2;

            case 2:
                Debug.Assert(level == 2);
                // Powers
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Value == "^")
                        {
                            return(functions.Operator("^").Create(InternalCompile(first, token.Previous, functions, level), InternalCompile(token.Next, last, functions, level)));
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                level++;
                goto case 3;

            case 3:
                Debug.Assert(level == 3);
                // Functions & variables
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Type == TokenType.Identifier)
                        {
                            if (token.Next != null && token.Next.Value.Type == TokenType.SBracket)
                            {
                                return(functions.Function(token.Value.Value).Create(FunctionArgumentsCompile(token.Next.Next, MatchingBracketForward(token.Next), functions)));
                            }
                            else
                            {
                                return(new Variable(token.Value.Value));
                            }
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                level++;
                goto case 4;

            case 4:
                Debug.Assert(level == 4);
                // Literals
                token = last;
                while (token != first.Previous)
                {
                    if (token.Value.Type == TokenType.SBracket)
                    {
                        brackets--;
                    }
                    else if (token.Value.Type == TokenType.EBracket)
                    {
                        brackets++;
                    }
                    else if (brackets == 0)
                    {
                        if (token.Value.Type == TokenType.Value)
                        {
                            return(new ValueExpression(double.Parse(token.Value.Value)));
                        }
                    }
                    else if (brackets <= 0)
                    {
                        throw new Exception("SumTingWong. Tokens: " + ContainerUtils.AsString(first, last));
                    }
                    token = token.Previous;
                }
                if (brackets != 0)
                {
                    throw new Exception("Unbalanced brackets");
                }
                //level++;
                goto default;

            default:
                throw new Exception();
            }
        }