示例#1
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);
        }
    }
示例#2
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);
        }
    }
示例#3
0
    // The DOWNLOAD service routine

    public static void DOWNLOAD(TPSVCINFO rqst)
    {
        if ((rqst.flags & ATMI.TPSENDONLY) == 0)
        {
            TUX.userlog("ERROR: Client not in receive mode");
            ATMI.tpreturn(ATMI.TPFAIL, 0, null, 0, 0); // Return null message as client is not in receive mode
            return;
        }

        string fileName = StringUtils.ReadStringBuffer(rqst.data, rqst.len);

        try
        {
            FileStream fs = File.OpenRead(fileName);
            try
            {
                Send(fs, rqst.cd);
            }
            finally
            {
                fs.Close();
            }
            ATMI.tpreturn(ATMI.TPSUCCESS, 0, null, 0, 0);
        }
        catch (FileNotFoundException eFileNotFound)
        {
            ServerUtils.ReturnReply(ATMI.TPFAIL, 0, eFileNotFound.Message);
        }
    }
示例#4
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();
        }
    }
示例#5
0
        /// <summary>
        /// Closes the conversation.
        /// </summary>
        ///
        /// <remarks>
        /// If the conversation has not terminated at the time this method is called
        /// then the conversation is aborted.
        /// </remarks>
        ///
        /// <exception cref="TPException">
        /// See the Tuxedo tpdiscon(3c) manual page.
        /// </exception>
        ///
        /// <seealso cref="ATMI.tpdiscon"/>

        public void Close()
        {
            if (cd != -1)
            {
                ATMI.tpdiscon(cd);
                cd = -1;
            }
        }
示例#6
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);
    }
示例#7
0
        /// <summary>
        /// Sends a message as part of the conversation.
        /// </summary>
        ///
        /// <param name="message">
        /// A typed buffer containing the message to send; may be null.
        /// </param>
        ///
        /// <param name="len">
        /// The length of the data in <paramref name="message"/>.
        /// </param>
        ///
        /// <param name="flags">
        /// Set TPRECVONLY to give up control of the conversation.
        /// See the Tuxedo tpsend(3c) manual page.
        /// </param>
        ///
        /// <exception cref="TPException">
        /// See the Tuxedo tpsend(3c) manual page.
        /// </exception>
        ///
        /// <seealso cref="ATMI.tpsend"/>.

        public void Send(ByteBuffer message, int len, int flags)
        {
            try {
                ATMI.tpsend(cd, message, len, flags);
            } catch (TPEEVENT eEvent) {
                cd = -1;
                throw eEvent;
            }
        }
示例#8
0
    static void ProcessMessages(int seconds)
    {
        Console.WriteLine("Waiting for message(s)");

        for (int i = 0, reps = seconds * 10; i < reps; i++)
        {
            Thread.Sleep(100);
            ATMI.tpchkunsol();
        }
    }
示例#9
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);
        }
示例#10
0
        /// <summary>
        /// Receives a message as part of a conversation.
        /// </summary>
        ///
        /// <param name="messageRef">
        /// A typed buffer allocated using <see cref="ATMI.tpalloc"/>.
        /// Gets updated with a typed buffer containing the message received
        /// a part of the conversation.
        /// </param>
        ///
        /// <param name="lenOut">
        /// Gets updated with the length of the data in <paramref name="messageRef"/>.
        /// If the length is 0 then a null message was received.
        /// </param>
        ///
        /// <param name="flags">
        /// See the Tuxedo tprecv(3c) manual page.
        /// </param>
        ///
        /// <exception cref="DotTux.Atmi.TPEV_SENDONLY">
        /// The other end of the connection has given up control of the conversation.
        /// </exception>
        ///
        /// <exception cref="DotTux.Atmi.TPEV_SVCSUCC">
        /// The service routine returned successfully.
        /// In this case, <paramref name="messageRef"/> and <paramref name="lenOut"/>
        /// are updated as described above.
        /// </exception>
        ///
        /// <exception cref="DotTux.Atmi.TPEV_SVCFAIL">
        /// The service routine returned with an application level service failure.
        /// In this case, <paramref name="messageRef"/> and <paramref name="lenOut"/>
        /// are updated as described above.
        /// </exception>
        ///
        /// <exception cref="TPException">
        /// See the Tuxedo tprecv(3c) manual page.
        /// </exception>
        ///
        /// <seealso cref="ATMI.tprecv"/>

        public void Receive(ref ByteBuffer messageRef, out int lenOut, int flags)
        {
            try {
                ATMI.tprecv(cd, ref messageRef, out lenOut, flags);
            } catch (TPEV_SENDONLY eSendOnly) {
                throw eSendOnly;
            } catch (TPEEVENT eEvent) {
                cd = -1;
                throw eEvent;
            }
        }
