/// <summary>
        /// Attempts to match a known kiosk based on the IP address of the client.
        /// </summary>
        private void GetKioskType(Kiosk kiosk, RockContext rockContext)
        {
            if (kiosk.KioskType != null)
            {
                DeviceService deviceService = new DeviceService(rockContext);
                //Load matching device and update or create information
                var device = deviceService.Queryable().Where(d => d.Name == kiosk.Name).FirstOrDefault();

                //create new device to match our kiosk
                if (device == null)
                {
                    device = new Device();
                    device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id;
                    device.Name = kiosk.Name;
                    deviceService.Add(device);
                }

                device.LoadAttributes();
                device.IPAddress = kiosk.IPAddress;
                device.Locations.Clear();
                foreach (var loc in kiosk.KioskType.Locations.ToList())
                {
                    device.Locations.Add(loc);
                }
                device.PrintFrom       = kiosk.PrintFrom;
                device.PrintToOverride = kiosk.PrintToOverride;
                device.PrinterDeviceId = kiosk.PrinterDeviceId;
                rockContext.SaveChanges();

                if (PageParameter("DateTime").AsDateTime().HasValue)
                {
                    device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime"));
                }
                else
                {
                    device.SetAttributeValue("core_device_DebugDateTime", "");
                }
                device.SaveAttributeValues(rockContext);

                CurrentKioskId      = device.Id;
                CurrentGroupTypeIds = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList();

                CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId;

                CurrentCheckInState     = null;
                CurrentWorkflow         = null;
                Session["KioskTypeId"]  = kiosk.KioskType.Id;
                Session["KioskMessage"] = kiosk.KioskType.Message;
                KioskDevice.Remove(device.Id);
                SaveState();
                NavigateToNextPage();
            }
            else
            {
                ltDNS.Text      = kiosk.Name;
                pnlMain.Visible = true;
            }
        }
