/// <summary>
        /// Validates disk space available
        /// </summary>
        /// <param name="virtualPathAndName">The system path. ie: C:\WebSites\DotNetNuke_Community\Portals\0\sample.gif</param>
        /// <param name="contentLength">Content Length</param>
        /// <returns>The error message or empty string</returns>
        /// <remarks></remarks>
        private object Check_DiskSpace(string virtualPathAndName, long contentLength)
        {
            try
            {
                var portalCtrl = new PortalController();
                if (!(portalCtrl.HasSpaceAvailable(PortalController.GetCurrentPortalSettings().PortalId, contentLength)))
                {
                    return(string.Format(Localization.GetString("DiskSpaceExceeded"), ToEndUserPath(virtualPathAndName)));
                }
            }
            catch (Exception ex)
            {
                return(LogUnknownError(ex, virtualPathAndName, contentLength.ToString(CultureInfo.InvariantCulture)));
            }

            return(string.Empty);
        }
示例#2
0
        private string ExportModule(int moduleID, string fileName, string folder)
        {
            var strMessage = "";

            if (Module != null)
            {
                if (!String.IsNullOrEmpty(Module.DesktopModule.BusinessControllerClass) && Module.DesktopModule.IsPortable)
                {
                    try
                    {
                        var objObject = Reflection.CreateObject(Module.DesktopModule.BusinessControllerClass, Module.DesktopModule.BusinessControllerClass);

                        //Double-check
                        if (objObject is IPortable)
                        {
                            var content = Convert.ToString(((IPortable)objObject).ExportModule(moduleID));
                            if (!String.IsNullOrEmpty(content))
                            {
                                //add attributes to XML document
                                content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<content type=\"" + CleanName(Module.DesktopModule.ModuleName) + "\" version=\"" +
                                          Module.DesktopModule.Version + "\">" + content + "</content>";

                                //First check the Portal limits will not be exceeded (this is approximate)
                                var objPortalController = new PortalController();
                                var strFile             = PortalSettings.HomeDirectoryMapPath + folder + fileName;
                                if (objPortalController.HasSpaceAvailable(PortalId, content.Length))
                                {
                                    //save the file
                                    var objStream = File.CreateText(strFile);
                                    objStream.WriteLine(content);
                                    objStream.Close();

                                    //add file to Files table
#pragma warning disable 612,618
                                    FileSystemUtils.AddFile(fileName, PortalId, folder, PortalSettings.HomeDirectoryMapPath, "application/octet-stream");
#pragma warning restore 612,618
                                }
                                else
                                {
                                    strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFile);
                                }
                            }
                            else
                            {
                                strMessage = Localization.GetString("NoContent", LocalResourceFile);
                            }
                        }
                        else
                        {
                            strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile);
                        }
                    }
                    catch
                    {
                        strMessage = Localization.GetString("Error", LocalResourceFile);
                    }
                }
                else
                {
                    strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile);
                }
            }
            return(strMessage);
        }
