示例#1
0
        // this upgrade is for anything prior to 03.01.02 which is the re-branding release
        // that removes all references to Gooddogs Repository Module.
        public static string CustomUpgradeGRM3toDRM3()
        {
            string m_message = "";

            try {
                PortalSettings          _portalSettings          = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
                DesktopModuleController _desktopModuleController = new DesktopModuleController();

                if ((DesktopModuleController.GetDesktopModuleByModuleName("Gooddogs Repository", Null.NullInteger) == null))
                {
                    return("Gooddogs Repository Not installed - no upgrade required");
                }

                ModuleDefinitionController _moduleDefinitionControler = new ModuleDefinitionController();
                int OldRepositoryDefId = ModuleDefinitionController.GetModuleDefinitionByDefinitionName("Gooddogs Repository", DesktopModuleController.GetDesktopModuleByModuleName("Gooddogs Repository", Null.NullInteger).DesktopModuleID).ModuleDefID;
                int OldDashboardDefId  = ModuleDefinitionController.GetModuleDefinitionByDefinitionName("Gooddogs Dashboard", DesktopModuleController.GetDesktopModuleByModuleName("Gooddogs Dashboard", Null.NullInteger).DesktopModuleID).ModuleDefID;
                int NewRepositoryDefId = ModuleDefinitionController.GetModuleDefinitionByDefinitionName("Repository", DesktopModuleController.GetDesktopModuleByModuleName("Repository", Null.NullInteger).DesktopModuleID).ModuleDefID;
                int NewDashboardDefId  = ModuleDefinitionController.GetModuleDefinitionByDefinitionName("Repository Dashboard", DesktopModuleController.GetDesktopModuleByModuleName("Repository Dashboard", Null.NullInteger).DesktopModuleID).ModuleDefID;


                RepositoryController m_repositoryController = new RepositoryController();

                ModuleInfo       _moduleInfo       = null;
                ModuleController _moduleController = new ModuleController();

                // replace all Gooddogs Repository controls with the new Repository controls
                ArrayList _allModules = _moduleController.GetAllModules();

                foreach (ModuleInfo mi in _allModules)
                {
                    if (mi.ModuleDefID == OldRepositoryDefId)
                    {
                        m_repositoryController.ChangeRepositoryModuleDefId(mi.ModuleID, mi.ModuleDefID, NewRepositoryDefId);
                    }

                    if (mi.ModuleDefID == OldDashboardDefId)
                    {
                        m_repositoryController.ChangeRepositoryModuleDefId(mi.ModuleID, mi.ModuleDefID, NewDashboardDefId);
                    }
                }

                // we're all done .. so now we can remove the old Gooddogs Repository and Gooddogs Dashboard modules
                m_repositoryController.DeleteRepositoryModuleDefId(OldRepositoryDefId);
                m_repositoryController.DeleteRepositoryModuleDefId(OldDashboardDefId);
            } catch (Exception ex) {
                m_message += "EXCEPTION: " + ex.Message + " - " + ex.StackTrace.ToString();
            }
            m_message += "All Modules upgraded from GRM3 to DRM3";
            return(m_message);
        }
        private void BindObjectList()
        {
            RepositoryController objRepository = new RepositoryController();

            DataSet  ds = new DataSet();
            DataView dv = null;

            if (string.IsNullOrEmpty(mSortOrder))
            {
                mSortOrder = "UpdatedDate";
            }


            try {
                lstObjects.DataSource = objRepository.GetRepositoryObjects(ModuleId, "", mSortOrder, oRepositoryBusinessController.NOT_APPROVED, -1, "", -1);
                lstObjects.DataBind();

                PagerText.Text = string.Format(Localization.GetString("Pager", LocalResourceFile), (lstObjects.CurrentPageIndex + 1).ToString(), lstObjects.PageCount.ToString());

                if (lstObjects.CurrentPageIndex == 0)
                {
                    lnkPrev.Enabled = false;
                }
                else
                {
                    lnkPrev.Enabled = true;
                }
                if (lstObjects.CurrentPageIndex < lstObjects.PageCount - 1)
                {
                    lnkNext.Enabled = true;
                }
                else
                {
                    lnkNext.Enabled = false;
                }
                CurrentObjectID = -1;

                if (lstObjects.Items.Count == 0)
                {
                    // no records
                    lstObjects.Visible   = false;
                    lblNoRecords.Visible = true;
                }
            } catch (Exception ex) {
            }
        }
