Ejemplo n.º 1
0
    static void Set(string cls, string state, string[] attributes)
    {
        ByteBuffer fbfr = ATMI.tpalloc("FML32", null, 1024);

        try {
            TPFBuilder.I.FaddString(ref fbfr, TMIB.TA_OPERATION, "SET");
            TPFBuilder.I.FaddString(ref fbfr, TMIB.TA_CLASS, cls);
            if (state != null)
            {
                TPFBuilder.I.FaddString(ref fbfr, TMIB.TA_STATE, state);
                if (state.Equals("CLEANING"))
                {
                    TPFBuilder.I.FaddInt(ref fbfr, TMIB.TA_FLAGS, TMIB.QMIB_FORCECLOSE);
                }
            }
            foreach (string attribute in attributes)
            {
                int    eqPos   = attribute.IndexOf('=');
                string key     = attribute.Substring(0, eqPos);
                string val     = attribute.Substring(eqPos + 1);
                int    fieldID = FML32.Fldid(key);
                TPFBuilder.I.FaddString(ref fbfr, fieldID, val);
            }
            try {
                Console.WriteLine("INFO: Executing " + cls + ".SET(" + state + ", "
                                  + ToString(attributes) + ")");
                ATMI.tpadmcall(fbfr, ref fbfr, 0);
            } catch (TPEMIB) {
                Console.WriteLine("ERROR: " + FML32.ToString(fbfr));
                Environment.Exit(1);
            }
        } finally {
            ATMI.tpfree(fbfr);
        }
    }
Ejemplo n.º 2
0
    // Receives data from a Conversation and writes it to a FileStream

    private static void Receive(Conversation conv, FileStream fs)
    {
        byte[] bytes = new byte[4096];
        int    len   = 0;

        ByteBuffer buffer = ATMI.tpalloc("CARRAY", null, 4096);

        try
        {
            while (true)
            {
                try
                {
                    conv.Receive(ref buffer, out len, 0);
                }
                catch (TPEV_SVCFAIL)
                { // A download error occurred
                    throw new IOException(StringUtils.ReadStringBuffer(buffer, len));
                }
                catch (TPEV_SVCSUCC)
                { // Download complete
                    Console.WriteLine();
                    return;
                }
                Console.Write('.'); // Progress indicator
                buffer.GetBytes(bytes, 0, len);
                fs.Write(bytes, 0, len);
            }
        }
        finally
        {
            ATMI.tpfree(buffer);
        }
    }
Ejemplo n.º 3
0
    public static void Main(string[] args)
    {
        if (args.Length != 2)
        {
            Console.WriteLine("Usage: SimpleDequeuer <qspace> <qname>");
            Environment.Exit(1);
        }

        string qSpace = args[0];
        string qName  = args[1];

        ATMI.tpinit(null);
        try
        {
            ByteBuffer data = ATMI.tpalloc("STRING", null, 512);
            try
            {
                TPQCTL ctl = new TPQCTL();
                ctl.flags = ATMI.TPQWAIT;
                int len;
                ATMI.tpdequeue(qSpace, qName, ctl, ref data, out len, 0);
                string message = StringUtils.ReadStringBuffer(data, len);
                Console.WriteLine("Dequeued '" + message + "' from " + qSpace + "." + qName);
            }
            finally
            {
                ATMI.tpfree(data);
            }
        }
        finally
        {
            ATMI.tpterm();
        }
    }
Ejemplo n.º 4
0
    // Creates a STRING buffer and fills it with the given string

    public static ByteBuffer NewStringBuffer(string s)
    {
        byte[]     bytes  = Encoding.Default.GetBytes(s);                   // Convert to single-byte character sequence
        ByteBuffer buffer = ATMI.tpalloc("STRING", null, bytes.Length + 1); // One byte extra for terminating zero

        buffer.PutBytes(bytes);
        buffer.PutByte(bytes.Length, 0); // Terminating zero
        return(buffer);
    }
Ejemplo n.º 5
0
        public static void TEST(TPSVCINFO svcInfo)
        {
            string message = "Installation OK";

            byte[]     bytes = Encoding.Default.GetBytes(message);
            ByteBuffer reply = ATMI.tpalloc("STRING", null, bytes.Length + 1);

            reply.PutBytes(bytes);
            reply.PutByte(bytes.Length, 0);
            ATMI.tpreturn(ATMI.TPSUCCESS, 0, reply, 0, 0);
        }
