示例#1
0
 /// <summary>
 /// Read the message content from the reader specified.
 /// </summary>
 public void FromElementReader(K3pElementReader r)
 {
     foreach (FieldInfo fi in this.GetType().GetFields())
     {
         fi.SetValue(this, InternalFromElementReader(r, fi.FieldType));
     }
 }
示例#2
0
        /// <summary>
        /// Handle the KMOD connection result.
        /// </summary>
        private void HandleConnectResult()
        {
            try
            {
                // Get an element reader and read the tool info.
                K3pElementReader reader = new K3pElementReader(m_curThread.GetNextK3pElement);
                UInt32           ins    = reader.Ins();
                if (ins != K3p.KMO_COGITO_ERGO_SUM)
                {
                    throw new Exception("unexpected reply to KMOD connect command");
                }
                (new K3p.kmo_tool_info()).FromElementReader(reader);

                // We have received the connect results.
                m_curThread.HaveConnectResultFlag = true;

                // We no longer have a command.
                m_curCommand = null;

                // If we have a transaction, start it.
                if (m_curTransaction != null)
                {
                    StartCurrentTransaction();
                }
            }

            catch (Exception ex)
            {
                Killall(ex);
            }

            RequestRun();
        }
示例#3
0
        /// <summary>
        /// Return the value of the K3P message field specified.
        /// </summary>
        private Object InternalFromElementReader(K3pElementReader r, Type t)
        {
            if (t == typeof(UInt32))
            {
                return(r.Int());
            }
            else if (t.IsEnum)
            {
                return(Enum.ToObject(t, r.Int()));
            }
            else if (t == typeof(String))
            {
                return(r.Str());
            }
            else if (t == typeof(byte[]))
            {
                return(r.Bin());
            }

            else if (t.IsArray)
            {
                Type   elType = t.GetElementType();
                UInt32 size   = r.Int();
                Array  a      = Array.CreateInstance(elType, size);
                for (UInt32 i = 0; i < size; i++)
                {
                    a.SetValue(InternalFromElementReader(r, elType), i);
                }
                return(a);
            }

            else if (t.IsSubclassOf(typeof(K3pMsg)))
            {
                K3pMsg m = (K3pMsg)Activator.CreateInstance(t);
                m.FromElementReader(r);
                return(m);
            }

            else
            {
                throw new K3pException("unsupported type " + t.FullName + " in K3P");
            }
        }