Пример #1
0
        // Internal version of SaveReportDefinition to allow SaveReport to use
        // the same ModuleController instance for both method calls
        private static void UpdateReportDefinition(ModuleController ctrl, int ModuleId, ReportInfo objReport)
        {
            var reportsModuleSettingsRepository = new ReportsModuleSettingsRepository();
            var moduleInfo            = ctrl.GetModule(ModuleId);
            var reportsModuleSettings = reportsModuleSettingsRepository.GetSettings(moduleInfo);

            // Update the module settings with the data from the report
            reportsModuleSettings.Title           = objReport.Title;
            reportsModuleSettings.Description     = objReport.Description;
            reportsModuleSettings.Parameters      = objReport.Parameters;
            reportsModuleSettings.DataSource      = objReport.DataSource;
            reportsModuleSettings.DataSourceClass = objReport.DataSourceClass;
            reportsModuleSettings.CreatedOn       = objReport.CreatedOn;
            reportsModuleSettings.CreatedBy       = objReport.CreatedBy;

            reportsModuleSettingsRepository.SaveSettings(moduleInfo, reportsModuleSettings);

            // Update data source settings
            // Can't do this in a common way because we must call a different method to
            // update Visualizer Settings and Data Source Settings
            if (!string.IsNullOrEmpty(objReport.DataSource))
            {
                var prefix = string.Format("{0}{1}_", ReportsConstants.PREFIX_DataSource, objReport.DataSource);
                foreach (var pair in objReport.DataSourceSettings)
                {
                    ctrl.UpdateModuleSetting(ModuleId, string.Concat(prefix, pair.Key), Convert.ToString(pair.Value));
                }
            }

            // Update Converter settigns
            var ConverterBuilder = new StringBuilder();

            foreach (var list in objReport.Converters.Values)
            {
                foreach (var Converter in list)
                {
                    ConverterBuilder.Append(Converter.FieldName);
                    ConverterBuilder.Append("|");
                    ConverterBuilder.Append(Converter.ConverterName);
                    if (Converter.Arguments != null && Converter.Arguments.Length > 0)
                    {
                        ConverterBuilder.Append("|");
                        ConverterBuilder.Append(string.Join(",", Converter.Arguments));
                    }
                    ConverterBuilder.Append(";");
                }
            }
            ctrl.UpdateModuleSetting(ModuleId, ReportsConstants.SETTING_Converters, ConverterBuilder.ToString());
        }
Пример #2
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.Reports.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);
        }
Пример #3
0
        public static Dictionary <string, object> BuildParameters(PortalModuleBase SrcModule, ReportInfo Report)
        {
            var dict = new Dictionary <string, object>();

            if (SrcModule != null)
            {
                dict.Add("PortalID", SrcModule.PortalId);
                dict.Add("TabID", SrcModule.TabId);
                dict.Add("ModuleID", SrcModule.ModuleId);
                dict.Add("UserID", SrcModule.UserId);

                if (!string.IsNullOrEmpty(Report.Parameters.Trim()))
                {
                    var @params = Report.Parameters.Split(',');

                    foreach (var param in @params)
                    {
                        // Get the value from the request
                        var value = SrcModule.Request.Params[param];

                        // Add the parameter
                        dict.Add("url_" + param, value);
                    }
                }
            }

            return(dict);
        }
