Example #1
0
        protected override void ProcessCommand(System.Net.Sockets.NetworkStream nstm, char tag)
        {
            int len;

            switch (tag)
            {
                case 'R': // Remote!
                    {
                        string classname = XContent.ReceiveXString(nstm, buf);

                        string xlibfn = CreateXlibFileName("remote");
                        {
                            buf = XContent.ReceiveXBytes(nstm, out len, buf);
                            if (0 != len)
                            {
                                System.IO.FileStream stm = System.IO.File.Create(xlibfn);
                                stm.Write(buf, 0, len);
                                stm.Close();
                            }
                        }

                        string dllfn = CreateDllFileName("remote");
                        {
                            buf = XContent.ReceiveXBytes(nstm, out len, buf);
                            System.IO.FileStream stm = System.IO.File.Create(dllfn);
                            stm.Write(buf, 0, len);
                            stm.Close();
                        }

                        if (XLog.logging)
                        {
                            string xclassname = classname;
                            if (null == xclassname)
                            {
                                xclassname = "<null>";
                            }
                            XLog.log("Loading IRemote plugin named " + xclassname + " for remote: " + dllfn);
                        }

                        rem = LoadRemotePlugin(dllfn, classname);
#if DEBUG
                        try
                        {
                            rem.OnRemote();
                        }
                        catch (Exception e)
                        {
                            throw new UserException(e);
                        }
#else
                        rem.OnRemote();
#endif
                    }
                    break;

                case 'O': //Query DGlobals
                    {
                        int byteCount = DGlobalsM.ToBytes(ref buf);
                        XContent.SendXContent(nstm, buf, byteCount);
                    }
                    break;

                case 'r':
                    {                      
                        buf = XContent.ReceiveXBytes(nstm, out len, buf);
                        int n = Entry.BytesToInt(buf);
                        int count = 0;
                        if (null != rem)
                        {
                            List<long> appendsizes = new List<long>();
                            try
                            {
                                count = rem.GetOutputFileCount(n, appendsizes);
                            }
                            catch(Exception e)
                            {
                                throw new DistributedObjectsSlave.DistObjectAbortException(e);
                            }
                            
                            if (buf.Length < 4 + 8 * appendsizes.Count)
                            {
                                buf = new byte[Entry.Round2Power(4 + 8 * appendsizes.Count)];
                            }
                            Entry.ToBytes(count, buf, 0);
                            int offset = 4;
                            for (int i = 0; i < appendsizes.Count; i++, offset += 8)
                            {
                                Entry.LongToBytes(appendsizes[i], buf, offset);
                            }
                            XContent.SendXContent(nstm, buf, 4 + 8 * appendsizes.Count);
                            break; // !
                        }
                        Entry.ToBytes(count, buf, 0);
                        XContent.SendXContent(nstm, buf, 4);
                    }
                    break;

                default:
                    base.ProcessCommand(nstm, tag);
                    break;
            }
        }
Example #2
0
        protected override void ProcessCommand(System.Net.Sockets.NetworkStream nstm, char tag)
        {
            int len;

            switch (tag)
            {
            case 'R':     // Remote!
            {
                string classname = XContent.ReceiveXString(nstm, buf);

                string xlibfn = CreateXlibFileName("remote");
                {
                    buf = XContent.ReceiveXBytes(nstm, out len, buf);
                    if (0 != len)
                    {
                        System.IO.FileStream stm = System.IO.File.Create(xlibfn);
                        stm.Write(buf, 0, len);
                        stm.Close();
                    }
                }

                string dllfn = CreateDllFileName("remote");
                {
                    buf = XContent.ReceiveXBytes(nstm, out len, buf);
                    System.IO.FileStream stm = System.IO.File.Create(dllfn);
                    stm.Write(buf, 0, len);
                    stm.Close();
                }

                if (XLog.logging)
                {
                    string xclassname = classname;
                    if (null == xclassname)
                    {
                        xclassname = "<null>";
                    }
                    XLog.log("Loading IRemote plugin named " + xclassname + " for remote: " + dllfn);
                }

                rem = LoadRemotePlugin(dllfn, classname);
#if DEBUG
                try
                {
                    rem.OnRemote();
                }
                catch (Exception e)
                {
                    throw new UserException(e);
                }
#else
                rem.OnRemote();
#endif
            }
            break;

            case 'O':     //Query DGlobals
            {
                int byteCount = DGlobalsM.ToBytes(ref buf);
                XContent.SendXContent(nstm, buf, byteCount);
            }
            break;

            case 'r':
            {
                buf = XContent.ReceiveXBytes(nstm, out len, buf);
                int n     = Entry.BytesToInt(buf);
                int count = 0;
                if (null != rem)
                {
                    List <long> appendsizes = new List <long>();
                    try
                    {
                        count = rem.GetOutputFileCount(n, appendsizes);
                    }
                    catch (Exception e)
                    {
                        throw new DistributedObjectsSlave.DistObjectAbortException(e);
                    }

                    if (buf.Length < 4 + 8 * appendsizes.Count)
                    {
                        buf = new byte[Entry.Round2Power(4 + 8 * appendsizes.Count)];
                    }
                    Entry.ToBytes(count, buf, 0);
                    int offset = 4;
                    for (int i = 0; i < appendsizes.Count; i++, offset += 8)
                    {
                        Entry.LongToBytes(appendsizes[i], buf, offset);
                    }
                    XContent.SendXContent(nstm, buf, 4 + 8 * appendsizes.Count);
                    break;         // !
                }
                Entry.ToBytes(count, buf, 0);
                XContent.SendXContent(nstm, buf, 4);
            }
            break;

            default:
                base.ProcessCommand(nstm, tag);
                break;
            }
        }