public ActionResult Information(DeviceRegistration registration) { if (ModelState.IsValid) { using (AzureManagerContext context = new AzureManagerContext()) { DeviceRegistration deviceRegistration = context.DeviceRegistrations.Find(registration.Id); if (HttpContext.Request.Files.Count > 0) { using (BinaryReader r = new BinaryReader(HttpContext.Request.Files[0].InputStream)) { byte[] buffer = new byte[HttpContext.Request.ContentLength]; r.Read(buffer, 0, HttpContext.Request.ContentLength); deviceRegistration.Certificate = buffer; } } deviceRegistration.SubscriptionId = registration.SubscriptionId; context.SaveChanges(); RegistrationModel model = new RegistrationModel(); String response = model.NotifyDeviceOfInformation(deviceRegistration); ViewBag.Response = response; } return RedirectToAction("InformationSent"); } return View(registration); }
public Stream RetrieveCertificate(string devicePin, string subscriptionId) { DeviceRegistration registration = null; using (AzureManagerContext context = new AzureManagerContext()) { registration = context.DeviceRegistrations.Where(dv => dv.DevicePin == devicePin && dv.SubscriptionId == subscriptionId).FirstOrDefault(); registration.Exhausted = true; context.SaveChanges(); } WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream"; return new MemoryStream(registration.Certificate); }
public ActionResult Information(string pinCode) { DeviceRegistration registration = null; using (AzureManagerContext context = new AzureManagerContext()) { registration = context.DeviceRegistrations.Where(dv => dv.DevicePin == pinCode).FirstOrDefault(); if (registration == null) { return View("NoMatch"); } // HACK This just is a default value. registration.SubscriptionId = "27b0e36c-5a3f-43e5-b104-1f5bdd1fa0e4"; } return View(registration); }