private string GetContent(string parameter = "")
 {
     return(AvalancheUtilities.ProcessLava(GetAttributeValue("Lava"),
                                           CurrentPerson,
                                           parameter,
                                           GetAttributeValue("EnabledLavaCommands")));
 }
Exemplo n.º 2
0
        public override MobileBlock GetMobile(string parameter)
        {
            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson, AvalancheUtilities.GetMergeFields(CurrentPerson),
                                              GetAttributeValue("EnabledLavaCommands"),
                                              parameter);

            if (!string.IsNullOrWhiteSpace(GetAttributeValue("Text")))
            {
                CustomAttributes["Text"] = GetAttributeValue("Text");
            }

            if (GetAttributeValue("AspectRatio").AsDouble() != 0)
            {
                CustomAttributes["AspectRatio"] = GetAttributeValue("AspectRatio");
            }


            CustomAttributes.Add("Source", AvalancheUtilities.ProcessLava(GetAttributeValue("Image"),
                                                                          CurrentPerson,
                                                                          parameter,
                                                                          GetAttributeValue("EnabledLavaCommands")
                                                                          ));
            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.TextOverImage",
                Attributes = CustomAttributes
            });
        }
        public override MobileBlock GetMobile(string parameter)
        {
            var pageList = new List <string>();
            var pages    = GetAttributeValue("PagesToPreload").ToKeyValuePairList();

            foreach (var item in pages)
            {
                var page = "/api/avalanche/page/" +
                           item.Key + "/" +
                           AvalancheUtilities.ProcessLava(( string )item.Value,
                                                          CurrentPerson,
                                                          parameter,
                                                          GetAttributeValue("EnabledLavaCommands")
                                                          );
                pageList.Add(page);
            }

            CustomAttributes.Add("Resources", string.Join("|", pageList));

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.Preload",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 4
0
        public Dictionary <string, string> RegisterFCM()
        {
            HttpContent requestContent = Request.Content;
            string      content        = requestContent.ReadAsStringAsync().Result;
            Dictionary <string, string> tokenDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(content);
            var person = GetPerson();

            if (tokenDictionary.ContainsKey("Token") &&
                !string.IsNullOrWhiteSpace(tokenDictionary["Token"]) &&
                person != null)
            {
                var userAgent = Request.Headers.UserAgent.ToString();
                var deviceId  = Regex.Match(userAgent, "(?<=-).+(?=\\))").Value.Trim();
                if (deviceId.Length > 20)
                {
                    deviceId = deviceId.Substring(0, 20);
                }
                RockContext    rockContext    = new RockContext();
                PersonalDevice personalDevice = AvalancheUtilities.GetPersonalDevice(deviceId, person.PrimaryAliasId, rockContext);
                if (personalDevice != null && personalDevice.DeviceRegistrationId != tokenDictionary["Token"])
                {
                    personalDevice.DeviceRegistrationId = tokenDictionary["Token"];
                    personalDevice.NotificationsEnabled = true;
                    rockContext.SaveChanges();
                }
            }
            return(new Dictionary <string, string> {
                { "Status", "Ok" }
            });
        }
        public override MobileBlock GetMobile(string parameter)
        {
            CustomAttributes.Add("Source", AvalancheUtilities.ProcessLava(GetAttributeValue("Source"),
                                                                          CurrentPerson,
                                                                          parameter,
                                                                          GetAttributeValue("EnabledLavaCommands")
                                                                          ));

            CustomAttributes.Add("Artist", AvalancheUtilities.ProcessLava(GetAttributeValue("Artist"),
                                                                          CurrentPerson,
                                                                          parameter,
                                                                          GetAttributeValue("EnabledLavaCommands")
                                                                          ));

            CustomAttributes.Add("Title", AvalancheUtilities.ProcessLava(GetAttributeValue("Title"),
                                                                         CurrentPerson,
                                                                         parameter,
                                                                         GetAttributeValue("EnabledLavaCommands")
                                                                         ));

            CustomAttributes.Add("AutoPlay", GetAttributeValue("AutoPlay"));
            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.AudioPlayerBlock",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 6
0
        public MobilePage GetPage(int id, string parameter = "")
        {
            var person = GetPerson();

            if (!HttpContext.Current.Items.Contains("CurrentPerson"))
            {
                HttpContext.Current.Items.Add("CurrentPerson", person);
            }

            var pageCache = PageCache.Read(id);

            if (!pageCache.IsAuthorized(Authorization.VIEW, person))
            {
                return(new MobilePage());
            }

            SavePageViewInteraction(pageCache, person);

            string theme      = pageCache.Layout.Site.Theme;
            string layout     = pageCache.Layout.FileName;
            string layoutPath = PageCache.FormatPath(theme, layout);

            Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));

            MobilePage mobilePage = new MobilePage();

            mobilePage.Layout    = AvalancheUtilities.GetLayout(pageCache.Layout.Name);
            mobilePage.Title     = pageCache.PageTitle;
            mobilePage.ShowTitle = pageCache.PageDisplayTitle;
            foreach (var attribute in pageCache.AttributeValues)
            {
                mobilePage.Attributes.Add(attribute.Key, attribute.Value.ValueFormatted);
            }
            foreach (var block in pageCache.Blocks)
            {
                if (block.IsAuthorized(Authorization.VIEW, person))
                {
                    var blockCache = BlockCache.Read(block.Id);
                    try
                    {
                        var control = ( RockBlock )cmsPage.TemplateControl.LoadControl(blockCache.BlockType.Path);
                        if (control is RockBlock && control is IMobileResource)
                        {
                            control.SetBlock(pageCache, blockCache);
                            var mobileResource = control as IMobileResource;
                            var mobileBlock    = mobileResource.GetMobile(parameter);
                            mobileBlock.BlockId = blockCache.Id;
                            mobileBlock.Zone    = blockCache.Zone;
                            mobilePage.Blocks.Add(mobileBlock);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionLogService.LogException(e, HttpContext.Current);
                    }
                }
            }
            HttpContext.Current.Response.Headers.Set("TTL", pageCache.OutputCacheDuration.ToString());
            return(mobilePage);
        }
        public override MobileBlock GetMobile(string parameter)
        {
            var groupMembers = GetGroupMembers(parameter, 0);

            if (groupMembers == null || !groupMembers.Any())
            {
                return(new MobileBlock()
                {
                    BlockType = "Avalanche.Blocks.Null",
                    Attributes = CustomAttributes
                });
            }

            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"), CustomAttributes, CurrentPerson);

            CustomAttributes["InitialRequest"] = parameter + "|0";
            CustomAttributes["NextRequest"]    = parameter + "|1";
            CustomAttributes["Content"]        = JsonConvert.SerializeObject(groupMembers);

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.ListViewBlock",
                Attributes = CustomAttributes
            });
        }
        public override MobileBlock GetMobile(string parameter)
        {
            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson, AvalancheUtilities.GetMergeFields(CurrentPerson),
                                              GetAttributeValue("EnabledLavaCommands"),
                                              parameter);

            var valueGuid = GetAttributeValue("Component");
            var value     = DefinedValueCache.Read(valueGuid);

            if (value != null)
            {
                CustomAttributes["Component"] = value.GetAttributeValue("ComponentType");
            }

            CustomAttributes["Content"]        = GetContent(parameter);
            CustomAttributes["InitialRequest"] = parameter;

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.ListViewBlock",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 9
0
 /// <summary>
 /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
 /// </summarysni>
 /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
 protected override void OnLoad(EventArgs e)
 {
     imgImage.ImageUrl = AvalancheUtilities.ProcessLava(GetAttributeValue("Image"),
                                                        CurrentPerson,
                                                        "",
                                                        GetAttributeValue("EnabledLavaCommands"));
     lLava.Text = GetAttributeValue("Image");
 }
 /// <summary>
 /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
 /// </summary>
 /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
 protected override void OnLoad(EventArgs e)
 {
     lLava.Text         = GetAttributeValue("Lava");
     lLavaRendered.Text = AvalancheUtilities.ProcessLava(GetAttributeValue("Lava"),
                                                         CurrentPerson,
                                                         enabledLavaCommands: GetAttributeValue("EnabledLavaCommands"))
                          .ConvertMarkdownToHtml();
 }
