public ActionResult UpdateAPPExpireTime(int messageId, string dateTime)
        {
            ResponseModel rm = new ResponseModel();

            rm.IsSuccess = false;
            string   errmsg = "";
            DateTime appTime;

            if (!DateTime.TryParse(dateTime, out appTime))
            {
                rm.OutMessage = "请输入正确的时间格式!";
                return(Json(rm));
            }
            if (User == null || User.Identity == null)
            {
                rm.OutMessage = "删除失败,登录信息错误";
                return(Json(rm));
            }
            else
            {
                try
                {
                    rm.IsSuccess  = PushHandler.UpdateAPPExpireTime(messageId, appTime, out errmsg);
                    rm.OutMessage = errmsg;
                    return(Json(rm));
                }
                catch (Exception ex)
                {
                    rm.IsSuccess  = false;
                    rm.OutMessage = "删除失败,服务异常";
                    return(Json(rm));
                }
            }
        }
        public ActionResult SeachPushHis(int?pageNo)
        {
            int sumNum;
            var pageSize  = 20;
            int pageIndex = (pageNo == null) ? 1: pageNo.Value;
            var model     = new PushMessageListModel();

            var taskList = PushHandler.SearchPushHis(pageIndex, pageSize, out sumNum);

            model.SumNum          = sumNum;
            model.PushMessageList = taskList;

            if (taskList != null && taskList.Count > 1)
            {
                double tmp     = sumNum / double.Parse(pageSize.ToString());
                int    pageNum = (int)Math.Ceiling(tmp);
                string tmpUrl  = string.Format("/Push/SeachPushHis?pageno={0}", "{0}");
                model.PagerStr = PageHtmlHelper.GetListPager(tmpUrl, pageNo.Value, pageNum);
                if (pageNum == 1)
                {
                    model.PagerStr = string.Empty;
                }
            }
            model.SearchInfo = new PushMessageSeachInfoModel
            {
                PageNo = pageNo
            };

            return(View(model));
        }
        public ActionResult DeletePushMessage(int messageId)
        {
            ResponseModel rm = new ResponseModel();

            rm.IsSuccess = false;
            string errmsg = "";

            if (User == null || User.Identity == null)
            {
                rm.OutMessage = "删除失败,登录信息错误";
            }
            else
            {
                try
                {
                    rm.IsSuccess  = PushHandler.DeleteMessages(messageId, User.Identity.Name, out errmsg);
                    rm.OutMessage = errmsg;
                }
                catch (Exception ex)
                {
                    rm.IsSuccess  = false;
                    rm.OutMessage = "删除失败,服务异常";
                }
            }
            return(Json(rm));
        }
Example #4
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              IApplicationLifetime lifetime)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(_configuration)
                         .WriteTo.Console(new JsonFormatter())
                         .Enrich.FromLogContext()
                         .CreateLogger();

            _logger.LogInformation("Starting service");
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            RunSSHDeamon(lifetime, loggerFactory.CreateLogger("sshd"));

            var executor = ShellHelper.Executor.WithWorkingDirectory(_configuration.GetValue <string>("REPO_LOCATION"))
                           .ForwardEnvVariable("GIT_SSH");



            var gitValidationFlow = new GitValidationFlow
            {
                Validators =
                {
                    (Patterns.Manifests, new CircularDependencyValidator()),
                    (Patterns.JPad,      new CompileJPadValidator())
                }
            };

            var minioConfig = _configuration.GetSection("Minio");

            var storageClient = Policy.Handle <Exception>()
                                .WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
                                .ExecuteAsync(() =>
                                              MinioBucketStorage.GetOrCreateBucket(CreateMinioClient(minioConfig),
                                                                                   minioConfig.GetValue("Bucket", "tweek-ruleset")))
                                .Result;

            var natsClient          = new NatsPublisher(_configuration.GetSection("Nats").GetValue <string>("Endpoint"));
            var versionPublisher    = natsClient.GetSubjectPublisher("version");
            var repoSynchronizer    = new RepoSynchronizer(executor.WithUser("git").CreateCommandExecutor("git"));
            var storageSynchronizer = new StorageSynchronizer(storageClient, executor.WithUser("git"), new Packer());

            storageSynchronizer.Sync(repoSynchronizer.CurrentHead().Result, checkForStaleRevision: false).Wait();
            RunIntervalPublisher(lifetime, versionPublisher, repoSynchronizer, storageSynchronizer);
            var syncActor = SyncActor.Create(storageSynchronizer, repoSynchronizer, natsClient, lifetime.ApplicationStopping, loggerFactory.CreateLogger("SyncActor"));

            app.UseRouter(router =>
            {
                router.MapGet("validate", ValidationHandler.Create(executor, gitValidationFlow, loggerFactory.CreateLogger <ValidationHandler>()));
                router.MapGet("sync", SyncHandler.Create(syncActor, _syncPolicy));
                router.MapGet("push", PushHandler.Create(syncActor));

                router.MapGet("log", async(req, res, routedata) => _logger.LogInformation(req.Query["message"]));
                router.MapGet("health", async(req, res, routedata) => await res.WriteAsync(JsonConvert.SerializeObject(new { })));
                router.MapGet("version", async(req, res, routedata) => await res.WriteAsync(Assembly.GetEntryAssembly()
                                                                                            .GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion));
            });
        }
