Пример #1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///     ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be imported</param>
        /// <param name="Content">The content to be imported</param>
        /// <param name="Version">The version of the module to be imported</param>
        /// <param name="UserId">The Id of the user performing the import</param>
        /// <history>
        ///     [anurse]	06/16/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            // Check Access and Version
            var objUser = UserController.Instance.GetCurrentUserInfo();

            if (ReferenceEquals(objUser, null) || !objUser.IsSuperUser)
            {
                return;
            }

            var objNewReport = new ReportInfo();
            var xmlDoc       = new XmlDocument();

            xmlDoc.LoadXml(string.Format("<content>{0}</content>", Content));
            var xmlRoot = xmlDoc.DocumentElement;

            objNewReport.Title       = XmlUtils.GetNodeValue(xmlRoot, "title", string.Empty);
            objNewReport.Description = XmlUtils.GetNodeValue(xmlRoot, "description", string.Empty);
            objNewReport.CreatedOn   = DateTime.Now;
            objNewReport.CreatedBy   = UserId;

            var ver = new Version(Version);

            if (ver.Major == 4)
            {
                var sQuery = XmlUtils.GetNodeValue(xmlRoot, "query", string.Empty);
                if (ver.Minor < 4)
                {
                    var queryBytes = Convert.FromBase64String(sQuery);
                    sQuery = Encoding.Default.GetString(queryBytes);
                }
                objNewReport.DataSource = "DotNetNuke.Modules.DTSReports.DataSources.DNNDataSource";
                objNewReport.DataSourceSettings.Add("Query", sQuery);
            }
            else
            {
                // Load converters
                foreach (XmlElement xmlElement in xmlRoot.SelectNodes("converters/converter"))
                {
                    var newConverter = new ConverterInstanceInfo();
                    newConverter.ConverterName = xmlElement.GetAttribute("name");
                    newConverter.FieldName     = xmlElement.GetAttribute("field");
                    newConverter.Arguments     = xmlElement.InnerText.Split(',');
                    ConverterUtils.AddConverter(objNewReport.Converters, newConverter);
                }

                var dsElement = (XmlElement)xmlRoot.SelectSingleNode("datasource");
                objNewReport.DataSource         = dsElement.GetAttribute("type");
                objNewReport.DataSourceClass    = dsElement.GetAttribute("class");
                objNewReport.DataSourceSettings = ReadSettingsDictionary(dsElement);
            }


            // Can't do this because Import/Export module does not have a TabModuleID
            //Dim visElement As XmlElement = DirectCast(xmlRoot.SelectSingleNode("visualizer"), XmlElement)
            //objNewReport.CacheDuration = XmlUtils.GetNodeValue(xmlRoot, "cacheDuration", String.Empty)
            //objNewReport.Visualizer = visElement.GetAttribute("name")
            //objNewReport.VisualizerSettings = ReadSettingsDictionary(visElement)

            UpdateReportDefinition(ModuleID, objNewReport);
            ClearCachedResults(ModuleID);
        }
Пример #2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///     Gets the report associated with a reports module (including tab module
        ///     specific settings)
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name=" ModuleInfo">The module info</param>
        /// <history>
        ///     [anurse]	01/15/2007	Created from GetReport(Integer)
        /// </history>
        /// -----------------------------------------------------------------------------
        public static ReportInfo GetReport(ModuleInfo ModuleInfo)
        {
            var ModuleId    = ModuleInfo.ModuleID;
            var TabModuleId = ModuleInfo.TabModuleID;

            // Check for a null Module Id
            if (ModuleId == Null.NullInteger)
            {
                return(null);
            }

            // Extract the Title, Description and Query from the settings
            var objModuleController = new ModuleController();

            var objSettings = ModuleInfo.ModuleSettings;

            // Check that the settings hashtable was retrieved
            if (ReferenceEquals(objSettings, null))
            {
                return(null);
            }

            // Setup the Report
            var objReport = new ReportInfo();

            // Build the Report from the Module Settings
            var reportsModuleSettingsRepository = new ReportsModuleSettingsRepository();
            var reportsModuleSettings           = reportsModuleSettingsRepository.GetSettings(ModuleInfo);

            objReport.Title           = reportsModuleSettings.Title;
            objReport.Description     = reportsModuleSettings.Description;
            objReport.Parameters      = reportsModuleSettings.Parameters;
            objReport.CreatedOn       = reportsModuleSettings.CreatedOn;
            objReport.CreatedBy       = reportsModuleSettings.CreatedBy;
            objReport.DataSource      = reportsModuleSettings.DataSource;
            objReport.DataSourceClass = reportsModuleSettings.DataSourceClass;
            objReport.ModuleID        = ModuleId;

            // Load Filter Settings
            var converterString =
                Convert.ToString(
                    SettingsUtil.GetHashtableSetting(objSettings, ReportsConstants.SETTING_Converters,
                                                     Null.NullString));

            if (!string.IsNullOrEmpty(converterString.Trim()))
            {
                foreach (var converterItem in converterString.Split(';'))
                {
                    if (!string.IsNullOrEmpty(converterItem.Trim()))
                    {
                        var converterArray = converterItem.Split('|');
                        if (converterArray.Length >= 2 && converterArray.Length <= 3)
                        {
                            var newconverter = new ConverterInstanceInfo();
                            newconverter.FieldName     = converterArray[0];
                            newconverter.ConverterName = converterArray[1];
                            if (converterArray.Length == 3)
                            {
                                newconverter.Arguments = converterArray[2].Split(',');
                            }

                            ConverterUtils.AddConverter(objReport.Converters, newconverter);
                        }
                    }
                }
            }

            // Load the tab module settings (visualizer settings) if we have a tab module Id
            Hashtable objTabModuleSettings = null;

            if (TabModuleId != Null.NullInteger)
            {
                objTabModuleSettings = ModuleInfo.TabModuleSettings;

                objReport.ShowControls  = reportsModuleSettings.ShowControls;
                objReport.ShowInfoPane  = reportsModuleSettings.ShowInfoPane;
                objReport.AutoRunReport = reportsModuleSettings.AutoRunReport;
                objReport.TokenReplace  = reportsModuleSettings.TokenReplace;
                objReport.CacheDuration = reportsModuleSettings.CacheDuration;

                // Read the visualizer name
                objReport.Visualizer =
                    Convert.ToString(
                        SettingsUtil.GetHashtableSetting(objTabModuleSettings, ReportsConstants.SETTING_Visualizer,
                                                         "Grid"));
            }

            LoadExtensionSettings(objSettings, objTabModuleSettings, objReport);

            return(objReport);
        }