Exemplo n.º 11
0
        public override MobileBlock GetMobile(string parameter)
        {
            var groups = GetGroups();

            CustomAttributes["Content"] = AvalancheUtilities.ProcessLava(
                GetAttributeValue("NoGroupsMarkdown"),
                CurrentPerson,
                parameter,
                GetAttributeValue("EnabledLavaCommands"));

            if (!groups.Any())
            {
                return(new MobileBlock()
                {
                    BlockType = "Avalanche.Blocks.MarkdownDetail",
                    Attributes = CustomAttributes
                });
            }

            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson, AvalancheUtilities.GetMergeFields(CurrentPerson),
                                              GetAttributeValue("EnabledLavaCommands"),
                                              parameter);

            var valueGuid = GetAttributeValue("Component");
            var value     = DefinedValueCache.Get(valueGuid);

            if (value != null)
            {
                CustomAttributes["Component"] = value.GetAttributeValue("ComponentType");
            }

            CustomAttributes["InitialRequest"] = parameter; //Request for pull to refresh
            Dictionary <string, object> mergeObjects = new Dictionary <string, object>
            {
                { "Groups", groups }
            };

            var content = AvalancheUtilities.ProcessLava(GetAttributeValue("Lava"),
                                                         CurrentPerson,
                                                         parameter,
                                                         GetAttributeValue("EnabledLavaCommands"),
                                                         mergeObjects);

            content = content.Replace("\\", "\\\\");
            CustomAttributes["Content"] = content;

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.ListViewBlock",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 12
0
        public override MobileBlock GetMobile(string parameter)
        {
            CustomAttributes["Text"] = AvalancheUtilities.ProcessLava(GetAttributeValue("Text"),
                                                                      CurrentPerson,
                                                                      parameter,
                                                                      GetAttributeValue("EnabledLavaCommands"));

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.LabelBlock",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 13
0
        public override MobileBlock GetMobile(string parameter)
        {
            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"), CustomAttributes, CurrentPerson);

            CustomAttributes.Add("Text", AvalancheUtilities.ProcessLava(GetAttributeValue("Text"), CurrentPerson, parameter));
            CustomAttributes.Add("Icon", AvalancheUtilities.ProcessLava(GetAttributeValue("Icon"), CurrentPerson, parameter));

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.IconButton",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 14
0
        public override MobileBlock GetMobile(string parameter)
        {
            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"), CustomAttributes, CurrentPerson);

            CustomAttributes.Add("Source", AvalancheUtilities.ProcessLava(GetAttributeValue("Image"),
                                                                          CurrentPerson,
                                                                          parameter,
                                                                          GetAttributeValue("EnabledLavaCommands")
                                                                          ));
            CustomAttributes.Add("Aspect", GetAttributeValue("Aspect"));

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.ImageBlock",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 15
0
        public override MobileBlock GetMobile(string parameter)
        {
            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson, AvalancheUtilities.GetMergeFields(CurrentPerson),
                                              GetAttributeValue("EnabledLavaCommands"),
                                              parameter);

            CustomAttributes["Text"] = AvalancheUtilities.ProcessLava(GetAttributeValue("Text"),
                                                                      CurrentPerson,
                                                                      parameter,
                                                                      GetAttributeValue("EnabledLavaCommands"));

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.IconBlock",
                Attributes = CustomAttributes
            });
        }
        public override MobileBlock GetMobile(string parameter)
        {
            _firstDayOfWeek = GetAttributeValue("StartofWeekDay").ConvertToEnum <DayOfWeek>();

            var eventCalendar = new EventCalendarService(new RockContext()).Get(GetAttributeValue("EventCalendar").AsGuid());

            if (eventCalendar != null)
            {
                _calendarId   = eventCalendar.Id;
                _calendarName = eventCalendar.Name;
            }

            CampusPanelOpen     = GetAttributeValue("CampusFilterDisplayMode") == "3";
            CampusPanelClosed   = GetAttributeValue("CampusFilterDisplayMode") == "4";
            CategoryPanelOpen   = !String.IsNullOrWhiteSpace(GetAttributeValue("FilterCategories")) && GetAttributeValue("CategoryFilterDisplayMode") == "3";
            CategoryPanelClosed = !String.IsNullOrWhiteSpace(GetAttributeValue("FilterCategories")) && GetAttributeValue("CategoryFilterDisplayMode") == "4";

            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson, AvalancheUtilities.GetMergeFields(CurrentPerson),
                                              GetAttributeValue("EnabledLavaCommands"),
                                              parameter);

            var valueGuid = GetAttributeValue("Component");
            var value     = DefinedValueCache.Read(valueGuid);

            if (value != null)
            {
                CustomAttributes["Component"] = value.GetAttributeValue("ComponentType");
            }


            var data = BindData();

            CustomAttributes["Content"]        = data;
            CustomAttributes["InitialRequest"] = parameter;

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.ListViewBlock",
                Attributes = CustomAttributes
            });
        }
        public override MobileBlock GetMobile(string paramater)
        {
            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"), CustomAttributes, CurrentPerson);
            var valueGuid = GetAttributeValue("Component");
            var value     = DefinedValueCache.Read(valueGuid);

            if (value != null)
            {
                CustomAttributes["Component"] = value.GetAttributeValue("ComponentType");
            }

            CustomAttributes["Content"]        = GetContent();
            CustomAttributes["InitialRequest"] = "Refresh";

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.ListViewBlock",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 18
0
        public override bool Execute(RockContext rockContext, WorkflowAction action, object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            var actionItemValue = GetAttributeValue(action, "ActionType");

            var actionDictionary = new Dictionary <string, string>();

            AvalancheUtilities.SetActionItems(actionItemValue, actionDictionary, action.Activity?.AssignedPersonAlias?.Person, GetMergeFields(action));


            var  processOpt      = GetAttributeValue(action, "ProcessingOptions");
            bool canSendRedirect = actionDictionary.ContainsKey("ActionType") && actionDictionary["ActionType"] != "0" && HttpContext.Current != null;

            if (canSendRedirect)
            {
                HttpContext.Current.Response.AddHeader("ActionType", actionDictionary["ActionType"]);

                if (actionDictionary.ContainsKey("Resource"))
                {
                    HttpContext.Current.Response.AddHeader("Resource", actionDictionary["Resource"]);
                }

                if (actionDictionary.ContainsKey("Parameter"))
                {
                    HttpContext.Current.Response.AddHeader("Parameter", actionDictionary["Parameter"]);
                }
            }

            if (processOpt == "1")
            {
                // 1) if HttpContext.Current is null, this workflow action might be running as a job (there is no browser session associated), so Redirect couldn't have been sent to a browser
                // 2) if there was no url specified, the redirect wouldn't have executed either
                return(canSendRedirect);
            }
            else
            {
                return(processOpt != "2");
            }
        }
Exemplo n.º 19
0
        public override MobileBlockResponse HandleRequest(string request, Dictionary <string, string> Body)
        {
            var groups = GetGroups();
            Dictionary <string, object> mergeObjects = new Dictionary <string, object>
            {
                { "Groups", groups }
            };
            var content = AvalancheUtilities.ProcessLava(GetAttributeValue("Lava"),
                                                         CurrentPerson,
                                                         request,
                                                         GetAttributeValue("EnabledLavaCommands"),
                                                         mergeObjects);

            content = content.Replace("\\", "\\\\");
            var response = "{\"Content\": " + content + "}";

            return(new MobileBlockResponse()
            {
                Request = request,
                Response = response,
                TTL = PageCache.OutputCacheDuration
            });
        }
Exemplo n.º 20
0
        public override MobileBlock GetMobile(string parameter)
        {
            var valueGuid = GetAttributeValue("Component");
            var value     = DefinedValueCache.Read(valueGuid);

            if (value != null)
            {
                CustomAttributes["Component"] = value.GetAttributeValue("ComponentType");
            }

            var groupMembers = GetGroupMembers(parameter, 0);

            if (groupMembers == null || !groupMembers.Any())
            {
                return(new MobileBlock()
                {
                    BlockType = "Avalanche.Blocks.Null",
                    Attributes = CustomAttributes
                });
            }

            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson, AvalancheUtilities.GetMergeFields(CurrentPerson),
                                              GetAttributeValue("EnabledLavaCommands"),
                                              parameter);

            CustomAttributes["InitialRequest"] = parameter + "|0";
            CustomAttributes["NextRequest"]    = parameter + "|1";
            CustomAttributes["Content"]        = JsonConvert.SerializeObject(groupMembers);

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.ListViewBlock",
                Attributes = CustomAttributes
            });
        }