Пример #4
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///     Executes a report and returns the results
        /// </summary>
        /// <param name="objReport">The ReportInfo object</param>
        /// <param name="cacheKey">The cache key for the module</param>
        /// <param name="bypassCache">A boolean indicating that the cache should be bypassed</param>
        /// <param name="hostModule">The module that is hosting the report</param>
        /// <param name="fromCache">A boolean indicating if the data was retrieved from the cache</param>
        /// <exception cref="System.ArgumentNullException">
        ///     The value of <paramref name="objReport" /> was null (Nothing in Visual Basic)
        /// </exception>
        /// <history>
        ///     [anurse]	08/25/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static DataTable ExecuteReport(ReportInfo objReport, string cacheKey, bool bypassCache,
                                              PortalModuleBase hostModule, ref bool fromCache)
        {
            fromCache = false;
            if (ReferenceEquals(objReport, null))
            {
                throw new ArgumentNullException("objReport");
            }

            if (string.IsNullOrEmpty(objReport.DataSource))
            {
                return(null); // If there's no data source, there's no report
            }
            // Check the cache
            DataTable results = null;

            if (!bypassCache)
            {
                results = DataCache.GetCache(cacheKey) as DataTable;
                if (results != null)
                {
                    fromCache = true;
                    return(results);
                }
            }

            // Get an instance of the data source
            //DotNetNuke.Modules.Reports.DataSources.IDataSource dataSource = GetDataSource(objReport.DataSourceClass) as DataSources.IDataSource;
            var dataSource = GetDataSource(objReport.DataSourceClass);

            // Create an extension context
            var moduleFolder = string.Empty;

            if (hostModule != null)
            {
                moduleFolder = hostModule.TemplateSourceDirectory;
            }
            var ctxt = new ExtensionContext(moduleFolder, "DataSource", objReport.DataSource);

            // Load Parameters
            IDictionary <string, object> parameters = BuildParameters(hostModule, objReport);

            if (objReport.CacheDuration != 0)
            {
                // Check the app setting
                if (!"True".Equals(
                        WebConfigurationManager.AppSettings[ReportsConstants.APPSETTING_AllowCachingWithParameters],
                        StringComparison.InvariantCulture))
                {
                    parameters.Clear();
                }
            }

            // Execute the report
            dataSource.Initialize(ctxt);
            results           = dataSource.ExecuteReport(objReport, hostModule, parameters).ToTable();
            results.TableName = "QueryResults";

            // Check if the converters were run
            if (!dataSource.CanProcessConverters)
            {
                // If not, run them the slow way :(
                foreach (DataRow row in results.Rows)
                {
                    foreach (DataColumn col in results.Columns)
                    {
                        if (!objReport.Converters.ContainsKey(col.ColumnName))
                        {
                            continue;
                        }
                        var list = objReport.Converters[col.ColumnName];
                        foreach (var converter in list)
                        {
                            row[col] = ApplyConverter(row[col], converter.ConverterName, converter.Arguments);
                        }
                    }
                }
            }

            // Do the token replace if specified
            if (objReport.TokenReplace)
            {
                var localTokenReplacer = new TokenReplace();
                foreach (DataColumn col in results.Columns)
                {
                    // Process each column of the resultset
                    if (col.DataType == typeof(string))
                    {
                        // We want to replace the data, we don't mind that it is marked as readonly
                        if (col.ReadOnly)
                        {
                            col.ReadOnly = false;
                        }

                        var maxLength  = col.MaxLength;
                        var resultText = "";

                        foreach (DataRow row in results.Rows)
                        {
                            resultText =
                                localTokenReplacer.ReplaceEnvironmentTokens(Convert.ToString(row[col].ToString()));

                            // Don't make it too long
                            if (resultText.Length > maxLength)
                            {
                                resultText = resultText.Substring(0, maxLength);
                            }

                            row[col] = resultText;
                        }
                    }
                }
            }


            // Cache it, if not asked to bypass the cache
            if (!bypassCache && results != null)
            {
                DataCache.SetCache(cacheKey, results);
            }

            // Return the results
            return(results);
        }
Пример #5
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///     Saves the report view (tab module settings) associated with a reports module
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="TabModuleId">
        ///     The Id of the instance ("TabModule") of the module to store the view
        ///     settings for.
        /// </param>
        /// <param name="objReport">The ReportInfo object to save</param>
        /// <history>
        ///     [anurse]	01/15/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void UpdateReportView(int TabModuleId, ReportInfo objReport)
        {
            var ctrl = new ModuleController();

            UpdateReportView(ctrl, TabModuleId, objReport);
        }
Пример #6
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///     Saves the report definition (module settings) associated with a reports module
        /// </summary>
        /// <param name="ModuleId">The ModuleId to set the report for</param>
        /// <param name="objReport">The ReportInfo object to save</param>
        /// <history>
        ///     [anurse]	01/15/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void UpdateReportDefinition(int ModuleId, ReportInfo objReport)
        {
            var ctrl = new ModuleController();

            UpdateReportDefinition(ctrl, ModuleId, objReport);
        }
Пример #7
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;
                objReport.ExportExcel   = reportsModuleSettings.ExportExcel;

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

            LoadExtensionSettings(objSettings, objTabModuleSettings, objReport);

            return(objReport);
        }