示例#1
0
        static void Test4()
        {
            foreach (var item in PushPositionQueue.QUEUE_SYMBOLS)
            {
                Console.WriteLine($"{item.Value} receive start...");
                MQConsumer.ReceiveMessage(item.Value, m =>
                {
                    string msg = Encoding.UTF8.GetString(m);
                    Console.WriteLine($"{item.Value}:{msg}");

                    try
                    {
                        PushModel model = JsonConvert.DeserializeObject <PushModel>(msg);
                        IConsumeHandler consumeHandler = ConsumeFactory.Create(model.PositionType);
                        consumeHandler.Process(model);
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"Process failure:{CommonCs.GetExceptionMessages(ex)}");
                        Console.ResetColor();
                    }
                });
            }
        }
        public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
        {
            var dataJObject = context.GetDataOrDefault <JObject>();
            var action      = context.Actions.First();
            var pushModel   = new PushModel();

            switch (action)
            {
            case "repo:push":

                pushModel.Repository = dataJObject["repository"].ToObject <BitbucketRepository>();
                pushModel.User       = dataJObject["actor"].ToObject <BitbucketUser>();
                foreach (var change in dataJObject["push"]["changes"])
                {
                    pushModel.Previous = change["old"]["target"].ToObject <BitbucketTarget>();

                    pushModel.Current = change["new"]["target"].ToObject <BitbucketTarget>();
                }
                break;

            default:
                pushModel.RawData = dataJObject.ToString();
                break;
            }
            return(Task.FromResult(true));
        }
示例#3
0
        public async Task <IActionResult> Create(PushModel model)
        {
            if (ModelState.IsValid)
            {
                var name       = User.Identity.Name;
                var loggedUser = await _adminRepository.GetByEmailAsync(name);


                await SendPushToAppCenter(model.Title, model.Content, model.SurveyId.ToString());

                await _pushRepository.AddAsync(
                    new DomainLayer.Entities.Push
                {
                    AdminId   = loggedUser.Id,
                    Content   = model.Content,
                    Title     = model.Title,
                    SurveyId  = model.SurveyId,
                    CreatedAt = DateTime.UtcNow
                }
                    );

                return(RedirectToAction("Index", "Home"));
            }

            return(View(model));
        }
        public IActionResult Send(PushModel model)
        {
            if (!string.IsNullOrEmpty(_pushNotificationsSettings.PrivateApiKey) && !string.IsNullOrEmpty(model.MessageText))
            {
                _pushNotificationsSettings.PicutreId = model.PictureId;
                _pushNotificationsSettings.ClickUrl  = model.ClickUrl;
                _settingService.SaveSetting(_pushNotificationsSettings);

                Tuple <bool, string> result = _pushNotificationsService.SendPushNotification(model.Title, model.MessageText,
                                                                                             _pictureService.GetPictureUrl(model.PictureId), model.ClickUrl);

                if (result.Item1)
                {
                    SuccessNotification(result.Item2);
                }
                else
                {
                    ErrorNotification(result.Item2);
                }
            }
            else
            {
                ErrorNotification(_localizationService.GetResource("PushNotifications.Error.PushApiMessage"));
            }

            return(RedirectToAction("Send"));
        }
示例#5
0
        public async Task Post(PushModel model)
        {
            var sen = new NotificationsModule.Push.GCM.GcmPushSender();

            var registration = db.Pushes.FirstOrDefault(c => c.DeviceId == model.DeviceId);

            if (String.IsNullOrWhiteSpace(registration?.UserId) && registration != null)
            {
                registration.UserId = model.User;
                await db.UpdateEntityAsync(registration, model.User);
            }

            if (db.Pushes.Any(c => c.DeviceId == model.DeviceId) && !String.IsNullOrWhiteSpace(registration?.UserId))
            {
                return;
            }

            if (registration == null)
            {
                var result = await sen.Single(model.DeviceId, "Успішна реєстрація", "Вітаємо, Ви успішно підписані на оновлення від PTP!", "RegisterToPush");

                if (result)
                {
                    var newClient = new Push(model.DeviceId, model.User);
                    db.Insert(newClient, model.User);
                }
            }
        }