Exemplo n.º 21
0
        private string GenerateCode(string resource)
        {
            if (resource == null || resource.Length != 10)
            {
                return("Please enter a 10 digit phone number.");
            }

            RockContext        rockContext        = new RockContext();
            PhoneNumberService phoneNumberService = new PhoneNumberService(rockContext);
            var numberOwners = phoneNumberService.Queryable()
                               .Where(pn => pn.Number == resource)
                               .Select(pn => pn.Person)
                               .DistinctBy(p => p.Id)
                               .ToList();

            if (numberOwners.Count == 0)
            {
                return("0|We are sorry, we could not find your phone number in our records.");
            }

            if (numberOwners.Count > 1)
            {
                return("2|We are sorry, we dected more than one person with your number in our records.");
            }

            var person = numberOwners.FirstOrDefault();

            UserLoginService userLoginService = new UserLoginService(rockContext);
            var userLogin = userLoginService.Queryable()
                            .Where(u => u.UserName == ("__PHONENUMBER__+1" + resource))
                            .FirstOrDefault();

            if (userLogin == null)
            {
                var entityTypeId = EntityTypeCache.Read("Avalanche.Security.Authentication.PhoneNumber").Id;

                userLogin = new UserLogin()
                {
                    UserName     = "******" + resource,
                    EntityTypeId = entityTypeId,
                };
                userLoginService.Add(userLogin);
            }

            userLogin.PersonId = person.Id;
            userLogin.LastPasswordChangedDateTime = Rock.RockDateTime.Now;
            userLogin.FailedPasswordAttemptWindowStartDateTime = Rock.RockDateTime.Now;
            userLogin.FailedPasswordAttemptCount = 0;
            userLogin.IsConfirmed = true;
            userLogin.Password    = new Random().Next(100000, 999999).ToString();

            rockContext.SaveChanges();

            var workflowName = string.Format("{0} ({1})", person.FullName, resource);
            var atts         = new Dictionary <string, string>
            {
                { "PhoneNumber", resource },
                { "Password", userLogin.Password }
            };

            var recipients = new List <RecipientData>();

            recipients.Add(new RecipientData(resource));

            var smsMessage = new RockSMSMessage();

            smsMessage.SetRecipients(recipients);

            // Get the From value
            Guid?fromGuid = GetAttributeValue("From").AsGuidOrNull();

            if (fromGuid.HasValue)
            {
                var fromValue = DefinedValueCache.Read(fromGuid.Value, rockContext);
                if (fromValue != null)
                {
                    smsMessage.FromNumber = DefinedValueCache.Read(fromValue.Id);
                }
            }

            var mergeObjects = new Dictionary <string, object> {
                { "password", userLogin.Password }
            };
            var message = AvalancheUtilities.ProcessLava(GetAttributeValue("Message"), CurrentPerson, mergeObjects: mergeObjects);

            smsMessage.Message = message;
            smsMessage.Send();

            return("1|Success!");
        }
