/// <summary> /// Create a new Session object. /// </summary> /// <param name="id">Initial value of the Id property.</param> public static Session CreateSession(global::System.Int32 id) { Session session = new Session(); session.Id = id; return session; }
public ActionResult Edit(int id, Session updatedSession) { SessionModelContainer ctx = new SessionModelContainer(); Session currentSession = ctx.Sessions.First(s => s.Id == id); String message = currentSession.Code + ": "; bool changed = false; currentSession.Code = updatedSession.Code; if (currentSession.Title != updatedSession.Title) { currentSession.Title = updatedSession.Title; message += "Title changed to "+updatedSession.Title; changed = true; } if (currentSession.Room != updatedSession.Room) { currentSession.Room = updatedSession.Room; message += "Room changed to "+updatedSession.Room; changed = true; } if (changed) { // send a push notification message to the device string host = "gateway.sandbox.push.apple.com"; int port = 2195; // load the certificate file string certPath = @"c:\temp\teched_APN.p12"; X509Certificate2 clientCert = new X509Certificate2(certPath, "Password"); X509Certificate2Collection certCollection = new X509Certificate2Collection(clientCert); // open connection and connect TcpClient client = new TcpClient(host, port); SslStream sslStream = new SslStream(client.GetStream(), false); try { sslStream.AuthenticateAsClient(host, certCollection, SslProtocols.Tls, false); } catch (AuthenticationException ex) { Console.WriteLine(ex.InnerException.ToString()); Console.In.Read(); client.Close(); return RedirectToAction("Index"); } MemoryStream memoryStream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(memoryStream); // construct the message writer.Write((byte)0); // Command writer.Write((byte)0); // First byte of device ID length writer.Write((byte)32); // Device id length String deviceId = "e18ac3b8a408e4e972e171a05cdba8f046ff3724ef999093c2b479397b8c40fe"; //Simon's iPhone // convert to hex and write to message byte[] deviceToken = new byte[deviceId.Length / 2]; for (int i = 0; i < deviceToken.Length; i++) deviceToken[i] = byte.Parse(deviceId.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber); writer.Write(deviceToken); // construct payload within JSON message framework String payload = "{\"aps\":{\"alert\":\""+message+"\",\"badge\":1}}"; // write payload data writer.Write((byte)0); // First byte of payload length writer.Write((byte)payload.Length); // Actual payload length byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload); writer.Write(b1); writer.Flush(); // send across the wire byte[] array = memoryStream.ToArray(); sslStream.Write(array); sslStream.Flush(); // Close the client connection. client.Close(); // Success Console.WriteLine("Message has been sent! Please check device."); Console.In.Read(); } ctx.SaveChanges(); return RedirectToAction("Index"); }
/// <summary> /// Deprecated Method for adding a new object to the Sessions EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToSessions(Session session) { base.AddObject("Sessions", session); }