示例#6
0
        public IActionResult Send(SendRequestModel model)
        {
            Application application = _dbContext.Application.SingleOrDefault(m => m.id == model.id);

            List <Device> devices = _dbContext.Device.Where(m => m.appId == application.id).ToList();

            string vapidPublicKey  = application.publicKey;
            string vapidPrivateKey = application.privateKey;

            PushModel payload = new PushModel
            {
                title   = model.title,
                message = model.message
            };

            foreach (Device device in devices)
            {
                var pushSubscription = new PushSubscription(device.pushEndpoint, device.pushP256DH, device.pushAuth);
                var vapidDetails     = new VapidDetails("mailto:[email protected]", vapidPublicKey, vapidPrivateKey);

                var webPushClient = new WebPushClient();
                webPushClient.SendNotification(pushSubscription, JsonConvert.SerializeObject(payload), vapidDetails);
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#7
0
        public ActionResult Post(PushModel data)
        {
            UserMocker.Mock(data.Id);

            using (var db = new RescContext())
            {
                var firstResponder = db.FirstResponders.SingleOrDefault(p => p.Id == data.Id);
                if (firstResponder == null)
                {
                    return(Ok("Fail"));
                }

                firstResponder.PushEndpoint = data.Endpoint;
                var tmp = data.Keys.SingleOrDefault(k => k.Key == "auth");
                firstResponder.PushAuth = tmp.Value;
                tmp = data.Keys.SingleOrDefault(k => k.Key == "p256dh");
                firstResponder.PushKey = tmp.Value;

                db.FirstResponders.Update(firstResponder);

                db.SaveChanges();
            }

            return(Ok());
        }
示例#8
0
        public async Task SendLogAsync()
        {
            PushModel model = new PushModel
            {
                AuthModel = _authModel,
                LogModel  = new LogModel
                {
                    UserName         = email,
                    Category         = "Apple Test",
                    EventId          = Guid.NewGuid().ToString(),
                    LogMessage       = "You can use html tag inside LogMessage. Please not use html, body or any head tag we can insert automatically for you :)",
                    LogTime          = DateTime.Now.ToShortTimeString(),
                    LogTypes         = LogPusher.NetConnector.Enums.LogType.Information,
                    ShortDescription = "Apple application test new logpusher client. Please see the detail.",
                    Source           = "LogPusherConnector",
                    Subject          = "A new Connector Test"
                }
            };

            ///    var returend = model.SendLog();

            //Exception ex = null;
            //System.ArgumentException argEx = new System.ArgumentException("Index is out of range", "index", ex);
            var returned = await model.SendLog();
        }
        public async Task <IActionResult> Send(PushModel model)
        {
            if (!string.IsNullOrEmpty(_pushNotificationsSettings.PrivateApiKey) && !string.IsNullOrEmpty(model.MessageText))
            {
                _pushNotificationsSettings.PictureId = model.PictureId;
                _pushNotificationsSettings.ClickUrl  = model.ClickUrl;
                await _settingService.SaveSetting(_pushNotificationsSettings);

                var pictureUrl = await _pictureService.GetPictureUrl(model.PictureId);

                var result = (await _pushNotificationsService.SendPushNotification(model.Title, model.MessageText, pictureUrl, model.ClickUrl));
                if (result.Item1)
                {
                    Success(result.Item2);
                }
                else
                {
                    Error(result.Item2);
                }
            }
            else
            {
                Error(_translationService.GetResource("PushNotifications.Error.PushApiMessage"));
            }

            return(RedirectToAction("Send"));
        }
示例#10
0
        public static void OrderInfoPush(int?corpId, String orerId, String moblie)
        {
            try
            {
                if (!corpId.HasValue)
                {
                    return;
                }
                System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    string appKey, appSecret, appIdentifier;
                    if (Common.Push.GetBusinessAppKeyAndAppSecret(PubConstant.tw2bsConnectionString, corpId.Value.ToString(), out appIdentifier, out appKey, out appSecret))
                    {
                        PushModel pushModel = new PushModel(appKey, appSecret, PushChannel.JPush, 3)
                        {
                            AppIdentifier = corpId.Value.ToString(),
                            Badge         = 1,
                            LowerExtraKey = false,
                        };

                        pushModel.Extras.Add("Id", orerId);
                        pushModel.Audience.Category = PushAudienceCategory.Alias;
                        pushModel.Message           = string.Format("你有新的订单,点击查看详情。");
                        pushModel.Command           = PushCommand.BusinessCorp_Order;
                        pushModel.CommandName       = PushCommand.CommandNameDict[pushModel.Command];
                        pushModel.Audience.Objects.Add(moblie);
                        TWTools.Push.Push.SendAsync(pushModel);
                    }
                });
            }
            catch (Exception ex) { GetLog().Error(ex.Message); }
        }