Exemplo n.º 22
0
        public override MobileBlockResponse HandleRequest(string request, Dictionary <string, string> Body)
        {
            body = Body;
            RockContext          rockContext          = new RockContext();
            PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext);
            PrayerRequest        prayerRequest        = new PrayerRequest();

            prayerRequest.EnteredDateTime          = RockDateTime.Now;
            prayerRequest.FirstName                = GetItem("firstName");
            prayerRequest.LastName                 = GetItem("lastName");
            prayerRequest.Text                     = GetItem("request");
            prayerRequest.RequestedByPersonAliasId = CurrentPersonAliasId;

            if (!string.IsNullOrWhiteSpace(GetItem("campus")))
            {
                prayerRequest.CampusId = GetItem("campus").AsInteger();
            }

            bool isAutoApproved = GetAttributeValue("EnableAutoApprove").AsBoolean();

            if (isAutoApproved)
            {
                prayerRequest.ApprovedByPersonAliasId = CurrentPersonAliasId;
                prayerRequest.ApprovedOnDateTime      = RockDateTime.Now;
                var expireDays = GetAttributeValue("ExpireDays").AsDouble();
                prayerRequest.ExpirationDate = RockDateTime.Now.AddDays(expireDays);
            }

            //Category
            if (GetItem("category").AsInteger() != 0)
            {
                prayerRequest.CategoryId = GetItem("category").AsInteger();
            }
            else
            {
                Guid defaultCategoryGuid = GetAttributeValue("DefaultCategory").AsGuid();
                var  defaultCategory     = CategoryCache.Read(defaultCategoryGuid);
                if (defaultCategory != null)
                {
                    prayerRequest.CategoryId = defaultCategory.Id;
                }
            }

            if (GetItem("urgent").AsBoolean())
            {
                prayerRequest.IsUrgent = true;
            }
            else
            {
                prayerRequest.IsUrgent = false;
            }

            if (GetItem("allowComments").AsBoolean())
            {
                prayerRequest.AllowComments = true;
            }
            else
            {
                prayerRequest.AllowComments = false;
            }

            if (GetItem("allowPublication").AsBoolean())
            {
                prayerRequest.IsPublic = true;
            }
            else
            {
                prayerRequest.IsPublic = false;
            }
            prayerRequestService.Add(prayerRequest);
            rockContext.SaveChanges();

            Guid?workflowTypeGuid = GetAttributeValue("Workflow").AsGuidOrNull();

            if (workflowTypeGuid.HasValue)
            {
                prayerRequest.LaunchWorkflow(workflowTypeGuid, prayerRequest.Name);
            }

            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson,
                                              AvalancheUtilities.GetMergeFields(CurrentPerson));

            var response = new FormResponse
            {
                Success = true,
                Message = GetAttributeValue("SaveSuccessText")
            };

            if (CustomAttributes.ContainsKey("ActionType") && CustomAttributes["ActionType"] != "0")
            {
                response.ActionType = CustomAttributes["ActionType"];
            }

            if (CustomAttributes.ContainsKey("Resource"))
            {
                response.Resource = CustomAttributes["Resource"];
            }

            if (CustomAttributes.ContainsKey("Parameter"))
            {
                response.Parameter = CustomAttributes["Parameter"];
            }


            return(new MobileBlockResponse()
            {
                Request = request,
                Response = JsonConvert.SerializeObject(response),
                TTL = 0
            });
        }