示例#3
0
        private string ExportModule(int ModuleID, string FileName)
        {
            string strMessage = "";

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

            if (objModule != null)
            {
                if (objModule.BusinessControllerClass != "" & objModule.IsPortable)
                {
                    try
                    {
                        object objObject = Reflection.CreateObject(objModule.BusinessControllerClass, objModule.BusinessControllerClass);

                        //Double-check
                        if (objObject is IPortable)
                        {
                            string Content = Convert.ToString(((IPortable)objObject).ExportModule(ModuleID));

                            if (Content != "")
                            {
                                // add attributes to XML document
                                Content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<content type=\"" + CleanName(objModule.FriendlyName) + "\" version=\"" + objModule.Version + "\">" + Content + "</content>";

                                //First check the Portal limits will not be exceeded (this is approximate)
                                PortalController objPortalController = new PortalController();
                                string           strFile             = PortalSettings.HomeDirectoryMapPath + FileName;
                                if (objPortalController.HasSpaceAvailable(PortalId, Content.Length))
                                {
                                    // save the file
                                    StreamWriter objStream = File.CreateText(strFile);
                                    objStream.WriteLine(Content);
                                    objStream.Close();

                                    // add file to Files table
                                    FileController               objFiles   = new FileController();
                                    FileInfo                     finfo      = new FileInfo(strFile);
                                    FolderController             objFolders = new FolderController();
                                    FolderInfo                   objFolder  = objFolders.GetFolder(PortalId, "");
                                    Services.FileSystem.FileInfo objFile    = objFiles.GetFile(lblFile.Text, PortalId, objFolder.FolderID);
                                    if (objFile == null)
                                    {
                                        objFiles.AddFile(PortalId, lblFile.Text, "xml", finfo.Length, 0, 0, "application/octet-stream", "", objFolder.FolderID, true);
                                    }
                                    else
                                    {
                                        objFiles.UpdateFile(objFile.FileId, objFile.FileName, "xml", finfo.Length, 0, 0, "application/octet-stream", "", objFolder.FolderID);
                                    }
                                }
                                else
                                {
                                    strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFile);
                                }
                            }
                            else
                            {
                                strMessage = Localization.GetString("NoContent", this.LocalResourceFile);
                            }
                        }
                        else
                        {
                            strMessage = Localization.GetString("ExportNotSupported", this.LocalResourceFile);
                        }
                    }
                    catch
                    {
                        strMessage = Localization.GetString("Error", this.LocalResourceFile);
                    }
                }
                else
                {
                    strMessage = Localization.GetString("ExportNotSupported", this.LocalResourceFile);
                }
            }

            return(strMessage);
        }
示例#4
0
        private string ExportModule(int moduleID, string fileName, IFolderInfo folder)
        {
            var strMessage = "";

            if (Module != null)
            {
                if (!String.IsNullOrEmpty(Module.DesktopModule.BusinessControllerClass) && Module.DesktopModule.IsPortable)
                {
                    try
                    {
                        var objObject = Reflection.CreateObject(Module.DesktopModule.BusinessControllerClass, Module.DesktopModule.BusinessControllerClass);

                        //Double-check
                        if (objObject is IPortable)
                        {
                            var content = Convert.ToString(((IPortable)objObject).ExportModule(moduleID));
                            if (!String.IsNullOrEmpty(content))
                            {
                                //remove invalid chars in content
                                content = Regex.Replace(content, _invalidCharsRegex, string.Empty);
                                //add attributes to XML document
                                content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<content type=\"" + CleanName(Module.DesktopModule.ModuleName) + "\" version=\"" +
                                          Module.DesktopModule.Version + "\">" + content + "</content>";

                                //First check the Portal limits will not be exceeded (this is approximate)
                                var objPortalController = new PortalController();
                                var strFile             = PortalSettings.HomeDirectoryMapPath + folder.FolderPath + fileName;
                                if (objPortalController.HasSpaceAvailable(PortalId, content.Length))
                                {
                                    //add file to Files table
                                    using (var fileContent = new MemoryStream(Encoding.UTF8.GetBytes(content)))
                                    {
                                        FileManager.Instance.AddFile(folder, fileName, fileContent, true, true, "application/octet-stream");
                                    }
                                }
                                else
                                {
                                    strMessage += "<br>" + string.Format(Localization.GetString("DiskSpaceExceeded"), strFile);
                                }
                            }
                            else
                            {
                                strMessage = Localization.GetString("NoContent", LocalResourceFile);
                            }
                        }
                        else
                        {
                            strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile);
                        }
                    }
                    catch
                    {
                        strMessage = Localization.GetString("Error", LocalResourceFile);
                    }
                }
                else
                {
                    strMessage = Localization.GetString("ExportNotSupported", LocalResourceFile);
                }
            }
            return(strMessage);
        }