public static int CalcCyclomaticComplexity(MethodDefinition method)
        {
            Contract.Requires(method != null);
            Contract.Requires(method.Body != null);
            Contract.Requires(method.Body.Instructions != null);

            var plusOneOpcodes = new[] { "br", "be", "bg", "bl" };

            int count =
                method.Body.Instructions.OfType<Instruction>().Count(
                    o => plusOneOpcodes.Contains(o.OpCode.ToString().Substring(0, 2)));

            return count + 1;
        }
예제 #2
0
 public DockerAppName(string appName)
 {
   Contract.Requires(appName != null);
   var delimiter = new[] {'/'};
   var output = appName.Split(delimiter, 2);
   if (output.Length == 2)
   {
     Container = output[0];
     App = output[1];
   }
   else
   {
     Container = null;
     App = appName;
   }
 }
예제 #3
0
        public static byte[] Decompress(BinaryReader input, int channelCount)
        {
            Contract.Requires(input != null);
            Contract.Requires(channelCount >= 0);
            Contract.Ensures(Contract.Result<byte[]>() != null);

            var array1 = new[] { 0x2c, 0x2c };
            var array2 = new int[channelCount];

            var outputStream = new MemoryStream();
            using (var output = new BinaryWriter(outputStream))
            {
                input.ReadByte();
                var shift = input.ReadByte();

                for (var i = 0; i < channelCount; i++)
                {
                    var temp = input.ReadInt16();
                    array2[i] = temp;
                    output.Write(temp);
                }

                var channel = channelCount - 1;

                while (!input.BaseStream.IsRead())
                {
                    var value = input.ReadByte();

                    if (channelCount == 2)
                        channel = 1 - channel;

                    if ((value & 0x80) != 0)
                    {
                        switch (value & 0x7f)
                        {
                            case 0:
                                if (array1[channel] != 0)
                                    array1[channel]--;

                                output.Write((short)array2[channel]);
                                break;
                            case 1:
                                array1[channel] += 8;

                                if (array1[channel] > 0x58)
                                    array1[channel] = 0x58;

                                if (channelCount == 2)
                                    channel = 1 - channel;
                                break;
                            case 2:
                                break;
                            default:
                                array1[channel] -= 8;
                                if (array1[channel] < 0)
                                    array1[channel] = 0;

                                if (channelCount == 2)
                                    channel = 1 - channel;
                                break;
                        }
                    }
                    else
                    {
                        var temp1 = _sLookup1[array1[channel]];
                        var temp2 = temp1 >> shift;

                        if ((value & 1) != 0)
                            temp2 += (temp1 >> 0);

                        if ((value & 2) != 0)
                            temp2 += (temp1 >> 1);

                        if ((value & 4) != 0)
                            temp2 += (temp1 >> 2);

                        if ((value & 8) != 0)
                            temp2 += (temp1 >> 3);

                        if ((value & 0x10) != 0)
                            temp2 += (temp1 >> 4);

                        if ((value & 0x20) != 0)
                            temp2 += (temp1 >> 5);

                        var temp3 = array2[channel];

                        if ((value & 0x40) != 0)
                        {
                            temp3 -= temp2;
                            if (temp3 <= short.MinValue)
                                temp3 = short.MinValue;
                        }
                        else
                        {
                            temp3 += temp2;
                            if (temp3 >= short.MaxValue)
                                temp3 = short.MaxValue;
                        }

                        array2[channel] = temp3;
                        output.Write((short)temp3);

                        array1[channel] += _sLookup2[value & 0x1f];

                        if (array1[channel] < 0)
                            array1[channel] = 0;
                        else if (array1[channel] > 0x58)
                            array1[channel] = 0x58;
                    }
                }

                return outputStream.ToArray();
            }
        }