Ejemplo n.º 1
0
        public static string getDependantParameters(string path, string paramName, string paramValue, string[] visibleDependants)
        {
            try
            {
                var crcRepDef = GetReportDefinition(path);
                logger.DebugFormat("getDependantParameters: Report {0} User {1} base param {2} value {3} visible dependants {4}",
                                   crcRepDef.DisplayName, HttpContext.Current.User.Identity.Name, paramName, paramValue, string.Join(", ", visibleDependants));
                // map the parameter values onto the report definition
                var choiceFactory    = new CrcParameterChoiceFactory();
                var choiceCollection = choiceFactory.Create(paramValue);

                var crServices = new CrissCrossLib.CrissCrossServices();
                crServices.RefreshDependantParameters(crcRepDef, choiceCollection);
                // only return visible dependant params back to ui
                List <CrcParameterDefinition> paramsToReturn = crcRepDef.ParameterDefinitions
                                                               .Where(p => visibleDependants.Contains(p.Name)).ToList();

                string json = CrissCrossWebHelper.SerializeObjectIntoJson <List <CrcParameterDefinition> >(paramsToReturn);
                return(json);
            }
            catch (Exception e)
            {
                LogAjaxError(e, "getDependantParameters");
                throw e;
            }
        }
Ejemplo n.º 2
0
        public void CanConvertEmptyParamString()
        {
            string testParam = "";
            var    fac       = new CrcParameterChoiceFactory();
            var    pcCol     = fac.Create(testParam);

            Assert.IsNotNull(pcCol);
            Assert.AreEqual(0, pcCol.ParameterChoiceList.Count());
        }
Ejemplo n.º 3
0
        public void RunReport()
        {
            var    crcRepDef   = GetReportDefinition(this.ReportPath);
            string paramString = uxHiddenParamString.Text;

            SetReportViewerSize();
            var choiceFactory    = new CrcParameterChoiceFactory();
            var choiceCollection = choiceFactory.Create(paramString);
            var mapResult        = crcRepDef.MapParameterChoices(choiceCollection);

            if (mapResult.MappingValid)
            {
                InitialiseReportViewer(this.ReportPath);

                logger.DebugFormat("RunReport: ReportPath: {0} User {1}", uxReportViewer.ServerReport.ReportPath, User.Identity.Name);
                var converter     = new CrcParameterConverter();
                var ssrsParamList = converter.GetReportParametersForSsrsReportViewer(crcRepDef);
                var userParamList = converter.GetReportParametersForUser(crcRepDef, 15);
                try
                {
                    uxReportViewer.ServerReport.SetParameters(ssrsParamList);
                }
                catch (ReportServerException rse)
                {
                    // check for problem with fixed user
                    if (rse.ErrorCode == "rsAccessDenied" && !this.GetImpersonateLoggedOnUser())
                    {
                        throw new ApplicationException(string.Format("ReportViewer is running as fixed user {0} but was passed a report {1} that it could not open",
                                                                     GetFixedSsrsUsername(), this.ReportPath));
                    }
                    else
                    {
                        throw rse;
                    }
                }
                string executionId = uxReportViewer.ServerReport.GetExecutionId();
                logger.DebugFormat("RunReport: running report, executionId is {0}", executionId);
                if (StoreCrissCrossHistory)
                {
                    // log executionid, logged in user and param description
                    var historyLogger = new CrissCrossLib.History.CrcHistoryLogger();
                    historyLogger.LogToCrissCrossHistory(crcRepDef, User.Identity.Name, executionId);
                }
                uxParamUserDescription.Text = string.Join("<br/>", userParamList.ToArray());
                uxResultsPanel.Visible      = true;
                uxParamSummaryPanel.Visible = true;
                this.RunningReport          = true;
            }
            else
            {
                // todo - friendly message back to ui
                throw new ApplicationException(string.Format("invalid params - could not map supplied values to definitions for report {0}. complaints: {1}",
                                                             crcRepDef.DisplayName, string.Join(", ", mapResult.Complaints.ToArray())));
            }
        }
Ejemplo n.º 4
0
        public void CanConvertSimpleParamString()
        {
            string testParam = "District=44";
            var    fac       = new CrcParameterChoiceFactory();
            var    pcCol     = fac.Create(testParam);

            Assert.IsNotNull(pcCol);
            Assert.AreEqual(1, pcCol.ParameterChoiceList.Count());
            Assert.AreEqual("District", pcCol.ParameterChoiceList[0].Name);
            Assert.AreEqual("44", pcCol.ParameterChoiceList[0].SingleValue);
        }
Ejemplo n.º 5
0
        public void CanConvertIsNullParamString()
        {
            string testParam = "SomeDate:isnull=true";
            var    fac       = new CrcParameterChoiceFactory();
            var    pcCol     = fac.Create(testParam);

            Assert.IsNotNull(pcCol);
            Assert.AreEqual(1, pcCol.ParameterChoiceList.Count());
            Assert.AreEqual("SomeDate", pcCol.ParameterChoiceList[0].Name);
            Assert.IsNull(pcCol.ParameterChoiceList[0].SingleValue);
        }