Ejemplo n.º 6
0
    public static void Main(string[] args)
    {
        if (args.Length != 1)
        {
            Console.WriteLine("Usage: SimpleAsyncClient <message>");
            Environment.Exit(1);
        }

        string message = args[0];

        ATMI.tpinit(null);
        try
        {
            int        cd;
            ByteBuffer sendbuf = StringUtils.NewStringBuffer(message);
            try
            {
                Console.WriteLine("Sending '" + message + "' to service TOUPPER");
                cd = ATMI.tpacall("TOUPPER", sendbuf, 0, 0);
            }
            finally
            {
                ATMI.tpfree(sendbuf);
            }

            ByteBuffer rcvbuf = ATMI.tpalloc("STRING", null, 256);
            try
            {
                int rcvlen;
                ATMI.tpgetrply(ref cd, ref rcvbuf, out rcvlen, 0);
                message = StringUtils.ReadStringBuffer(rcvbuf, rcvlen);
                Console.WriteLine("Returned string is: " + message);
            }
            finally
            {
                ATMI.tpfree(rcvbuf);
            }
        }
        finally
        {
            ATMI.tpterm();
        }
    }
Ejemplo n.º 7
0
    public static void Main(string[] args)
    {
        if (args.Length != 1)
        {
            Console.WriteLine("Usage: SimpleClient <message>");
            Environment.Exit(1);
        }

        string message = args[0];

        ATMI.tpinit(null);
        try
        {
            byte[]     bytes   = Encoding.Default.GetBytes(message);
            int        sendlen = bytes.Length + 1; // One byte extra for terminating zero
            ByteBuffer sendbuf = ATMI.tpalloc("STRING", null, sendlen);
            try
            {
                ByteBuffer rcvbuf = ATMI.tpalloc("STRING", null, sendlen);
                try
                {
                    sendbuf.PutBytes(bytes);
                    sendbuf.PutByte(bytes.Length, 0); // Terminating zero
                    int rcvlen;
                    ATMI.tpcall("TOUPPER", sendbuf, 0, ref rcvbuf, out rcvlen, 0);
                    rcvbuf.GetBytes(bytes);
                    Console.WriteLine("Returned string is: " + Encoding.Default.GetString(bytes));
                }
                finally
                {
                    ATMI.tpfree(rcvbuf);
                }
            }
            finally
            {
                ATMI.tpfree(sendbuf);
            }
        }
        finally
        {
            ATMI.tpterm();
        }
    }
Ejemplo n.º 8
0
 public static void Main(string[] args)
 {
     ATMI.tpinit(null);
     try {
         ByteBuffer reply = ATMI.tpalloc("STRING", null, 1024);
         try {
             int len;
             ATMI.tpcall("TEST", null, 0, ref reply, out len, 0);
             byte[] bytes = new byte[len - 1];
             reply.GetBytes(bytes);
             string message = Encoding.Default.GetString(bytes);
             Console.WriteLine(message);
         } finally {
             ATMI.tpfree(reply);
         }
     } finally {
         ATMI.tpterm();
     }
 }
Ejemplo n.º 9
0
    public static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("Usage: SimpleFML32Client <field>=<value> ...");
            Environment.Exit(1);
        }

        ATMI.tpinit(null);
        try
        {
            ByteBuffer fbfr = ATMI.tpalloc("FML32", null, 512);
            try
            {
                foreach (string arg in args)
                {
                    int    eqPos = arg.IndexOf('=');
                    string key   = arg.Substring(0, eqPos);
                    string val   = arg.Substring(eqPos + 1);
                    int    fldid = FML32.Fldid(key);
                    TPFBuilder.I.FaddString(ref fbfr, fldid, val);
                }

                int len;
                ATMI.tpcall("FML32_TOUPPER", fbfr, 0, ref fbfr, out len, 0);

                Console.WriteLine("Returned FML32 buffer is: " + FML32.ToString(fbfr));
            }
            finally
            {
                ATMI.tpfree(fbfr);
            }
        }
        finally
        {
            ATMI.tpterm();
        }
    }
Ejemplo n.º 10
0
    // Reads data from a FileStream and sends it across a conversational connection.

    private static void Send(FileStream fs, int cd)
    {
        byte[] bytes = new byte[4096];

        ByteBuffer buffer = ATMI.tpalloc("CARRAY", null, 4096);

        try
        {
            while (true)
            {
                int len = fs.Read(bytes, 0, 4096);
                if (len == 0)
                { // End of file
                    return;
                }
                buffer.PutBytes(bytes, 0, len);
                ATMI.tpsend(cd, buffer, len, 0);
            }
        }
        finally
        {
            ATMI.tpfree(buffer);
        }
    }