Example #1
0
        private byte[] HandleGetFriend(EventDataMsg eventMsg, MsgContext ctx)
        {
            User userReq = _api.Services.User.GetUserByClientId(ctx.senderId);

            if (userReq == null)
            {
                throw new FriendsAppProviderException("You must be signedIn to add some friends.");
            }
            User userTo = User.Get(eventMsg.LongValue);

            if (userTo == null)
            {
                throw new FriendsAppProviderException("User with this ID could not be found.");
            }
            List <ulong> friends = _friendsData.GetFriendsList(userReq.Id);

            if (!friends.Contains(userTo.Id))
            {
                throw new FriendsAppProviderException("This user is not your friend.");
            }
            FriendsAppUser friendDetail = ToFriendsAppUser(userTo.Id);
            FriendsAppMsg  msg          = new FriendsAppMsg();

            msg.FriendDetail = friendDetail.ToNetworkModel();
            return(msg.ToByteArray());
        }
Example #2
0
        private byte[] HandleAddFriend(EventDataMsg eventMsg, MsgContext ctx)
        {
            if (ctx.senderType != SenderType.USER)
            {
                throw new FriendsAppProviderException("Only client machine can call this event.");
            }
            User userReq = _api.Services.User.GetUserByClientId(ctx.senderId);

            if (userReq == null)
            {
                throw new FriendsAppProviderException("You must be signedIn to add some friends.");
            }
            User userTo = User.Get(eventMsg.LongValue);

            if (userTo == null)
            {
                throw new FriendsAppProviderException("User with this ID could not be found.");
            }
            List <ulong> requests = _friendsData.GetFriendRequests(userReq.Id);

            if (requests.Contains(userTo.Id))
            {
                _friendsData.AcceptFriendRequest(userTo.Id, userReq.Id);
            }
            else
            {
                _friendsData.SendFriendRequest(userReq.Id, userTo.Id);
            }
            return(null);
        }
        /// <summary>
        ///  执行基础事件消息类型
        /// </summary>
        /// <param name="recEventMsg"></param>
        /// <param name="recEventDirs"></param>
        /// <returns>返回基础事件消息处理结果</returns>
        private MsgContext ProcessExecute_BasicEventMsg(XmlDocument recEventMsg, Dictionary <string, string> recEventDirs)
        {
            string     eventType = recEventDirs["Event"].ToLower();
            MsgContext context   = null;

            switch (eventType)
            {
            case "subscribe":
                context = ExecuteBasicMsgHandler(recEventMsg, recEventDirs, SubscribeEventHandler);
                break;

            case "unsubscribe":
                context = ExecuteBasicMsgHandler(recEventMsg, recEventDirs, SubscribeEventHandler);
                break;

            case "scan":
                context = ExecuteBasicMsgHandler(recEventMsg, recEventDirs, ScanEventHandler);
                break;

            case "location":
                context = ExecuteBasicMsgHandler(recEventMsg, recEventDirs, LocationEventHandler);
                break;

            case "click":
                context = ExecuteBasicMsgHandler(recEventMsg, recEventDirs, ClickEventHandler);
                break;

            case "view":
                context = ExecuteBasicMsgHandler(recEventMsg, recEventDirs, ViewEventHandler);
                break;
            }
            return(context);
        }