Ejemplo n.º 6
0
        public void PrepareReportDefn(string reportPath)
        {
            var crServices = new CrissCrossLib.CrissCrossServices();
            var crcRepDefn = crServices.GetReportDefn(reportPath, User.Identity.Name);

            if (!String.IsNullOrEmpty(this.InitialParameterString))
            {
                var choiceFactory    = new CrcParameterChoiceFactory();
                var choiceCollection = choiceFactory.Create(this.InitialParameterString);
                if (crcRepDefn.HasDependantParameters)
                {
                    crServices.RefreshDependantParameters(crcRepDefn, choiceCollection);
                }
                else
                {
                    var mapResult = crcRepDefn.MapParameterChoices(choiceCollection);
                    if (!mapResult.MappingValid)
                    {
                        throw new ApplicationException(String.Format("Could not apply parameters to report {0}. problems: {1}",
                                                                     crcRepDefn.DisplayName, String.Join(", ", mapResult.Complaints.ToArray())));
                    }
                }
            }

            uxReportName.Text = crcRepDefn.DisplayName;
            string combinedDesc = BuildCombinedDescription(crcRepDefn);

            if (!string.IsNullOrEmpty(combinedDesc))
            {
                uxReportHint.Text = combinedDesc;
            }
            else
            {
                uxReportDescriptionPanel.Visible = false;
            }

            uxReportFolderLink.Text        = crcRepDefn.GetReportFolder();
            uxReportFolderLink.NavigateUrl = string.Format("AllCatalog.aspx?Folder={0}",
                                                           Server.UrlEncode(crcRepDefn.GetReportFolder()));
            uxResultsPanel.Visible = false;
            // stash it in session
            Session[crcRepDefn.ReportPath] = crcRepDefn;
        }
Ejemplo n.º 7
0
        public void CanConvertParamStringWithRepeatingName()
        {
            string testParam = "District=44&Customer=55445&District=77";
            var    fac       = new CrcParameterChoiceFactory();
            var    pcCol     = fac.Create(testParam);

            Assert.IsNotNull(pcCol);
            Assert.AreEqual(2, pcCol.ParameterChoiceList.Count());
            var p1 = pcCol.ParameterChoiceList.FirstOrDefault(p => p.Name == "District");

            Assert.IsNotNull(p1);
            Assert.AreEqual(2, p1.Values.Count());
            Assert.IsNotNull(p1.Values.FirstOrDefault(v => v == "44"));
            Assert.IsNotNull(p1.Values.FirstOrDefault(v => v == "77"));
            var p2 = pcCol.ParameterChoiceList.FirstOrDefault(p => p.Name == "Customer");

            Assert.IsNotNull(p2);
            Assert.AreEqual("55445", p2.SingleValue);
        }
Ejemplo n.º 8
0
        public void CanConvertParamStringWithSeveralClauses()
        {
            string testParam = "District=44&Customer=55445&Product=8889";
            var    fac       = new CrcParameterChoiceFactory();
            var    pcCol     = fac.Create(testParam);

            Assert.IsNotNull(pcCol);
            Assert.AreEqual(3, pcCol.ParameterChoiceList.Count());
            var p1 = pcCol.ParameterChoiceList.FirstOrDefault(p => p.Name == "District");

            Assert.IsNotNull(p1);
            Assert.AreEqual("44", p1.SingleValue);
            var p2 = pcCol.ParameterChoiceList.FirstOrDefault(p => p.Name == "Customer");

            Assert.IsNotNull(p2);
            Assert.AreEqual("55445", p2.SingleValue);
            var p3 = pcCol.ParameterChoiceList.FirstOrDefault(p => p.Name == "Product");

            Assert.AreEqual("8889", p3.SingleValue);
        }
Ejemplo n.º 9
0
        public void CanConvertParamStringWithUrlEncodedContent()
        {
            // this is the kind of encoding that comes back from the execution log
            string testParam = "District=one%3Dtwo&Customer=Red %26 Black";

            var fac   = new CrcParameterChoiceFactory();
            var pcCol = fac.Create(testParam);

            Assert.IsNotNull(pcCol);
            Assert.AreEqual(2, pcCol.ParameterChoiceList.Count());
            var p1 = pcCol.ParameterChoiceList.FirstOrDefault(p => p.Name == "District");

            Assert.IsNotNull(p1);
            Assert.AreEqual(1, p1.Values.Count());
            Assert.AreEqual("one=two", p1.SingleValue);
            var p2 = pcCol.ParameterChoiceList.FirstOrDefault(p => p.Name == "Customer");

            Assert.IsNotNull(p2);
            Assert.AreEqual(1, p2.Values.Count());
            Assert.AreEqual("Red & Black", p2.SingleValue);
        }