示例#11
0
        public void Process(PushModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("PushModel");
            }

            this.sourceType    = model.SourceType;
            this.userId        = model.PositionModel?.UserId ?? 0;
            this.messageType   = model.PushMessageType;
            this.messageModel  = model.MessageModel;
            this.positionModel = model.PositionModel;

            if (this.userId <= 0)
            {
                throw new ArgumentNullException("UserId");
            }

            if (this.positionModel == null)
            {
                throw new ArgumentNullException("PushPositionModel");
            }

            this.CheckMessageModel();

            this.AddNearCircle();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            PushModel pushModel = db.PushModel.Find(id);

            db.PushModel.Remove(pushModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#13
0
        public UserResponseModel CreateNewUser(PushModel model)
        {
            string            errMsg = string.Empty;
            UserResponseModel ret    = new UserResponseModel();
            var result = Post <UserResponseModel, PushModel>(model, Functions[UserConstant.InsertUser], token: TokenString);

            return(ret);
        }
示例#14
0
        public bool PUSH(string device_Feature, PushModel pushdata)
        {
            int    statusCode = 0;
            string Jsondata   = JsonConvert.SerializeObject(pushdata);
            string is_success = csmapi.Push(custom.SSLIoTTalkServer, custom.Mac_Addr, device_Feature, Jsondata, custom.passwordkey, ref statusCode);

            return(true);
        }
示例#15
0
        public static async Task Main(string[] args)
        {
            RongCloud rongCloud = RongCloud.GetInstance(appKey, appSecret);

            /**
             *
             * API 文档:
             * https://www.rongcloud.cn/docs/push_service.html#broadcast
             *
             * 广播消息
             *
             **/
            BroadcastModel broadcast = new BroadcastModel();

            broadcast.SetFromuserid("fromuserid");
            broadcast.SetPlatform(new string[] { "ios", "android" });
            Audience audience = new Audience();

            audience.SetUserid(new string[] { "userid1", "userid2" });
            broadcast.SetAudience(audience);
            Message message = new Message();

            message.SetContent("this is message");
            message.SetObjectName("RC:TxtMsg");
            broadcast.SetMessage(message);
            Notification notification = new Notification();

            notification.SetAlert("this is broadcast");
            broadcast.SetNotification(notification);
            PushResult result = await rongCloud.Broadcast.Send(broadcast);

            Console.WriteLine("broadcast: " + result);


            /**
             *
             * API 文档:
             * https://www.rongcloud.cn/docs/push_service.html#push
             *
             * 推送消息
             *
             **/
            PushModel pushmodel = new PushModel();

            pushmodel.SetPlatform(new string[] { "ios", "android" });
            audience = new Audience();
            audience.SetUserid(new string[] { "userid1", "userid2" });
            pushmodel.SetAudience(audience);
            notification = new Notification();
            notification.SetAlert("this is push");
            pushmodel.SetNotification(notification);
            result = await rongCloud.Push.Send(pushmodel);

            Console.WriteLine("push: " + result);

            Console.ReadLine();
        }
 public ActionResult Edit([Bind(Include = "PushId,IdAsiento,NoAsiento,DescripcionAsiento,FechaAsiento,CuentaContable,TipoMovimiento,Monto")] PushModel pushModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pushModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(pushModel));
 }
        public async Task <ResponseResult <PushActivityEvent> > SaveGithubPushEvent(PushModel model)
        {
            var mapped = _mapper.Map <PushActivity>(model);
            await _dbContext.PushActivities.AddAsync(mapped);

            await _dbContext.SaveChangesAsync();

            return(new ResponseResult <PushActivityEvent>(new PushActivityEvent {
                Id = mapped.Id
            }));
        }
        public ActionResult Create([Bind(Include = "PushId,IdAsiento,NoAsiento,DescripcionAsiento,FechaAsiento,CuentaContable,TipoMovimiento,Monto")] PushModel pushModel)
        {
            if (ModelState.IsValid)
            {
                db.PushModel.Add(pushModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(pushModel));
        }
        public IActionResult Send()
        {
            var model = new PushModel();

            model.MessageText = _localizationService.GetResource("PushNotifications.MessageTextPlaceholder");
            model.Title       = _localizationService.GetResource("PushNotifications.MessageTitlePlaceholder");
            model.PictureId   = _pushNotificationsSettings.PicutreId;
            model.ClickUrl    = _pushNotificationsSettings.ClickUrl;

            return(View(model));
        }
        public IActionResult Send()
        {
            var model = new PushModel
            {
                MessageText = _translationService.GetResource("Admin.PushNotifications.MessageTextPlaceholder"),
                Title       = _translationService.GetResource("Admin.PushNotifications.MessageTitlePlaceholder"),
                PictureId   = _pushNotificationsSettings.PictureId,
                ClickUrl    = _pushNotificationsSettings.ClickUrl
            };

            return(View(model));
        }
示例#21
0
        public MainPage()
        {
            pushModel     = new PushModel();
            Notifications = new ObservableCollection <Notification>();

            InitializeComponent();

            // Data binding to UI
            list.ItemsSource = Notifications;

            pushModel.NotificationReceived     += MainPage_NotificationReceived;
            pushModel.RegistrationStateChanged += MainPage_RegistrationStateChanged;
        }
示例#22
0
        public ActionResult PushDev()
        {
            var model = new PushModel();

            model.badge   = 14;
            model.message = "antCart App test ";
            TestPushDev(model);
            return(Json(new
            {
                status = model.IsResult,
                msgerror = GenerateMsgError(model.MsgError)
            }, JsonRequestBehavior.AllowGet));
        }
        public async Task <bool> Upload(List <Commit <T> > commits, string pointerId)
        {
            if (_ws?.State != WebSocketState.Open)
            {
                return(false);
            }
            var model = new PushModel <T> {
                Commits = commits, Start = pointerId
            };
            await _ws.SendObject(model);

            return(true);
        }
示例#24
0
        public IActionResult Publish(PushModel model)
        {
            if (model == null)
            {
                return(Json(new { state = -1, error = "Publish data can't be empty." }));
            }

            if (model.MessageModel == null)
            {
                return(Json(new { state = -1, error = "Publish message content can't be empty." }));
            }

            if (model.PositionModel == null || string.IsNullOrEmpty(model.PositionModel.PosDetails))
            {
                return(Json(new { state = -1, error = "Publish position can't be empty." }));
            }

            if (model.PositionModel.UserId <= 0)
            {
                return(Json(new { state = -1, error = "UserId can't be empty." }));
            }

            UserService userService = new UserService(dbContext);

            if (!userService.IsExistUser(model.PositionModel.UserId))
            {
                return(Json(new { state = -1, error = $"Not found user data by current id of {model.PositionModel.UserId}." }));
            }

            string[] posDetails = model.PositionModel.PosDetails?.Split(',');
            if (posDetails != null && posDetails.Length > 0)
            {
                model.PositionModel.PosDetails = posDetails[posDetails.Length - 1];
            }

            if (model.MessageModel?.ImageUrls != null)
            {
                model.MessageModel.ImageUrls.RemoveAll(r => string.IsNullOrEmpty(r));
            }

            try
            {
                PushService.PushEntry.Process(model);
            }
            catch (Exception ex)
            {
                return(Json(new { state = -1, error = ex.Message }));
            }
            return(Json(new { state = 1 }));
        }
        // GET: PushModel/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PushModel pushModel = db.PushModel.Find(id);

            if (pushModel == null)
            {
                return(HttpNotFound());
            }
            return(View(pushModel));
        }