示例#3
0
        // ///
        // /// CusomtUpgrade315:
        // /// This upgrade deals with changing the author info as stored from username to userid
        // /// because of this user folders where files are stored will change from the user's username to the
        // /// user's id. The sql script will handle updating the tables, but we need this upgrade function
        // /// to change the name of the folder where each users files have been stored.
        // ///
        // /// cycle through all the repository modules. if they are using user folders, get the root location, then
        // /// rename all the user folders
        // ///
        public static string CustomUpgrade315()
        {
            string    m_message    = "";
            Hashtable settings     = null;
            string    m_foldername = null;

            string[] m_Folders    = null;
            string   m_Folder     = null;
            string   m_userFolder = null;
            string   m_newFolder  = null;

            DotNetNuke.Entities.Users.UserController m_userController = new DotNetNuke.Entities.Users.UserController();
            DotNetNuke.Entities.Users.UserInfo       m_userInfo       = null;

            try {
                PortalSettings          _portalSettings          = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
                DesktopModuleController _desktopModuleController = new DesktopModuleController();

                if ((DesktopModuleController.GetDesktopModuleByModuleName("Repository", Null.NullInteger) == null))
                {
                    return("No existing Repository modules found - no upgrade required");
                }

                RepositoryController repositories = new RepositoryController();
                ArrayList            arrModules   = new ArrayList();
                ModuleInfo           objModule    = null;
                arrModules = repositories.GetRepositoryModules(_portalSettings.PortalId);

                foreach (ModuleInfo objModule_loopVariable in arrModules)
                {
                    objModule = objModule_loopVariable;
                    // get the module settings
                    settings = objModule.ModuleSettings;

                    // if this module is using UserFolders...

                    if (!string.IsNullOrEmpty(Convert.ToString(settings["userfolders"])))
                    {
                        // then get the base folder name
                        if (!string.IsNullOrEmpty(Convert.ToString(settings["folderlocation"])))
                        {
                            m_foldername = Convert.ToString(settings["folderlocation"]);

                            // look in the base folder for any user folders
                            m_Folders = Directory.GetDirectories(m_foldername);

                            foreach (string m_Folder_loopVariable in m_Folders)
                            {
                                m_Folder     = m_Folder_loopVariable;
                                m_userFolder = m_Folder.Substring(m_Folder.LastIndexOf("\\") + 1);
                                m_userInfo   = DotNetNuke.Entities.Users.UserController.GetUserByName(objModule.PortalID, m_userFolder);

                                if ((m_userInfo != null))
                                {
                                    // we have a user folder, change the folder name to be the userid
                                    m_newFolder = m_Folder.Substring(0, m_Folder.LastIndexOf("\\") + 1) + m_userInfo.UserID.ToString();
                                    Directory.Move(m_Folder, m_newFolder);
                                }
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                m_message += "EXCEPTION: " + ex.Message + " - " + ex.StackTrace.ToString();
            }

            m_message += "All DRM3 Modules upgraded to 3.1.5";
            return(m_message);
        }
        private void Page_Load(System.Object sender, System.EventArgs e)
        {
            //Read the querystring params to determine the image to create a thumbnail
            string ImageId        = Request.QueryString["id"];
            string ModuleId       = Request.QueryString["mid"];
            int    imageHeight    = int.TryParse(Request.QueryString["h"], out imageHeight) ? imageHeight : 0;
            int    imageWidth     = int.TryParse(Request.QueryString["w"], out imageWidth) ? imageWidth : 0;
            string strPathToImage = "";
            string strExtension   = "";
            bool   b_UseIcon      = false;
            string sNoImage       = null;
            bool   bIsURL         = false;

            PortalSettings   _portalSettings   = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
            ModuleController _moduleController = new ModuleController();

            RepositoryController repository    = new RepositoryController();
            RepositoryInfo       objRepository = null;

            objRepository = repository.GetSingleRepositoryObject(Convert.ToInt32(ImageId));


            if (!string.IsNullOrEmpty(ImageId))
            {
                if ((objRepository != null))
                {
                    if (string.IsNullOrEmpty(objRepository.Image))
                    {
                        // no image, display an icon or generic image based on module settings
                        var moduleController = new ModuleController();
                        var moduleInfo       = moduleController.GetModule(int.Parse(ModuleId));
                        var settings         = moduleInfo.ModuleSettings;

                        if (!string.IsNullOrEmpty(Convert.ToString(settings["noimage"])))
                        {
                            strPathToImage = _portalSettings.HomeDirectory + Convert.ToString(settings["noimage"]);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(Convert.ToString(settings["useicon"])))
                            {
                                if (Convert.ToString(settings["useicon"]) == "Yes")
                                {
                                    // get the file type
                                    if ((objRepository != null))
                                    {
                                        strExtension = Strings.Replace(Path.GetExtension(objRepository.FileName), ".", "");
                                        if (File.Exists(MapPath(_portalSettings.HomeDirectory + strExtension + ".jpg")))
                                        {
                                            strPathToImage = _portalSettings.HomeDirectory + strExtension + ".jpg";
                                            b_UseIcon      = true;
                                        }
                                        if (File.Exists(MapPath(_portalSettings.HomeDirectory + strExtension + ".gif")))
                                        {
                                            strPathToImage = _portalSettings.HomeDirectory + strExtension + ".gif";
                                            b_UseIcon      = true;
                                        }
                                        if (File.Exists(MapPath(_portalSettings.HomeDirectory + strExtension + ".png")))
                                        {
                                            strPathToImage = _portalSettings.HomeDirectory + strExtension + ".png";
                                            b_UseIcon      = true;
                                        }
                                    }
                                    else
                                    {
                                        strPathToImage = _portalSettings.HomeDirectory + "Repository\\noImage.jpg";
                                    }
                                    if (b_UseIcon == false)
                                    {
                                        strPathToImage = _portalSettings.HomeDirectory + "Repository\\noImage.jpg";
                                    }
                                }
                                else
                                {
                                    strPathToImage = _portalSettings.HomeDirectory + "Repository\\noImage.jpg";
                                }
                            }
                            else
                            {
                                strPathToImage = _portalSettings.HomeDirectory + "Repository\\noImage.jpg";
                            }
                        }
                        strPathToImage = Request.MapPath(strPathToImage);
                    }
                    else
                    {
                        // we have an image, display it
                        if (objRepository.Image.ToLower().StartsWith("fileid="))
                        {
                            strPathToImage = oRepositoryBusinessController.ConvertFileIDtoPath(_portalSettings.PortalId, int.Parse(objRepository.Image.Substring(7)));
                        }
                        else
                        {
                            oRepositoryBusinessController.SetRepositoryFolders(objRepository.ModuleId);
                            if (objRepository.Approved == oRepositoryBusinessController.IS_APPROVED)
                            {
                                if (string.IsNullOrEmpty(objRepository.CreatedByUser))
                                {
                                    strPathToImage = oRepositoryBusinessController.g_AnonymousFolder + "\\" + objRepository.Image;
                                }
                                else
                                {
                                    if (oRepositoryBusinessController.g_UserFolders)
                                    {
                                        strPathToImage = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser.ToString() + "\\" + objRepository.Image;
                                    }
                                    else
                                    {
                                        strPathToImage = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.Image;
                                    }
                                }
                            }
                            else
                            {
                                strPathToImage = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.Image;
                            }
                        }
                    }
                }
            }
            else
            {
                // no image id, then we display the "No Image" image for this module
                var    moduleController = new ModuleController();
                var    moduleInfo       = moduleController.GetModule(int.Parse(ModuleId));
                var    settings         = moduleInfo.ModuleSettings;
                string noImageURL       = Convert.ToString(settings["noimage"]);
                if (System.Text.RegularExpressions.Regex.IsMatch(noImageURL.ToLower(), "(http|https|ftp|gopher)://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"))
                {
                    strPathToImage = noImageURL;
                    bIsURL         = true;
                }
                else
                {
                    strPathToImage = Server.MapPath(_portalSettings.HomeDirectory + noImageURL);
                }
            }

            // determine the image type
            string imageType = strPathToImage.Substring(strPathToImage.LastIndexOf(".")).ToUpper();

            System.Drawing.Image fullSizeImg = null;
            if (bIsURL)
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                Stream wStream          = null;
                wStream     = wc.OpenRead(strPathToImage);
                fullSizeImg = System.Drawing.Image.FromStream(wStream);
                wStream.Close();
            }
            else
            {
                fullSizeImg = System.Drawing.Image.FromFile(strPathToImage);
            }

            int fullHeight = fullSizeImg.Height;
            int fullWidth  = fullSizeImg.Width;

            if (imageWidth > 0 & imageHeight == 0)
            {
                // calc the height based on the width ratio
                imageHeight = (imageWidth * fullHeight) / fullWidth;
            }

            if (imageHeight > 0 & imageWidth == 0)
            {
                // calc the width based on the height ratio
                imageWidth = (imageHeight * fullWidth) / fullHeight;
            }

            if ((imageHeight == 0 & imageWidth == 0) | b_UseIcon)
            {
                imageHeight = fullHeight;
                imageWidth  = fullWidth;
            }

            Response.Clear();
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            System.Drawing.Image thumbNailImg = null;

            if (imageWidth < fullWidth | imageHeight < fullHeight)
            {
                // we are producing a resized image, most probably a thumbnail

                System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = null;
                dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                thumbNailImg  = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero);

                switch (imageType)
                {
                case ".JPG":
                    Response.ContentType = "image/jpeg";
                    thumbNailImg.Save(Response.OutputStream, ImageFormat.Jpeg);
                    break;

                case ".GIF":
                    Response.ContentType = "image/gif";
                    thumbNailImg.Save(Response.OutputStream, ImageFormat.Gif);
                    break;

                case ".PNG":
                    MemoryStream stmMemory = new MemoryStream();
                    Response.ContentType = "image/png";
                    thumbNailImg.Save(stmMemory, System.Drawing.Imaging.ImageFormat.Png);
                    stmMemory.WriteTo(Response.OutputStream);
                    break;
                }
            }
            else
            {
                // we are serving out the full size image
                // if the settings indicate to use a watermark, add the watermark to the image
                var moduleController = new ModuleController();
                var moduleInfo       = moduleController.GetModule(int.Parse(ModuleId));
                var settings         = moduleInfo.ModuleSettings;

                string watermarkText = "";

                // to avoid GIF image issues, create a new blank canvas and copy the image.
                Bitmap   newImage = new Bitmap(fullSizeImg.Width, fullSizeImg.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Graphics canvas   = Graphics.FromImage(newImage);
                canvas.DrawImage(fullSizeImg, new Rectangle(new Point(0, 0), fullSizeImg.Size));

                // check to see if we need to overlay a watermark

                if (!string.IsNullOrEmpty(Convert.ToString(settings["watermark"])))
                {
                    watermarkText = Convert.ToString(settings["watermark"]);

                    SizeF StringSizeF      = default(SizeF);
                    float DesiredWidth     = 0;
                    Font  wmFont           = null;
                    float RequiredFontSize = 0;
                    float Ratio            = 0;
                    wmFont       = new Font("Verdana", 6, FontStyle.Bold);
                    DesiredWidth = fullSizeImg.Width * 0.75f;

                    StringSizeF      = canvas.MeasureString(watermarkText, wmFont);
                    Ratio            = StringSizeF.Width / wmFont.SizeInPoints;
                    RequiredFontSize = DesiredWidth / Ratio;
                    wmFont           = new Font("Verdana", RequiredFontSize, FontStyle.Bold);

                    int wmLeft = (newImage.Width - canvas.MeasureString(watermarkText, wmFont).ToSize().Width) / 2;
                    int wmTop  = (newImage.Height - canvas.MeasureString(watermarkText, wmFont).ToSize().Height) / 2;

                    canvas.DrawString(watermarkText, wmFont, new SolidBrush(Color.FromArgb(128, 255, 255, 255)), wmLeft, wmTop);
                }

                switch (imageType)
                {
                case ".JPG":
                    Response.ContentType = "image/jpeg";
                    newImage.Save(Response.OutputStream, ImageFormat.Jpeg);
                    break;

                case ".GIF":
                    Response.ContentType = "image/gif";
                    newImage.Save(Response.OutputStream, ImageFormat.Gif);
                    break;

                case ".PNG":
                    MemoryStream stmMemory = new MemoryStream();
                    Response.ContentType = "image/png";
                    newImage.Save(stmMemory, System.Drawing.Imaging.ImageFormat.Png);
                    stmMemory.WriteTo(Response.OutputStream);
                    break;
                }
            }
        }
示例#5
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be imported</param>
        /// <history>
        ///		[cnurse]	11/17/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            string catString = null;

            string[] aCategories   = null;
            string   thisCategory  = null;
            int      newCategoryID = 0;
            int      newItemID     = 0;

            System.Collections.Specialized.NameValueCollection categoryMapping = new System.Collections.Specialized.NameValueCollection();
            System.Collections.Specialized.NameValueCollection objectMapping   = new System.Collections.Specialized.NameValueCollection();

            XmlNode xmlDocuments = DotNetNuke.Common.Globals.GetContent(Content, "repository");

            RepositoryController                 RepositoryController         = new RepositoryController();
            RepositoryCategoryController         CategoryController           = new RepositoryCategoryController();
            RepositoryObjectCategoriesController RepositoryCategoryController = new RepositoryObjectCategoriesController();
            RepositoryCommentController          RepositoryCommentController  = new RepositoryCommentController();

            RepositoryObjectCategoriesInfo RepositoryCategory = null;
            RepositoryCommentInfo          RepositoryComment  = null;

            // clear out any existing categories
            foreach (RepositoryCategoryInfo cat in CategoryController.GetRepositoryCategories(ModuleID, -1))
            {
                CategoryController.DeleteRepositoryCategory(cat.ItemId);
            }

            // add the categories
            foreach (XmlNode xmlDocument in xmlDocuments.SelectNodes("category"))
            {
                RepositoryCategoryInfo objCategory = new RepositoryCategoryInfo();
                objCategory.ItemId    = 0;
                objCategory.ModuleId  = ModuleID;
                objCategory.Category  = xmlDocument["category"].InnerText;
                objCategory.Parent    = int.Parse(xmlDocument["parent"].InnerText);
                objCategory.ViewOrder = int.Parse(xmlDocument["vieworder"].InnerText);
                objCategory.Count     = int.Parse(xmlDocument["count"].InnerText);
                if (objCategory.Parent == -1)
                {
                    newCategoryID = CategoryController.AddRepositoryCategory(0, objCategory.ModuleId, objCategory.Category, objCategory.Parent, objCategory.ViewOrder);
                }
                else
                {
                    newCategoryID = CategoryController.AddRepositoryCategory(0, objCategory.ModuleId, objCategory.Category, int.Parse(categoryMapping[objCategory.Parent.ToString()]), objCategory.ViewOrder);
                }
                categoryMapping.Add(xmlDocument["itemid"].InnerText, newCategoryID.ToString());
            }

            // add each item
            foreach (XmlNode xmlDocument in xmlDocuments.SelectNodes("item"))
            {
                RepositoryInfo objDocument = new RepositoryInfo();
                objDocument.ItemId        = 0;
                objDocument.ModuleId      = ModuleID;
                objDocument.CreatedByUser = xmlDocument["createdbyuser"].InnerText;
                objDocument.CreatedDate   = System.DateTime.Parse(xmlDocument["createddate"].InnerText);
                objDocument.UpdatedByUser = xmlDocument["updatedbyuser"].InnerText;
                objDocument.UpdatedDate   = System.DateTime.Parse(xmlDocument["updateddate"].InnerText);
                objDocument.Name          = xmlDocument["name"].InnerText;
                objDocument.Description   = xmlDocument["description"].InnerText;
                objDocument.Author        = xmlDocument["author"].InnerText;
                objDocument.AuthorEMail   = xmlDocument["authoremail"].InnerText;
                objDocument.FileSize      = xmlDocument["filesize"].InnerText;
                objDocument.Downloads     = int.Parse(xmlDocument["downloads"].InnerText);
                objDocument.PreviewImage  = xmlDocument["previewimage"].InnerText;
                objDocument.Image         = xmlDocument["image"].InnerText;
                objDocument.FileName      = xmlDocument["filename"].InnerText;
                objDocument.Clicks        = int.Parse(xmlDocument["clicks"].InnerText);
                objDocument.RatingVotes   = long.Parse(xmlDocument["ratingvotes"].InnerText);
                objDocument.RatingTotal   = long.Parse(xmlDocument["ratingtotal"].InnerText);
                objDocument.RatingAverage = double.Parse(xmlDocument["ratingaverage"].InnerText);
                objDocument.CommentCount  = int.Parse(xmlDocument["commentcount"].InnerText);
                objDocument.Approved      = int.Parse(xmlDocument["approved"].InnerText);
                objDocument.ShowEMail     = int.Parse(xmlDocument["showemail"].InnerText);
                objDocument.Summary       = xmlDocument["summary"].InnerText;
                objDocument.SecurityRoles = xmlDocument["securityroles"].InnerText;
                newItemID = RepositoryController.AddRepositoryObject(objDocument.UpdatedByUser.ToString(), ModuleID, objDocument);
                objectMapping.Add(xmlDocument["itemid"].InnerText, newItemID.ToString());
            }

            // add new items to new categories
            foreach (XmlNode xmlCatDocument in xmlDocuments.SelectNodes("item/categories/category"))
            {
                RepositoryCategory            = new RepositoryObjectCategoriesInfo();
                RepositoryCategory.ItemID     = 0;
                RepositoryCategory.CategoryID = int.Parse(categoryMapping[xmlCatDocument["categoryid"].InnerText]);
                RepositoryCategory.ObjectID   = int.Parse(objectMapping[xmlCatDocument["objectid"].InnerText]);
                RepositoryCategoryController.AddRepositoryObjectCategories(RepositoryCategory);
            }

            // add any comments
            foreach (XmlNode xmlComDocument in xmlDocuments.SelectNodes("item/comments/comment"))
            {
                RepositoryComment               = new RepositoryCommentInfo();
                RepositoryComment.ItemId        = 0;
                RepositoryComment.ObjectId      = int.Parse(objectMapping[xmlComDocument["objectid"].InnerText]);
                RepositoryComment.CreatedByUser = xmlComDocument["createdbyuser"].InnerText;
                RepositoryComment.CreatedDate   = System.DateTime.Parse(xmlComDocument["createddate"].InnerText);
                RepositoryComment.Comment       = xmlComDocument["comment"].InnerText;
                RepositoryCommentController.AddRepositoryComment(0, ModuleID, RepositoryComment.CreatedByUser, RepositoryComment.Comment);
            }
        }
        private void lstObjects_ItemCommand1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Table       objTable          = null;
            Table       objRejectionTable = null;
            Label       objLabel          = null;
            ImageButton objImageButton    = null;
            DataList    objDataList       = null;
            bool        bMovedFile        = false;
            bool        bMovedImage       = false;

            objTable          = (Table)e.Item.Cells[0].FindControl("ItemDetailsTable");
            objRejectionTable = (Table)objTable.Rows[0].Cells[0].FindControl("tblReject");

            RepositoryController        repository         = new RepositoryController();
            RepositoryCommentController repositoryComments = new RepositoryCommentController();
            RepositoryInfo objRepository = repository.GetSingleRepositoryObject(int.Parse(e.CommandArgument.ToString()));

            string sFileName  = null;
            string sImageName = null;

            try {
                sFileName  = objRepository.FileName;
                sImageName = objRepository.Image;
            } catch (Exception ex) {
                sFileName  = string.Empty;
                sImageName = string.Empty;
            }

            if (sFileName.ToLower().StartsWith("fileid="))
            {
                sFileName = oRepositoryBusinessController.ConvertFileIDtoFileName(PortalId, int.Parse(objRepository.FileName.Substring(7)));
            }
            if (sImageName.ToLower().StartsWith("fileid="))
            {
                sImageName = oRepositoryBusinessController.ConvertFileIDtoFileName(PortalId, int.Parse(objRepository.Image.Substring(7)));
            }

            switch (e.CommandName)
            {
            case "ViewFile":
                // admin wants to view the file
                oRepositoryBusinessController.DownloadFile(e.CommandArgument.ToString());

                break;

            case "Approve":
                repository.ApproveRepositoryObject(objRepository.ItemId);
                string strSourceFilename = "";
                string strImageFilename  = "";
                string strTargetFilename = "";
                oRepositoryBusinessController.SetRepositoryFolders(ModuleId);

                bMovedFile  = false;
                bMovedImage = false;

                // if this is an anonymous upload, move the file to the Anonymous folder,
                // otherwise, move it to the user's folder
                if (!objRepository.FileName.ToLower().StartsWith("fileid="))
                {
                    try {
                        strSourceFilename = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.FileName.ToString();
                        if (string.IsNullOrEmpty(objRepository.CreatedByUser))
                        {
                            strTargetFilename = oRepositoryBusinessController.g_AnonymousFolder + "\\" + objRepository.FileName.ToString();
                        }
                        else
                        {
                            if (oRepositoryBusinessController.g_UserFolders)
                            {
                                if (!Directory.Exists(oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser))
                                {
                                    Directory.CreateDirectory(oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser);
                                }
                                strTargetFilename = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser + "\\" + objRepository.FileName.ToString();
                            }
                            else
                            {
                                strTargetFilename = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.FileName.ToString();
                            }
                        }
                        if (strSourceFilename != strTargetFilename)
                        {
                            File.Copy(strSourceFilename, strTargetFilename, true);
                            File.SetAttributes(strSourceFilename, FileAttributes.Normal);
                            File.Delete(strSourceFilename);
                            bMovedFile = true;
                        }
                    } catch (Exception ex) {
                    }
                }

                if (!objRepository.Image.ToLower().StartsWith("fileid="))
                {
                    // move the image file from the Pending folder to the Users folder
                    try {
                        strImageFilename = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.Image.ToString();
                        if (string.IsNullOrEmpty(objRepository.CreatedByUser))
                        {
                            strTargetFilename = oRepositoryBusinessController.g_AnonymousFolder + "\\" + objRepository.Image.ToString();
                        }
                        else
                        {
                            if (oRepositoryBusinessController.g_UserFolders)
                            {
                                if (!Directory.Exists(oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser))
                                {
                                    Directory.CreateDirectory(oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser);
                                }
                                strTargetFilename = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser + "\\" + objRepository.Image.ToString();
                            }
                            else
                            {
                                strTargetFilename = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.Image.ToString();
                            }
                        }
                        if (strImageFilename != strTargetFilename)
                        {
                            File.Copy(strImageFilename, strTargetFilename, true);
                            File.SetAttributes(strImageFilename, FileAttributes.Normal);
                            File.Delete(strImageFilename);
                            bMovedImage = true;
                        }
                    } catch (Exception ex) {
                    }
                }

                UserInfo objModerator = UserController.Instance.GetCurrentUserInfo();
                string   strBody      = "";
                if (((objRepository != null)) & ((objModerator != null)))
                {
                    if (!string.IsNullOrEmpty(objRepository.AuthorEMail.ToString()))
                    {
                        strBody = objRepository.Author.ToString() + "," + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("TheFile", LocalResourceFile) + " (" + sFileName + ") " + Localization.GetString("ThatYouUploadedTo", LocalResourceFile) + " " + PortalSettings.PortalName + " " + Localization.GetString("HasBeenApprovedShort", LocalResourceFile) + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("PortalAddress", LocalResourceFile) + ": " + DotNetNuke.Common.Globals.GetPortalDomainName(PortalAlias.HTTPAlias, Request, false) + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("ThankYou", LocalResourceFile) + Constants.vbCrLf;
                        DotNetNuke.Services.Mail.Mail.SendMail(objModerator.Email, objRepository.AuthorEMail, "", PortalSettings.PortalName + ": " + Localization.GetString("HasBeenApprovedLong", LocalResourceFile), strBody, "", "html", "", "", "",
                                                               "");
                    }
                }

                BindObjectList();

                // sometimes IIS doesn't release a file immediately. So, if we get here and the original
                // source file still exits, try to delete it one more time before we leave.
                if (bMovedFile)
                {
                    try {
                        File.SetAttributes(strSourceFilename, FileAttributes.Normal);
                        File.Delete(strSourceFilename);
                    } catch (Exception ex) {
                    }
                }
                if (bMovedImage)
                {
                    try {
                        File.SetAttributes(strImageFilename, FileAttributes.Normal);
                        File.Delete(strImageFilename);
                    } catch (Exception ex) {
                    }
                }

                break;

            case "Reject":
                if (objRejectionTable.Visible == false)
                {
                    objRejectionTable.Visible = true;
                }
                else
                {
                    objRejectionTable.Visible = false;
                }

                break;

            case "SendRejection":
                UserInfo objSendRejectionModerator = UserController.Instance.GetCurrentUserInfo();
                strBody = "";
                TextBox txtComment       = null;
                string  strFileName      = null;
                string  strImageFileName = null;
                txtComment = (TextBox)objRejectionTable.Rows[1].Cells[0].FindControl("txtReason");
                if (((objRepository != null)) & ((objSendRejectionModerator != null)))
                {
                    if (!string.IsNullOrEmpty(objRepository.AuthorEMail.ToString()))
                    {
                        strBody = objRepository.Author.ToString() + "," + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("TheFile", LocalResourceFile) + " (" + sFileName + ") " + Localization.GetString("ThatYouUploadedTo", LocalResourceFile) + " " + PortalSettings.PortalName + " " + Localization.GetString("HasBeenRejectedShort", LocalResourceFile) + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("PortalAddress", LocalResourceFile) + ": " + DotNetNuke.Common.Globals.GetPortalDomainName(PortalAlias.HTTPAlias, Request, false) + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + txtComment.Text + Constants.vbCrLf + Constants.vbCrLf;
                        DotNetNuke.Services.Mail.Mail.SendMail(objSendRejectionModerator.Email, objRepository.AuthorEMail, "", PortalSettings.PortalName + ": " + Localization.GetString("HasBeenRejectedLong", LocalResourceFile), strBody, "", "html", "", "", "",
                                                               "");
                    }
                }

                // delete the files
                if (!objRepository.FileName.ToLower().StartsWith("fileid="))
                {
                    try {
                        strTargetFilename = "";
                        oRepositoryBusinessController.SetRepositoryFolders(ModuleId);
                        if (!string.IsNullOrEmpty(objRepository.FileName))
                        {
                            strFileName = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.FileName.ToString();
                            if (File.Exists(strFileName))
                            {
                                File.SetAttributes(strFileName, FileAttributes.Normal);
                                File.Delete(strFileName);
                            }
                        }
                    } catch (Exception ex) {
                    }
                }

                if (!objRepository.Image.ToLower().StartsWith("fileid="))
                {
                    try {
                        if (!string.IsNullOrEmpty(objRepository.Image))
                        {
                            strFileName = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.Image.ToString();
                            if (File.Exists(strFileName))
                            {
                                File.SetAttributes(strFileName, FileAttributes.Normal);
                                File.Delete(strFileName);
                            }
                        }
                    } catch (Exception ex) {
                    }
                }

                repository.DeleteRepositoryObject(objRepository.ItemId);
                BindObjectList();

                break;
            }
        }
