예제 #1
0
        protected override void RegisterModules(PaFolder Folder, ArrayList Modules, ArrayList Controls)
        {
            InstallerInfo.Log.AddInfo(REGISTER_Controls);

            ModuleControlController objModuleControls = new ModuleControlController();

            ModuleControlInfo objModuleControl;

            foreach (ModuleControlInfo tempLoopVar_objModuleControl in Controls)
            {
                objModuleControl = tempLoopVar_objModuleControl;
                // Skins Objects have a null ModuleDefID
                objModuleControl.ModuleDefID = Null.NullInteger;

                // check if control exists
                ModuleControlInfo objModuleControl2 = objModuleControls.GetModuleControlByKeyAndSrc(Null.NullInteger, objModuleControl.ControlKey, objModuleControl.ControlSrc);
                if (objModuleControl2 == null)
                {
                    // add new control
                    objModuleControls.AddModuleControl(objModuleControl);
                }
                else
                {
                    // update existing control
                    objModuleControl.ModuleControlID = objModuleControl2.ModuleControlID;
                    objModuleControls.UpdateModuleControl(objModuleControl);
                }
            }

            InstallerInfo.Log.EndJob(REGISTER_End);
        }
예제 #2
0
        /// <inheritdoc cref="IViewManager.SaveModuleControlAsync(ModuleControlInfo)" />
        public async Task <bool> SaveModuleControlAsync(ModuleControlInfo moduleControlInfo)
        {
            if (moduleControlInfo is null)
            {
                return(false);
            }

            ModuleControl moduleControl = await _dbContext.KastraModuleControls
                                          .SingleOrDefaultAsync(mc => mc.ModuleControlId == moduleControlInfo.ModuleControlId);

            ModuleDefinitionInfo moduleDef = await GetModuleDefAsync(moduleControlInfo.ModuleDefId);

            if (moduleDef is null)
            {
                return(false);
            }

            moduleControl = moduleControlInfo.ToModuleControl();

            if (moduleControl.ModuleControlId > 0)
            {
                _dbContext.KastraModuleControls.Update(moduleControl);
            }
            else
            {
                _dbContext.KastraModuleControls.Add(moduleControl);
            }

            await _dbContext.SaveChangesAsync();

            // Clear cache
            _cacheEngine.ClearCacheContains("Module");

            return(true);
        }
        private static void ProcessControls(XPathNavigator controlNav, string moduleFolder, ModuleDefinitionInfo definition)
        {
            var moduleControl = new ModuleControlInfo();

            moduleControl.ControlKey   = Util.ReadElement(controlNav, "key");
            moduleControl.ControlTitle = Util.ReadElement(controlNav, "title");

            //Write controlSrc
            string controlSrc = Util.ReadElement(controlNav, "src");

            if (!(controlSrc.ToLower().StartsWith("desktopmodules") || !controlSrc.ToLower().EndsWith(".ascx")))
            {
                //this code allows a developer to reference an ASCX file in a different folder than the module folder ( good for ASCX files shared between modules where you want only a single copy )
                //or it allows the developer to use webcontrols rather than usercontrols

                controlSrc = Path.Combine("DesktopModules", Path.Combine(moduleFolder, controlSrc));
            }
            controlSrc = controlSrc.Replace('\\', '/');
            moduleControl.ControlSrc = controlSrc;

            moduleControl.IconFile = Util.ReadElement(controlNav, "iconfile");

            string controlType = Util.ReadElement(controlNav, "type");

            if (!string.IsNullOrEmpty(controlType))
            {
                try
                {
                    moduleControl.ControlType = (SecurityAccessLevel)TypeDescriptor.GetConverter(typeof(SecurityAccessLevel)).ConvertFromString(controlType);
                }
                catch (Exception exc)
                {
                    Logger.Error(exc);

                    throw new Exception(Util.EXCEPTION_Type);
                }
            }
            string viewOrder = Util.ReadElement(controlNav, "vieworder");

            if (!string.IsNullOrEmpty(viewOrder))
            {
                moduleControl.ViewOrder = int.Parse(viewOrder);
            }
            moduleControl.HelpURL = Util.ReadElement(controlNav, "helpurl");
            string supportsPartialRendering = Util.ReadElement(controlNav, "supportspartialrendering");

            if (!string.IsNullOrEmpty(supportsPartialRendering))
            {
                moduleControl.SupportsPartialRendering = bool.Parse(supportsPartialRendering);
            }
            string supportsPopUps = Util.ReadElement(controlNav, "supportspopups");

            if (!string.IsNullOrEmpty(supportsPopUps))
            {
                moduleControl.SupportsPartialRendering = bool.Parse(supportsPopUps);
            }

            definition.ModuleControls[moduleControl.ControlKey] = moduleControl;
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// SaveModuleDefinition saves the Module Definition to the database
        /// </summary>
        /// <param name="moduleDefinition">The Module Definition to save</param>
        /// <param name="saveChildren">A flag that determines whether the child objects are also saved</param>
        /// <param name="clearCache">A flag that determines whether to clear the host cache</param>
        /// <history>
        ///     [cnurse]	01/14/2008   Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static int SaveModuleDefinition(ModuleDefinitionInfo moduleDefinition, bool saveChildren, bool clearCache)
        {
            int moduleDefinitionID = moduleDefinition.ModuleDefID;

            if (moduleDefinitionID == Null.NullInteger)
            {
                //Add new Module Definition
                moduleDefinitionID = dataProvider.AddModuleDefinition(moduleDefinition.DesktopModuleID,
                                                                      moduleDefinition.FriendlyName,
                                                                      moduleDefinition.DefinitionName,
                                                                      moduleDefinition.DefaultCacheTime,
                                                                      UserController.GetCurrentUserInfo().UserID);
            }
            else
            {
                //Upgrade Module Definition
                dataProvider.UpdateModuleDefinition(moduleDefinition.ModuleDefID, moduleDefinition.FriendlyName, moduleDefinition.DefinitionName, moduleDefinition.DefaultCacheTime, UserController.GetCurrentUserInfo().UserID);
            }
            if (saveChildren)
            {
                foreach (KeyValuePair <string, PermissionInfo> kvp in moduleDefinition.Permissions)
                {
                    kvp.Value.ModuleDefID = moduleDefinitionID;

                    //check if permission exists
                    var       permissionController = new PermissionController();
                    ArrayList permissions          = permissionController.GetPermissionByCodeAndKey(kvp.Value.PermissionCode, kvp.Value.PermissionKey);
                    if (permissions != null && permissions.Count == 1)
                    {
                        var permission = (PermissionInfo)permissions[0];
                        kvp.Value.PermissionID = permission.PermissionID;
                        permissionController.UpdatePermission(kvp.Value);
                    }
                    else
                    {
                        permissionController.AddPermission(kvp.Value);
                    }
                }
                foreach (KeyValuePair <string, ModuleControlInfo> kvp in moduleDefinition.ModuleControls)
                {
                    kvp.Value.ModuleDefID = moduleDefinitionID;

                    //check if definition exists
                    ModuleControlInfo moduleControl = ModuleControlController.GetModuleControlByControlKey(kvp.Value.ControlKey, kvp.Value.ModuleDefID);
                    if (moduleControl != null)
                    {
                        kvp.Value.ModuleControlID = moduleControl.ModuleControlID;
                    }
                    ModuleControlController.SaveModuleControl(kvp.Value, clearCache);
                }
            }
            if (clearCache)
            {
                DataCache.ClearHostCache(true);
            }
            return(moduleDefinitionID);
        }
예제 #5
0
        /// <Summary>Page_Load runs when the control is loaded.</Summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            string FriendlyName = "";

            ModuleController objModules = new ModuleController();
            ModuleInfo       objModule  = objModules.GetModule(ModuleId, TabId, false);

            if (objModule != null)
            {
                FriendlyName = objModule.FriendlyName;
            }

            int ModuleControlId = Null.NullInteger;

            if (!(Request.QueryString["ctlid"] == null))
            {
                ModuleControlId = int.Parse(Request.QueryString["ctlid"]);
            }

            ModuleControlController objModuleControls = new ModuleControlController();
            ModuleControlInfo       objModuleControl  = objModuleControls.GetModuleControl(ModuleControlId);

            if (objModuleControl != null)
            {
                string FileName          = Path.GetFileName(objModuleControl.ControlSrc);
                string localResourceFile = objModuleControl.ControlSrc.Replace(FileName, Localization.LocalResourceDirectory + "/" + FileName);
                if (Localization.GetString(ModuleActionType.HelpText, localResourceFile) != "")
                {
                    lblHelp.Text = Localization.GetString(ModuleActionType.HelpText, localResourceFile);
                }
                _key = objModuleControl.ControlKey;

                string helpUrl = Globals.GetOnLineHelp(objModuleControl.HelpURL, ModuleConfiguration);
                if (!Null.IsNull(helpUrl))
                {
                    cmdHelp.NavigateUrl = Globals.FormatHelpUrl(helpUrl, PortalSettings, FriendlyName);
                    cmdHelp.Visible     = true;
                }
                else
                {
                    cmdHelp.Visible = false;
                }
            }

            if (Page.IsPostBack == false)
            {
                if (Request.UrlReferrer != null)
                {
                    ViewState["UrlReferrer"] = Convert.ToString(Request.UrlReferrer);
                }
                else
                {
                    ViewState["UrlReferrer"] = "";
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CurrentUser.IsSuperAdmin)
            {
                Response.Redirect(AppEnv.ADMIN_CMD);
            }

            controlId = ConvertUtility.ToInt32(Request.QueryString["cid"]);
            moduleId  = ConvertUtility.ToInt32(Request.QueryString["mid"]);
            ModuleInfo        module        = ModuleController.GetModule(moduleId);
            ModuleControlInfo moduleControl = ModuleControlController.GetModuleControl(controlId);

            if (moduleControl == null)
            {
                this.btnDelete.Visible = false;
            }

            if (module == null)
            {
                module = ModuleController.GetModule(moduleControl.ModuleID);
            }
            if (module != null)
            {
                lblModuleName.Text         = module.ModuleName;
                txtControlIcon.fpUploadDir = CheckPath(module);
            }

            if (!Page.IsPostBack)
            {
                if (module != null && module.ModuleFolder.Length > 0)
                {
                    GetFiles(Server.MapPath("/"), Server.MapPath(module.ModuleFolder));
                    dropPath.DataSource = lstFile;
                    dropPath.DataBind();
                }
                MiscUtility.FillIndex(dropControlOrder, 30, 1);
                chkControlType.DataSource = RoleController.GetRoles();
                chkControlType.DataBind();
                if (moduleControl == null)
                {
                    return;
                }
                lblModuleName.Text         = ModuleController.GetModule(moduleControl.ModuleID).ModuleName;
                txtControlName.Text        = moduleControl.ControlName;
                txtControlDescription.Text = moduleControl.ControlDescription;
                txtControlKey.Text         = moduleControl.ControlKey;
                MiscUtility.SelectItemFromList(dropPath, moduleControl.ControlPath);
                txtControlIcon.Text        = moduleControl.ControlIcon;
                txtControlDescription.Text = moduleControl.ControlDescription;
                chkControlHeader.Checked   = moduleControl.ControlHeader;
                MiscUtility.SelectItemFromList(dropControlOrder, moduleControl.ControlOrder.ToString());
                string[] roleList = (moduleControl.ControlRole != null)?moduleControl.ControlRole.Split("|".ToCharArray()):null;
                MiscUtility.SelectItemFromList(chkControlType, roleList);
            }
        }
예제 #7
0
 private void cmdUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (Page.IsValid)
         {
             if (cboSource.SelectedIndex != 0 || !String.IsNullOrEmpty(txtSource.Text))
             {
                 //check whether have a same control key in the module definition
                 var controlKey     = !String.IsNullOrEmpty(txtKey.Text) ? txtKey.Text : Null.NullString;
                 var moduleControls = ModuleControlController.GetModuleControlsByModuleDefinitionID(ModuleDefId).Values;
                 var keyExists      = moduleControls.Any(c => c.ControlKey.Equals(controlKey, StringComparison.InvariantCultureIgnoreCase) &&
                                                         c.ModuleControlID != ModuleControlId);
                 if (keyExists)
                 {
                     UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("DuplicateKey.ErrorMessage", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                     return;
                 }
                 var moduleControl = new ModuleControlInfo
                 {
                     ModuleControlID          = ModuleControlId,
                     ModuleDefID              = ModuleDefId,
                     ControlKey               = controlKey,
                     ControlTitle             = !String.IsNullOrEmpty(txtTitle.Text) ? txtTitle.Text : Null.NullString,
                     ControlSrc               = !String.IsNullOrEmpty(txtSource.Text) ? txtSource.Text : cboSource.SelectedItem.Text,
                     ControlType              = (SecurityAccessLevel)Enum.Parse(typeof(SecurityAccessLevel), cboType.SelectedItem.Value),
                     ViewOrder                = !String.IsNullOrEmpty(txtViewOrder.Text) ? int.Parse(txtViewOrder.Text) : Null.NullInteger,
                     IconFile                 = cboIcon.SelectedIndex > 0 ? cboIcon.SelectedItem.Text : Null.NullString,
                     HelpURL                  = !String.IsNullOrEmpty(txtHelpURL.Text) ? txtHelpURL.Text : Null.NullString,
                     SupportsPartialRendering = chkSupportsPartialRendering.Checked,
                     SupportsPopUps           = supportsModalPopUpsCheckBox.Checked
                 };
                 try
                 {
                     ModuleControlController.SaveModuleControl(moduleControl, true);
                 }
                 catch
                 {
                     UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("AddControl.ErrorMessage", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                     return;
                 }
                 Response.Redirect(ReturnURL, true);
             }
             else
             {
                 UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("MissingSource.ErrorMessage", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
             }
         }
     }
     catch (Exception exc)
     {
         Exceptions.ProcessModuleLoadException(this, exc);
     }
 }
예제 #8
0
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Reads the ModuleControls from an XmlReader
 /// </summary>
 /// <param name="reader">The XmlReader to use</param>
 /// <history>
 ///     [cnurse]	01/17/2008   Created
 /// </history>
 /// -----------------------------------------------------------------------------
 private void ReadModuleControls(XmlReader reader)
 {
     reader.ReadStartElement("moduleControls");
     do
     {
         reader.ReadStartElement("moduleControl");
         var moduleControl = new ModuleControlInfo();
         moduleControl.ReadXml(reader);
         ModuleControls.Add(moduleControl.ControlKey, moduleControl);
     } while (reader.ReadToNextSibling("moduleControl"));
 }
예제 #9
0
        public override RouteData GetRouteData(HttpContextBase httpContext, ModuleControlInfo moduleControl)
        {
            var assemblyName = moduleControl.ControlTitle;

            var    segments       = moduleControl.ControlSrc.Replace(".razorpages", "").Split('/');
            string routeNamespace = String.Empty;
            string routeModuleName;
            string routePageName;

            if (segments.Length == 3)
            {
                routeNamespace  = segments[0];
                routeModuleName = segments[1];
                routePageName   = segments[2];
            }
            else
            {
                routeModuleName = segments[0];
                routePageName   = segments[1];
            }

            var pageName   = (httpContext == null) ? routePageName : httpContext.Request.QueryString.GetValueOrDefault("action", routePageName);
            var moduleName = (httpContext == null) ? routeModuleName : httpContext.Request.QueryString.GetValueOrDefault("controller", routeModuleName);

            var routeData = new RouteData();

            routeData.Values.Add("module", moduleName);
            routeData.Values.Add("page", pageName);
            routeData.Values.Add("assembly", assemblyName);

            var moduleDef     = ModuleDefinitionController.GetModuleDefinitionByID(moduleControl.ModuleDefID);
            var desktopModule = DesktopModuleController.GetDesktopModule(moduleDef.DesktopModuleID, -1);

            routeData.Values.Add("page-path", $"~/DesktopModules/MVC/{desktopModule.FolderName}/Pages/{pageName}.cshtml");

            if (httpContext != null)
            {
                foreach (var param in httpContext.Request.QueryString.AllKeys)
                {
                    if (!ExcludedQueryStringParams.Split(',').ToList().Contains(param.ToLower()))
                    {
                        routeData.Values.Add(param, httpContext.Request.QueryString[param]);
                    }
                }
            }
            if (!String.IsNullOrEmpty(routeNamespace))
            {
                routeData.DataTokens.Add("namespaces", new string[] { routeNamespace });
            }

            return(routeData);
        }
예제 #10
0
 public ModuleControlDto(ModuleControlInfo moduleControl)
 {
     this.Id                      = moduleControl.ModuleControlID;
     this.DefinitionId            = moduleControl.ModuleDefID;
     this.Key                     = moduleControl.ControlKey;
     this.Title                   = moduleControl.ControlTitle;
     this.Source                  = moduleControl.ControlSrc;
     this.Type                    = moduleControl.ControlType;
     this.Order                   = moduleControl.ViewOrder;
     this.Icon                    = moduleControl.IconFile;
     this.HelpUrl                 = moduleControl.HelpURL;
     this.SupportPopups           = moduleControl.SupportsPopUps;
     this.SupportPartialRendering = moduleControl.SupportsPartialRendering;
 }
예제 #11
0
 public ModuleControlDto(ModuleControlInfo moduleControl)
 {
     Id                      = moduleControl.ModuleControlID;
     DefinitionId            = moduleControl.ModuleDefID;
     Key                     = moduleControl.ControlKey;
     Title                   = moduleControl.ControlTitle;
     Source                  = moduleControl.ControlSrc;
     Type                    = moduleControl.ControlType;
     Order                   = moduleControl.ViewOrder;
     Icon                    = moduleControl.IconFile;
     HelpUrl                 = moduleControl.HelpURL;
     SupportPopups           = moduleControl.SupportsPopUps;
     SupportPartialRendering = moduleControl.SupportsPartialRendering;
 }
예제 #12
0
        protected override ModuleControlInfo GetModuleControlFromNode(string Foldername, int TempModuleID, XmlElement ModuleControl)
        {
            // Version 3 .dnn file format adds the helpurl node to the controls/control node element
            ModuleControlInfo ModControl = base.GetModuleControlFromNode(Foldername, TempModuleID, ModuleControl);

            if (ModControl != null)
            {
                XmlElement helpElement = (XmlElement)ModuleControl.SelectSingleNode("helpurl");
                if (helpElement != null)
                {
                    ModControl.HelpURL = helpElement.InnerText.Trim();
                }
            }
            return(ModControl);
        }
        /// <summary>
        /// Convert ModuleControlInfo to ModuleControl.
        /// </summary>
        /// <param name="moduleControlInfo">Module control info</param>
        /// <returns>Module control</returns>
        public static ModuleControl ToModuleControl(this ModuleControlInfo moduleControlInfo)
        {
            if (moduleControlInfo is null)
            {
                return(null);
            }

            return(new ModuleControl()
            {
                ModuleControlId = moduleControlInfo.ModuleControlId,
                ModuleDefinitionId = moduleControlInfo.ModuleDefId,
                KeyName = moduleControlInfo.KeyName,
                Path = moduleControlInfo.Path
            });
        }
예제 #14
0
        protected void Page_Init(Object sender, EventArgs e)
        {
            ModuleController        objModules = new ModuleController();
            ModuleControlController objModuleControlController = new ModuleControlController();

            // get ModuleId
            if ((Request.QueryString["ModuleId"] != null))
            {
                moduleId = int.Parse(Request.QueryString["ModuleId"]);
            }

            // get module
            ModuleInfo objModule = objModules.GetModule(moduleId, TabId, false);

            if (objModule != null)
            {
                tabModuleId = objModule.TabModuleID;

                //get Settings Control(s)
                ArrayList arrModuleControls = objModuleControlController.GetModuleControlsByKey("Settings", objModule.ModuleDefID);

                if (arrModuleControls.Count > 0)
                {
                    ModuleControlInfo objModuleControlInfo = (ModuleControlInfo)arrModuleControls[0];
                    string            src = "~/" + objModuleControlInfo.ControlSrc;
                    ctlSpecific             = (ModuleSettingsBase)LoadControl(src);
                    ctlSpecific.ID          = src.Substring(src.LastIndexOf("/") + 1);
                    ctlSpecific.ModuleId    = moduleId;
                    ctlSpecific.TabModuleId = tabModuleId;
                    dshSpecific.Text        = Localization.LocalizeControlTitle(objModuleControlInfo.ControlTitle, objModuleControlInfo.ControlSrc, "settings");
                    pnlSpecific.Controls.Add(ctlSpecific);

                    if (Localization.GetString(ModuleActionType.HelpText, ctlSpecific.LocalResourceFile) != "")
                    {
                        rowspecifichelp.Visible       = true;
                        imgSpecificHelp.AlternateText = Localization.GetString(ModuleActionType.ModuleHelp, Localization.GlobalResourceFile);
                        lnkSpecificHelp.Text          = Localization.GetString(ModuleActionType.ModuleHelp, Localization.GlobalResourceFile);
                        lnkSpecificHelp.NavigateUrl   = Globals.NavigateURL(TabId, "Help", "ctlid=" + objModuleControlInfo.ModuleControlID, "moduleid=" + moduleId);
                    }
                    else
                    {
                        rowspecifichelp.Visible = false;
                    }
                }
            }
        }
예제 #15
0
        private static void EnsureEditScriptControlIsRegistered(int moduleDefId)
        {
            if (ModuleControlController.GetModuleControlByControlKey("EditRazorScript", moduleDefId) != null)
            {
                return;
            }
            var m = new ModuleControlInfo
            {
                ControlKey   = "EditRazorScript",
                ControlSrc   = "DesktopModules/RazorModules/RazorHost/EditScript.ascx",
                ControlTitle = "Edit Script",
                ControlType  = SecurityAccessLevel.Host,
                ModuleDefID  = moduleDefId
            };

            ModuleControlController.UpdateModuleControl(m);
        }
예제 #16
0
        /// <summary>
        /// Gets the module data by module identifier.
        /// </summary>
        /// <returns>The module data by module identifier.</returns>
        /// <param name="page">Page.</param>
        /// <param name="module">Module.</param>
        /// <param name="moduleControlKeyName">Module control key name.</param>
        /// <param name="moduleAction">Module action.</param>
        public ModuleDataComponent GetModuleDataByModuleId(
            PageInfo page,
            ModuleInfo module,
            string moduleControlKeyName,
            string moduleAction)
        {
            ModuleControlInfo   moduleControl = null;
            ModuleDataComponent moduleData    = new ModuleDataComponent()
            {
                Module       = module,
                Page         = page,
                ModuleAction = moduleAction,
                CacheEngine  = _cacheEngine
            };

            if (module.ModulePermissions is not null)
            {
                moduleData.RequiredClaims = module.ModulePermissions
                                            .Where(mp => mp.Permission is not null)
                                            .Select(mp => mp.Permission)
                                            .ToList();
            }

            // Get module control
            if (!string.IsNullOrEmpty(moduleControlKeyName) && module != null)
            {
                moduleControl = module.ModuleDefinition.ModuleControls
                                .SingleOrDefault(mc => mc.KeyName.ToLower() == moduleControlKeyName.ToLower());

                if (moduleControl != null)
                {
                    moduleData.ModuleViewComponent = GetModelFullname(module.ModuleDefinition.Namespace, moduleControl.Path);
                }
                else
                {
                    moduleData.ModuleViewComponent = GetModelFullname(module.ModuleDefinition.Namespace, module.ModuleDefinition.KeyName);
                }
            }
            else
            {
                moduleData.ModuleViewComponent = GetModelFullname(module.ModuleDefinition.Namespace, module.ModuleDefinition.KeyName);
            }

            return(moduleData);
        }
        public override RouteData GetRouteData(HttpContextBase httpContext, ModuleControlInfo moduleControl)
        {
            var    segments       = moduleControl.ControlSrc.Replace(".mvc", string.Empty).Split('/');
            string routeNamespace = string.Empty;
            string routeControllerName;
            string routeActionName;

            if (segments.Length == 3)
            {
                routeNamespace      = segments[0];
                routeControllerName = segments[1];
                routeActionName     = segments[2];
            }
            else
            {
                routeControllerName = segments[0];
                routeActionName     = segments[1];
            }

            var actionName     = (httpContext == null) ? routeActionName : httpContext.Request.QueryString.GetValueOrDefault("action", routeActionName);
            var controllerName = (httpContext == null) ? routeControllerName : httpContext.Request.QueryString.GetValueOrDefault("controller", routeControllerName);

            var routeData = new RouteData();

            routeData.Values.Add("controller", controllerName);
            routeData.Values.Add("action", actionName);

            if (httpContext != null)
            {
                foreach (var param in httpContext.Request.QueryString.AllKeys)
                {
                    if (!ExcludedQueryStringParams.Split(',').ToList().Contains(param.ToLowerInvariant()))
                    {
                        routeData.Values.Add(param, httpContext.Request.QueryString[param]);
                    }
                }
            }

            if (!string.IsNullOrEmpty(routeNamespace))
            {
                routeData.DataTokens.Add("namespaces", new string[] { routeNamespace });
            }

            return(routeData);
        }
 public static int SaveModuleControl(ModuleControlInfo moduleControl, bool clearCache)
 {
     int moduleControlID = moduleControl.ModuleControlID;
     if (moduleControlID == Null.NullInteger)
     {
         moduleControlID = dataProvider.AddModuleControl(moduleControl.ModuleDefID, moduleControl.ControlKey, moduleControl.ControlTitle, moduleControl.ControlSrc, moduleControl.IconFile, Convert.ToInt32(moduleControl.ControlType), moduleControl.ViewOrder, moduleControl.HelpURL, moduleControl.SupportsPartialRendering, UserController.GetCurrentUserInfo().UserID);
     }
     else
     {
         dataProvider.UpdateModuleControl(moduleControl.ModuleControlID, moduleControl.ModuleDefID, moduleControl.ControlKey, moduleControl.ControlTitle, moduleControl.ControlSrc, moduleControl.IconFile, Convert.ToInt32(moduleControl.ControlType), moduleControl.ViewOrder, moduleControl.HelpURL, moduleControl.SupportsPartialRendering,
         UserController.GetCurrentUserInfo().UserID);
     }
     if (clearCache)
     {
         DataCache.ClearHostCache(true);
     }
     return moduleControlID;
 }
예제 #19
0
 private void cmdUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (Page.IsValid)
         {
             if (cboSource.SelectedIndex != 0 || !String.IsNullOrEmpty(txtSource.Text))
             {
                 var moduleControl = new ModuleControlInfo
                 {
                     ModuleControlID          = ModuleControlId,
                     ModuleDefID              = ModuleDefId,
                     ControlKey               = !String.IsNullOrEmpty(txtKey.Text) ? txtKey.Text : Null.NullString,
                     ControlTitle             = !String.IsNullOrEmpty(txtTitle.Text) ? txtTitle.Text : Null.NullString,
                     ControlSrc               = !String.IsNullOrEmpty(txtSource.Text) ? txtSource.Text : cboSource.SelectedItem.Text,
                     ControlType              = (SecurityAccessLevel)Enum.Parse(typeof(SecurityAccessLevel), cboType.SelectedItem.Value),
                     ViewOrder                = !String.IsNullOrEmpty(txtViewOrder.Text) ? int.Parse(txtViewOrder.Text) : Null.NullInteger,
                     IconFile                 = cboIcon.SelectedIndex > 0 ? cboIcon.SelectedItem.Text : Null.NullString,
                     HelpURL                  = !String.IsNullOrEmpty(txtHelpURL.Text) ? txtHelpURL.Text : Null.NullString,
                     SupportsPartialRendering = chkSupportsPartialRendering.Checked,
                     SupportsPopUps           = supportsModalPopUpsCheckBox.Checked
                 };
                 try
                 {
                     ModuleControlController.SaveModuleControl(moduleControl, true);
                 }
                 catch
                 {
                     UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("AddControl.ErrorMessage", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                     return;
                 }
                 Response.Redirect(ReturnURL, true);
             }
             else
             {
                 UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("MissingSource.ErrorMessage", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
             }
         }
     }
     catch (Exception exc)
     {
         Exceptions.ProcessModuleLoadException(this, exc);
     }
 }
        private static void ProcessControls(XPathNavigator controlNav, string moduleFolder, ModuleDefinitionInfo definition)
        {
            ModuleControlInfo moduleControl = new ModuleControlInfo();

            moduleControl.ControlKey   = Util.ReadElement(controlNav, "key");
            moduleControl.ControlTitle = Util.ReadElement(controlNav, "title");
            string ControlSrc = Util.ReadElement(controlNav, "src");

            if (!(ControlSrc.ToLower().StartsWith("desktopmodules") || !ControlSrc.ToLower().EndsWith(".ascx")))
            {
                ControlSrc = Path.Combine("DesktopModules", Path.Combine(moduleFolder, ControlSrc));
            }
            ControlSrc = ControlSrc.Replace('\\', '/');
            moduleControl.ControlSrc = ControlSrc;
            moduleControl.IconFile   = Util.ReadElement(controlNav, "iconfile");
            string controlType = Util.ReadElement(controlNav, "type");

            if (!string.IsNullOrEmpty(controlType))
            {
                try
                {
                    moduleControl.ControlType = (SecurityAccessLevel)TypeDescriptor.GetConverter(typeof(SecurityAccessLevel)).ConvertFromString(controlType);
                }
                catch (Exception ex)
                {
                    throw new Exception(Util.EXCEPTION_Type + ex.ToString());
                }
            }
            string viewOrder = Util.ReadElement(controlNav, "vieworder");

            if (!string.IsNullOrEmpty(viewOrder))
            {
                moduleControl.ViewOrder = int.Parse(viewOrder);
            }
            moduleControl.HelpURL = Util.ReadElement(controlNav, "helpurl");
            string supportsPartialRendering = Util.ReadElement(controlNav, "supportspartialrendering");

            if (!string.IsNullOrEmpty(supportsPartialRendering))
            {
                moduleControl.SupportsPartialRendering = bool.Parse(supportsPartialRendering);
            }
            definition.ModuleControls[moduleControl.ControlKey] = moduleControl;
        }
예제 #21
0
        private void EnsureEditScriptControlIsRegistered()
        {
            var moduleDefId = this.ParentModule.ModuleConfiguration.ModuleDefID;

            if (ReferenceEquals(ModuleControlController.GetModuleControlByControlKey("EditRazorScript", moduleDefId),
                                null))
            {
                var m = default(ModuleControlInfo);
                m = new ModuleControlInfo
                {
                    ControlKey   = "EditRazorScript",
                    ControlSrc   = "DesktopModules/RazorModules/RazorHost/EditScript.ascx",
                    ControlTitle = "Edit Script",
                    ControlType  = SecurityAccessLevel.Host,
                    ModuleDefID  = moduleDefId
                };
                ModuleControlController.UpdateModuleControl(m);
            }
        }
예제 #22
0
 public bool HasSettings(Page Page, ModuleInfo Module)
 {
     try
     {
         ModuleControlInfo moduleControlInfo = ModuleControlController.GetModuleControlByControlKey("Settings", Module.ModuleDefID);
         if (moduleControlInfo != null)
         {
             Control          _control        = ModuleControlPipeline.LoadSettingsControl(Page, Module, moduleControlInfo.ControlSrc);
             ISettingsControl settingsControl = _control as ISettingsControl;
             if (settingsControl != null)
             {
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
     }
     return(false);
 }
예제 #23
0
        protected ModuleControlBase LoadAdminControl(string controlKey)
        {
            ModuleControlInfo moduleControl = ModuleControlController.GetModuleControl(controlKey);

            if (moduleControl != null)
            {
                if (File.Exists(Server.MapPath(moduleControl.ControlPath)))
                {
                    try
                    {
                        ModuleControlBase controlToLoad = (ModuleControlBase)LoadControl(moduleControl.ControlPath);
                        controlToLoad.ControlID = moduleControl.ControlID;
                        return(controlToLoad);
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                    }
                }
            }
            return(null);
        }
예제 #24
0
        /// <summary>
        /// LoadDefinitions fetches the control data from the database
        /// </summary>
        /// <param name="ModuleDefId">The Module definition Id</param>
        /// <history>
        ///     [cnurse]	9/28/2004	Updated to reflect design changes for Help, 508 support
        ///                       and localisation
        /// </history>
        private void LoadControls(int ModuleDefId)
        {
            ModuleControlController objModuleControls = new ModuleControlController();
            ArrayList arrModuleControls = objModuleControls.GetModuleControls(ModuleDefId);

            if (DesktopModuleId == -2)
            {
                int intIndex;
                for (intIndex = arrModuleControls.Count - 1; intIndex >= 0; intIndex--)
                {
                    ModuleControlInfo objModuleControl = (ModuleControlInfo)arrModuleControls[intIndex];
                    if (objModuleControl.ControlType != SecurityAccessLevel.SkinObject)
                    {
                        arrModuleControls.RemoveAt(intIndex);
                    }
                }
            }

            grdControls.DataSource = arrModuleControls;
            grdControls.DataBind();

            cmdAddControl.Visible = true;
            grdControls.Visible   = true;
        }
 private void ReadModuleControls(XmlReader reader)
 {
     reader.ReadStartElement("moduleControls");
     do
     {
         reader.ReadStartElement("moduleControl");
         ModuleControlInfo moduleControl = new ModuleControlInfo();
         moduleControl.ReadXml(reader);
         ModuleControls.Add(moduleControl.ControlKey, moduleControl);
     } while (reader.ReadToNextSibling("moduleControl"));
 }
예제 #26
0
        /// <summary>
        /// Creates the Kastra view by returning a model to fill a template.
        /// </summary>
        /// <returns>The view model.</returns>
        /// <param name="moduleControlKeyName">Module control key name.</param>
        /// <param name="moduleId">Module identifier.</param>
        /// <param name="moduleAction">Module action.</param>
        public object CreateView(string moduleControlKeyName, int moduleId, string moduleAction)
        {
            PropertyInfo property = null;

            ModuleInfo          module        = null;
            ModuleControlInfo   moduleControl = null;
            ModuleDataComponent moduleData    = null;

            // Get template
            if (_page is null || _page.PageTemplate is null)
            {
                return(null);
            }

            TemplateInfo template = _page.PageTemplate;

            // Get the template model in cache
            string templateCacheKey = string.Format(
                TemplateConfiguration.TemplateModelTypeCacheKey,
                _page.PageId,
                moduleControlKeyName,
                moduleId,
                moduleAction
                );

            if (_cacheEngine.GetCacheObject(templateCacheKey, out object model))
            {
                return(model);
            }

            // Instanciate the template model
            Type type = KastraAssembliesContext.Instance.GetType(template.ModelClass);

            if (type is null)
            {
                throw new NullReferenceException($"Invalid template path for {template.ModelClass}");
            }

            model = Activator.CreateInstance(type);

            // Get places and complete the model with modules
            IList <PlaceInfo> places = template.Places.ToList();

            foreach (PlaceInfo place in places)
            {
                property = type.GetProperty(place.KeyName);

                // Get default module
                if (property is null || property.PropertyType != typeof(ModuleDataComponent))
                {
                    continue;
                }

                module = place.Modules?.SingleOrDefault(m =>
                                                        !m.IsDisabled &&
                                                        m.PlaceId == place.PlaceId &&
                                                        m.PageId == _page.PageId
                                                        );

                // If there is no module but if the place has a static module
                if (module is null && place.StaticModule is not null && !place.StaticModule.IsDisabled)
                {
                    module = place.StaticModule;
                }

                if (module is null)
                {
                    module = new ModuleInfo()
                    {
                        Place            = place,
                        ModuleDefinition = new ModuleDefinitionInfo()
                    };
                }

                moduleData = new ModuleDataComponent()
                {
                    Module       = module,
                    Page         = _page,
                    ModuleAction = moduleAction,
                    CacheEngine  = _cacheEngine
                };

                if (module.ModulePermissions is not null)
                {
                    moduleData.RequiredClaims = module.ModulePermissions
                                                .Where(mp => mp.Permission != null)
                                                .Select(mp => mp.Permission)
                                                .ToList();
                }

                // Get module control
                if (!string.IsNullOrEmpty(moduleControlKeyName) && moduleId > 0 && module.ModuleId == moduleId)
                {
                    moduleControl = module.ModuleDefinition.ModuleControls
                                    .SingleOrDefault(mc => mc.KeyName.ToLower() == moduleControlKeyName.ToLower());

                    if (moduleControl is not null)
                    {
                        moduleData.ModuleViewComponent = GetModelFullname(module.ModuleDefinition.Namespace, moduleControl.Path);
                    }
                    else
                    {
                        moduleData.ModuleViewComponent = GetModelFullname(module.ModuleDefinition.Namespace, module.ModuleDefinition.KeyName);
                    }
                }
                else
                {
                    moduleData.ModuleViewComponent = GetModelFullname(module.ModuleDefinition.Namespace, module.ModuleDefinition.KeyName);
                }

                // Set the place to find module
                property.SetValue(model, moduleData);
            }

            if (type is not null)
            {
                _cacheEngine.SetCacheObject(templateCacheKey, model);
            }

            return(model);
        }
예제 #27
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            try
            {
                chkAllTabs.CheckedChanged            += OnAllTabsCheckChanged;
                chkInheritPermissions.CheckedChanged += OnInheritPermissionsChanged;
                chkWebSlice.CheckedChanged           += OnWebSliceCheckChanged;
                cboCacheProvider.TextChanged         += OnCacheProviderIndexChanged;
                cmdDelete.Click += OnDeleteClick;
                cmdUpdate.Click += OnUpdateClick;

                JavaScript.RequestRegistration(CommonJs.DnnPlugins);

                //get ModuleId
                if ((Request.QueryString["ModuleId"] != null))
                {
                    _moduleId = Int32.Parse(Request.QueryString["ModuleId"]);
                }
                if (Module.ContentItemId == Null.NullInteger && Module.ModuleID != Null.NullInteger)
                {
                    //This tab does not have a valid ContentItem
                    ModuleController.Instance.CreateContentItem(Module);

                    ModuleController.Instance.UpdateModule(Module);
                }

                //Verify that the current user has access to edit this module
                if (!ModulePermissionController.HasModuleAccess(SecurityAccessLevel.Edit, "MANAGE", Module))
                {
                    if (!(IsSharedViewOnly() && TabPermissionController.CanAddContentToPage()))
                    {
                        Response.Redirect(Globals.AccessDeniedURL(), true);
                    }
                }
                if (Module != null)
                {
                    //get module
                    TabModuleId = Module.TabModuleID;

                    //get Settings Control
                    ModuleControlInfo moduleControlInfo = ModuleControlController.GetModuleControlByControlKey("Settings", Module.ModuleDefID);

                    if (moduleControlInfo != null)
                    {
                        _control = ModuleControlFactory.LoadSettingsControl(Page, Module, moduleControlInfo.ControlSrc);

                        var settingsControl = _control as ISettingsControl;
                        if (settingsControl != null)
                        {
                            hlSpecificSettings.Text = Localization.GetString("ControlTitle_settings",
                                                                             settingsControl.LocalResourceFile);
                            if (String.IsNullOrEmpty(hlSpecificSettings.Text))
                            {
                                hlSpecificSettings.Text =
                                    String.Format(Localization.GetString("ControlTitle_settings", LocalResourceFile),
                                                  Module.DesktopModule.FriendlyName);
                            }
                            pnlSpecific.Controls.Add(_control);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Exceptions.ProcessModuleLoadException(this, err);
            }
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            chkAllTabs.CheckedChanged            += OnAllTabsCheckChanged;
            chkInheritPermissions.CheckedChanged += OnInheritPermissionsChanged;
            chkWebSlice.CheckedChanged           += OnWebSliceCheckChanged;
            cboCacheProvider.TextChanged         += OnCacheProviderIndexChanged;
            cmdDelete.Click         += OnDeleteClick;
            cmdUpdate.Click         += OnUpdateClick;
            dgOnTabs.NeedDataSource += OnPagesGridNeedDataSource;

            jQuery.RequestDnnPluginsRegistration();

            //get ModuleId
            if ((Request.QueryString["ModuleId"] != null))
            {
                _moduleId = Int32.Parse(Request.QueryString["ModuleId"]);
            }
            if (Module.ContentItemId == Null.NullInteger && Module.ModuleID != Null.NullInteger)
            {
                //This tab does not have a valid ContentItem
                ModuleController.Instance.CreateContentItem(Module);

                ModuleController.Instance.UpdateModule(Module);
            }

            //Verify that the current user has access to edit this module
            if (!ModulePermissionController.HasModuleAccess(SecurityAccessLevel.Edit, "MANAGE", Module))
            {
                if (!(IsSharedViewOnly() && TabPermissionController.CanAddContentToPage()))
                {
                    Response.Redirect(Globals.AccessDeniedURL(), true);
                }
            }
            if (Module != null)
            {
                //get module
                TabModuleId = Module.TabModuleID;

                //get Settings Control
                ModuleControlInfo moduleControlInfo = ModuleControlController.GetModuleControlByControlKey("Settings", Module.ModuleDefID);

                if (moduleControlInfo != null)
                {
                    _control = ControlUtilities.LoadControl <Control>(Page, moduleControlInfo.ControlSrc);

                    var settingsControl = _control as ISettingsControl;
                    if (settingsControl != null)
                    {
                        //Set ID
                        var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(moduleControlInfo.ControlSrc);
                        if (fileNameWithoutExtension != null)
                        {
                            _control.ID = fileNameWithoutExtension.Replace('.', '-');
                        }

                        //add module settings
                        settingsControl.ModuleContext.Configuration = Module;

                        hlSpecificSettings.Text = Localization.GetString("ControlTitle_settings", settingsControl.LocalResourceFile);
                        if (String.IsNullOrEmpty(hlSpecificSettings.Text))
                        {
                            hlSpecificSettings.Text = String.Format(Localization.GetString("ControlTitle_settings", LocalResourceFile), Module.DesktopModule.FriendlyName);
                        }
                        pnlSpecific.Controls.Add(_control);
                    }
                }
            }
        }
예제 #29
0
        /// <summary>
        /// </summary>
        /// <remarks>
        /// Loads the cboSource control list with locations of controls.
        /// </remarks>
        /// <history>
        /// </history>
        private ModuleDefinitionInfo ImportControl(string controlSrc)
        {
            ModuleDefinitionInfo moduleDefinition = null;

            try
            {
                string folder        = PathUtils.Instance.RemoveTrailingSlash(GetSourceFolder());
                string friendlyName  = txtName.Text;
                string name          = GetClassName();
                string moduleControl = "DesktopModules/" + folder + "/" + controlSrc;

                var packageInfo = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.Name == name || p.FriendlyName == friendlyName);
                if (packageInfo != null)
                {
                    UI.Skins.Skin.AddModuleMessage(this, String.Format(Localization.GetString("NonuniqueNameModule", LocalResourceFile), packageInfo.FriendlyName), ModuleMessage.ModuleMessageType.RedError);
                }
                else
                {
                    var package = new PackageInfo
                    {
                        Name         = name,
                        FriendlyName = friendlyName,
                        Description  = txtDescription.Text,
                        Version      = new Version(1, 0, 0),
                        PackageType  = "Module",
                        License      = Util.PACKAGE_NoLicense
                    };

                    //Save Package
                    PackageController.Instance.SaveExtensionPackage(package);

                    var objDesktopModule = new DesktopModuleInfo
                    {
                        DesktopModuleID         = Null.NullInteger,
                        ModuleName              = name,
                        FolderName              = folder,
                        FriendlyName            = friendlyName,
                        Description             = txtDescription.Text,
                        IsPremium               = false,
                        IsAdmin                 = false,
                        Version                 = "01.00.00",
                        BusinessControllerClass = "",
                        CompatibleVersions      = "",
                        Dependencies            = "",
                        Permissions             = "",
                        PackageID               = package.PackageID
                    };

                    objDesktopModule.DesktopModuleID = DesktopModuleController.SaveDesktopModule(objDesktopModule, false, true);

                    //Add module to all portals
                    DesktopModuleController.AddDesktopModuleToPortals(objDesktopModule.DesktopModuleID);

                    //Save module definition
                    moduleDefinition = new ModuleDefinitionInfo();

                    moduleDefinition.ModuleDefID      = Null.NullInteger;
                    moduleDefinition.DesktopModuleID  = objDesktopModule.DesktopModuleID;
                    moduleDefinition.FriendlyName     = friendlyName;
                    moduleDefinition.DefaultCacheTime = 0;

                    moduleDefinition.ModuleDefID = ModuleDefinitionController.SaveModuleDefinition(moduleDefinition, false, true);

                    //Save module control
                    var objModuleControl = new ModuleControlInfo();

                    objModuleControl.ModuleControlID          = Null.NullInteger;
                    objModuleControl.ModuleDefID              = moduleDefinition.ModuleDefID;
                    objModuleControl.ControlKey               = "";
                    objModuleControl.ControlSrc               = moduleControl;
                    objModuleControl.ControlTitle             = "";
                    objModuleControl.ControlType              = SecurityAccessLevel.View;
                    objModuleControl.HelpURL                  = "";
                    objModuleControl.IconFile                 = "";
                    objModuleControl.ViewOrder                = 0;
                    objModuleControl.SupportsPartialRendering = false;

                    ModuleControlController.AddModuleControl(objModuleControl);
                }
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("ImportControl.ErrorMessage", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
            }
            return(moduleDefinition);
        }
예제 #30
0
        private string CreateModuleControl()
        {
            var objModuleControl    = ModuleControlController.GetModuleControl(ModuleControlId);
            var objModuleDefinition = ModuleDefinitionController.GetModuleDefinitionByID(objModuleControl.ModuleDefID);
            var objDesktopModule    = DesktopModuleController.GetDesktopModule(objModuleDefinition.DesktopModuleID, PortalId);
            var objPackage          = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == objDesktopModule.PackageID);

            var moduleTemplatePath = Server.MapPath(ControlPath) + "Templates\\" + optLanguage.SelectedValue + "\\" + cboTemplate.SelectedValue + "\\";


            EventLogController.Instance.AddLog("Processing Template Folder", moduleTemplatePath, PortalSettings, -1, EventLogController.EventLogType.HOST_ALERT);


            var controlName = Null.NullString;
            var fileName    = Null.NullString;
            var modulePath  = Null.NullString;
            var sourceCode  = Null.NullString;

            //iterate through files in template folder
            string[] fileList = Directory.GetFiles(moduleTemplatePath);
            foreach (string filePath in fileList)
            {
                modulePath = Server.MapPath("DesktopModules/" + objDesktopModule.FolderName + "/");

                //open file
                using (TextReader tr = new StreamReader(filePath))
                {
                    sourceCode = tr.ReadToEnd();
                    tr.Close();
                }

                //replace tokens
                var owner = objPackage.Owner.Replace(" ", "");
                if (string.IsNullOrEmpty(owner))
                {
                    owner = "DNN";
                }
                sourceCode = sourceCode.Replace("_OWNER_", owner);
                sourceCode = sourceCode.Replace("_MODULE_", objDesktopModule.FriendlyName.Replace(" ", ""));
                sourceCode = sourceCode.Replace("_CONTROL_", GetControl());
                sourceCode = sourceCode.Replace("_YEAR_", DateTime.Now.Year.ToString());

                //get filename
                fileName = Path.GetFileName(filePath);
                fileName = fileName.Replace("template", GetControl());
                fileName = fileName.Replace("_OWNER_", objPackage.Owner.Replace(" ", ""));
                fileName = fileName.Replace("_MODULE_", objDesktopModule.FriendlyName.Replace(" ", ""));
                fileName = fileName.Replace("_CONTROL_", GetControl());

                switch (Path.GetExtension(filePath).ToLower())
                {
                case ".ascx":
                    controlName = fileName;
                    break;

                case ".vbhtml":
                    controlName = fileName;
                    break;

                case ".cshtml":
                    controlName = fileName;
                    break;

                case ".resx":
                    modulePath = modulePath + "\\App_LocalResources\\";
                    break;

                case ".vb":
                    if (filePath.ToLower().IndexOf(".ascx") == -1)
                    {
                        modulePath = modulePath.Replace("DesktopModules", "App_Code");
                    }
                    break;

                case ".cs":
                    if (filePath.ToLower().IndexOf(".ascx") == -1)
                    {
                        modulePath = modulePath.Replace("DesktopModules", "App_Code");
                    }
                    break;

                case ".js":
                    modulePath = modulePath + "\\js\\";
                    break;
                }

                //check if folder exists
                if (!Directory.Exists(modulePath))
                {
                    Directory.CreateDirectory(modulePath);
                }

                //check if file already exists
                if (!File.Exists(modulePath + fileName))
                {
                    //create file
                    using (TextWriter tw = new StreamWriter(modulePath + fileName))
                    {
                        tw.WriteLine(sourceCode);
                        tw.Close();
                    }

                    EventLogController.Instance.AddLog("Created File", modulePath + fileName, PortalSettings, -1, EventLogController.EventLogType.HOST_ALERT);
                }
            }

            //Create module control
            if (controlName != Null.NullString)
            {
                try
                {
                    objModuleControl = new ModuleControlInfo();
                    objModuleControl.ModuleControlID          = Null.NullInteger;
                    objModuleControl.ModuleDefID              = objModuleDefinition.ModuleDefID;
                    objModuleControl.ControlKey               = GetControl();
                    objModuleControl.ControlSrc               = "DesktopModules/" + objDesktopModule.FolderName + "/" + controlName;
                    objModuleControl.ControlTitle             = txtControl.Text;
                    objModuleControl.ControlType              = (SecurityAccessLevel)Enum.Parse(typeof(SecurityAccessLevel), cboType.SelectedItem.Value);
                    objModuleControl.HelpURL                  = "";
                    objModuleControl.IconFile                 = "";
                    objModuleControl.ViewOrder                = 0;
                    objModuleControl.SupportsPartialRendering = true;
                    objModuleControl.SupportsPopUps           = true;
                    ModuleControlController.AddModuleControl(objModuleControl);
                    controlName = objModuleControl.ControlSrc;
                }
                catch
                {
                    //Suppress error
                }
            }

            DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("ControlCreated", LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess);

            return(controlName);
        }
예제 #31
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded.
        /// </summary>
        /// <remarks>
        /// </remarks>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            cmdCancel.Click += cmdCancel_Click;
            int moduleControlId = Null.NullInteger;

            if (Request.QueryString["ctlid"] != null)
            {
                moduleControlId = Int32.Parse(Request.QueryString["ctlid"]);
            }
            else if (Host.EnableModuleOnLineHelp)
            {
                helpFrame.Text = string.Format("<iframe src='{0}' id='helpFrame' width='100%' height='500' />", Host.HelpURL);
            }

            ModuleControlInfo objModuleControl = ModuleControlController.GetModuleControl(moduleControlId);

            if (objModuleControl != null)
            {
                if (!string.IsNullOrEmpty(objModuleControl.HelpURL) && Host.EnableModuleOnLineHelp)
                {
                    helpFrame.Text = string.Format("<iframe src='{0}' id='helpFrame' width='100%' height='500' />", objModuleControl.HelpURL);;
                }
                else
                {
                    string fileName          = Path.GetFileName(objModuleControl.ControlSrc);
                    string localResourceFile = objModuleControl.ControlSrc.Replace(fileName, Localization.LocalResourceDirectory + "/" + fileName);
                    if (!String.IsNullOrEmpty(Localization.GetString(ModuleActionType.HelpText, localResourceFile)))
                    {
                        lblHelp.Text = Localization.GetString(ModuleActionType.HelpText, localResourceFile);
                    }
                    else
                    {
                        lblHelp.Text = Localization.GetString("lblHelp.Text", Localization.GetResourceFile(this, MyFileName));
                    }
                }

                _key = objModuleControl.ControlKey;
                //display module info to Host users
                if (UserInfo.IsSuperUser)
                {
                    string strInfo = Localization.GetString("lblInfo.Text", Localization.GetResourceFile(this, MyFileName));
                    strInfo = strInfo.Replace("[CONTROL]", objModuleControl.ControlKey);
                    strInfo = strInfo.Replace("[SRC]", objModuleControl.ControlSrc);
                    ModuleDefinitionInfo objModuleDefinition = ModuleDefinitionController.GetModuleDefinitionByID(objModuleControl.ModuleDefID);
                    if (objModuleDefinition != null)
                    {
                        strInfo = strInfo.Replace("[DEFINITION]", objModuleDefinition.FriendlyName);
                        DesktopModuleInfo objDesktopModule = DesktopModuleController.GetDesktopModule(objModuleDefinition.DesktopModuleID, PortalId);
                        if (objDesktopModule != null)
                        {
                            PackageInfo objPackage = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == objDesktopModule.PackageID);
                            if (objPackage != null)
                            {
                                strInfo = strInfo.Replace("[ORGANIZATION]", objPackage.Organization);
                                strInfo = strInfo.Replace("[OWNER]", objPackage.Owner);
                                strInfo = strInfo.Replace("[EMAIL]", objPackage.Email);
                                strInfo = strInfo.Replace("[URL]", objPackage.Url);
                                strInfo = strInfo.Replace("[MODULE]", objPackage.Name);
                                strInfo = strInfo.Replace("[VERSION]", objPackage.Version.ToString());
                            }
                        }
                    }
                    lblInfo.Text = Server.HtmlDecode(strInfo);
                }

                cmdHelp.Visible = !string.IsNullOrEmpty(objModuleControl.HelpURL);
            }
            if (Page.IsPostBack == false)
            {
                if (Request.UrlReferrer != null)
                {
                    ViewState["UrlReferrer"] = Convert.ToString(Request.UrlReferrer);
                }
                else
                {
                    ViewState["UrlReferrer"] = "";
                }
            }
        }
 public static void UpdateModuleControl(ModuleControlInfo objModuleControl)
 {
     SaveModuleControl(objModuleControl, true);
 }
예제 #33
0
        private static void AddModuleControl(int ModuleDefId, string ControlKey, string ControlTitle, string ControlSrc, string IconFile, SecurityAccessLevel ControlType, int ViewOrder, string HelpURL, bool SupportsPartialRendering)
        {

            // check if module control exists
            ModuleControlInfo objModuleControl = ModuleControlController.GetModuleControlByControlKey(ControlKey, ModuleDefId);
            if (objModuleControl == null)
            {
                objModuleControl = new ModuleControlInfo();

                objModuleControl.ModuleControlID = Null.NullInteger;
                objModuleControl.ModuleDefID = ModuleDefId;
                objModuleControl.ControlKey = ControlKey;
                objModuleControl.ControlTitle = ControlTitle;
                objModuleControl.ControlSrc = ControlSrc;
                objModuleControl.ControlType = ControlType;
                objModuleControl.ViewOrder = ViewOrder;
                objModuleControl.IconFile = IconFile;
                objModuleControl.SupportsPartialRendering = SupportsPartialRendering;

                ModuleControlController.AddModuleControl(objModuleControl);
            }
        }
예제 #34
0
        /// <summary>
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        private bool CreateModuleDefinition()
        {
            try
            {
                if (PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.Name == GetClassName()) == null)
                {
                    var controlName = Null.NullString;

                    //Create module folder
                    CreateModuleFolder();

                    //Create module control
                    controlName = CreateModuleControl();
                    if (controlName != "")
                    {
                        //Create package
                        var objPackage = new PackageInfo();
                        objPackage.Name         = GetClassName();
                        objPackage.FriendlyName = txtModule.Text;
                        objPackage.Description  = txtDescription.Text;
                        objPackage.Version      = new Version(1, 0, 0);
                        objPackage.PackageType  = "Module";
                        objPackage.License      = "";
                        objPackage.Owner        = txtOwner.Text;
                        objPackage.Organization = txtOwner.Text;
                        objPackage.FolderName   = "DesktopModules/" + GetFolderName();
                        objPackage.License      = "The license for this package is not currently included within the installation file, please check with the vendor for full license details.";
                        objPackage.ReleaseNotes = "This package has no Release Notes.";
                        PackageController.Instance.SaveExtensionPackage(objPackage);

                        //Create desktopmodule
                        var objDesktopModules = new DesktopModuleController();
                        var objDesktopModule  = new DesktopModuleInfo();
                        objDesktopModule.DesktopModuleID         = Null.NullInteger;
                        objDesktopModule.ModuleName              = GetClassName();
                        objDesktopModule.FolderName              = GetFolderName();
                        objDesktopModule.FriendlyName            = txtModule.Text;
                        objDesktopModule.Description             = txtDescription.Text;
                        objDesktopModule.IsPremium               = false;
                        objDesktopModule.IsAdmin                 = false;
                        objDesktopModule.Version                 = "01.00.00";
                        objDesktopModule.BusinessControllerClass = "";
                        objDesktopModule.CompatibleVersions      = "";
                        objDesktopModule.Dependencies            = "";
                        objDesktopModule.Permissions             = "";
                        objDesktopModule.PackageID               = objPackage.PackageID;
                        objDesktopModule.DesktopModuleID         = objDesktopModules.AddDesktopModule(objDesktopModule);
                        objDesktopModule = objDesktopModules.GetDesktopModule(objDesktopModule.DesktopModuleID);

                        //Add OwnerName to the DesktopModule taxonomy and associate it with this module
                        var vocabularyId      = -1;
                        var termId            = -1;
                        var objTermController = DotNetNuke.Entities.Content.Common.Util.GetTermController();
                        var objTerms          = objTermController.GetTermsByVocabulary("Module_Categories");
                        foreach (Term term in objTerms)
                        {
                            vocabularyId = term.VocabularyId;
                            if (term.Name == txtOwner.Text)
                            {
                                termId = term.TermId;
                            }
                        }
                        if (termId == -1)
                        {
                            termId = objTermController.AddTerm(new Term(vocabularyId)
                            {
                                Name = txtOwner.Text
                            });
                        }
                        var objTerm = objTermController.GetTerm(termId);
                        var objContentController = DotNetNuke.Entities.Content.Common.Util.GetContentController();
                        var objContent           = objContentController.GetContentItem(objDesktopModule.ContentItemId);
                        objTermController.AddTermToContent(objTerm, objContent);

                        //Add desktopmodule to all portals
                        DesktopModuleController.AddDesktopModuleToPortals(objDesktopModule.DesktopModuleID);

                        //Create module definition
                        var objModuleDefinition = new ModuleDefinitionInfo();
                        objModuleDefinition.ModuleDefID     = Null.NullInteger;
                        objModuleDefinition.DesktopModuleID = objDesktopModule.DesktopModuleID;
                        // need core enhancement to have a unique DefinitionName
                        objModuleDefinition.FriendlyName = GetClassName();
                        //objModuleDefinition.FriendlyName = txtModule.Text;
                        //objModuleDefinition.DefinitionName = GetClassName();
                        objModuleDefinition.DefaultCacheTime = 0;
                        objModuleDefinition.ModuleDefID      = ModuleDefinitionController.SaveModuleDefinition(objModuleDefinition, false, true);

                        //Create modulecontrol
                        var objModuleControl = new ModuleControlInfo();
                        objModuleControl.ModuleControlID          = Null.NullInteger;
                        objModuleControl.ModuleDefID              = objModuleDefinition.ModuleDefID;
                        objModuleControl.ControlKey               = "";
                        objModuleControl.ControlSrc               = "DesktopModules/" + GetFolderName() + "/" + controlName;
                        objModuleControl.ControlTitle             = "";
                        objModuleControl.ControlType              = SecurityAccessLevel.View;
                        objModuleControl.HelpURL                  = "";
                        objModuleControl.IconFile                 = "";
                        objModuleControl.ViewOrder                = 0;
                        objModuleControl.SupportsPartialRendering = false;
                        objModuleControl.SupportsPopUps           = false;
                        ModuleControlController.AddModuleControl(objModuleControl);

                        //Update current module to reference new moduledefinition
                        var objModules = new ModuleController();
                        var objModule  = objModules.GetModule(ModuleId, TabId, false);
                        objModule.ModuleDefID = objModuleDefinition.ModuleDefID;
                        objModule.ModuleTitle = txtModule.Text;

                        //HACK - need core enhancement to be able to update ModuleDefID
                        DotNetNuke.Data.DataProvider.Instance().ExecuteSQL("Update dbo.Modules set ModuleDefID = " + objModule.ModuleDefID.ToString() + " where ModuleID = " + ModuleId.ToString());

                        objModules.UpdateModule(objModule);

                        return(true);
                    }
                    else
                    {
                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("TemplateProblem.ErrorMessage", LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning);
                        return(false);
                    }
                }
                else
                {
                    DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("AlreadyExists.ErrorMessage", LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning);
                    return(false);
                }
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
                DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, exc.ToString(), ModuleMessage.ModuleMessageType.RedError);
                return(false);
            }
        }
 private static void ProcessControls(XPathNavigator controlNav, string moduleFolder, ModuleDefinitionInfo definition)
 {
     ModuleControlInfo moduleControl = new ModuleControlInfo();
     moduleControl.ControlKey = Util.ReadElement(controlNav, "key");
     moduleControl.ControlTitle = Util.ReadElement(controlNav, "title");
     string ControlSrc = Util.ReadElement(controlNav, "src");
     if (!(ControlSrc.ToLower().StartsWith("desktopmodules") || !ControlSrc.ToLower().EndsWith(".ascx")))
     {
         ControlSrc = Path.Combine("DesktopModules", Path.Combine(moduleFolder, ControlSrc));
     }
     ControlSrc = ControlSrc.Replace('\\', '/');
     moduleControl.ControlSrc = ControlSrc;
     moduleControl.IconFile = Util.ReadElement(controlNav, "iconfile");
     string controlType = Util.ReadElement(controlNav, "type");
     if (!string.IsNullOrEmpty(controlType))
     {
         try
         {
             moduleControl.ControlType = (SecurityAccessLevel)TypeDescriptor.GetConverter(typeof(SecurityAccessLevel)).ConvertFromString(controlType);
         }
         catch (Exception ex)
         {
             throw new Exception(Util.EXCEPTION_Type + ex.ToString());
         }
     }
     string viewOrder = Util.ReadElement(controlNav, "vieworder");
     if (!string.IsNullOrEmpty(viewOrder))
     {
         moduleControl.ViewOrder = int.Parse(viewOrder);
     }
     moduleControl.HelpURL = Util.ReadElement(controlNav, "helpurl");
     string supportsPartialRendering = Util.ReadElement(controlNav, "supportspartialrendering");
     if (!string.IsNullOrEmpty(supportsPartialRendering))
     {
         moduleControl.SupportsPartialRendering = bool.Parse(supportsPartialRendering);
     }
     definition.ModuleControls[moduleControl.ControlKey] = moduleControl;
 }