示例#26
0
 public HttpResponseMessage Push([FromUri] PushModel model)
 {
     try
     {
         StartClass.log.WriteInfo(model.signature);
         StartClass.log.WriteInfo(model.timestamp);
         StartClass.log.WriteInfo(model.nonce);
         StartClass.log.WriteInfo(model.echostr);
         StartClass.log.WriteInfo(Request.Method.Method.ToLower());
         if (Request.Method.Method.ToLower() == "post")
         {
             if (CheckSignature(model.signature, model.timestamp, model.nonce, model.echostr))
             {
                 StartClass.log.WriteInfo("准备解析xml");
                 //返回xml消息
                 var result = ReceiveXML(ActionContext);
                 if (result != null)
                 {
                     return(result);
                 }
                 else
                 {
                     return(new HttpResponseMessage()
                     {
                         Content = new StringContent("success", Encoding.GetEncoding("UTF-8"), "application/x-www-form-urlencoded")
                     });
                 }
             }
         }
         else
         {
             if (CheckSignature(model.signature, model.timestamp, model.nonce, model.echostr))
             {
                 return(new HttpResponseMessage()
                 {
                     Content = new StringContent(model.echostr, Encoding.GetEncoding("UTF-8"), "application/x-www-form-urlencoded")
                 });
             }
         }
     }
     catch (Exception ex)
     {
         StartClass.log.WriteError(ex.Message);
     }
     return(new HttpResponseMessage()
     {
         Content = new StringContent("success", Encoding.GetEncoding("UTF-8"), "application/x-www-form-urlencoded")
     });
 }