Exemplo n.º 23
0
        private List <FormElementItem> BuildForm(bool setValues)
        {
            var formElements = new List <FormElementItem>();

            var mergeFields = AvalancheUtilities.GetMergeFields(CurrentPerson);

            mergeFields.Add("Action", _action);
            mergeFields.Add("Activity", _activity);
            mergeFields.Add("Workflow", _workflow);

            var form = _actionType.WorkflowForm;

            foreach (var formAttribute in form.FormAttributes.OrderBy(a => a.Order))
            {
                if (formAttribute.IsVisible)
                {
                    var attribute = AttributeCache.Read(formAttribute.AttributeId);

                    string value = attribute.DefaultValue;
                    if (_workflow != null && _workflow.AttributeValues.ContainsKey(attribute.Key) && _workflow.AttributeValues[attribute.Key] != null)
                    {
                        value = _workflow.AttributeValues[attribute.Key].Value;
                    }
                    // Now see if the key is in the activity attributes so we can get it's value
                    else if (_activity != null && _activity.AttributeValues.ContainsKey(attribute.Key) && _activity.AttributeValues[attribute.Key] != null)
                    {
                        value = _activity.AttributeValues[attribute.Key].Value;
                    }

                    value = attribute.FieldType.Field.EncodeAttributeValue(attribute, value, formAttribute.IsReadOnly);

                    if (!string.IsNullOrWhiteSpace(formAttribute.PreHtml))
                    {
                        formElements.Add(new FormElementItem
                        {
                            Type  = FormElementType.Label,
                            Value = formAttribute.PreHtml.ResolveMergeFields(mergeFields)
                        });
                    }

                    if (formAttribute.IsReadOnly)
                    {
                        formElements.Add(new FormElementItem
                        {
                            Type  = FormElementType.Label,
                            Value = value,
                            Label = formAttribute.HideLabel ? string.Empty : attribute.Name
                        });
                    }
                    else
                    {
                        var formElement = attribute.FieldType.Field.GetMobileElement(attribute);
                        formElement.Key      = attribute.Key;
                        formElement.Label    = formAttribute.HideLabel ? string.Empty : attribute.Name;
                        formElement.Required = formAttribute.IsRequired;
                        formElement.Value    = value;

                        formElements.Add(formElement);
                    }
                    if (!string.IsNullOrWhiteSpace(formAttribute.PostHtml))
                    {
                        formElements.Add(new FormElementItem
                        {
                            Type  = FormElementType.Label,
                            Value = formAttribute.PostHtml.ResolveMergeFields(mergeFields)
                        });
                    }
                }
            }


            foreach (var action in form.Actions.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var details = action.Split(new char[] { '^' });
                if (details.Length > 0)
                {
                    formElements.Add(new FormElementItem
                    {
                        Type  = FormElementType.Button,
                        Value = details[0].EscapeQuotes(),
                        Label = details[0].EscapeQuotes(),
                        Key   = details[0].EscapeQuotes()
                    });
                }
            }

            formElements.Add(new FormElementItem
            {
                Type  = FormElementType.Hidden,
                Key   = "__WorkflowId__",
                Value = _workflow.Id.ToString()
            });

            formElements.Add(new FormElementItem
            {
                Type  = FormElementType.Hidden,
                Key   = "__ActionTypeId__",
                Value = _action.ActionTypeId.ToString()
            });

            return(formElements);
        }