Example #5
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // Set log level for debugging config loading (optional)
            // It will be set to the value in the loaded config upon takeOff
            UAirship.LogLevel = UALogLevel.Trace;

            // Populate AirshipConfig.plist with your app's info from https://go.urbanairship.com
            // or set runtime properties here.
            UAConfig config = UAConfig.DefaultConfig();

            if (!config.Validate())
            {
                throw new RuntimeException("The AirshipConfig.plist must be a part of the app bundle and " +
                                           "include a valid appkey and secret for the selected production level.");
            }

            WarnIfSimulator();

            // Bootstrap the Airship SDK
            UAirship.TakeOff(config, options);

            Console.WriteLine("Config:{0}", config);

            UAirship.Push.ResetBadge();

            pushHandler = new PushHandler();
            UAirship.Push.PushNotificationDelegate = pushHandler;

            UNNotificationAction sampleAction = UNNotificationAction.FromIdentifier("sampleAction", title: "Sample Action Title", options: UNNotificationActionOptions.Destructive);

            var sampleActions     = new UNNotificationAction[] { sampleAction };
            var intentIdentifiers = new string[] { };

            // Create category for sample content extension
            UNNotificationCategory[]       SampleCategoryArray = { UNNotificationCategory.FromIdentifier("sample-extension-category", actions: sampleActions, intentIdentifiers: intentIdentifiers, options: UNNotificationCategoryOptions.None) };
            NSSet <UNNotificationCategory> categories          = new NSSet <UNNotificationCategory>(SampleCategoryArray);

            // Add sample content extension category to Airship custom categories
            UAirship.Push.CustomCategories = categories;

            UAirship.Push.WeakRegistrationDelegate = this;

            NSNotificationCenter.DefaultCenter.AddObserver(new NSString("channelIDUpdated"), (notification) =>
            {
                //FIXME: Find a way to call the refreshView from the HomeViewController
            });

            InitFormsApp();

            return(base.FinishedLaunching(app, options));
        }
 public ActorController(
     ActorSettings settings,
     ActorModel model,
     MoveHandler moveHandler,
     InteractHandler interactHandler,
     PushHandler pushHandler,
     ResetHandler resetHandler)
 {
     _settings        = settings;
     _model           = model;
     _moveHandler     = moveHandler;
     _interactHandler = interactHandler;
     _pushHandler     = pushHandler;
     _resetHandler    = resetHandler;
 }
        private static Command WithPushCommands(this Command parent)
        {
            var extCmd = BuildCommand("push", true)
                         .WithSubCommand("indicators", true, subCommand => {
                subCommand
                .WithHandler(CommandHandler.Create((DateTime from, DateTime to, string cfg) => PushHandler.PushIndicators(from, to, cfg)))
                .WithDateTimeOption("--from", "period FROM", true)
                .WithDateTimeOption("--to", "period TO", true)
                .WithOption <string>("--cfg", "cfg file name", true);
            });

            parent.AddCommand(extCmd);
            return(parent);
        }
        public JsonResult SubmitPushMessage(PushMessageViewModel message)
        {
            var count = -1;

            if (message != null &&
                !string.IsNullOrWhiteSpace(message.Description) &&
                !string.IsNullOrWhiteSpace(message.Title) &&
                !string.IsNullOrWhiteSpace(message.Content))
            {
                if (message.ExpireTime.HasValue)
                {
                    message.SendTime = message.SendTime ?? DateTime.Now;
                    if (message.ExpireTime < DateTime.Now || message.ExpireTime < message.SendTime.Value.AddMinutes(30))
                    {
                        return(Json(-2));
                    }
                }
                if (message.APPExpireTime.HasValue)
                {
                    message.SendTime = message.SendTime ?? DateTime.Now;
                    if (message.APPExpireTime < DateTime.Now || message.APPExpireTime < message.SendTime.Value.AddMinutes(30))
                    {
                        return(Json(-2));
                    }
                }

                if (message.AfterOpen == "1" && string.IsNullOrWhiteSpace(message.AppActivity))
                {
                    return(Json(-3));
                }

                if (!string.IsNullOrWhiteSpace(message.IOSValue1))
                {
                    message.IOSValue1 = message.IOSValue1.Replace("“", "\"");
                    message.IOSValue1 = message.IOSValue1.Replace("”", "\"");
                }

                if (!string.IsNullOrWhiteSpace(message.IOSValue2))
                {
                    message.IOSValue2 = message.IOSValue2.Replace("“", "\"");
                    message.IOSValue2 = message.IOSValue2.Replace("”", "\"");
                }

                if (!string.IsNullOrWhiteSpace(message.IOSValue3))
                {
                    message.IOSValue3 = message.IOSValue3.Replace("“", "\"");
                    message.IOSValue3 = message.IOSValue3.Replace("”", "\"");
                }

                if (!string.IsNullOrWhiteSpace(message.AndriodValue1))
                {
                    message.AndriodValue1 = message.AndriodValue1.Replace("“", "\"");
                    message.AndriodValue1 = message.AndriodValue1.Replace("”", "\"");
                }

                if (!string.IsNullOrWhiteSpace(message.AndriodValue2))
                {
                    message.AndriodValue2 = message.AndriodValue2.Replace("“", "\"");
                    message.AndriodValue2 = message.AndriodValue2.Replace("”", "\"");
                }
                if (User == null || User.Identity == null)
                {
                    return(Json(10));
                }
                message.OperUser = User.Identity.Name;

                if (message.PushType == Push_Broadcast) // 广播
                {
                    var result = PushHandler.PushTaskMessage(message);
                    count = result ? 1 : -10;
                }
                else if (message.PushType == Push_Groupcast) // 组播
                {
                    if (string.IsNullOrEmpty(message.Tags))
                    {
                        return(Json(-6));
                    }
                    var result = PushHandler.PushTaskMessage(message);
                    count = result ? 1 : -10;
                }
                else if (message.PushType == Push_Single) // 单播
                {
                    #region Get phone numbers

                    var cellphones     = new List <string>(10000);
                    var cellphonesFile = Request.Files.Count > 0 ? Request.Files[0] : null;
                    if (cellphonesFile == null || cellphonesFile.ContentLength < 11)
                    {
                        return(Json(-5));
                    }

                    try
                    {
                        using (var stream = new StreamReader(cellphonesFile.InputStream, Encoding.UTF8))
                        {
                            foreach (var item in Regex.Split(stream.ReadToEnd(), @"\D")
                                     .Where(
                                         cellphone => !string.IsNullOrEmpty(cellphone) && Regex.IsMatch(cellphone, @"^1\d{10}$"))
                                     .Distinct())
                            {
                                cellphones.Add(item);
                            }
                        }

                        //var preList = new PushManager().GetPushMsgPersonConfig();

                        //if (preList != null)
                        //// 添加预配置的手机号
                        //{
                        //    cellphones.AddRange(preList);
                        //    cellphones = cellphones.Select(x => x).Distinct().ToList();
                        //}

                        if (cellphones.Count < 1)
                        {
                            return(Json(0));
                        }
                        var result = PushHandler.PushMessage(message, cellphones);
                        count = result ? cellphones.Count : -10;
                    }
                    catch (Exception)
                    {
                        return(Json(-10));
                    }
                    #endregion
                }
            }

            return(Json(count));
        }
Example #9
0
 public MessageController(PushHandler notificationsMessageHandler)
 {
     _notifications = notificationsMessageHandler;
 }
Example #10
0
 public EventModule(RPGClient client) : base(client)
 {
     mPushHandler = game_client.Listen <ClientGameEventNotify>(OnRemoteGameEventNotify);
     Logger       = LoggerFactory.GetLogger(GetType().Name);
 }