Example #1
0
        public MainMessage HandleMessage(MainMessage msg)
        {
            AppMsg appMsg = msg.AppMsg;
            ulong  appId  = appMsg.AppId;

            if (!_appInstances.ContainsKey(appId))
            {
                return(ISystemService.CreateErrorMessage(msg.MsgId, 0, 0, "No handler could be found for this event."));
            }
            MainMessage response = new MainMessage();

            response.AppMsg       = new AppMsg();
            response.AppMsg.AppId = appId;
            byte[] data = appMsg.Data.ToByteArray();
            try
            {
                byte[] responseData = _appInstances[appId].HandleMessage(data, data.Length, new MsgContext(msg));
                if (responseData != null)
                {
                    response.AppMsg.Data = ByteString.CopyFrom(responseData);
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
                return(ISystemService.CreateErrorMessage(msg.MsgId, 0, 0, e.Message));
            }
            return(response);
        }
Example #2
0
        public ServiceCallback <byte[]> SendAppMsg(AppInfo app, byte[] data, AppMsgRecipient recipient)
        {
            return(new ServiceCallback <byte[]>(() =>
            {
                MainMessage mainMsg = new MainMessage();
                mainMsg.AppMsg = new AppMsg();
                mainMsg.AppMsg.AppId = app.ID;
                mainMsg.AppMsg.Data = ByteString.CopyFrom(data);
                MainMessage response = null;
                switch (recipient)
                {
                case AppMsgRecipient.FORWARDER:
                    response = _api.OpenAPI.Networking.Send(mainMsg, _api.Services.Room.ForwarderAddress);
                    break;

                case AppMsgRecipient.PROVIDER:
                    response = _api.OpenAPI.Networking.Send(mainMsg, _api.OpenAPI.Config.MainServer);
                    break;
                }
                if (response == null)
                {
                    throw new AppServiceException("Unknown response.");
                }
                if (SystemServiceClient.IsErrorMsg(response))
                {
                    throw new AppServiceException(response.SystemMsg.ErrorMsg.ErrorMsg_);
                }
                AppMsg appMsg = response.AppMsg;
                if (appMsg == null)
                {
                    throw new AppServiceException("Unknown response.");
                }
                return appMsg.Data.ToByteArray();
            }));
        }
Example #3
0
    public static AppMsg trace(string title, string msg, int?tpad = null, SeverityLevel?severity = null)
    {
        var titleFmt = tpad.Map(pad => title.PadRight(pad), () => title.PadRight(20));
        var appMsg   = AppMsg.Define($"{titleFmt}: {msg}", severity ?? SeverityLevel.Babble);

        print(appMsg);
        return(appMsg);
    }
        public bool doSceneSendAppMsg(string toUsername, int source, string xmlstr)
        {
            AppMsgInfo info = AppMsgMgr.ParseAppXml(xmlstr);

            if (info == null)
            {
                //Log.e("NetSceneSendAppMsg", "invalid AppMsgInfo, msg.strMsg = " + this.mAppMsg.strMsg);
                return(false);
            }
            base.beginBuilder();
            base.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
            AppMsg.Builder builder = AppMsg.CreateBuilder();
            builder.AppId = info.appid;
            uint result = 0;

            builder.SdkVersion = uint.TryParse(info.sdkVer, out result) ? result : 0;
            builder.ToUserName = toUsername;
            info.fromUserName  = AccountMgr.curUserName;
            //if (info.fromUserName != AccountMgr.curUserName)
            //{
            //    Log.e("NetSceneSendAppMsg", "invalid from username = "******"appmsg") ?? "";
            if (info.showtype == 2)
            {
                //builder.Content = builder.Content + AppMsgMgr.getXmlNodeString(this.mAppMsg.strMsg, "ShakePageResult");
                builder.Content = builder.Content;
            }
            if (string.IsNullOrEmpty(builder.Content))
            {
                Log.e("NetSceneSendAppMsg", "invalid appmsgBuilder.Content = " + builder.Content);
                return(false);
            }
            builder.CreateTime  = (uint)Util.getNowSeconds();
            builder.ClientMsgId = MD5Core.GetHashString(toUsername + Util.getNowMilliseconds());;
            byte[] inBytes = null;//StorageIO.readFromFile(ChatMsgMgr.getMsgThumbnail(this.mAppMsg));
            if (inBytes != null)
            {
                builder.Thumb = Util.toSKBuffer(inBytes);
            }
            builder.Source           = (int)source;
            base.mBuilder.Msg        = builder.Build();
            base.mSessionPack.mCmdID = 0x6b;
            base.endBuilder();
            return(true);
        }
Example #5
0
        public void pack_span64u()
        {
            var x0     = BitVector32.FromScalar(0b00001010110000101001001111011001u);
            var x1     = BitVector32.FromScalar(0b00001010110110101001001111000001u);
            var src    = Random.Span <byte>(Pow2.T04).ReadOnly();
            var packed = span <ulong>(src.Length / 8);

            gbits.pack(src, packed);

            for (var i = 0; i < packed.Length; i++)
            {
                var x = BitVector64.FromScalar(BitConverter.ToUInt64(src.Slice(8 * i)));
                var y = BitVector64.FromScalar(packed[i]);
                Claim.eq((ulong)x, (ulong)y, AppMsg.Error($"{x.ToBitString()} != {y.ToBitString()}"));
            }
        }
Example #6
0
        public MainMessage HandleMessage(MainMessage msg)
        {
            AppMsg appMsg = msg.AppMsg;
            ulong? userId = _api.Services.User.GetUserIdByClientId(msg.ClientId, true);

            if (!userId.HasValue)
            {
                return(ISystemService.CreateErrorMessage(msg.MsgId, 0, 0, "Unauthenticated user."));
            }
            uint?roomId = _api.Services.Room.RoomByUserId(userId.Value);

            if (!roomId.HasValue)
            {
                return(ISystemService.CreateErrorMessage(msg.MsgId, 0, 0, "User is not connected to any room."));
            }
            ulong appId = appMsg.AppId;

            if (!_appInstances.ContainsKey(roomId.Value) || !_appInstances[roomId.Value].ContainsKey(appId))
            {
                return(ISystemService.CreateErrorMessage(msg.MsgId, 0, 0, "No handler could be found for this event."));
            }
            MainMessage response = new MainMessage();

            response.AppMsg       = new AppMsg();
            response.AppMsg.AppId = appId;
            byte[] data = appMsg.Data.ToByteArray();
            try
            {
                response.AppMsg.Data = ByteString.CopyFrom(
                    _appInstances[roomId.Value][appId].HandleMessage(data, data.Length, new MsgContext(msg))
                    );
            }
            catch (Exception e)
            {
                return(ISystemService.CreateErrorMessage(msg.MsgId, 0, 0, e.Message));
            }
            return(response);
        }
Example #7
0
 /// <summary>
 /// Writes a named value to standard output
 /// </summary>
 /// <param name="nv">The named vaue to emit</param>
 /// <typeparam name="T">The value type</typeparam>
 public static void show <T>(NamedValue <T> nv)
 {
     print(AppMsg.Define($"{nv}", SeverityLevel.HiliteCL));
 }
Example #8
0
File: FsmES.cs Project: 0xCM/arrows
 void OnWarning(AppMsg msg)
 {
 }
Example #9
0
 public void HandleMessage(MainMessage msg)
 {
     AppMsg appMsg = msg.AppMsg;
 }
Example #10
0
 MklException(string msg, string caller, string file, int?line)
     : base(AppMsg.define($"{msg} {caller} {file} {line}", LogLevel.Error))
 {
 }
Example #11
0
 public static AppMsg appMsg(object content, SeverityLevel level = SeverityLevel.Info)
 => AppMsg.Define($"{content}", level);
Example #12
0
 /// <summary>
 /// Emits an error-level message
 /// </summary>
 /// <param name="msg">The message to emit</param>
 /// <param name="host">The declaring type of the member</param>
 /// <param name="caller">The calling member</param>
 public static void error <T>(object msg, T host, [CallerName] string caller = null, [CallerFile] string file = null, [CallerLine] int?line = null)
 => terminal.WriteError(AppMsg.Define(msg?.ToString() ?? string.Empty, SeverityLevel.Error, $"{label<T>()}/{caller}", file, line));
Example #13
0
 /// <summary>
 /// Emits an information-level message with a cyan foreground
 /// </summary>
 /// <param name="msg">The message to emit</param>
 /// <param name="caller">The calling member</param>
 public static void cyan(object msg)
 => terminal.WriteMessage(AppMsg.Define(msg?.ToString() ?? string.Empty, SeverityLevel.HiliteCL));
Example #14
0
 /// <summary>
 /// Emits an information-level message with a magenta foreground
 /// </summary>
 /// <param name="msg">The message to emit</param>
 /// <param name="caller">The calling member</param>
 public static void magenta(string title, object msg)
 => terminal.WriteMessage(AppMsg.Define($"{title}: " + msg?.ToString() ?? string.Empty, SeverityLevel.HiliteML));
Example #15
0
 /// <summary>
 /// Emits a highlighted information-level message
 /// </summary>
 /// <param name="msg">The message to emit</param>
 /// <param name="caller">The calling member</param>
 public static void hilite(object msg, SeverityLevel?level = null, [CallerName] string caller = null, [CallerFile] string file = null, [CallerLine] int?line = null)
 => terminal.WriteMessage(AppMsg.Define(msg?.ToString() ?? string.Empty, level ?? SeverityLevel.HiliteBL, caller, file, line));
Example #16
0
File: FsmES.cs Project: 0xCM/arrows
 public ReceiptLimitExceeded(string machine, ulong limit)
     : base(AppMsg.Define($"{machine} Event receipt limit of {limit} was exeeded", SeverityLevel.Warning))
 {
 }
Example #17
0
File: App.cs Project: 0xCM/arrows
 static AppMsg CompleteMsg <T>(ITimeSeries <T> series, Duration runtime)
     where T : struct
 => AppMsg.Define($"Series Id = {series.Id} | Last Term = {series.Observed} | Evolution Time = {runtime.Ms} ms", SeverityLevel.Info);
Example #18
0
 /// <summary>
 /// Writes a single messages to the terminal
 /// </summary>
 /// <param name="msg">The message to print</param>
 public static void print(AppMsg msg)
 => terminal.WriteMessage(msg);
Example #19
0
 public static AppMsg errorMsg(object content)
 => AppMsg.Define($"{content}", SeverityLevel.Error);
Example #20
0
 /// <summary>
 /// Prints an operation timing message to the console
 /// </summary>
 /// <param name="time">The operation timing</param>
 /// <param name="labelPad">Option label pad width</param>
 public static void print(OpTime time, int?labelPad = null)
 => print(AppMsg.Define(time.Format(labelPad), SeverityLevel.Benchmark));
Example #21
0
File: log.cs Project: 0xCM/arrows
 /// <summary>
 /// Writes a message to a log
 /// </summary>
 /// <param name="messages">The message to emit</param>
 /// <param name="dst">The destination log</param>
 public static void log(AppMsg message, LogArea dst)
 => Log.Get(LogTarget.AreaRoot(dst)).Log(message);
Example #22
0
 /// <summary>
 /// Emits an information-level message
 /// </summary>
 /// <param name="msg">The message to emit</param>
 /// <param name="caller">The calling member</param>
 public static void inform(object msg, [CallerName] string caller = null, [CallerFile] string file = null, [CallerLine] int?line = null)
 => terminal.WriteMessage(AppMsg.Define(msg?.ToString() ?? string.Empty, SeverityLevel.Info, caller, file, line));
Example #23
0
 void Trace(AppMsg msg)
 {
     print(msg);
 }
Example #24
0
File: t_mkl.cs Project: 0xCM/z0
 /// <summary>
 /// Submits a diagnostic message to the queue related to performance/benchmarking
 /// </summary>
 /// <param name="msg">The message to submit</param>
 protected void TracePerf(string msg)
 {
     Trace(AppMsg.define($"{msg}", LogLevel.Status));
 }
Example #25
0
        public string ActivityTheme(string promotionCode, string templateCode, string lx = "PC")
        {
            AppMsg <Object> jsonResult = new AppMsg <Object>();
            string          html       = "";

            try
            {
                SqlRun  sql = new SqlRun(SqlRun.sqlstr);
                DataSet dt  = sql.RunProDataSet("Pc_TemplateRelation", new SqlParameter[]
                {
                    new SqlParameter("@type", "CX_GetTemplateRelation"),
                    new SqlParameter("@PromotionCode", promotionCode),
                    new SqlParameter("@TemplateCode", templateCode)
                });
                if (dt.Tables.Count == 2 && dt.Tables[0].Rows.Count > 0 && dt.Tables[1].Rows.Count > 0)
                {
                    html = dt.Tables[0].Rows[0]["TemplateText"].ToString();
                    DataRowCollection datalist = dt.Tables[1].Rows;
                    string            boxTop   = GetRegValue(html, "<!--截取TopStatr-->", "<!--截取TopEnd-->");
                    string            tboxTop  = boxTop;
                    if (boxTop != "")
                    {
                        string Topleft = GetRegValue(boxTop, "<!--leftTopStatr-->", "<!--leftTopEnd-->");
                        string tleft   = Topleft;
                        if (datalist.Count == 1)
                        {
                            tleft = tleft.Replace("@left@article_id", datalist[0]["article_id"].ToString());
                            tleft = tleft.Replace("@left@pdoduct", datalist[0]["sub_title"].ToString());
                            tleft = tleft.Replace("@left@old", datalist[0]["price"].ToString());
                            tleft = tleft.Replace("@left@new", datalist[0]["price"].ToString());
                            tleft = tleft.Replace("@left@image", datalist[0]["img_url"].ToString());
                            tleft = tleft.Replace("@left@gg", datalist[0]["drug_spec"].ToString());
                            tboxTop.Replace(Topleft, tleft);
                            html.Replace(boxTop, tboxTop);
                            datalist.Remove(datalist[0]);
                        }
                        else if (datalist.Count >= 2)
                        {
                            var leftobj  = datalist[0];
                            var rightobj = datalist[1];
                            tleft = tleft.Replace("@left@article_id", leftobj["article_id"].ToString());
                            tleft = tleft.Replace("@left@pdoduct", leftobj["sub_title"].ToString());
                            tleft = tleft.Replace("@left@old", leftobj["price"].ToString());
                            tleft = tleft.Replace("@left@new", leftobj["price"].ToString());
                            tleft = tleft.Replace("@left@image", leftobj["img_url"].ToString());
                            tleft = tleft.Replace("@left@gg", leftobj["drug_spec"].ToString());
                            //分割线 第二块
                            tboxTop = tboxTop.Replace("@right@article_id", rightobj["article_id"].ToString());
                            tboxTop = tboxTop.Replace("@right@pdoduct", rightobj["sub_title"].ToString());
                            tboxTop = tboxTop.Replace("@right@old", rightobj["price"].ToString());
                            tboxTop = tboxTop.Replace("@right@new", rightobj["price"].ToString());
                            tboxTop = tboxTop.Replace("@right@image", rightobj["img_url"].ToString());
                            tboxTop = tboxTop.Replace("@right@gg", rightobj["drug_spec"].ToString());
                            tboxTop = tboxTop.Replace(Topleft, tleft);
                            html    = html.Replace(boxTop, tboxTop);
                            datalist.Remove(leftobj);
                            datalist.Remove(rightobj);
                        }
                    }
                    string boxAll   = GetRegValue(html, "<!--截取Statr-->", "<!--截取end-->");
                    string leftAll  = GetRegValue(boxAll, "<!--leftStatr-->", "<!--leftEnd-->");
                    string left     = leftAll;
                    string box      = boxAll;
                    string texthtml = "";
                    if (datalist.Count == 1)
                    {
                        //left = left.Replace("@left@huodong", datalist[0]["fabh"].ToString());
                        left      = left.Replace("@left@article_id", datalist[0]["article_id"].ToString());
                        left      = left.Replace("@left@pdoduct", datalist[0]["sub_title"].ToString());
                        left      = left.Replace("@left@old", datalist[0]["price"].ToString());
                        left      = left.Replace("@left@new", datalist[0]["price"].ToString());
                        left      = left.Replace("@left@image", datalist[0]["img_url"].ToString());
                        left      = left.Replace("@left@gg", datalist[0]["drug_spec"].ToString());
                        texthtml += left;
                        left      = leftAll;
                    }
                    else if (datalist.Count % 2 != 0)
                    {
                        for (var i = 0; i < datalist.Count; i++)
                        {
                            //box = box.Replace("@left@huodong", datalist[i]["fabh"].ToString());
                            box = box.Replace("@left@article_id", datalist[i]["article_id"].ToString());
                            box = box.Replace("@left@pdoduct", datalist[i]["sub_title"].ToString());
                            box = box.Replace("@left@old", datalist[i]["price"].ToString());
                            box = box.Replace("@left@new", datalist[i]["price"].ToString());
                            box = box.Replace("@left@image", datalist[i]["img_url"].ToString());
                            box = box.Replace("@left@gg", datalist[i]["drug_spec"].ToString());
                            i++;
                            //box = box.Replace("@right@huodong", datalist[i]["fabh"].ToString());
                            box       = box.Replace("@right@article_id", datalist[i]["article_id"].ToString());
                            box       = box.Replace("@right@pdoduct", datalist[i]["sub_title"].ToString());
                            box       = box.Replace("@right@old", datalist[i]["price"].ToString());
                            box       = box.Replace("@right@new", datalist[i]["price"].ToString());
                            box       = box.Replace("@right@image", datalist[i]["img_url"].ToString());
                            box       = box.Replace("@right@gg", datalist[i]["drug_spec"].ToString());
                            texthtml += box;
                            box       = boxAll;
                            if ((i + 1) == (datalist.Count - 1))
                            {
                                i++;
                                //left = left.Replace("@left@huodong", datalist[i]["fabh"].ToString());
                                left      = left.Replace("@left@article_id", datalist[i]["article_id"].ToString());
                                left      = left.Replace("@left@pdoduct", datalist[i]["sub_title"].ToString());
                                left      = left.Replace("@left@old", datalist[i]["price"].ToString());
                                left      = left.Replace("@left@new", datalist[i]["price"].ToString());
                                left      = left.Replace("@left@image", datalist[i]["img_url"].ToString());
                                left      = left.Replace("@left@gg", datalist[i]["drug_spec"].ToString());
                                texthtml += left;
                                left      = leftAll;
                            }
                        }
                    }
                    else
                    {
                        for (var i = 0; i < datalist.Count; i++)
                        {
                            //box = box.Replace("@left@huodong", datalist[i]["fabh"].ToString());
                            box = box.Replace("@left@article_id", datalist[i]["article_id"].ToString());
                            box = box.Replace("@left@pdoduct", datalist[i]["sub_title"].ToString());
                            box = box.Replace("@left@old", datalist[i]["price"].ToString());
                            box = box.Replace("@left@new", datalist[i]["price"].ToString());
                            box = box.Replace("@left@image", datalist[i]["img_url"].ToString());
                            box = box.Replace("@left@gg", datalist[i]["drug_spec"].ToString());
                            i++;
                            //box = box.Replace("@right@huodong", datalist[i]["fabh"].ToString());
                            box       = box.Replace("@right@article_id", datalist[i]["article_id"].ToString());
                            box       = box.Replace("@right@pdoduct", datalist[i]["sub_title"].ToString());
                            box       = box.Replace("@right@old", datalist[i]["price"].ToString());
                            box       = box.Replace("@right@new", datalist[i]["price"].ToString());
                            box       = box.Replace("@right@image", datalist[i]["img_url"].ToString());
                            box       = box.Replace("@right@gg", datalist[i]["drug_spec"].ToString());
                            texthtml += box;
                            box       = boxAll;
                        }
                    }
                    html = "<body>" + html.Replace(boxAll, texthtml) + "</body>";
                }
                else
                {
                    throw new Exception("没有主题页");
                }
            }
            catch (Exception ex)
            {
                html = ex.Message;
            }
            return(html);
        }
Example #26
0
    /// <summary>
    /// Evaluates the expression and writes the result to standard output
    /// </summary>
    /// <param name="fx">The expression to evaluate</param>
    /// <typeparam name="T">The evaluation value type</typeparam>
    public static void show <T>(Expression <Func <T> > fx)
    {
        var nv = fx.Evaluate();

        print(AppMsg.Define($"{nv}", SeverityLevel.HiliteCL));
    }
Example #27
0
 public static bool require(bool value, string info      = null, [CallerFilePath] string caller = null,
                            [CallerFilePath] string file = null, [CallerLineNumber] int?line    = null)
 => value ? true : throw new AppException(AppMsg.Define($"Invariant failure: {info}", SeverityLevel.Error, caller, file, line));
Example #28
0
File: FsmES.cs Project: 0xCM/arrows
 void RaiseWarning(AppMsg msg)
 {
     OnWarning(msg);
 }