Exemplo n.º 24
0
        public override MobileBlockResponse HandleRequest(string request, Dictionary <string, string> Body)
        {
            if (Body.ContainsKey("__WorkflowId__"))
            {
                int id = 0;
                int.TryParse(Body["__WorkflowId__"], out id);
                if (id > 0)
                {
                    WorkflowId = id;
                }
            }

            if (Body.ContainsKey("__ActionTypeId__"))
            {
                int id = 0;
                int.TryParse(Body["__ActionTypeId__"], out id);
                if (id > 0)
                {
                    ActionTypeId = id;
                }
            }

            HydrateObjects();

            var response = new FormResponse();

            SetFormValues(Body);

            if (!string.IsNullOrWhiteSpace(request) &&
                _workflow != null &&
                _actionType != null &&
                _actionType.WorkflowForm != null &&
                _activity != null &&
                _action != null)
            {
                var mergeFields = AvalancheUtilities.GetMergeFields(this.CurrentPerson);
                mergeFields.Add("Action", _action);
                mergeFields.Add("Activity", _activity);
                mergeFields.Add("Workflow", _workflow);

                Guid   activityTypeGuid = Guid.Empty;
                string responseText     = "Your information has been submitted successfully.";

                foreach (var action in _actionType.WorkflowForm.Actions.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var actionDetails = action.Split(new char[] { '^' });
                    if (actionDetails.Length > 0 && actionDetails[0] == request)
                    {
                        if (actionDetails.Length > 2)
                        {
                            activityTypeGuid = actionDetails[2].AsGuid();
                        }

                        if (actionDetails.Length > 3 && !string.IsNullOrWhiteSpace(actionDetails[3]))
                        {
                            responseText = actionDetails[3].ResolveMergeFields(mergeFields);
                        }
                        break;
                    }
                }

                _action.MarkComplete();
                _action.FormAction = request;
                _action.AddLogEntry("Form Action Selected: " + _action.FormAction);

                if (_action.ActionTypeCache.IsActivityCompletedOnSuccess)
                {
                    _action.Activity.MarkComplete();
                }

                if (_actionType.WorkflowForm.ActionAttributeGuid.HasValue)
                {
                    var attribute = AttributeCache.Read(_actionType.WorkflowForm.ActionAttributeGuid.Value);
                    if (attribute != null)
                    {
                        IHasAttributes item = null;
                        if (attribute.EntityTypeId == _workflow.TypeId)
                        {
                            item = _workflow;
                        }
                        else if (attribute.EntityTypeId == _activity.TypeId)
                        {
                            item = _activity;
                        }

                        if (item != null)
                        {
                            item.SetAttributeValue(attribute.Key, request);
                        }
                    }
                }

                if (!activityTypeGuid.IsEmpty())
                {
                    var activityType = _workflowType.ActivityTypes.Where(a => a.Guid.Equals(activityTypeGuid)).FirstOrDefault();
                    if (activityType != null)
                    {
                        WorkflowActivity.Activate(activityType, _workflow);
                    }
                }

                List <string> errorMessages;
                if (_workflowService.Process(_workflow, out errorMessages))
                {
                    int?previousActionId = null;

                    if (_action != null)
                    {
                        previousActionId = _action.Id;
                    }

                    ActionTypeId = null;
                    _action      = null;
                    _actionType  = null;
                    _activity    = null;

                    if (HttpContext.Current.Response.Headers.GetValues("ActionType") != null && HttpContext.Current.Response.Headers.GetValues("ActionType").Any())
                    {
                        response.Success    = true;
                        response.ActionType = HttpContext.Current.Response.Headers.GetValues("ActionType").FirstOrDefault();
                        if (HttpContext.Current.Response.Headers.GetValues("Resource") != null)
                        {
                            response.Resource = HttpContext.Current.Response.Headers.GetValues("Resource").FirstOrDefault();
                        }
                        if (HttpContext.Current.Response.Headers.GetValues("Parameter") != null)
                        {
                            response.Parameter = HttpContext.Current.Response.Headers.GetValues("Parameter").FirstOrDefault();
                        }
                    }
                    else
                    {
                        if (HydrateObjects() && _action != null && _action.Id != previousActionId)
                        {
                            response.FormElementItems = BuildForm(true);
                            response.Success          = true;
                        }
                        else
                        {
                            response.Message = responseText;
                            response.Success = true;
                        }
                    }
                }
                else
                {
                    response.Message  = "Workflow Processing Error(s): \n";
                    response.Message += errorMessages.AsDelimited("\n", null, false);
                }
            }


            return(new MobileBlockResponse()
            {
                Request = request,
                Response = JsonConvert.SerializeObject(response),
                TTL = 0
            });
        }
