Exemplo n.º 1
0
        protected void OnExportClick(Object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsValid)
                {
                    return;
                }

                if (cboFolders.SelectedItem != null)
                {
                    var folder = FolderManager.Instance.GetFolder(cboFolders.SelectedItemValueAsInt);
                    if (folder != null)
                    {
                        var filename = PortalSettings.HomeDirectoryMapPath + folder.FolderPath + txtFile.Text + ".page.template";
                        filename = filename.Replace("/", "\\");

                        var     xmlTemplate = new XmlDocument();
                        XmlNode nodePortal  = xmlTemplate.AppendChild(xmlTemplate.CreateElement("portal"));
                        if (nodePortal.Attributes != null)
                        {
                            nodePortal.Attributes.Append(XmlUtils.CreateAttribute(xmlTemplate, "version", "3.0"));
                        }

                        //Add template description
                        XmlElement node = xmlTemplate.CreateElement("description");
                        node.InnerXml = Server.HtmlEncode(txtDescription.Text);
                        nodePortal.AppendChild(node);

                        //Serialize tabs
                        XmlNode nodeTabs = nodePortal.AppendChild(xmlTemplate.CreateElement("tabs"));
                        SerializeTab(xmlTemplate, nodeTabs);

                        xmlTemplate.Save(filename);
                        UI.Skins.Skin.AddModuleMessage(this, "", string.Format(Localization.GetString("ExportedMessage", LocalResourceFile), filename), ModuleMessage.ModuleMessageType.BlueInfo);

                        //add file to Files table
#pragma warning disable 612,618
                        FileSystemUtils.AddFile(txtFile.Text + ".page.template", PortalId, folder.FolderPath, PortalSettings.HomeDirectoryMapPath, "application/octet-stream");
#pragma warning restore 612,618
                    }
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemplo n.º 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);
        }