protected string GetInjectionTypeForDisplay(object InjectionId)
        {
            if (InjectionId == null)
            {
                return(string.Empty);
            }

            var ctl           = new InjectionController();
            var injection     = ctl.GetInjectionContent(int.Parse(InjectionId.ToString(), NumberStyles.Integer));
            var injectionType = InjectionController.GetInjectionType(injection);

            if (injectionType == InjectionType.HtmlBottom || injectionType == InjectionType.HtmlTop)
            {
                return(GetLocalizedString(injectionType.ToString()));
            }
            else
            {
                var injectionProvider = InjectionController.GetCrmProvider(injection);

                if (string.IsNullOrEmpty(injectionProvider))
                {
                    return(string.Concat(GetLocalizedString(injectionType.ToString()),
                                         GetLocalizedString(InjectionController.GetCrmProviderDefault(injectionType))));
                }
                else
                {
                    return(string.Concat(GetLocalizedString(injectionType.ToString()),
                                         GetLocalizedString(injectionProvider)));
                }
            }
        }
        private int ParsePriotityLevel(PortalSecurity security)
        {
            var priorityInput = security.InputFilter(txtCrmPriority.Text.Trim(), PortalSecurity.FilterFlag.NoMarkup);
            var priorityLevel = InjectionController.GetCrmPriority(priorityInput);

            return((priorityLevel > Null.NullInteger) ? priorityLevel : Null.NullInteger);
        }
        protected void cvContent_OnServerValidate(object source, ServerValidateEventArgs args)
        {
            if (radType.SelectedIndex == 0)
            {
                var isValidPathFormat = false;
                var isValidFilePath   = false;
                var pathToTest        = txtContent.Text.Trim();

                isValidPathFormat = (InjectionController.IsValidCssInjectionType(pathToTest) ||
                                     InjectionController.IsValidJavaScriptInjectionType(pathToTest));

                if (pathToTest.StartsWith("http"))
                {
                    // external file path
                    isValidFilePath = InjectionController.IsValidFilePath(pathToTest);
                }
                else
                {
                    // local file path
                    var fullFilePath = Server.MapPath(pathToTest);
                    isValidFilePath = File.Exists(fullFilePath);
                }

                args.IsValid = (isValidPathFormat && isValidFilePath);
            }
            else
            {
                args.IsValid = true;
            }
        }
        private void SaveInjection()
        {
            try
            {
                var           ctlModule = new InjectionController();
                InjectionInfo objInj    = null;

                objInj = !string.IsNullOrEmpty(hidInjectionId.Value) ? ctlModule.GetInjectionContent(int.Parse(hidInjectionId.Value)) : new InjectionInfo();

                PopulateInjectionForSave(ref objInj);

                if (!string.IsNullOrEmpty(hidInjectionId.Value))
                {
                    ctlModule.UpdateInjectionContent(objInj);
                }
                else
                {
                    ctlModule.AddInjectionContent(objInj);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Пример #5
0
        private void ExecutePageInjection()
        {
            var ctlModule = new InjectionController();
            var collInj   = new InjectionInfoCollection();

            collInj = ctlModule.GetActiveInjectionContents(ModuleId);

            if (collInj.Count <= 0)
            {
                return;
            }

            p_Header = string.Format("<!-- {0} -->", GetLocalizedString("HeaderHeader"));
            p_Footer = string.Format("<!-- {0} -->", GetLocalizedString("FooterHeader"));

            foreach (var injection in collInj)
            {
                var injectionType = InjectionController.GetInjectionType(injection);
                var priority      = InjectionController.GetCrmPriority(injection);
                var provider      = InjectionController.GetCrmProvider(injection);

                switch (injectionType)
                {
                case InjectionType.CSS:
                    RegisterStyleSheet(injection.InjectContent, priority, provider);
                    break;

                case InjectionType.JavaScript:
                    RegisterScript(injection.InjectContent, priority, provider);
                    break;

                case InjectionType.HtmlBottom:
                    p_Footer = string.Concat(p_Footer, Server.HtmlDecode(injection.InjectContent));
                    break;

                case InjectionType.HtmlTop:
                    p_Header = string.Concat(p_Header, Server.HtmlDecode(injection.InjectContent));
                    break;
                }
            }

            p_Header = string.Concat(p_Header, string.Format("<!-- {0} -->", GetLocalizedString("HeaderFooter")));
            p_Footer = string.Concat(p_Footer, string.Format("<!-- {0} -->", GetLocalizedString("FooterFooter")));

            // add the injection content to the header
            if (!string.IsNullOrEmpty(HeaderInjection))
            {
                Parent.Page.Header.Controls.Add(new LiteralControl(HeaderInjection));
            }

            // add the injection content to the footer
            if (!string.IsNullOrEmpty(FooterInjection))
            {
                Page.LoadComplete += new EventHandler(InjectIntoFooter);
            }
        }
        private void SwapOrder(int ItemId, string UpDown)
        {
            // set the global id to match the one we're looking for
            p_SearchParam = ItemId;

            // change the order
            InjectionController ctlModule = new InjectionController();

            ctlModule.ChangeOrder(ItemId, UpDown);
        }
        protected bool CommandUpVisible(object InjectionId)
        {
            if (InjectionId == null)
            {
                return(false);
            }

            var ctlModule = new InjectionController();
            var oInject   = ctlModule.GetInjectionContent(int.Parse(InjectionId.ToString(), NumberStyles.Integer));

            return(oInject.OrderShown != 1);
        }
        protected void cmdDelete_Click(object sender, EventArgs e)
        {
            if (Regex.IsMatch(hidInjectionId.Value, "^\\d+$"))
            {
                InjectionController ctlModule = new InjectionController();
                ctlModule.DeleteInjectionContent(int.Parse(hidInjectionId.Value, System.Globalization.NumberStyles.Integer));
            }

            ClearForm();
            TogglePanels();
            BindData();
        }
Пример #9
0
        public void ControllerTest()
        {
            // Arrange
            var data = new[] { new Product {
                                   Name = "Test", Price = 100M
                               } };

            var mock = new Mock <IRepository>();

            mock.SetupGet(m => m.Products).Returns(data);

            var controller = new InjectionController(mock.Object);

            // Act
            var result = controller.Index();

            // Assert
            Assert.Equal(data, result.ViewData.Model);
        }
        protected void dlInjection_ItemCommand(object source, DataListCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case c_Command_MoveUp:
                SwapOrder(Convert.ToInt32(e.CommandArgument), c_Command_MoveUp);
                BindData();
                break;

            case c_Command_MoveDown:
                SwapOrder(Convert.ToInt32(e.CommandArgument), c_Command_MoveDown);
                BindData();
                break;

            case c_Command_Edit:
                BindForm(Convert.ToInt32(e.CommandArgument));
                ToggleType();
                TogglePanels();
                break;

            case c_Command_Insert:
                ClearForm();
                TogglePanels();
                break;

            case c_Command_Delete:
                InjectionController ctlModule = new InjectionController();
                ctlModule.DeleteInjectionContent(Convert.ToInt32(e.CommandArgument));
                BindData();
                break;

            default:
                return;

                break;
            }
        }
        private void BindForm(int ItemId)
        {
            var ctlModule = new InjectionController();
            var injection = new InjectionInfo();

            injection = ctlModule.GetInjectionContent(ItemId);

            txtName.Text    = injection.InjectName;
            txtContent.Text = Server.HtmlDecode(injection.InjectContent);
            radInject.ClearSelection();

            if (injection.InjectTop)
            {
                radInject.Items.FindByText(GetLocalizedString("radInject.0.Text")).Selected = true;
            }
            else
            {
                radInject.Items.FindByText(GetLocalizedString("radInject.1.Text")).Selected = true;
            }

            chkEnabled.Checked   = injection.IsEnabled;
            hidInjectionId.Value = injection.InjectionId.ToString();
            cvName.Enabled       = false;

            cmdDelete.Visible = !string.IsNullOrEmpty(hidInjectionId.Value);

            if (injection.CustomProperties.Any(p => p.Name == InjectionInfoMembers.CrmPriorityField))
            {
                var priorityLevel = injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.CrmPriorityField).Value;
                txtCrmPriority.Text = (priorityLevel == "-1") ? string.Empty : priorityLevel;
            }

            if (injection.CustomProperties.Any(p => p.Name == InjectionInfoMembers.CrmProviderField))
            {
                var provider = injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.CrmProviderField).Value;
                ddlCrmProvider.ClearSelection();
                ddlCrmProvider.SelectedIndex = int.Parse(provider);
            }

            if (injection.CustomProperties.Any(p => p.Name == InjectionInfoMembers.LastUpdatedByField))
            {
                var updatedBy   = injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.LastUpdatedByField);
                var updatedDate = injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.LastUpdatedDateField);

                var user = UserController.GetUserById(PortalSettings.PortalId, int.Parse(updatedBy.Value, NumberStyles.Integer));

                lblAudit.Text = string.Format(GetLocalizedString("lblAudit"), user.DisplayName, updatedDate.Value);
            }

            if (injection.CustomProperties.Any(p => p.Name == InjectionInfoMembers.InjectionTypeField))
            {
                var intType = int.Parse(
                    injection.CustomProperties.FirstOrDefault(p => p.Name == InjectionInfoMembers.InjectionTypeField)
                    .Value);

                radType.SelectedIndex = intType;
            }
            else
            {
                // the default for existing injections is 1 because JS/CSS wasn't an option in the past
                radType.SelectedIndex = 1;
            }

            ToggleType();
        }
        protected void cvName_ServerValidate(object source, ServerValidateEventArgs args)
        {
            InjectionController ctlModule = new InjectionController();

            args.IsValid = (!ctlModule.DoesInjectionNameExist(txtName.Text, ModuleId));
        }