Exemplo n.º 1
0
 public override void Run()
 {
     Feedback f = new Feedback();
     f.DeviceToken = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
     f.Timestamp = DateTime.Now;
     feedback(this, f);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Initiates the Connection to the Feedback Server and receives all Feedback data then closes the connection
        /// </summary>
        public void Run()
        {
            disposing = false;

            encoding = Encoding.ASCII;

            // certificate will already be set if one of the constructors that takes a byte array was used.
             	    if (certificate == null)
             	    {
                // Fixed by [email protected] :
             	        //      The default is UserKeySet, which has caused internal encryption errors,
             	        //      Because of lack of permissions on most hosting services.
             	        //      So MachineKeySet should be used instead.
                certificate = new X509Certificate2(System.IO.File.ReadAllBytes(P12File), P12FilePassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
             	    }

            certificates = new X509CertificateCollection();
            certificates.Add(certificate);

            if (ensureConnected() && !disposing)
            {
                //Set up
                byte[] buffer = new byte[38];
                int recd = 0;
                DateTime minTimestamp = DateTime.Now.AddYears(-1);

                //Get the first feedback
                recd = apnsStream.Read(buffer, 0, buffer.Length);

                //Continue while we have results and are not disposing
                while (recd > 0 && !disposing)
                {
                    try
                    {
                        Feedback fb = new Feedback();

                        //Get our seconds since 1970 ?
                        byte[] bSeconds = new byte[4];
                        byte[] bDeviceToken = new byte[32];

                        Array.Copy(buffer, 0, bSeconds, 0, 4);

                        //Check endianness
                        if (BitConverter.IsLittleEndian)
                            Array.Reverse(bSeconds);

                        int tSeconds = BitConverter.ToInt32(bSeconds, 0);

                        //Add seconds since 1970 to that date, in UTC and then get it locally
                        fb.Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tSeconds).ToLocalTime();

                        //Now copy out the device token
                        Array.Copy(buffer, 6, bDeviceToken, 0, 32);

                        fb.DeviceToken = BitConverter.ToString(bDeviceToken).Replace("-", "").ToLower().Trim();

                        //Make sure we have a good feedback tuple
                        if (fb.DeviceToken.Length == 64
                            && fb.Timestamp > minTimestamp
                            && this.Feedback != null)
                        {
                            //Raise event
                            this.Feedback(this, fb);
                        }

                    }
                    catch (Exception ex)
                    {
                        if (this.Error != null)
                            this.Error(this, ex);
                    }

                    //Clear our array to reuse it
                    Array.Clear(buffer, 0, buffer.Length);

                    //Read the next feedback
                    recd = apnsStream.Read(buffer, 0, buffer.Length);
                }
            }

            ensureDisconnected();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initiates the Connection to the Feedback Server and receives all Feedback data then closes the connection
        /// </summary>
        public void Run()
        {
            disposing = false;

            encoding = Encoding.ASCII;

            // certificate will already be set if one of the constructors that takes a byte array was used.
            if (certificate == null)
            {
                // Fixed by [email protected] :
                //      The default is UserKeySet, which has caused internal encryption errors,
                //      Because of lack of permissions on most hosting services.
                //      So MachineKeySet should be used instead.
                certificate = new X509Certificate2(System.IO.File.ReadAllBytes(P12File), P12FilePassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
            }

            certificates = new X509CertificateCollection();
            certificates.Add(certificate);

            if (ensureConnected() && !disposing)
            {
                //Set up
                byte[]   buffer       = new byte[38];
                int      recd         = 0;
                DateTime minTimestamp = DateTime.Now.AddYears(-1);

                //Get the first feedback
                recd = apnsStream.Read(buffer, 0, buffer.Length);

                //Continue while we have results and are not disposing
                while (recd > 0 && !disposing)
                {
                    try
                    {
                        Feedback fb = new Feedback();

                        //Get our seconds since 1970 ?
                        byte[] bSeconds     = new byte[4];
                        byte[] bDeviceToken = new byte[32];

                        Array.Copy(buffer, 0, bSeconds, 0, 4);

                        //Check endianness
                        if (BitConverter.IsLittleEndian)
                        {
                            Array.Reverse(bSeconds);
                        }

                        int tSeconds = BitConverter.ToInt32(bSeconds, 0);

                        //Add seconds since 1970 to that date, in UTC and then get it locally
                        fb.Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tSeconds).ToLocalTime();


                        //Now copy out the device token
                        Array.Copy(buffer, 6, bDeviceToken, 0, 32);

                        fb.DeviceToken = BitConverter.ToString(bDeviceToken).Replace("-", "").ToLower().Trim();

                        //Make sure we have a good feedback tuple
                        if (fb.DeviceToken.Length == 64 &&
                            fb.Timestamp > minTimestamp &&
                            this.Feedback != null)
                        {
                            //Raise event
                            this.Feedback(this, fb);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (this.Error != null)
                        {
                            this.Error(this, ex);
                        }
                    }

                    //Clear our array to reuse it
                    Array.Clear(buffer, 0, buffer.Length);

                    //Read the next feedback
                    recd = apnsStream.Read(buffer, 0, buffer.Length);
                }
            }

            ensureDisconnected();
        }
Exemplo n.º 4
0
		static void service_Feedback(object sender, Feedback feedback)
		{
			Console.WriteLine(string.Format("Feedback - Timestamp: {0} - DeviceId: {1}", feedback.Timestamp, feedback.DeviceToken));
		}
Exemplo n.º 5
0
        /// <summary>
        /// Initiates the Connection to the Feedback Server and receives all Feedback data then closes the connection
        /// </summary>
        public void Run()
        {
            disposing = false;

            encoding = Encoding.ASCII;

            if (string.IsNullOrEmpty(P12FilePassword))
            {
                certificate = new X509Certificate2(System.IO.File.ReadAllBytes(P12File));
            }
            else
            {
                certificate = new X509Certificate2(System.IO.File.ReadAllBytes(P12File), P12FilePassword);
            }

            certificates = new X509CertificateCollection();
            certificates.Add(certificate);

            if (ensureConnected() && !disposing)
            {
                //Set up
                byte[]   buffer       = new byte[38];
                int      recd         = 0;
                DateTime minTimestamp = DateTime.Now.AddYears(-1);

                //Get the first feedback
                recd = apnsStream.Read(buffer, 0, buffer.Length);

                //Continue while we have results and are not disposing
                while (recd > 0 && !disposing)
                {
                    try
                    {
                        Feedback fb = new Feedback();

                        //Get our seconds since 1970 ?
                        byte[] bSeconds     = new byte[4];
                        byte[] bDeviceToken = new byte[32];

                        Array.Copy(buffer, 0, bSeconds, 0, 4);

                        //Check endianness
                        if (BitConverter.IsLittleEndian)
                        {
                            Array.Reverse(bSeconds);
                        }

                        int tSeconds = BitConverter.ToInt32(bSeconds, 0);

                        //Add seconds since 1970 to that date, in UTC and then get it locally
                        fb.Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tSeconds).ToLocalTime();


                        //Now copy out the device token
                        Array.Copy(buffer, 6, bDeviceToken, 0, 32);

                        fb.DeviceToken = BitConverter.ToString(bDeviceToken).Replace("-", "").ToLower().Trim();

                        //Make sure we have a good feedback tuple
                        if (fb.DeviceToken.Length == 64 &&
                            fb.Timestamp > minTimestamp &&
                            this.Feedback != null)
                        {
                            //Raise event
                            this.Feedback(this, fb);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (this.Error != null)
                        {
                            this.Error(this, ex);
                        }
                    }

                    //Clear our array to reuse it
                    Array.Clear(buffer, 0, buffer.Length);

                    //Read the next feedback
                    recd = apnsStream.Read(buffer, 0, buffer.Length);
                }
            }

            ensureDisconnected();
        }