public static void Main(string[] args)
        {
            PushPayload pushPayload = new PushPayload();
            pushPayload.platform = Platform.all();
            pushPayload.audience = Audience.all();
            pushPayload.notification = new Notification().setAlert(ALERT);
            ScheduleClient scheduleclient = new ScheduleClient(app_key, master_secret);

            //init a TriggerPayload
            TriggerPayload triggerConstructor = new TriggerPayload(START, END, TIME_PERIODICAL, TIME_UNIT, FREQUENCY, POINT);
            //init a SchedulePayload
            SchedulePayload schedulepayloadperiodical = new SchedulePayload(NAME, ENABLED, triggerConstructor, pushPayload);

            try
            {
                var result = scheduleclient.sendSchedule(schedulepayloadperiodical);
                Console.WriteLine(result);
            }
            catch (APIRequestException e)
            {
                Console.WriteLine("Error response from JPush server. Should review and fix it. ");
                Console.WriteLine("HTTP Status: " + e.Status);
                Console.WriteLine("Error Code: " + e.ErrorCode);
                Console.WriteLine("Error Message: " + e.ErrorCode);
            }
            catch (APIConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public ScheduleResult sendSchedule(SchedulePayload schedulepayload)
        {
            Preconditions.checkArgument(schedulepayload != null, (object)"schedulepayload should not be empty");
            schedulepayload.Check();
            string json = schedulepayload.ToJson();

            Console.WriteLine(json);
            return(this.sendSchedule(json));
        }
Exemple #3
0
        //获取指定的定时任务
        //GET https://api.jpush.cn/v3/schedules/{schedule_id}

        public SchedulePayload getScheduleById(String id)
        {
            Preconditions.checkArgument(!String.IsNullOrEmpty(id), "id should be set.");
            jSetting = new JsonSerializerSettings();
            jSetting.NullValueHandling    = NullValueHandling.Ignore;
            jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
            String url = HOST_NAME_SSL;

            url += PUSH_PATH;
            url += "/";
            url += id;
            ResponseWrapper result = sendGet(url, Authorization(), id);

            String          schedule        = result.responseContent;
            SchedulePayload schedulepayload = JsonConvert.DeserializeObject <SchedulePayload>(schedule, jSetting);

            return(schedulepayload);
        }
        public ScheduleResult putSchedule(
            SchedulePayload schedulepayload,
            string schedule_id)
        {
            Preconditions.checkArgument(schedulepayload != null, (object)"schedulepayload should not be empty");
            Preconditions.checkArgument(schedule_id != null, (object)"schedule_id should not be empty");
            if (schedulepayload.push.audience == null || schedulepayload.push.platform == null)
            {
                schedulepayload.push = (PushPayload)null;
            }
            if (schedulepayload.trigger.getTime() == null && schedulepayload.trigger.getSingleTime() == null)
            {
                schedulepayload.trigger = (TriggerPayload)null;
            }
            string json = schedulepayload.ToJson();

            Console.WriteLine(json);
            return(this.putSchedule(json, schedule_id));
        }
        public static void Main(string[] args)
        {
            //init a pushpayload
            PushPayload pushPayload = new PushPayload();
            pushPayload.platform = Platform.all();
            pushPayload.audience = Audience.all();
            pushPayload.notification = new Notification().setAlert(ALERT);

            ScheduleClient scheduleclient = new ScheduleClient(app_key, master_secret);

            //init a TriggerPayload
            TriggerPayload triggerConstructor = new TriggerPayload(START, END, TIME_PERIODICAL, TIME_UNIT, FREQUENCY, POINT);
            //init a SchedulePayload
            SchedulePayload schedulepayloadperiodical = new SchedulePayload(NAME, ENABLED, triggerConstructor, pushPayload);

            //PUT the name
            SchedulePayload putschedulepayload = new SchedulePayload();

            putschedulepayload.setName(NAME);

            //the default enabled is true,if you want to change it,you have to set it to false
            try
            {
                var result = scheduleclient.putSchedule(putschedulepayload, SCHEDULE_ID);
                Console.WriteLine(result);
            }
            catch (APIRequestException e)
            {
                Console.WriteLine("Error response from JPush server. Should review and fix it. ");
                Console.WriteLine("HTTP Status: " + e.Status);
                Console.WriteLine("Error Code: " + e.ErrorCode);
                Console.WriteLine("Error Message: " + e.ErrorCode);
            }
            catch (APIConnectionException e)
            {
                Console.WriteLine(e.Message);
            }
        }
 //POST https://api.jpush.cn/v3/schedules
 //创建一个新的定时任务。
 public ScheduleResult sendSchedule(SchedulePayload schedulepayload)
 {
     Preconditions.checkArgument(schedulepayload != null, "schedulepayload should not be empty");
     schedulepayload.Check();
     String schedulepayloadJson = schedulepayload.ToJson();
     Console.WriteLine(schedulepayloadJson);
     return sendSchedule(schedulepayloadJson);
 }
        //PUT  https://api.jpush.cn/v3/schedules/{schedule_id}
        //修改指定的Schedule
        public ScheduleResult putSchedule(SchedulePayload schedulepayload,String schedule_id)
        {
            Preconditions.checkArgument(schedulepayload != null, "schedulepayload should not be empty");
            Preconditions.checkArgument(schedule_id != null, "schedule_id should not be empty");

            if (schedulepayload.push.audience == null || schedulepayload.push.platform == null) {
                schedulepayload.push = null;
            }

            if(schedulepayload.trigger.getTime()==null && schedulepayload.trigger.getSingleTime() == null)
            {
                schedulepayload.trigger = null;
            }

            String schedulepayloadJson = schedulepayload.ToJson();
            Console.WriteLine(schedulepayloadJson);
            return putSchedule(schedulepayloadJson,schedule_id);
        }