示例#7
0
        private void Page_Load(System.Object sender, System.EventArgs e)
        {
            // Obtain PortalSettings from Current Context
            PortalSettings _portalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"];

            try {
                ModuleController  mc = new ModuleController();
                TabController     tc = new TabController();
                PackageController pc = new PackageController();


                // Get settings from the database
                var moduleInfo = ModuleController.Instance.GetModule(ModuleId, TabId, false);
                var settings   = moduleInfo.ModuleSettings;

                if ((Page.IsPostBack == false))
                {
                    lblMessage.Text = "";
                    // get a list of repository modules on this portal
                    ddlRepositoryID.Items.Clear();

                    RepositoryController repositories = new RepositoryController();
                    TabController        tabs         = new TabController();
                    TabInfo    objTab    = null;
                    ModuleInfo objModule = null;
                    ListItem   objItem   = null;

                    // get a list of all of the Repository Modules installed in this
                    // portal

                    ModuleDefinitionInfo repModInfo = ModuleDefinitionController.GetModuleDefinitionByFriendlyName("Repository");
                    PackageInfo          package    = PackageController.Instance.GetExtensionPackage(PortalId, m => m.Name == "DotNetNuke.Repository");
                    IDictionary <int, Entities.Tabs.TabInfo> tabsWithModule = tc.GetTabsByPackageID(PortalId, package.PackageID, false);

                    // first, get a list of all the tabs that contain at least one repository

                    foreach (Entities.Tabs.TabInfo tab in tabsWithModule.Values)
                    {
                        // for each tab, get the repository module info
                        Dictionary <int, ModuleInfo> modules = mc.GetTabModules(tab.TabID);
                        foreach (ModuleInfo objModule_loopVariable in modules.Values)
                        {
                            objModule = objModule_loopVariable;
                            if (objModule.ModuleDefID == repModInfo.ModuleDefID)
                            {
                                objItem       = new ListItem();
                                objItem.Text  = string.Format("{0} : {1}", tab.TabName, objModule.ModuleTitle);
                                objItem.Value = objModule.ModuleID.ToString();
                                ddlRepositoryID.Items.Add(objItem);
                            }
                        }
                    }

                    objItem       = new ListItem();
                    objItem.Text  = Localization.GetString("plRepositoryPrompt", this.LocalResourceFile);
                    objItem.Value = "";
                    ddlRepositoryID.Items.Insert(0, objItem);

                    if (!string.IsNullOrEmpty(Convert.ToString(settings["repository"])))
                    {
                        ddlRepositoryID.SelectedValue = settings["repository"].ToString();
                    }

                    if (!string.IsNullOrEmpty(Convert.ToString(settings["rowcount"])))
                    {
                        txtRowCount.Text = Convert.ToString(settings["rowcount"]);
                    }

                    if (!string.IsNullOrEmpty(Convert.ToString(settings["style"])))
                    {
                        rbStyle.SelectedValue = Convert.ToString(settings["style"]);
                    }
                }
                //Module failed to load
            } catch (Exception exc) {
                Exceptions.ProcessModuleLoadException(this, exc);
            }

            // Localization
            rbStyle.Items[0].Text = Localization.GetString("CategoryListing", LocalResourceFile);
            rbStyle.Items[1].Text = Localization.GetString("MultiColumnCategoryListing", LocalResourceFile);
            rbStyle.Items[2].Text = Localization.GetString("LatestUploads", LocalResourceFile);
            rbStyle.Items[3].Text = Localization.GetString("TopDownloads", LocalResourceFile);
            rbStyle.Items[4].Text = Localization.GetString("TopRated", LocalResourceFile);
        }