Example #4
0
        private byte[] HandleDelFriend(EventDataMsg eventMsg, MsgContext ctx)
        {
            User userReq = _api.Services.User.GetUserByClientId(ctx.senderId);

            if (userReq == null)
            {
                throw new FriendsAppProviderException("You must be signedIn to add some friends.");
            }
            User userTo = User.Get(eventMsg.LongValue);

            if (userTo == null)
            {
                throw new FriendsAppProviderException("User with this ID could not be found.");
            }
            List <ulong> friendList = _friendsData.GetFriendsList(userReq.Id);

            if (friendList.Contains(userTo.Id))
            {
                _friendsData.RemoveFriend(userReq.Id, userTo.Id);
            }
            else
            {
                List <ulong> fromRequests = _friendsData.GetFriendRequests(userReq.Id);
                if (fromRequests.Contains(userTo.Id))
                {
                    _friendsData.RemoveFriendRequest(userTo.Id, userReq.Id);
                }
                else
                {
                    _friendsData.RemoveFriendRequest(userReq.Id, userTo.Id);
                }
            }
            return(null);
        }
        /// <summary>
        /// 請求授權(自動加值/代行)
        /// </summary>
        /// <param name="requestToBank">請求授權物件</param>
        /// <returns>請求授權電文</returns>
        private string ConvertALOL(AutoloadRqt_2Bank requestToBank)
        {
            try
            {
                Console.WriteLine("開始轉換要求授權物件");
                //Message Header
                string fromTo = "8888" + requestToBank.BANK_CODE.PadLeft(4, '0');//8888表示愛金卡機構代號
                //initial BitMap List
                string[] srcList = new string[129];
                for (int i = 0; i < srcList.Length; i++)
                {
                    srcList[i] = "";
                }
                srcList[2]  = requestToBank.ICC_NO;          //"0417149984000007"//"0000000000000000";
                srcList[3]  = requestToBank.PROCESSING_CODE; //"990174"//"990174";
                srcList[4]  = requestToBank.AMOUNT;          //"000000000500"//"000000000055";
                srcList[7]  = requestToBank.TRANS_DATETIME;  //"0115135959"//"0128180006";
                srcList[11] = requestToBank.STAN;            //"005009"//"666666";
                srcList[32] = requestToBank.STORE_NO;        //"st00896159"// "st00000001";
                srcList[37] = requestToBank.RRN;             //"501513005009"//"502818666666";
                srcList[41] = requestToBank.POS_NO;          //"00000001"//"00000001";
                srcList[42] = requestToBank.MERCHANT_NO;     //"000000022555003"//"000000022555003";

                //init Field 61
                string[] srcListDf61 = new string[65];
                for (int i = 0; i < srcListDf61.Length; i++)
                {
                    srcListDf61[i] = "";
                }
                srcListDf61[3]  = requestToBank.ICC_info.STORE_NO;    // 8碼
                srcListDf61[4]  = requestToBank.ICC_info.REG_ID;      // 3碼
                srcListDf61[8]  = requestToBank.ICC_info.TX_DATETIME; //14碼
                srcListDf61[10] = requestToBank.ICC_info.ICC_NO;      //16碼
                srcListDf61[11] = requestToBank.ICC_info.AMT;         // 8碼,"00000000"//"00000000";
                srcListDf61[35] = requestToBank.ICC_info.NECM_ID;     //20碼
                MsgContext msgContextDf61 = df61MsgWorker.Build(null, null, srcListDf61);

                srcList[61] = msgContextDf61.SrcMessage;            //16碼"808000000000000000000000" //"008000000000000000000000";
                //"0120" + "0115135959" + "005002" + "00896159" + "501513005002" + "  ";
                //"0100" + "0128183005" + "555555" + "00000001" + "502818666666" + "  ";

                MsgContext msgResult = mainMsgWorker.Build(fromTo, requestToBank.MESSAGE_TYPE, srcList);//"88880000","0420"
                Console.WriteLine("轉換後的銀行訊息(Length:" + msgResult.SrcMessage.Length + "): " + msgResult.SrcMessage);
                return(msgResult.SrcMessage);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
        private byte[] SendMessage(ulong from, ulong to, string message, MsgContext ctx)
        {
            InitChat(from, to);
            ChatObj    chat = _chats[from][to];
            ChatObjMsg msg  = new ChatObjMsg((ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
                                             from, to, message);

            lock (chat)
            {
                chat.Messages.Add(msg);
                AddToQueue(to, msg);
            }
            return(null);
        }
        /// <summary>
        ///  根据具体的消息类型执行相关的消息委托方法(基础消息)
        /// </summary>
        /// <typeparam name="TRecMsg"></typeparam>
        /// <param name="recMsgXml"></param>
        /// <param name="recMsgDirs"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        private static MsgContext ExecuteBasicMsgHandler <TRecMsg>(XmlDocument recMsgXml,
                                                                   IDictionary <string, string> recMsgDirs, Func <TRecMsg, BaseReplyMsg> func)
            where TRecMsg : BaseRecMsg, new()
        {
            var msgContext = new MsgContext();

            var recMsg = WxMsgHelper.GetMsg <TRecMsg>(recMsgDirs);

            recMsg.RecMsgXml = recMsgXml;

            msgContext.ReplyMsg = ExecuteHandler(recMsg, func);
            msgContext.RecMsg   = recMsg;

            return(msgContext);
        }
Example #8
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                MsgContext.CreateAndInitDb();
                Application.Run(new Forms.FrmMain());
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Komunikaty", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #9
0
        private byte[] ListRequest(ulong userId, MsgContext ctx)
        {
            ChatAppMsg msg = new ChatAppMsg();

            msg.List = new ChatList();
            if (_chats.ContainsKey(userId))
            {
                msg.List.List.AddRange(_chats[userId].Select(x => x.Value.ToNetworkModel()));
                if (_newMsgs.TryGetValue(userId, out Queue <ChatObjMsg> updates))
                {
                    updates.Clear();
                }
            }
            return(msg.ToByteArray());
        }
Example #10
0
        static void Main(string[] args)
        {
            //send message to hub
            Console.WriteLine("enter \"q\" to quit application");
            string body;

            do
            {
                Console.WriteLine("Enter message:");

                body = Console.ReadLine();

                if (body.ToLower() == "q")
                {
                    Environment.Exit(0);
                }

                Message message = new Message(body, DateTime.Now, false);

                var connection = new HubConnection("http://localhost:20135");

                var proxy = connection.CreateHubProxy("chatHub");

                try {
                    connection.Start().Wait();

                    if (connection.State == ConnectionState.Connected)
                    {
                        proxy.Invoke("receiveNotification", message);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Cannot connect to client. Please make sure the MVC application is started at port 20135");
                }

                //insert message in database
                using (var db = new MsgContext())
                {
                    db.Messages.Add(new Message(body, DateTime.Now, false));
                    db.SaveChanges();
                    Console.WriteLine("Message saved to DB");
                }
            }while (!String.IsNullOrWhiteSpace(body) || body.ToLower() != "q");
        }
        public static IList <SingleQuery> GetQueries(MsgContext ctx)
        {
            IList <SingleQuery> result = new List <SingleQuery>();

            if (ctx.Data is JArray)
            {
                foreach (var item in (JArray)ctx.Data)
                {
                    result.Add(GetQuery(item));
                }
            }
            else
            {
                result.Add(GetQuery(ctx.Data));
            }

            return(result);
        }
        public static IList <string> GetQueriesJson(MsgContext ctx)
        {
            IList <string> result = new List <string>();

            if (ctx.Data is JArray)
            {
                foreach (var item in (JArray)ctx.Data)
                {
                    result.Add(item.ToString());
                }
            }
            else
            {
                result.Add(ctx.Data.ToString());
            }

            return(result);
        }
Example #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MsgContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            context.Database.EnsureCreatedAsync().Wait();
        }
Example #14
0
        /// <summary>
        ///  执行基础消息类型
        /// </summary>
        /// <param name="recMsgXml"></param>
        /// <param name="msgType"></param>
        /// <param name="recMsgDirs"></param>
        /// <returns>返回基础消息处理结果</returns>
        private MsgContext ProcessExecute_BasicMsg(XmlDocument recMsgXml, string msgType,
                                                   Dictionary <string, string> recMsgDirs)
        {
            MsgContext context = null;

            switch (msgType.ToLower())
            {
            case "event":
                context = ProcessExecute_BasicEventMsg(recMsgXml, recMsgDirs);
                break;

            case "text":
                context = ExecuteBasicMsgHandler(recMsgXml, recMsgDirs, TextHandler);
                break;

            case "image":
                context = ExecuteBasicMsgHandler(recMsgXml, recMsgDirs, ImageHandler);
                break;

            case "voice":
                context = ExecuteBasicMsgHandler(recMsgXml, recMsgDirs, VoiceHandler);
                break;

            case "video":
                context = ExecuteBasicMsgHandler(recMsgXml, recMsgDirs, VideoHandler);
                break;

            case "shortvideo":
                context = ExecuteBasicMsgHandler(recMsgXml, recMsgDirs, VideoHandler);
                break;

            case "location":
                context = ExecuteBasicMsgHandler(recMsgXml, recMsgDirs, LocationHandler);
                break;

            case "link":
                context = ExecuteBasicMsgHandler(recMsgXml, recMsgDirs, LinkHandler);
                break;
            }
            return(context);
        }
Example #15
0
        private byte[] HandleListFriendRequests(EventDataMsg eventMsg, MsgContext ctx)
        {
            User userReq = _api.Services.User.GetUserByClientId(ctx.senderId);

            if (userReq == null)
            {
                throw new FriendsAppProviderException("You must be signedIn to add some friends.");
            }
            List <ulong>          requests     = _friendsData.GetFriendRequests(userReq.Id);
            List <FriendsAppUser> requestUsers = requests
                                                 .Select(x => User.Get(x))
                                                 .Where(x => x != null)
                                                 .Select(x => new FriendsAppUser(x.ToMessage(), null, null))
                                                 .ToList();
            FriendsAppMsg msg = new FriendsAppMsg();

            msg.FriendRequests        = new FriendsAppRequestsMsg();
            msg.FriendRequests.ToUser = userReq.Id;
            msg.FriendRequests.FriendRequestsList.AddRange(requestUsers.Select(x => x.ToNetworkModel()));
            return(msg.ToByteArray());
        }
Example #16
0
        public byte[] HandleEvent(EventDataMsg eventData, MsgContext ctx)
        {
            if (ctx.senderType != SenderType.USER)
            {
                throw new ChatAppException("Server can not use this app.");
            }
            ulong?userId = _api.User.ClientId2UserId(ctx.senderId);

            if (!userId.HasValue)
            {
                throw new ChatAppException("You must be signedIn to add some friends.");
            }
            switch ((ChatAppEventType)eventData.EventType)
            {
            case ChatAppEventType.GET_UPDATE:
                return(GetMsgUpdate(userId.Value));

            default:
                throw new ChatAppException("Unknown event type.");
            }
        }
Example #17
0
        private byte[] HandleListFriends(EventDataMsg eventMsg, MsgContext ctx)
        {
            User userReq = _api.Services.User.GetUserByClientId(ctx.senderId);

            if (userReq == null)
            {
                throw new FriendsAppProviderException("You must be signedIn to add some friends.");
            }
            List <ulong> friendIds = _friendsData.GetFriendsList(userReq.Id);

            if (friendIds == null)
            {
                friendIds = new List <ulong>();
            }
            List <FriendsAppUser> friends = friendIds.Select(x => ToFriendsAppUser(x)).ToList();
            FriendsAppMsg         msg     = new FriendsAppMsg();

            msg.FriendsList = new FriendsAppListMsg();
            msg.FriendsList.FriendsList.AddRange(friends.Select(x => x.ToNetworkModel()));
            return(msg.ToByteArray());
        }
Example #18
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Logger.Error("网站启动了:" + DateTime.Now);

            AccessTokenManage.GetAccessTokenName(true);
            ButtonHelp.InitButton();

            Task.Factory.StartNew(() =>
            {
                var msgContext = new MsgContext(new SendData());
                while (true)
                {
                    msgContext.Process();
                    Thread.Sleep(60000 * 1435);
                }
            });
        }
Example #19
0
        void IMsgIsTheApp.SetContextFor(MsgContext access, IMsgContext context, object msg)
        {
            Validate.NotNull(access);

            MsgContextProxy prev;
            _contexts.TryGetValue(msg, out prev);

            if (prev != null)
            {
                validate_it_is_not_a_merge(prev.Impl, context.Impl, msg);
                return;
            }

            var proxy = new MsgContextProxy(context);
            proxy.SetMsgIsTheApp(this);

            try
            {
                _contexts.Add(msg, proxy);
            }
            catch (ArgumentException)   // key already exists
            {}
        }
Example #20
0
        public byte[] HandleEvent(EventDataMsg eventData, MsgContext ctx)
        {
            switch ((FriendsAppEvents)eventData.EventType)
            {
            case FriendsAppEvents.ADD_FRIEND:
                return(HandleAddFriend(eventData, ctx));

            case FriendsAppEvents.DEL_FRIEND:
                return(HandleDelFriend(eventData, ctx));

            case FriendsAppEvents.GET_FRIEND:
                return(HandleGetFriend(eventData, ctx));

            case FriendsAppEvents.LIST_FRIEND_REQUESTS:
                return(HandleListFriendRequests(eventData, ctx));

            case FriendsAppEvents.LIST_FRIENDS:
                return(HandleListFriends(eventData, ctx));

            default:
                throw new FriendsAppProviderException("Unknown event type.");
            }
        }
Example #21
0
        public byte[] HandleMessage(byte[] data, int size, MsgContext ctx)
        {
            if (ctx.senderType != SenderType.USER)
            {
                throw new ChatAppException("Server can not use this app.");
            }
            ChatAppMsg appMsg = ChatAppMsg.Parser.ParseFrom(data);

            if (appMsg == null)
            {
                throw new ChatAppException("Unknown message format.");
            }
            ChatRequest request = appMsg.Request;

            if (request == null)
            {
                throw new ChatAppException("Invalid message type.");
            }
            ulong?userId = _api.User.ClientId2UserId(ctx.senderId);

            if (!userId.HasValue)
            {
                throw new ChatAppException("You must be signedIn to add some friends.");
            }
            switch (request.RequestTypeCase)
            {
            case ChatRequest.RequestTypeOneofCase.SendRequest:
                return(SendMessage(userId.Value, request.SendRequest.To, request.SendRequest.Message, ctx));

            case ChatRequest.RequestTypeOneofCase.ListRequest:
                return(ListRequest(userId.Value, ctx));

            default:
                throw new ChatAppException("Unknown request type.");
            }
        }
        protected object NotifyInternal(object msg, string topic, string sender)
        {
            object ret = null;
            MsgContext ctx = new MsgContext(sender, topic);
            ctx.CancelFurtherProcessing = false;

            Type t = msg.GetType();
            while (t != null)
            {
                NotifyInternalForType(msg, t, ctx);
                if (ctx.CancelFurtherProcessing)
                {
                    ret = ctx.Retval;
                    break;
                }
                t = t.BaseType;
            }
            return ret;
        }
 private void NotifyInternalForType(object msg, Type t, MsgContext ctx)
 {
     ArrayList al;
     lock (this)
     {
         al = (ArrayList) _typeToSubscriberInfo[t];
     }
     if (al == null) return;
     NotifyInternalList(msg, al, ctx);
 }
Example #24
0
 protected override void ProcessEnd(MsgContext msgContext)
 {
     LogUtil.Info(msgContext.RecMsg.RecMsgXml?.OuterXml);
 }
 private void NotifyInternalList(object msg, ArrayList subscribers, MsgContext ctx)
 {
     foreach (SubscriberInfo si in subscribers)
     {
         if (si.MatchesTopic(ctx.Topic))
         {
             if (si.Handler != null)
             {
                 ctx.AnyNotified = true;
                 si.Handler.Invoke(msg, ctx);
                 if (ctx.CancelFurtherProcessing)
                 {
                     break;
                 }
             }
         }
     }
 }
Example #26
0
 public byte[] HandleMessage(byte[] data, int size, MsgContext context)
 {
     throw new NotImplementedException();
 }
Example #27
0
 public byte[] HandleEvent(EventDataMsg eventData, MsgContext context)
 {
     throw new NotImplementedException();
 }
Example #28
0
        private void PublishEvent(string elem, string action, string phase, object objToSend, MsgType msgType, MsgContext ctx)
        {
            if (objToSend == null)
            {
                throw new Exception("Content is null");
            }

            if (string.IsNullOrEmpty(elem) || string.IsNullOrEmpty(action))
            {
                throw new ArgumentException("eventCode is empty");
            }

            var s = (EventSender)Resolver.Resolve(typeof(EventSender));

            if (s == null)
            {
                throw new Exception("No sender initialized");
            }

            var ctxCopy = (MsgContext)ctx.Clone();

            /* ctxCopy.Event.EventUniqueId = Guid.NewGuid();
             * ctxCopy.Event.EventAction = action;
             * ctxCopy.Event.EventPhase = phase;
             * ctxCopy.Event.EventPath = elem;
             *
             * ctxCopy.Event.Content = JsonConvert.SerializeObject(objToSend);
             * ctxCopy.Event.ContentType = TypeHelper.GetTypeFullName(objToSend.GetType());
             *
             * ctxCopy.Event.EventType = msgType;
             *
             * s.SendEvent(ctxCopy);*/
        }
Example #29
0
 /// <summary>
 ///  执行结束方法
 /// </summary>
 /// <param name="msgContext"></param>
 protected virtual void ProcessEnd(MsgContext msgContext)
 {
 }
Example #30
0
 public byte[] HandleMessage(byte[] data, int size, MsgContext context)
 {
     throw new FriendsAppProviderException("FriendsAppProvider accepts requests only through event system.");
 }