示例#27
0
        public ActionResult Index()
        {
            BPDbContext      db    = new BPDbContext();
            var              blogs = db.Blogs.OrderByDescending(b => b.BlogsId).ToList();
            List <PushModel> push  = new List <PushModel>();

            if (blogs.Count() < 4)
            {
                foreach (var item in blogs)
                {
                    PushModel pm = new PushModel {
                        blog = item
                    };
                    if (item.Context.Count() > 220)
                    {
                        pm.shortcontext = item.Context.Substring(0, 220) + "...";
                    }
                    else
                    {
                        pm.shortcontext = item.Context;
                    }
                    push.Add(pm);
                }
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    var       item = blogs[i];
                    PushModel pm   = new PushModel {
                        blog = item
                    };
                    if (item.Context.Count() > 220)
                    {
                        pm.shortcontext = item.Context.Substring(0, 220) + "...";
                    }
                    else
                    {
                        pm.shortcontext = item.Context;
                    }
                    push.Add(pm);
                }
            }

            return(View(push));
        }
示例#28
0
        public static void Process(PushModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("PushModel");
            }

            if (model.PositionModel == null)
            {
                throw new ArgumentNullException("PositionModel");
            }

            string queueName = PushPositionQueue.GetQueueName(model.PositionType);

            byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(model));
            RabbitMQ.MQPublisher.PushMessage(queueName, bytes);
        }
示例#29
0
        /**
         * 推送
         *
         * @param push 推送数据
         * @return PushResult
         **/
        public PushResult Send(PushModel push)
        {
            // 需要校验的字段
            String message = CommonUtil.CheckFiled(push, PATH, CheckMethod.PUSH);

            if (null != message)
            {
                return((PushResult)RongJsonUtil.JsonStringToObj <PushResult>(message));
            }

            String body = RongJsonUtil.ObjToJsonString(push);

            String result = RongHttpClient.ExecutePost(appKey, appSecret, body,
                                                       RongCloud.ApiHostType.Type + "/push.json", "application/json");

            return((PushResult)RongJsonUtil.JsonStringToObj <PushResult>(CommonUtil.GetResponseByCode(PATH, CheckMethod.BROADCAST, result)));
        }
示例#30
0
        public JsonResult InsertUser(UserRequestModel model)
        {
            TraceModel trace = new TraceModel()
            {
                userId          = "gdv.01",
                appCode         = "APP_ADMIN",
                clientTransId   = new Guid().ToString(),
                clientTimestamp = DateTime.Now.ToString("yyyyMMddHHmmssfff")
            };
            PushModel request = new PushModel()
            {
                trace = trace,
                data  = model
            };
            var rs = _userService.CreateNewUser(request);

            return(Json("1"));
        }