示例#11
0
    // Connects to the DOWNLOAD service, passing the name of the file to download in the connect request

    private static Conversation Connect(string remoteFileName)
    {
        ByteBuffer request = StringUtils.NewStringBuffer(remoteFileName);

        try
        {
            return(new Conversation("DOWNLOAD", request, 0, ATMI.TPRECVONLY));
        }
        finally
        {
            ATMI.tpfree(request);
        }
    }
示例#12
0
 private static void WaitForMessages(int timeout)
 {
     while (timeout > 0)
     {
         Console.WriteLine("Waiting for unsolicited message(s)");
         Thread.Sleep(1000);
         if (ATMI.tpchkunsol() > 0)
         {
             return;
         }
         timeout--;
     }
     Console.WriteLine("Giving up");
 }
示例#13
0
    public static void Main(string[] args)
    {
        if (args.Length != 2)
        {
            Console.WriteLine("Usage: UnsolClient <service> <message>");
            Environment.Exit(1);
        }

        string service = args[0];
        string message = args[1];

        TPINIT tpinfo = new TPINIT();

        tpinfo.cltname = "sample";

        ATMI.tpinit(tpinfo);
        try
        {
            ATMI.tpsetunsol(new UnsolHandler(tpunsol));
            try
            {
                ByteBuffer data = StringUtils.NewStringBuffer(message);
                try
                {
                    Console.WriteLine("Sending '" + message + "' to service " + service);
                    int cd = ATMI.tpacall(service, data, 0, 0);

                    WaitForMessages(10);

                    int len;
                    ATMI.tpgetrply(ref cd, ref data, out len, 0);
                    message = StringUtils.ReadStringBuffer(data, len);
                    Console.WriteLine("Returned string is: " + message);
                }
                finally
                {
                    ATMI.tpfree(data);
                }
            }
            finally
            {
                ATMI.tpsetunsol(null);
            }
        }
        finally
        {
            ATMI.tpterm();
        }
    }
示例#14
0
    public static void BRDCST_TOUPPER(TPSVCINFO rqst)
    {
        ByteBuffer message = StringUtils.NewStringBuffer("Forwarding request to service TOUPPER");

        try
        {
            ATMI.tpbroadcast(null, null, "sample", message, 0, 0);
        }
        finally
        {
            ATMI.tpfree(message);
        }

        ATMI.tpforward("TOUPPER", rqst.data, rqst.len, 0);
    }
示例#15
0
    public static void NOTIFY_TOUPPER(TPSVCINFO rqst)
    {
        ByteBuffer message = StringUtils.NewStringBuffer("Your request is forwarded to the TOUPPER service");

        try
        {
            ATMI.tpnotify(rqst.cltid, message, 0, 0);
        }
        finally
        {
            ATMI.tpfree(message);
        }

        ATMI.tpforward("TOUPPER", rqst.data, rqst.len, 0);
    }
示例#16
0
    // The TOUPPER service routine

    public static void TOUPPER(TPSVCINFO rqst)
    {
        ByteBuffer data = rqst.data;

        byte[] bytes = new byte[rqst.len - 1];
        data.GetBytes(bytes);
        string s = Encoding.Default.GetString(bytes);

        s = s.ToUpper();

        bytes = Encoding.Default.GetBytes(s);
        data.PutBytes(bytes);
        data.PutByte(bytes.Length, 0);

        ATMI.tpreturn(ATMI.TPSUCCESS, 0, data, 0, 0);
    }
示例#17
0
    // Returns a STRING message from a service routine.

    public static void ReturnReply(int rval, int rcode, string message)
    {
        bool       returned = false;
        ByteBuffer reply    = StringUtils.NewStringBuffer(message);

        try
        {
            ATMI.tpreturn(ATMI.TPFAIL, rcode, reply, 0, 0);
            returned = true;
        }
        finally
        {
            if (!returned)
            {
                ATMI.tpfree(reply);
            }
        }
    }
示例#18
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();
        }
    }
示例#19
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();
     }
 }
示例#20
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();
        }
    }
示例#21
0
    public static void Main(string[] args)
    {
        if (args.Length != 2)
        {
            Console.WriteLine("Usage: DownloadClient <remote file> <local file>");
            Environment.Exit(1);
        }

        string remoteFileName = args[0];
        string localFileName  = args[1];

        ATMI.tpinit(null);
        try
        {
            Conversation conv = Connect(remoteFileName);
            try
            {
                FileStream fs = File.OpenWrite(localFileName);
                try
                {
                    Receive(conv, fs);
                }
                finally
                {
                    fs.Close();
                }
            }
            finally
            {
                conv.Close();
            }
        }
        catch (IOException eIO)
        {
            Console.WriteLine("ERROR: " + eIO.Message);
            Environment.Exit(1);
        }
        finally
        {
            ATMI.tpterm();
        }
    }