Exemplo n.º 25
0
        public void Execute()
        {
            if (PageId.HasValue || !string.IsNullOrWhiteSpace(ComponentName))
            {
                using (var rockContext = new RockContext())
                {
                    int channelMediumTypeValueId  = DefinedValueCache.Get(AvalancheUtilities.AppMediumValue.AsGuid()).Id;
                    var interactionChannelService = new InteractionChannelService(rockContext);
                    var interactionService        = new InteractionService(rockContext);
                    var interactionChannel        = interactionChannelService.Queryable()
                                                    .Where(a =>
                                                           a.ChannelTypeMediumValueId == channelMediumTypeValueId &&
                                                           a.ChannelEntityId == this.SiteId)
                                                    .FirstOrDefault();
                    if (interactionChannel == null)
                    {
                        interactionChannel      = new InteractionChannel();
                        interactionChannel.Name = SiteCache.Get(SiteId ?? 1).Name;
                        interactionChannel.ChannelTypeMediumValueId = channelMediumTypeValueId;
                        interactionChannel.ChannelEntityId          = this.SiteId;
                        interactionChannel.ComponentEntityTypeId    = EntityTypeCache.Get <Rock.Model.Page>().Id;
                        interactionChannelService.Add(interactionChannel);
                        rockContext.SaveChanges();
                    }

                    InteractionComponent interactionComponent = null;
                    var interactionComponentService           = new InteractionComponentService(rockContext);

                    if (PageId.HasValue)
                    {
                        interactionComponent = interactionComponentService.GetComponentByEntityId(interactionChannel.Id, PageId.Value, PageTitle);
                    }
                    else
                    {
                        interactionComponent = interactionComponentService.GetComponentByComponentName(interactionChannel.Id, ComponentName);
                    }
                    rockContext.SaveChanges();

                    // Add the interaction
                    if (interactionComponent != null)
                    {
                        var deviceId = Regex.Match(UserAgent, "(?<=-).+(?=\\))").Value.Trim();
                        if (deviceId.Length > 20)
                        {
                            deviceId = deviceId.Substring(0, 20);
                        }
                        var deviceApplication = Regex.Match(UserAgent, "^[\\S]{0,}").Value.Trim() + " " + deviceId;
                        var clientOs          = Regex.Match(UserAgent, "(?<=;).+(?=-)").Value.Trim();
                        var clientType        = Regex.Match(UserAgent, "(?<=\\().+(?=;)").Value.Trim();

                        var deviceType = interactionService.GetInteractionDeviceType(deviceApplication, clientOs, clientType, UserAgent);
                        var interactionSessionService = new InteractionSessionService(rockContext);
                        var interactionSession        = interactionSessionService.Queryable().Where(s => s.IpAddress == IPAddress && s.DeviceTypeId == deviceType.Id).FirstOrDefault();

                        if (interactionSession == null)
                        {
                            interactionSession = new InteractionSession()
                            {
                                DeviceTypeId = deviceType.Id,
                                IpAddress    = TrimString(IPAddress, 25)
                            };
                            interactionSessionService.Add(interactionSession);
                            rockContext.SaveChanges();
                        }

                        Operation          = TrimString(Operation, 25);
                        InteractionSummary = TrimString(InteractionSummary, 500);
                        clientType         = TrimString(clientType, 25);
                        deviceApplication  = TrimString(deviceApplication, 100);
                        clientOs           = TrimString(clientOs, 100);

                        var interaction = new InteractionService(rockContext).AddInteraction(interactionComponent.Id, null, Operation, InteractionData, PersonAliasId, DateViewed,
                                                                                             deviceApplication, clientOs, clientType, UserAgent, IPAddress, interactionSession.Guid);

                        interaction.InteractionSummary = InteractionSummary;

                        PersonalDevice personalDevice = AvalancheUtilities.GetPersonalDevice(deviceId, PersonAliasId, rockContext);
                        if (personalDevice != null)
                        {
                            interaction.PersonalDeviceId = personalDevice.Id;
                        }

                        rockContext.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 26
0
        public override MobileBlock GetMobile(string parameter)
        {
            if (CurrentPerson == null)
            {
                return(new MobileBlock()
                {
                    BlockType = "Avalanche.Blocks.Null",
                    Attributes = CustomAttributes
                });
            }

            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson, AvalancheUtilities.GetMergeFields(CurrentPerson),
                                              GetAttributeValue("EnabledLavaCommands"),
                                              parameter);

            var valueGuid = GetAttributeValue("Component");
            var value     = DefinedValueCache.Get(valueGuid);

            if (value != null)
            {
                CustomAttributes["Component"] = value.GetAttributeValue("ComponentType");
            }

            CustomAttributes["InitialRequest"] = parameter; //Request for pull to refresh

            var family = new List <ListElement>();

            family.Add(
                new ListElement
            {
                Image       = GlobalAttributesCache.Value("InternalApplicationRoot") + CurrentPerson.PhotoUrl,
                Id          = CurrentPersonAlias.Guid.ToString(),
                Title       = CurrentPerson.FullName,
                Description = GetInfo(CurrentPerson, true)
            });

            foreach (var member in CurrentPerson.GetFamilyMembers())
            {
                family.Add(new ListElement
                {
                    Image       = GlobalAttributesCache.Value("InternalApplicationRoot") + member.Person.PhotoUrl,
                    Id          = member.Person.PrimaryAlias.Guid.ToString(),
                    Title       = member.Person.FullName,
                    Description = GetInfo(member.Person, false)
                });
            }

            family.Add(new ListElement
            {
                Id    = "0",
                Title = "Add New Family Member"
            });

            var additionalChanges = GetAttributeValue("AdditionalChangesLink");

            var additionalChangesPage = PageCache.Get(additionalChanges);

            if (additionalChangesPage != null)
            {
                family.Add(new ListElement
                {
                    ActionType = "1",
                    Resource   = additionalChangesPage.Id.ToString(),
                    Title      = "Request Additional Changes",
                    Id         = "1"
                });
            }



            CustomAttributes["Content"] = JsonConvert.SerializeObject(family);

            return(new MobileBlock()
            {
                BlockType = "Avalanche.Blocks.ListViewBlock",
                Attributes = CustomAttributes
            });
        }