Esempio n. 1
0
            public void Read(TProtocol iprot)
            {
                TField field;

                iprot.ReadStructBegin();
                while (true)
                {
                    field = iprot.ReadFieldBegin();
                    if (field.Type == TType.Stop)
                    {
                        break;
                    }
                    switch (field.ID)
                    {
                    case 0:
                        if (field.Type == TType.Struct)
                        {
                            Success = new SharedStruct();
                            Success.Read(iprot);
                        }
                        else
                        {
                            TProtocolUtil.Skip(iprot, field.Type);
                        }
                        break;

                    default:
                        TProtocolUtil.Skip(iprot, field.Type);
                        break;
                    }
                    iprot.ReadFieldEnd();
                }
                iprot.ReadStructEnd();
            }
        public int calculate(int logid, Work work)
        {
            Console.WriteLine("calculate({0}, [{1},{2},{3}])", logid, work.Op, work.Num1, work.Num2);
            int val = 0;
            switch (work.Op)
            {
                case Operation.ADD:
                    val = work.Num1 + work.Num2;
                    break;

                case Operation.SUBTRACT:
                    val = work.Num1 - work.Num2;
                    break;

                case Operation.MULTIPLY:
                    val = work.Num1*work.Num2;
                    break;

                case Operation.DIVIDE:
                    if (work.Num2 == 0)
                    {
                        var io = new InvalidOperation();
                        io.What = (int) work.Op;
                        io.Why = "Cannot divide by 0";
                        throw io;
                    }
                    val = work.Num1/work.Num2;
                    break;

                default:
                    {
                        var io = new InvalidOperation();
                        io.What = (int) work.Op;
                        io.Why = "Unknown operation";
                        throw io;
                    }
            }

            var entry = new SharedStruct();
            entry.Key = logid;
            entry.Value = val.ToString();
            log[logid] = entry;

            return val;
        }
 public void Read(TProtocol iprot)
 {
     TField field;
     iprot.ReadStructBegin();
     while (true)
     {
       field = iprot.ReadFieldBegin();
       if (field.Type == TType.Stop) {
     break;
       }
       switch (field.ID)
       {
     case 0:
       if (field.Type == TType.Struct) {
     Success = new SharedStruct();
     Success.Read(iprot);
       } else {
     TProtocolUtil.Skip(iprot, field.Type);
       }
       break;
     default:
       TProtocolUtil.Skip(iprot, field.Type);
       break;
       }
       iprot.ReadFieldEnd();
     }
     iprot.ReadStructEnd();
 }