Exemplo n.º 1
0
 protected void rptControls_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         var control = e.Item.DataItem as DashboardControl;
         if (control != null)
         {
             Control dashboardControl;
             if (control.DashboardControlSrc.ToLowerInvariant().EndsWith("ascx"))
             {
                 //load from a user control on the file system
                 dashboardControl = LoadControl("~/" + control.DashboardControlSrc);
             }
             else
             {
                 //load from a typename in an assembly ( ie. server control )
                 dashboardControl = LoadControl(Reflection.CreateType(control.DashboardControlSrc), null);
             }
             dashboardControl.ID = Path.GetFileNameWithoutExtension(control.DashboardControlSrc);
             var placeHolder = (PlaceHolder)e.Item.FindControl("phControl");
             placeHolder.Controls.Add(dashboardControl);
         }
     }
 }
Exemplo n.º 2
0
        private void DoAddExistingModule(int moduleId, int tabId, string paneName, int position, string align, bool cloneModule)
        {
            ModuleInfo moduleInfo = ModuleController.Instance.GetModule(moduleId, tabId, false);

            int userID = -1;

            if (this.Request.IsAuthenticated)
            {
                UserInfo user = UserController.Instance.GetCurrentUserInfo();
                if (user != null)
                {
                    userID = user.UserID;
                }
            }

            if (moduleInfo != null)
            {
                // Is this from a site other than our own? (i.e., is the user requesting "module sharing"?)
                var remote = moduleInfo.PortalID != PortalSettings.Current.PortalId;
                if (remote)
                {
                    switch (moduleInfo.DesktopModule.Shareable)
                    {
                    case ModuleSharing.Unsupported:
                        // Should never happen since the module should not be listed in the first place.
                        throw new ApplicationException(string.Format(
                                                           "Module '{0}' does not support Shareable and should not be listed in Add Existing Module from a different source site",
                                                           moduleInfo.DesktopModule.FriendlyName));

                    case ModuleSharing.Supported:
                        break;

                    default:
                    case ModuleSharing.Unknown:
                        break;
                    }
                }

                // clone the module object ( to avoid creating an object reference to the data cache )
                ModuleInfo newModule = moduleInfo.Clone();

                newModule.UniqueId    = Guid.NewGuid(); // Cloned Module requires a different uniqueID
                newModule.TabModuleID = Null.NullInteger;
                newModule.TabID       = PortalSettings.Current.ActiveTab.TabID;
                newModule.ModuleOrder = position;
                newModule.PaneName    = paneName;
                newModule.Alignment   = align;

                if (cloneModule)
                {
                    newModule.ModuleID = Null.NullInteger;

                    // copy module settings and tab module settings
                    newModule.ModuleSettings.Clear();
                    foreach (var key in moduleInfo.ModuleSettings.Keys)
                    {
                        newModule.ModuleSettings.Add(key, moduleInfo.ModuleSettings[key]);
                    }

                    newModule.TabModuleSettings.Clear();
                    foreach (var key in moduleInfo.TabModuleSettings.Keys)
                    {
                        newModule.TabModuleSettings.Add(key, moduleInfo.TabModuleSettings[key]);
                    }

                    // reset the module id
                    newModule.ModuleID = ModuleController.Instance.AddModule(newModule);

                    if (!string.IsNullOrEmpty(newModule.DesktopModule.BusinessControllerClass))
                    {
                        object objObject = Reflection.CreateObject(newModule.DesktopModule.BusinessControllerClass, newModule.DesktopModule.BusinessControllerClass);
                        if (objObject is IPortable)
                        {
                            try
                            {
                                SetCloneModuleContext(true);
                                string content = Convert.ToString(((IPortable)objObject).ExportModule(moduleId));
                                if (!string.IsNullOrEmpty(content))
                                {
                                    ((IPortable)objObject).ImportModule(newModule.ModuleID, content, newModule.DesktopModule.Version, userID);
                                }
                            }
                            finally
                            {
                                SetCloneModuleContext(false);
                            }
                        }
                    }
                }
                else
                {
                    // copy tab module settings
                    newModule.TabModuleSettings.Clear();
                    foreach (var key in moduleInfo.TabModuleSettings.Keys)
                    {
                        newModule.TabModuleSettings.Add(key, moduleInfo.TabModuleSettings[key]);
                    }

                    ModuleController.Instance.AddModule(newModule);
                }

                if (remote)
                {
                    // Ensure the Portal Admin has View rights
                    var       permissionController           = new PermissionController();
                    ArrayList arrSystemModuleViewPermissions = permissionController.GetPermissionByCodeAndKey("SYSTEM_MODULE_DEFINITION", "VIEW");
                    AddModulePermission(
                        newModule,
                        (PermissionInfo)arrSystemModuleViewPermissions[0],
                        PortalSettings.Current.AdministratorRoleId,
                        Null.NullInteger,
                        true);

                    // Set PortalID correctly
                    newModule.OwnerPortalID = newModule.PortalID;
                    newModule.PortalID      = PortalSettings.Current.PortalId;
                    ModulePermissionController.SaveModulePermissions(newModule);
                }

                // Add Event Log
                EventLogController.Instance.AddLog(newModule, PortalSettings.Current, userID, string.Empty, EventLogController.EventLogType.MODULE_CREATED);
            }
        }