Пример #1
0
 public SessionSummary[] GetSessions()
 {
     List<SessionSummary> activeSessions = new List<SessionSummary>();
     SessionModelContainer ctx = new SessionModelContainer();
     foreach (Session s in ctx.Sessions)
     {
         activeSessions.Add(new SessionSummary() { Code = s.Code, Title = s.Title, PrimarySpeaker = s.PrimarySpeakers.First().Name });
     }
     return activeSessions.ToArray();
 }
Пример #2
0
 public string GetTitleForCode(string code)
 {
     SessionModelContainer ctx = new SessionModelContainer();
     if (ctx.Sessions.Count(c => c.Code == code) == 0)
     {
         return "Session not found.";
     }
     else
     {
         return ctx.Sessions.First(c => c.Code == code).Title;
     }
 }
        public SessionSummary[] GetData()
        {
            List<SessionSummary> sessionsOnNow = new List<SessionSummary>();

            SessionModelContainer ctx = new SessionModelContainer();
            foreach (Session session in ctx.Sessions)
            {
                sessionsOnNow.Add(new SessionSummary() { Code = session.Code, Title = session.Title, PrimarySpeaker = session.PrimarySpeakers.First().Name });
            }

            return sessionsOnNow.ToArray();
        }
        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");
        }
 public ActionResult Edit(int id)
 {
     SessionModelContainer ctx = new SessionModelContainer();
     return View(ctx.Sessions.First(s => s.Id == id));
 }
 public ActionResult Lookup()
 {
     String sessionCode = Request.QueryString["session"];
     SessionModelContainer ctx = new SessionModelContainer();
     Session foundSession = ctx.Sessions.First(s => s.Code.StartsWith(sessionCode));
     return RedirectToAction("Details",new { id = foundSession.Id });
 }
 public ActionResult Index()
 {
     SessionModelContainer ctx = new SessionModelContainer();
     return View(ctx.Sessions);
 }
        public ActionResult Reset()
        {
            SessionModelContainer ctx = new SessionModelContainer();

            // First let's get rid of the old data
            List<Session> sessionsToBeDeleted = ctx.Sessions.ToList();
            foreach (Session session in sessionsToBeDeleted)
            {
                session.PrimarySpeakers.Clear();
                session.AssistantSpeakers.Clear();
                ctx.SaveChanges();
                ctx.DeleteObject(session);
            }
            ctx.SaveChanges();

            List<Speaker> speakersToBeDeleted = ctx.Speakers.ToList();
            foreach (Speaker speaker in speakersToBeDeleted)
            {
                ctx.DeleteObject(speaker);
            }
            ctx.SaveChanges();

            List<Timeslot> timeslotsToBeDeleted = ctx.Timeslots.ToList();
            foreach (Timeslot timeslot in timeslotsToBeDeleted)
            {
                ctx.DeleteObject(timeslot);
            }
            ctx.SaveChanges();

            // Create the new sample data for the demo
            Timeslot mySlot = new Timeslot() { Name = "Timeslot 15", Start = new DateTime(2011, 5, 17, 13, 30, 0), End = new DateTime(2011, 5, 17, 14, 45, 0) };

            mySlot.Sessions.Add(new Session()
            {
                Code = "BOF06-DEV",
                Title = "How on Earth Do I Keep Up with All the New Technologies That Come Along?",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Peter Mourfield") },
                Room = "B209"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "BOF06-ITP",
                Title = "When Is Cloud an Option?",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Dmitry Sotnikov") },
                Room = "B210"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "COS315",
                Title = "Building Windows Phone Applications with the Windows Azure Platform",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Wade Wegner") },
                Room = "C211"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DBI211",
                Title = "What’s New in Microsoft SQL Server Code-Named Denali for Reporting Services",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Ariel Netz") },
                Room = "C203"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DBI304",
                Title = "What's New in Manageability for Microsoft SQL Server Code- Named Denali",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Denny Cherry") },
                Room = "B207"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DBI323",
                Title = "Using Cloud (Microsoft SQL Azure) and PowerPivot to Deliver Data and Self-Service BI at Microsoft",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Diana Putnam") },
                Room = "C208"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DEV209",
                Title = "From Zero to Silverlight in 75 Minutes",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Paul Sheriff") },
                Room = "C305"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DEV304",
                Title = "Advanced Programming Patterns for Windows 7",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Kate Gregory") },
                Room = "B103"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DEV306",
                Title = "Branching and Merging for Parallel Development",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Jeff Levinson") },
                Room = "B101"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DEV345",
                Title = "Writing an ASP.NET MVC View Engine",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Louis DeJardin") },
                Room = "B211"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DEV355",
                Title = "Orchard 1.1: Build, Customize, Extend, Ship",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Sebastien Ros") },
                Room = "C205"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DPR209",
                Title = "Fundamental Design Principles for UI Developers",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Billy Hollis") },
                Room = "B406"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "DPR304",
                Title = "My Customers Are Using iPhone/Android, but I'm a Microsoft Guy. Now What?",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Simon Guest") },
                Room = "Georgia Ballroom 1"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "EXL307",
                Title = "Load Balancing with Microsoft Exchange Server 2010",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Andrew Ehrensing") },
                Room = "B206"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "MID201",
                Title = "An Overview of the Microsoft Middleware Strategy",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Robert Dimpsey") },
                Room = "B314"
            });

            mySlot.Sessions.Add(new Session()
            {
                Code = "OSP213",
                Title = "What Do Existing BPOS Customers Need to Do to Prepare for Microsoft Office 365?",
                PrimarySpeakers = new EntityCollection<Speaker>() { new Speaker("Erik Ashby") },
                Room = "B314"
            });

            // create context and add
            ctx.AddToTimeslots(mySlot);
            ctx.SaveChanges();

            ViewBag.Message = "Sample data reset and loaded.";

            return View("Index");
        }