Пример #1
0
        internal unsafe void SendRequest(string[] cmds, uint cmdidx)
        { // ReqName times
            f9oms.Layout *pReqLayout = GetRequestLayout(cmds, cmdidx++);
            if (pReqLayout == null)
            {
                return;
            }
            Int32 times = 0;

            if (cmdidx < cmds.Length)
            {
                Int32.TryParse(cmds[cmdidx], out times);
            }
            RequestRec req = this.RequestRecs_[pReqLayout->LayoutId_ - 1];

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            Int32 count = 0;

            sw.Start();
            do // 最少送一次.
            {
                ++count;
                f9oms.Api.SendRequestString(this, ref *pReqLayout, req.RequestPacket);
            } while (--times > 0);
            sw.Stop();
            double us = 1000L * 1000L * sw.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency;

            Console.WriteLine($"Elapsed={us} us / {count}; Avg={us / count} us");
        }
Пример #2
0
        internal unsafe void SetRequest(string[] cmds, uint cmdidx)
        { // ReqName tag=value...
            f9oms.Layout *pReqLayout = GetRequestLayout(cmds, cmdidx++);
            if (pReqLayout == null)
            {
                return;
            }
            RequestRec req = this.RequestRecs_[pReqLayout->LayoutId_ - 1];

            if (cmdidx < cmds.Length)
            {
                string tvstr = cmds[cmdidx];
                int    iend;
                for (int ifrom = 0; 0 <= ifrom && ifrom < tvstr.Length;)
                {
                    int iFld = GetFieldIndex(tvstr, ref ifrom, pReqLayout);
                    if (iFld < 0)
                    {
                        break;
                    }
                    string val;
                    char   chbr = (ifrom < tvstr.Length ? tvstr[ifrom] : '\0');
                    switch (chbr)
                    {
                    case '\'':
                    case '"':
                        iend = tvstr.IndexOf(chbr, ++ifrom);
                        if (iend < ifrom)
                        {
                            Console.WriteLine($"Cannot find matching [{chbr}].\n");
                            goto __BREAK_PUT_FIELDS;
                        }
                        val   = tvstr.Substring(ifrom, iend - ifrom);
                        ifrom = tvstr.IndexOf('|', iend + 1);
                        break;

                    default:
                        iend = tvstr.IndexOf('|', ifrom);
                        if (iend < ifrom)
                        {
                            val   = tvstr.Substring(ifrom);
                            ifrom = -1;
                        }
                        else
                        {
                            val   = tvstr.Substring(ifrom, iend - ifrom);
                            ifrom = iend + 1;
                        }
                        break;
                    }
                    req.Fields_[iFld] = val;
                }
                __BREAK_PUT_FIELDS :;
                MakeRequestStr(pReqLayout, req);
            }
            PrintRequest(pReqLayout, req);
            Console.WriteLine($"RequestStr = [{req.RequestStr}]");
        }
Пример #3
0
        static unsafe void MakeRequestStr(f9oms.Layout *pReqLayout, RequestRec req)
        {
            StringBuilder res = new StringBuilder();

            for (uint iFld = 0; iFld < pReqLayout->FieldCount_; ++iFld)
            {
                if (iFld != 0)
                {
                    res.Append('\x01');
                }
                res.Append(req.Fields_[iFld]);
            }
            req.RequestStr = res.ToString();
        }
Пример #4
0
        // ---------------------------------------------------------------------
        static unsafe void PrintRequest(f9oms.Layout *pReqLayout, RequestRec req)
        {
            Console.WriteLine($"[{pReqLayout->LayoutId_}] {pReqLayout->LayoutName_}");
            StringBuilder typeId = new StringBuilder();

            for (uint iFld = 0; iFld < pReqLayout->FieldCount_; ++iFld)
            {
                f9sv.Field *fld = &pReqLayout->FieldArray_[iFld];
                typeId.Clear();
                byte *p = fld->TypeId_;
                while (*p != 0)
                {
                    typeId.Append((char)*p++);
                }
                Console.WriteLine($"\t[{iFld,2}] {typeId,-6} {fld->Named_.Name_,-10} = '{req.Fields_[iFld]}'");
            }
        }