Exemple #2
0
        private Kiosk ConfigureKiosk()
        {
            var rockContext = new RockContext();
            var kioskTypeId = ddlCampus.SelectedValue.AsInteger();

            var kioskType = KioskTypeCache.Get(kioskTypeId);

            var kioskName = "Mobile:" + kioskType.Name.RemoveAllNonAlphaNumericCharacters();

            var mobileUserCategory = CategoryCache.Get(org.secc.FamilyCheckin.Utilities.Constants.KIOSK_CATEGORY_MOBILEUSER);

            var kioskService = new KioskService(rockContext);
            var kiosk        = kioskService.Queryable("KioskType")
                               .Where(k => k.Name == kioskName)
                               .FirstOrDefault();

            if (kiosk == null)
            {
                kiosk = new Kiosk
                {
                    Name        = kioskName,
                    CategoryId  = mobileUserCategory.Id,
                    Description = "Automatically created mobile Kiosk"
                };
                kioskService.Add(kiosk);
            }

            kiosk.KioskTypeId = kioskType.Id;
            rockContext.SaveChanges();

            DeviceService deviceService = new DeviceService(rockContext);


            //Load matching device and update or create information
            var device = deviceService.Queryable("Location").Where(d => d.Name == kioskName).FirstOrDefault();

            var dirty = false;

            //create new device to match our kiosk
            if (device == null)
            {
                device = new Device();
                device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id;
                device.Name = kioskName;
                deviceService.Add(device);
                device.PrintFrom       = PrintFrom.Client;
                device.PrintToOverride = PrintTo.Default;
                dirty = true;
            }

            var deviceLocationIds = device.Locations.Select(l => l.Id);
            var ktLocationIds     = kioskType.Locations.Select(l => l.Id);

            var unmatchedDeviceLocations = deviceLocationIds.Except(ktLocationIds).Any();
            var unmatchedKtLocations     = ktLocationIds.Except(deviceLocationIds).Any();

            if (unmatchedDeviceLocations || unmatchedKtLocations)
            {
                LocationService locationService = new LocationService(rockContext);
                device.Locations.Clear();
                foreach (var loc in kioskType.Locations.ToList())
                {
                    var location = locationService.Get(loc.Id);
                    device.Locations.Add(location);
                }
                dirty = true;
            }

            if (this.IsUserAuthorized(Rock.Security.Authorization.ADMINISTRATE))
            {
                device.LoadAttributes();

                if (PageParameter("datetime").IsNotNullOrWhiteSpace())
                {
                    device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime"));
                }
                else
                {
                    device.SetAttributeValue("core_device_DebugDateTime", "");
                }
            }

            if (dirty)
            {
                rockContext.SaveChanges();
                device.SaveAttributeValues(rockContext);
                KioskDevice.Remove(device.Id);
            }

            LocalDeviceConfig.CurrentKioskId       = device.Id;
            LocalDeviceConfig.CurrentGroupTypeIds  = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList();
            LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId;

            CurrentCheckInState = null;
            CurrentWorkflow     = null;

            var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"];

            if (kioskTypeCookie == null)
            {
                kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId");
            }

            kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1);
            kioskTypeCookie.Value   = kiosk.KioskType.Id.ToString();

            this.Page.Response.Cookies.Set(kioskTypeCookie);

            Session["KioskTypeId"] = kioskType.Id;
            SaveState();
            return(kiosk);
        }
        private void ActivateKiosk(Kiosk kiosk, bool logout)
        {
            RockContext   rockContext   = new RockContext();
            DeviceService deviceService = new DeviceService(rockContext);
            KioskService  kioskService  = new KioskService(rockContext);

            //The kiosk can come in a variety of states.
            //Get a fresh version with our context to avoid context errors.
            kiosk = kioskService.Get(kiosk.Id);

            //Load matching device and update or create information
            var device = deviceService.Queryable().Where(d => d.Name == kiosk.Name).FirstOrDefault();

            //create new device to match our kiosk
            if (device == null)
            {
                device = new Device();
                device.DeviceTypeValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.DEVICE_TYPE_CHECKIN_KIOSK).Id;
                device.Name = kiosk.Name;
                deviceService.Add(device);
            }

            device.LoadAttributes();
            device.IPAddress = kiosk.IPAddress;
            device.Locations.Clear();
            foreach (var loc in kiosk.KioskType.Locations.ToList())
            {
                device.Locations.Add(loc);
            }
            device.PrintFrom       = kiosk.PrintFrom;
            device.PrintToOverride = kiosk.PrintToOverride;
            device.PrinterDeviceId = kiosk.PrinterDeviceId;
            rockContext.SaveChanges();

            if (PageParameter("DateTime").AsDateTime().HasValue)
            {
                device.SetAttributeValue("core_device_DebugDateTime", PageParameter("datetime"));
            }
            else
            {
                device.SetAttributeValue("core_device_DebugDateTime", "");
            }
            device.SaveAttributeValues(rockContext);

            LocalDeviceConfig.CurrentKioskId       = device.Id;
            LocalDeviceConfig.CurrentGroupTypeIds  = kiosk.KioskType.GroupTypes.Select(gt => gt.Id).ToList();
            LocalDeviceConfig.CurrentCheckinTypeId = kiosk.KioskType.CheckinTemplateId;

            CurrentCheckInState = null;
            CurrentWorkflow     = null;

            var kioskTypeCookie = this.Page.Request.Cookies["KioskTypeId"];

            if (kioskTypeCookie == null)
            {
                kioskTypeCookie = new System.Web.HttpCookie("KioskTypeId");
            }

            kioskTypeCookie.Expires = RockDateTime.Now.AddYears(1);
            kioskTypeCookie.Value   = kiosk.KioskType.Id.ToString();

            this.Page.Response.Cookies.Set(kioskTypeCookie);

            Session["KioskTypeId"]  = kiosk.KioskType.Id;
            Session["KioskMessage"] = kiosk.KioskType.Message;

            //Clean things up so we have the freshest possible version.
            KioskTypeCache.Remove(kiosk.KioskTypeId ?? 0);
            KioskDevice.Remove(device.Id);

            Dictionary <string, string> pageParameters = new Dictionary <string, string>();

            if (kiosk.KioskType.Theme.IsNotNullOrWhiteSpace() && !GetAttributeValue("Manual").AsBoolean())
            {
                LocalDeviceConfig.CurrentTheme = kiosk.KioskType.Theme;
                pageParameters.Add("theme", LocalDeviceConfig.CurrentTheme);
            }

            if (logout)
            {
                pageParameters.Add("logout", "true");
            }

            SaveState();

            NavigateToNextPage(pageParameters);
        }