示例#1
0
        public GcmMessageResponse SendMessage(GcmMessage message)
        {
            GcmMessageResponse response = Send <GcmMessage, GcmMessageResponse>(message, GCM_SEND_URL);

            response.Message = message;
            UpdateResponseStatusForGcmMessage(response);
            return(response);
        }
示例#2
0
文件: Program.cs 项目: bkzhn/GcmSharp
        static void Main(string[] args)
        {
            string AuthKey = "AIzaSyDZD29PWZQBmSvW0vAYIu0mvkg2ny5TD9A";
            string PackageName = "com.mydealerlot.mdlmobile";
            string SenderId = "595292508198";
            GcmManagerOptions options = new GcmManagerOptions() { 
                AuthenticationKey = AuthKey, 
                PackageName = PackageName,
                SenderId = SenderId,
                Expect100Continue = false, //default
                UseNagleAlgorithm = false //default
            };

            GcmManager manager = new GcmManager(options);

            GcmMessage message = new GcmMessage().To("RegistrationTokenHere")
                .WithData(new { body = "Client: MR. SMITH, Appointment Time: today 3:00pm", title = "Your Appointment Has Arrived" })
                .WithNotification(new GcmNotification().WithBody("body text here").WithTitle("Title Here"));
               // ;
                //.WithRestrictedPackageName(PackageName).WithTimeToLive(400)
                //.WithIcon("myIcon.png").WithColor("color"));


            Stopwatch watch = new Stopwatch();
            Console.ReadKey();
            //for (int i = 0; i < 10; i++)
            //{
                watch.Start();
                Console.WriteLine("getting instance response");

                GcmMessageResponse response = manager.SendMessage(message);
                //var r = manager.GetInstanceIdResponse(true, "APA91bEVUAdCF4XdfV6cnecuih5SY48lePF8ZCiBgL8fgqRlB9CKlRyZbqOpfOOfP3SkOG2VYH1LDrYi80aotHg1at6QdcDrk_2t1_Iopw7MAkjv0dD-4DCbyqw7qKpF7INfiRQ2u_Ax");
                //Console.WriteLine(r.ToString());

                watch.Stop();
                Console.WriteLine("\nOVERALL: {0}\n\n", watch.Elapsed);
                watch.Reset();
            //}
            
            //bool again = true;
            //while(again)
            //{

            //Console.WriteLine("ready?");
            //Console.ReadLine();
            // var response = manager.SendMessage(message);
            string data = JsonConvert.SerializeObject(message, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore});
            Console.WriteLine(data);
            Debug.WriteLine(data);
            //Console.WriteLine("\n again?");
            //var s = Console.ReadLine();
            //if (s.Contains("no"))
            //    again = false;
            //}
            Console.ReadKey();


        }
示例#3
0
 public static GcmMessage WithRegistrationId(this GcmMessage msg, string id)
 {
     if (msg.RegistrationIds == null)
     {
         msg.RegistrationIds = new List <string>();
     }
     msg.RegistrationIds.Add(id);
     return(msg);
 }
示例#4
0
 public static GcmMessage WithRegistrationIds(this GcmMessage msg, List <string> ids)
 {
     if (msg.RegistrationIds == null)
     {
         msg.RegistrationIds = new List <string>();
     }
     msg.RegistrationIds.AddRange(ids);
     return(msg);
 }
示例#5
0
 public static GcmMessage WithDeliveryReceiptRequested(this GcmMessage msg, bool deliveryReceiptRequested)
 {
     msg.DeliveryReceiptRequested = deliveryReceiptRequested;
     return(msg);
 }
示例#6
0
 public static GcmMessage WithTimeToLive(this GcmMessage msg, int timeToLive)
 {
     msg.TimeToLive = timeToLive;
     return(msg);
 }
示例#7
0
 public static GcmMessage WithDelayWhileIdle(this GcmMessage msg, bool delayWhileIdle)
 {
     msg.DelayWhileIdle = delayWhileIdle;
     return(msg);
 }
示例#8
0
 public static GcmMessage WithContentAvailable(this GcmMessage msg, bool contentAvailable)
 {
     msg.ContentAvailable = contentAvailable;
     return(msg);
 }
示例#9
0
 public GcmException(string message, GcmMessage gcmMessage)
     : base(message)
 {
     Message = gcmMessage;
 }
示例#10
0
 public GcmException(string message, Exception innerException, GcmMessage gcmMessage)
     : base(message, innerException) { Message = gcmMessage; }
示例#11
0
 public GcmManagerTimeoutException(string message, GcmMessage gcmMessage)
     : base(message) { Message = gcmMessage; }
示例#12
0
 public static GcmMessage WithNotification(this GcmMessage msg, GcmNotification not)
 {
     msg.Notification = not;
     return(msg);
 }
示例#13
0
 public static GcmMessage To(this GcmMessage msg, string to)
 {
     msg.To = to;
     return(msg);
 }
示例#14
0
 public static GcmMessage WithData(this GcmMessage msg, object data)
 {
     msg.Data = data;
     return(msg);
 }
示例#15
0
 public GcmException(string message, Exception innerException, GcmMessage gcmMessage)
     : base(message, innerException)
 {
     Message = gcmMessage;
 }
示例#16
0
 public static GcmMessage WithRestrictedPackageName(this GcmMessage msg, string packageName)
 {
     msg.RestrictedPackageName = packageName;
     return(msg);
 }
示例#17
0
 public static GcmMessage IsDryRun(this GcmMessage msg, bool isDryRun)
 {
     msg.DryRun = isDryRun;
     return(msg);
 }
示例#18
0
 public static GcmMessage WithMessageId(this GcmMessage msg, string id)
 {
     msg.MessageId = id;
     return(msg);
 }
示例#19
0
 public GcmException(string message, GcmMessage gcmMessage)
     : base(message) { Message = gcmMessage; }
示例#20
0
 public static GcmMessage WithCollapseKey(this GcmMessage msg, string key)
 {
     msg.CollapseKey = key;
     return(msg);
 }
示例#21
0
 public static GcmMessage WithPriority(this GcmMessage msg, int priority)
 {
     msg.Priority = priority;
     return(msg);
 }
示例#22
0
 public GcmManagerTimeoutException(string message, GcmMessage gcmMessage)
     : base(message)
 {
     Message = gcmMessage;
 }