示例#22
0
    public static void Main(string[] args)
    {
        if ((args.Length < 3) || (args.Length > 4))
        {
            Console.WriteLine("Usage: SimpleEnqueuer <qspace> <qname> <message> [<replyq>]");
            Environment.Exit(1);
        }

        string qSpace  = args[0];
        string qName   = args[1];
        string message = args[2];
        string replyQ  = (args.Length < 4) ? null : args[3];

        ATMI.tpinit(null);
        try
        {
            ByteBuffer data = StringUtils.NewStringBuffer(message);
            try
            {
                TPQCTL ctl = new TPQCTL();
                ctl.flags = ATMI.TPNOFLAGS;
                if (replyQ != null)
                {
                    ctl.flags      = ctl.flags | ATMI.TPQREPLYQ;
                    ctl.replyqueue = replyQ;
                }
                ATMI.tpenqueue(qSpace, qName, ctl, data, 0, 0);
                Console.WriteLine("Enqueued '" + message + "' in " + qSpace + "." + qName);
            }
            finally
            {
                ATMI.tpfree(data);
            }
        }
        finally
        {
            ATMI.tpterm();
        }
    }
示例#23
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();
        }
    }
示例#24
0
    public static void Main(string[] args)
    {
        if ((args.Length < 1) || (args.Length > 2))
        {
            Console.WriteLine("Usage: SimpleSubscriber <eventexpr> [<filter>]");
            Environment.Exit(1);
        }

        string eventexpr = args[0];
        string filter    = (args.Length < 2) ? null : args[1];

        ATMI.tpinit(null);
        try
        {
            ATMI.tpsetunsol(new UnsolHandler(tpunsol));
            try
            {
                Console.WriteLine("Subscribing to events matching '" + eventexpr + "'");
                int handle = ATMI.tpsubscribe(eventexpr, filter, null, 0);
                try
                {
                    ProcessMessages(5);
                }
                finally
                {
                    ATMI.tpunsubscribe(handle, 0);
                }
            }
            finally
            {
                ATMI.tpsetunsol(null);
            }
        }
        finally
        {
            ATMI.tpterm();
        }
    }
示例#25
0
    public static void PUBLISH_TIME(TPSVCINFO svcinfo)
    {
        ByteBuffer message = StringUtils.NewStringBuffer("It is now " + DateTime.Now);

        try
        {
            ATMI.tppost("TIME", message, 0, 0);
        }
        catch (TPENOENT)
        {
            // EventBroker not running yet (ignored)
        }
        finally
        {
            ATMI.tpfree(message);
        }

        Thread.Sleep(1000);

        ATMI.tpacall("PUBLISH_TIME", null, 0, ATMI.TPNOREPLY);

        ATMI.tpreturn(ATMI.TPSUCCESS, 0, null, 0, 0);
    }
示例#26
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);
        }
    }
示例#27
0
    public static void FML32_TOUPPER(TPSVCINFO rqst)
    {
        ByteBuffer fbfr = rqst.data;

        int fldid = FML32.FIRSTFLDID;
        int occ   = 0;

        while (FML32.Fnext(fbfr, ref fldid, ref occ))
        {
            int occur = FML32.Foccur(fbfr, fldid);
            if (FML32.Fldtype(fldid) == FML32.FLD_STRING)
            {
                for (int i = 0; i < occur; i++)
                {
                    string s = FML32.FgetString(fbfr, fldid, i);
                    s = s.ToUpper();
                    FML32.Fchg(fbfr, fldid, i, s);
                }
            }
            occ = occur; // Skip to next field id
        }

        ATMI.tpreturn(ATMI.TPSUCCESS, 0, fbfr, 0, 0);
    }
示例#28
0
        /// <summary>
        /// Reallocates the given buffer using <see cref="DotTux.Atmi.ATMI.tprealloc"/>.
        /// </summary>

        public override ByteBuffer realloc(ByteBuffer fbfr, int newSize)
        {
            return(ATMI.tprealloc(fbfr, newSize));
        }
示例#29
0
        /// <summary>
        /// Initializes a new Conversation by establishing a connection with a conversational Tuxedo service.
        /// </summary>
        ///
        /// <param name="svc">
        /// The name of the Tuxedo service.
        /// </param>
        ///
        /// <param name="message">
        /// A typed buffer containing the message to send along with the connect request; may be null.
        /// </param>
        ///
        /// <param name="len">
        /// The length of the data in <paramref name="message"/>.
        /// </param>
        ///
        /// <param name="flags">
        /// Must contain either TPSENDONLY or TPRECVONLY.
        /// See the Tuxedo tpconnect(3c) manual page.
        /// </param>
        ///
        /// <exception cref="TPException">
        /// See the Tuxedo tpconnect(3c) manual page.
        /// </exception>
        ///
        /// <seealso cref="ATMI.tpconnect"/>.

        public Conversation(string svc, ByteBuffer message, int len, int flags)
        {
            cd = ATMI.tpconnect(svc, message, len, flags);
        }
示例#30
0
 public static int tpsvrinit(string[] args)
 {
     ATMI.tpacall("PUBLISH_TIME", null, 0, ATMI.TPNOREPLY);
     return(0);
 }