private void Aggregate(object currentHttpContext) { HttpContext httpContext = FakeHttpContext( new Dictionary <string, object>(), ((HttpContext)currentHttpContext).Request.Url.ToString() ); this.Sessions.Add(httpContext.Session); ReportDefinition reportDefinition = new ReportDefinition( this.Core, this.ReportDefinitionFileName, new Crosstables.Classes.HierarchyClasses.HierarchyFilter(null) ); ReportCalculator calculator = new ReportCalculator( reportDefinition, this.Core, httpContext.Session ); //try //{ calculator.Aggregate("1.0.0.0", false); /*} * catch { * httpContext.Session["DataAggregationProgress"] = 100; * }*/ }
public void ConditionCoverageTest() { var report = new CoverageReport { Packages = new Packages { Package = new List <Package> { new Package { Classes = new Classes { Class = new List <Class> { new Class { Methods = new Methods { Method = new List <Method>() }, Lines = new Lines { Line = new List <Line> { new Line { Number = 1, Hits = 0, Branch = "True", ConditionCoverage = "33% (1/3)", Conditions = new Conditions { Condition = new List <Condition> { new Condition { Number = "1", Coverage = "33.3%", Type = "jump" } } } } } } } } } } } } }; var logger = new MessageLogger <ReportCalculator>(); var reportCalculator = new ReportCalculator(logger); reportCalculator.CalculateStatistics(report); // TODO: Not correct, but no exception Assert.Equal("33.3% (0.7/2)", report.Packages.Package[0].Classes.Class[0].Lines.Line[0].ConditionCoverage); }
public void ExecuteTest() { var mergeOptions = new MergeOptions { InputFiles = new[] { @"TestFiles\TestFile1.xml", @"TestFiles\TestFile2.xml" }, OutputFile = "merged.xml", LogLevel = LogLevel.Trace, DisableSanitize = false }; var fileLoader = new FileLoader(new NullLogger <FileLoader>()); var reportSanitizer = new ReportSanitizer(new NullLogger <ReportSanitizer>()); var reportMerger = new ReportMerger(new NullLogger <ReportMerger>()); var reportCalculator = new ReportCalculator(new NullLogger <ReportCalculator>()); var reportWriter = new ReportWriter(new NullLogger <ReportWriter>()); var logger = new MessageLogger <Runner>(); var runner = new Runner(logger, fileLoader, reportSanitizer, reportMerger, reportCalculator, reportWriter); Assert.True(runner.Execute(mergeOptions.InputFiles, mergeOptions.OutputFile, mergeOptions.DisableSanitize)); Assert.Empty(logger.Messages); }
public void CalculateTotalOfThree() { // ARRANGE var sut = new ReportCalculator(_threeNumberResultSampleData); // ACT var numbers = sut.FindThreeNumberResult(); // ASSERT numbers.TotalExpense.Should().Be(257575250); }
public void CalculateTotalOfTwo() { // ARRANGE var sut = new ReportCalculator(_twoNumberResultSampleData); // ACT var numbers = sut.FindTwoNumberResult(); // ASSERT numbers.TotalExpenses.Should().Be(1020100); }
public void ReturnThreeNumbersWithTotalOf2020() { // ARRANGE var sut = new ReportCalculator(_threeNumberResultSampleData); // ACT var result = sut.FindThreeNumberResult(); // ASSERT (result.Number1 + result.Number2 + result.Number3).Should().Be(ReportCalculator.Total); }
public void ReturnThreeNumbersResult() { // ARRANGE var sut = new ReportCalculator(_threeNumberResultSampleData); // ACT var result = sut.FindThreeNumberResult(); // ASSERT result.Should().BeOfType <ThreeNumberResult>(); }
private void InitFilter(string source, DatabaseCore.Core core, HierarchyFilter hierarchyFilter) { ReportDefinitionClasses.ReportDefinition definition = new ReportDefinitionClasses.ReportDefinition( core, source, hierarchyFilter ); DataCore.Classes.ReportCalculator test = new ReportCalculator( definition, core, HttpContext.Current.Session ); this.Filter = test.GetFilter(); }
private void RenderMeasure(LinkBiDefinitionDimension measure, string _selection, StringBuilder writer, int columnOffset, Data filter = null) { DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database( base.Core, null ); // Check if the measure is a numeric variable. if (measure.Type == VariableType.Numeric) { string label = ""; if (measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage] == null) { if (measure.IsTaxonomy) { label = (string)this.Core.TaxonomyVariableLabels.GetValue( "Label", new string[] { "IdTaxonomyVariable", "IdLanguage" }, new object[] { measure.Identity, this.Definition.Settings.IdLanguage } ); } else { label = (string)this.Core.VariableLabels.GetValue( "Label", new string[] { "IdVariable", "IdLanguage" }, new object[] { measure.Identity, this.Definition.Settings.IdLanguage } ); } measure.XmlNode.AddAttribute("Label" + this.Definition.Settings.IdLanguage, label); } label = measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value; string selection = _selection + string.Format( "\"{0}\",", (label) ); Data result = storageMethod.GetRespondentsNumeric( measure.Identity, measure.IsTaxonomy, this.Core.CaseDataLocation, filter, this.Definition.WeightingFilters ); writer.Append("[" + selection); //empty for responses writer.Append(string.Format( "\"{0}\",", "" )); writer.Append(string.Format( "\"{0}\",", result.Base.ToString(new CultureInfo("en-GB")) )); writer.Append(string.Format( "\"{0}\",", result.Value.ToString(new CultureInfo("en-GB")) )); //writer.Append(string.Format( // "\"{0}\"", // result.GetStdDev(1, result.GetMean(1)).ToString(new CultureInfo("en-GB")) //)); writer.Append(string.Format( "\"\"" )); writer.Append("],"); } else { // Create a new report calculator to calculate the // significant difference between categories. ReportCalculator calculator = new ReportCalculator( null, base.Core, null ); filter = storageMethod.GetRespondents(measure, filter, this.Definition.WeightingFilters); string baseValue = filter.Base.ToString(new CultureInfo("en-GB")); string uBaseValueStr = filter.Responses.Count.ToString(new CultureInfo("en-GB")); string eBaseValueStr = filter.Responses.Count.ToString(new CultureInfo("en-GB")); int rowOffset = i; Dictionary <Guid, double> categoryValues = new Dictionary <Guid, double>(); TaskCollection tasks = new TaskCollection(); tasks.Synchronously = true; // Run through all scores of the measure. /*foreach (LinkBiDefinitionDimensionScore score in measure.Scores) * { * if (score.Equation != null) * { * tasks.Synchronously = true; * break; * } * }*/ // Run through all scores of the measure. foreach (LinkBiDefinitionDimensionScore score in measure.Scores) { tasks.Add(() => { Data scoreFilter = score.GetRespondents(filter, this.StorageMethod); categoryValues.Add(score.Identity, scoreFilter.Value); }); } tasks.WaitAll(); // Run through all scores of the measure. foreach (LinkBiDefinitionDimensionScore score in measure.Scores) { if (measure.IsTaxonomy && score.Persistent && base.Definition.HierarchyFilter.TaxonomyCategories.ContainsKey(score.Identity) == false) { continue; } string label = ""; if (score.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage] == null) { if (measure.IsTaxonomy) { label = (string)this.Core.TaxonomyCategoryLabels.GetValue( "Label", new string[] { "IdTaxonomyCategory", "IdLanguage" }, new object[] { score.Identity, this.Definition.Settings.IdLanguage } ); } else { label = (string)this.Core.CategoryLabels.GetValue( "Label", new string[] { "IdCategory", "IdLanguage" }, new object[] { score.Identity, this.Definition.Settings.IdLanguage } ); } score.XmlNode.AddAttribute("Label" + this.Definition.Settings.IdLanguage, label); } label = score.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value; string selection = _selection + string.Format( " \"{0}\",", measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value ); writer.Append("[" + selection); writer.Append(string.Format( "\"{0}\",", (label) )); if (this.Definition.Settings.DisplayUnweightedBase) { writer.Append(string.Format( "\"{0}\",", uBaseValueStr )); } if (this.Definition.Settings.DisplayEffectiveBase) { writer.Append(string.Format( "\"{0}\",", eBaseValueStr )); } writer.Append(string.Format( "\"{0}\",", baseValue )); double catgValue = categoryValues.ContainsKey(score.Identity) ? categoryValues[score.Identity] : 0; writer.Append(string.Format( "\"{0}\"", catgValue )); if (this.Definition.Settings.ExportPercentage) { double percent = 0; if (!string.IsNullOrEmpty(baseValue)) { percent = (catgValue / double.Parse(baseValue)) * 100; } writer.Append(string.Format( ",\"{0}\"", percent )); } writer.Append("],"); i++; } } }
private void RenderMeasure(LinkBiDefinitionDimension measure, string _selection, StringBuilder writer, int columnOffset, Data filter = null) { DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database( base.Core, null ); // Check if the measure is a numeric variable. if (measure.Type == VariableType.Numeric) { string label = ""; if (measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage] == null) { if (measure.IsTaxonomy) { label = (string)this.Core.TaxonomyVariableLabels.GetValue( "Label", new string[] { "IdTaxonomyVariable", "IdLanguage" }, new object[] { measure.Identity, this.Definition.Settings.IdLanguage } ); } else { label = (string)this.Core.VariableLabels.GetValue( "Label", new string[] { "IdVariable", "IdLanguage" }, new object[] { measure.Identity, this.Definition.Settings.IdLanguage } ); } measure.XmlNode.AddAttribute("Label" + this.Definition.Settings.IdLanguage, label); } label = measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value; string selection = _selection + string.Format( "\"Label\": \"{0}\",", label ); Data result = storageMethod.GetRespondentsNumeric( measure.Identity, measure.IsTaxonomy, this.Core.CaseDataLocation, filter, this.Definition.WeightingFilters ); writer.Append("{" + selection); writer.Append(string.Format( "\"Base\": \"{0}\",", result.Base.ToString(new CultureInfo("en-GB")) )); writer.Append(string.Format( "\"Value\": \"{0}\",", result.Value.ToString(new CultureInfo("en-GB")) )); writer.Append(string.Format( "\"StdDev\": \"{0}\"", result.GetStdDev(1, result.GetMean(1)).ToString(new CultureInfo("en-GB")) )); writer.Append("},"); } else { // Create a new report calculator to calculate the // significant difference between categories. ReportCalculator calculator = new ReportCalculator( null, base.Core, null ); filter = storageMethod.GetRespondents(measure, filter); string baseValue = filter.Base.ToString(new CultureInfo("en-GB")); int rowOffset = i; Dictionary <Guid, double> categoryValues = new Dictionary <Guid, double>(); TaskCollection tasks = new TaskCollection(); tasks.Synchronously = true; // Run through all scores of the measure. /*foreach (LinkBiDefinitionDimensionScore score in measure.Scores) * { * if (score.Equation != null) * { * tasks.Synchronously = true; * break; * } * }*/ // Run through all scores of the measure. foreach (LinkBiDefinitionDimensionScore score in measure.Scores) { tasks.Add(() => { Data scoreFilter = score.GetRespondents(filter, this.StorageMethod); categoryValues.Add(score.Identity, scoreFilter.Value); }); } tasks.WaitAll(); // Run through all scores of the measure. foreach (LinkBiDefinitionDimensionScore score in measure.Scores) { if (measure.IsTaxonomy && score.Persistent && base.Definition.HierarchyFilter.TaxonomyCategories.ContainsKey(score.Identity) == false) { continue; } string label = ""; if (score.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage] == null) { if (measure.IsTaxonomy) { label = (string)this.Core.TaxonomyCategoryLabels.GetValue( "Label", new string[] { "IdTaxonomyCategory", "IdLanguage" }, new object[] { score.Identity, this.Definition.Settings.IdLanguage } ); } else { label = (string)this.Core.CategoryLabels.GetValue( "Label", new string[] { "IdCategory", "IdLanguage" }, new object[] { score.Identity, this.Definition.Settings.IdLanguage } ); } score.XmlNode.AddAttribute("Label" + this.Definition.Settings.IdLanguage, label); } label = score.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value; string selection = _selection + string.Format( "\"Label\": \"{0}\",", HttpUtility.HtmlEncode(label) ); writer.Append("{" + selection); writer.Append(string.Format( "\"Base\": \"{0}\",", baseValue )); writer.Append(string.Format( "\"Value\": \"{0}\"", categoryValues.ContainsKey(score.Identity) ? categoryValues[score.Identity] : 0 )); writer.Append("},"); i++; if (totalToProcess != 0) { int progress = i * 100 / totalToProcess; if (progress == 100) { base.Progress = 99; } else { base.Progress = progress; } } } } }
public void CalculateStatisticsTest() { var reports = LoadReport(); var sanitizer = new ReportSanitizer(new NullLogger <ReportSanitizer>()); sanitizer.Sanitize(reports); var reportMerger = new ReportMerger(new NullLogger <ReportMerger>()); var mergedReport = reportMerger.Merge(reports); var logger = new MessageLogger <ReportCalculator>(); var reportCalculator = new ReportCalculator(logger); reportCalculator.CalculateStatistics(mergedReport); Assert.Single(mergedReport.Packages.Package); var package = mergedReport.Packages.Package[0]; Assert.Equal("DummyProject.Server", package.Name); Assert.Equal(1, package.LineRate); Assert.Equal(1, package.BranchRate); Assert.Equal(0, package.Complexity); Assert.Equal(2, package.Classes.Class.Count); var class0 = package.Classes.Class[0]; Assert.Equal("DummyProject.Server.Controllers.DummyController (0)", class0.Name); Assert.EndsWith(@"src\DummyProject.Server\Controllers\DummyController.cs", class0.Filename); Assert.Equal(1, class0.LineRate); Assert.Equal(1, class0.BranchRate); Assert.Equal(0, class0.Complexity); Assert.Equal(3, class0.Methods.Method.Count); Assert.Equal(15, class0.Lines.Line.Count); Assert.Contains(class0.Lines.Line, l => l.Number == 1 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 2 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 3 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 4 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 5 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 6 && l.Hits == 3 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 7 && l.Hits == 3 && l.ConditionCoverage == "100% (2/2)"); Assert.Contains(class0.Lines.Line, l => l.Number == 8 && l.Hits == 3 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 9 && l.Hits == 3 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 10 && l.Hits == 3 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 11 && l.Hits == 6 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 12 && l.Hits == 6 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 13 && l.Hits == 6 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 14 && l.Hits == 6 && l.ConditionCoverage == null); Assert.Contains(class0.Lines.Line, l => l.Number == 15 && l.Hits == 6 && l.ConditionCoverage == null); var method01 = class0.Methods.Method[0]; Assert.Equal("DummyMethod1", method01.Name); Assert.Equal(1, method01.LineRate); Assert.Equal(1, method01.BranchRate); Assert.Contains(method01.Lines.Line, l => l.Number == 1 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(method01.Lines.Line, l => l.Number == 2 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(method01.Lines.Line, l => l.Number == 3 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(method01.Lines.Line, l => l.Number == 4 && l.Hits == 12 && l.ConditionCoverage == null); Assert.Contains(method01.Lines.Line, l => l.Number == 5 && l.Hits == 12 && l.ConditionCoverage == null); var method02 = class0.Methods.Method[1]; Assert.Equal("DummyMethod2", method02.Name); Assert.Equal(1, method02.LineRate); Assert.Equal(1, method02.BranchRate); Assert.Contains(method02.Lines.Line, l => l.Number == 6 && l.Hits == 3 && l.ConditionCoverage == null); Assert.Contains(method02.Lines.Line, l => l.Number == 7 && l.Hits == 3 && l.ConditionCoverage == "100% (2/2)"); Assert.Contains(method02.Lines.Line, l => l.Number == 8 && l.Hits == 3 && l.ConditionCoverage == null); Assert.Contains(method02.Lines.Line, l => l.Number == 9 && l.Hits == 3 && l.ConditionCoverage == null); Assert.Contains(method02.Lines.Line, l => l.Number == 10 && l.Hits == 3 && l.ConditionCoverage == null); var method03 = class0.Methods.Method[2]; Assert.Equal("DummyMethod4", method03.Name); Assert.Equal(1, method03.LineRate); Assert.Equal(1, method03.BranchRate); Assert.Contains(method03.Lines.Line, l => l.Number == 11 && l.Hits == 6 && l.ConditionCoverage == null); Assert.Contains(method03.Lines.Line, l => l.Number == 12 && l.Hits == 6 && l.ConditionCoverage == null); Assert.Contains(method03.Lines.Line, l => l.Number == 13 && l.Hits == 6 && l.ConditionCoverage == null); Assert.Contains(method03.Lines.Line, l => l.Number == 14 && l.Hits == 6 && l.ConditionCoverage == null); Assert.Contains(method03.Lines.Line, l => l.Number == 15 && l.Hits == 6 && l.ConditionCoverage == null); var class1 = package.Classes.Class[1]; Assert.Equal("DummyProject.Server.Controllers.DummyController (1)", class1.Name); Assert.EndsWith(@"src\DummyProject.Server\Controllers\DummyControllerPartial.cs", class1.Filename); Assert.Equal(1, class1.LineRate); Assert.Equal(1, class1.BranchRate); Assert.Single(class1.Methods.Method); Assert.Equal(5, class1.Lines.Line.Count); Assert.Contains(class1.Lines.Line, l => l.Number == 1 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Contains(class1.Lines.Line, l => l.Number == 2 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Contains(class1.Lines.Line, l => l.Number == 3 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Contains(class1.Lines.Line, l => l.Number == 4 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Contains(class1.Lines.Line, l => l.Number == 5 && l.Hits == 24 && l.ConditionCoverage == null); var method11 = class1.Methods.Method[0]; Assert.Equal("DummyMethod3", method11.Name); Assert.Equal(1, method11.LineRate); Assert.Equal(1, method11.BranchRate); Assert.Contains(method11.Lines.Line, l => l.Number == 1 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Contains(method11.Lines.Line, l => l.Number == 2 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Contains(method11.Lines.Line, l => l.Number == 3 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Contains(method11.Lines.Line, l => l.Number == 4 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Contains(method11.Lines.Line, l => l.Number == 5 && l.Hits == 24 && l.ConditionCoverage == null); Assert.Single(logger.Messages); Assert.Equal("Calculating the statistics of the merged report...", logger.Messages[0]); }
public Day1_TotalExpenses() { var input = File.ReadAllLines("Input/day1.txt").Select(int.Parse).ToArray(); _expenseCalculator = new ReportCalculator(input); }
private void CreateReport() { ReportDefinition reportDefinition; string fileName; string directoryName; if (this.Request.Params["SavedReport"] == null) { // Get the full path to the directory // where the saved report is saved. directoryName = Path.Combine( Request.PhysicalApplicationPath, "Fileadmin", "ReportDefinitions", Global.Core.ClientName, Global.User.Id.ToString() ); lblPageTitle.Text = Global.LanguageManager.GetText("Crosstabs"); if (HttpContext.Current.Session["ActiveSavedReport"] != null && Directory.Exists((string)HttpContext.Current.Session["ActiveSavedReport"])) { Directory.Delete((string)HttpContext.Current.Session["ActiveSavedReport"], true); } HttpContext.Current.Session["ActiveSavedReport"] = null; if (HttpContext.Current.Session["ReportDefinition"] != null && (new FileInfo(HttpContext.Current.Session["ReportDefinition"].ToString())).DirectoryName != directoryName) { HttpContext.Current.Session["ReportDefinition"] = null; } } else { Guid idUser = Guid.Parse(this.Request.Params["SavedReport"].Substring(0, 36)); Guid idReport = Guid.Parse(this.Request.Params["SavedReport"].Substring(36, 36)); directoryName = Path.Combine( Request.PhysicalApplicationPath, "Fileadmin", "Temp", "OpenSavedReports", HttpContext.Current.Session.SessionID, this.Request.Params["SavedReport"] ); if (HttpContext.Current.Session["ActiveSavedReport"] == null || Directory.Exists(directoryName) == false) { // Get the full path to the directory // where the user's reports are saved. string sourceDirectoryName = ""; if (HttpContext.Current.Session["ManualSaveReportFolderSelect"] != null) { sourceDirectoryName = HttpContext.Current.Session["ManualSaveReportFolderSelect"].ToString() + "/" + idReport.ToString(); } if (sourceDirectoryName == "") { sourceDirectoryName = Path.Combine( Request.PhysicalApplicationPath, "Fileadmin", "SavedReports", Global.Core.ClientName, idUser.ToString(), idReport.ToString() ); } if (HttpContext.Current.Session["LinkCloudSelectedReportUrl"] == null && HttpContext.Current.Session["ManualSaveReportFolderSelect"] != null) { HttpContext.Current.Session["LinkCloudSelectedReportUrl"] = HttpContext.Current.Session["ManualSaveReportFolderSelect"]; } if (HttpContext.Current.Session["LinkCloudSelectedReportUrl"] == null || !Directory.Exists(sourceDirectoryName)) { string[] paths = Directory.GetDirectories(Path.Combine(Request.PhysicalApplicationPath, "Fileadmin", "SavedReports", Global.Core.ClientName, idUser.ToString()), "*", SearchOption.AllDirectories); if (paths.Where(x => x.ToLower().IndexOf(idReport.ToString().ToLower()) > -1) != null) { HttpContext.Current.Session["LinkCloudSelectedReportUrl"] = paths.Where(x => x.ToLower().IndexOf(idReport.ToString().ToLower()) > -1).FirstOrDefault(); } } if (HttpContext.Current.Session["LinkCloudSelectedReportUrl"].ToString().IndexOf(idReport.ToString()) != -1) { sourceDirectoryName = HttpContext.Current.Session["LinkCloudSelectedReportUrl"].ToString(); } if (Directory.Exists(directoryName)) { Directory.Delete(directoryName, true); } Directory.CreateDirectory(directoryName); foreach (string file in Directory.GetFiles(sourceDirectoryName).OrderBy(d => new FileInfo(d).CreationTime)) { File.Copy(file, Path.Combine( directoryName, new FileInfo(file).Name )); File.SetCreationTime(Path.Combine( directoryName, new FileInfo(file).Name ), File.GetCreationTime(file)); } //foreach (string file in Directory.GetFiles(sourceDirectoryName)) //{ // File.Copy(file, Path.Combine( // directoryName, // new FileInfo(file).Name // )); //} } if (HttpContext.Current.Session["ActiveSavedReport"] == null) { HttpContext.Current.Session["ReportDefinition"] = null; } HttpContext.Current.Session["ActiveSavedReport"] = directoryName; if (HttpContext.Current.Session["ReportDefinition"] != null) { if (new FileInfo(HttpContext.Current.Session["ReportDefinition"].ToString()).DirectoryName != directoryName) { HttpContext.Current.Session["ReportDefinition"] = null; } } ReportDefinitionInfo savedReportInfo = new ReportDefinitionInfo(Path.Combine( directoryName, "Info.xml" )); lblPageTitle.Text = "<table style=\"display:inline-block\"><tbody style=\"display:inline-block\"><tr style=\"display:inline-block\"><td style=\"display:inline-block\"><img src=\"/Images/Icons/Back.png\" onclick=\"window.location='/Pages/LinkCloud.aspx'\" " + "onmouseover=\"this.src='/Images/Icons/Back_Hover.png'\" onmouseout=\"this.src='/Images/Icons/Back.png'\" style=\"cursor:pointer;\" />" + "</td><tr style=\"margin-top:-20px;display:inline-block \"><td style=\"display:inline-block\">" + savedReportInfo.Name + "</td></tr></tr></tbody></table>"; } if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } ReportDefinitionInfo info = new ReportDefinitionInfo(Path.Combine( directoryName, "Info.xml" )); info.LatestAccess = DateTime.Now; info.Save(); // Get all the reports of the user. List <string> reports = info.GetReports( Global.Core, Global.IdUser.Value ); if (HttpContext.Current.Session["ReportDefinition"] != null) { if (!reports.Contains(HttpContext.Current.Session["ReportDefinition"])) { HttpContext.Current.Session["ReportDefinition"] = null; } } if (HttpContext.Current.Session["ReportDefinition"] == null && info.ActiveReport.HasValue) { HttpContext.Current.Session["ReportDefinition"] = Path.Combine( directoryName, info.ActiveReport.Value + ".xml" ); } // Check if for the current session a report is selected. if (HttpContext.Current.Session["ReportDefinition"] == null || File.Exists(HttpContext.Current.Session["ReportDefinition"].ToString()) == false) { // Check if the user has reports defined. if (reports.Count == 0) { fileName = Path.Combine( directoryName, Guid.NewGuid().ToString() + ".xml" ); string fileNameWorkflow = Path.Combine( Request.PhysicalApplicationPath, "App_Data", "ReportingWorkflows", Global.Core.ClientName + ".xml" ); string fileNameWeighting = Path.Combine( Request.PhysicalApplicationPath, "App_Data", "WeightingDefaults", Global.Core.ClientName + ".xml" ); if (!File.Exists(fileNameWeighting)) { fileNameWeighting = null; } reportDefinition = new ReportDefinition( Global.Core, fileName, fileNameWorkflow, fileNameWeighting, Global.HierarchyFilters[fileName, false], Global.UserDefaults["ReportDefinitionSettings"] ); reportDefinition.XmlDocument.DocumentElement.SetAttribute("Name", GetUniqueReportName(string.Format(Global.LanguageManager.GetText("NewReport"), "").Trim(), directoryName)); reportDefinition.Save(); reports = info.GetReports( Global.Core, Global.IdUser.Value ); } else { // Select the first report as the selected report. fileName = reports[0]; } HttpContext.Current.Session["ReportDefinition"] = fileName; } else { // Get the full path to the currently selected report's definition file. fileName = HttpContext.Current.Session["ReportDefinition"].ToString(); } // Get the full path of the current session's report definition file. string directory = (new FileInfo(HttpContext.Current.Session["ReportDefinition"].ToString())).DirectoryName; // Run through all files of the directory. foreach (string file in Directory.GetFiles(directory).OrderBy(x => new FileInfo(x).CreationTime)) { if (Path.GetFileName(file) == "Info.xml") { continue; } csFilterDefinition.Source = file; EquationDefinition.Source = file; HierarchySelector.FileName = Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "HierarchySelectors", Global.Core.ClientName + ".xml" ); HierarchySelector.Source = file; // Create a new report definition by the report definition file. reportDefinition = new ReportDefinition( Global.Core, file, Global.HierarchyFilters[file] ); bool hasNewCategories1 = reportDefinition.CheckForNewCategories(); if (hasNewCategories1) { reportDefinition.Save(); reportDefinition = new ReportDefinition( Global.Core, file, Global.HierarchyFilters[file] ); ReportCalculator calculator = new ReportCalculator( reportDefinition, Global.Core, HttpContext.Current.Session ); calculator.Aggregate((string)HttpContext.Current.Session["Version"]); } if (HierarchySelector.Exists) { HierarchySelector.Parse(); } reportDefinition.Save(); } csFilterDefinition.Source = fileName; EquationDefinition.Source = fileName; HierarchySelector.FileName = Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "HierarchySelectors", Global.Core.ClientName + ".xml" ); HierarchySelector.Source = fileName; // Create a new report definition by the report definition file. reportDefinition = new ReportDefinition( Global.Core, fileName, Global.HierarchyFilters[fileName] ); bool hasNewCategories = reportDefinition.CheckForNewCategories(); if (hasNewCategories) { reportDefinition.Save(); reportDefinition = new ReportDefinition( Global.Core, fileName, Global.HierarchyFilters[fileName] ); ReportCalculator calculator = new ReportCalculator( reportDefinition, Global.Core, HttpContext.Current.Session ); calculator.Aggregate((string)HttpContext.Current.Session["Version"]); } if (HierarchySelector.Exists) { HierarchySelector.Parse(); int optionCount = 0; foreach (Classes.Controls.HierarchySelectorSection section in HierarchySelector.Sections.Values) { optionCount += section.OptionCount; } if (optionCount <= 1) { pnlRightPanelHierarchy.Visible = false; } else { pnlRightPanelHierarchy.Attributes.Add("onclick", string.Format( "InitDragBox('boxHierarchySelectorControl');LoadHierarchySelectedItems('{0}');", HttpUtility.UrlEncode(fileName.Replace("\\", "/")) )); if (reportDefinition.XmlDocument.DocumentElement.SelectSingleNode("HierarchyFilter") == null) { Page.ClientScript.RegisterStartupScript( this.GetType(), "ShowHierarchySelector", string.Format("InitDragBox('boxHierarchySelectorControl');LoadHierarchySelectedItems('{0}');", HttpUtility.UrlEncode(fileName.Replace("\\", "/"))), true ); } } } else { pnlRightPanelHierarchy.Visible = false; } if (base.ContentWidth != 0) { reportDefinition.Settings.TableWidth = base.ContentWidth; } if (base.ContentHeight != 0) { reportDefinition.Settings.TableHeight = base.ContentHeight; } reportDefinition.Save(); Crosstables.Classes.Crosstable crosstable = new Crosstables.Classes.Crosstable( Global.Core, fileName ); //crosstable.FilterClickAction = "ctl00$cphContent$btnDisplayFilters"; pnl.Controls.Add(crosstable); BindSettings(reportDefinition); BindFilteredCategories(reportDefinition); BindWeightingDefinition(reportDefinition); BindReports(reports); if (reportDefinition.Workflow.Selections.Count > 0) { if (bool.Parse(Global.UserDefaults["BottomBarPinned", "false"])) { pnlWorkflowContainer.CssClass = "WorkflowPinned BorderColor1"; } pnlWorkflow.Controls.Add(reportDefinition.Workflow); } else { pnlWorkflowContainer.Visible = false; } if ((fileName.IndexOf(IdUser.ToString()) == -1) && (Convert.ToBoolean(HttpContext.Current.Session["RenderValues"]) == true)) { HttpContext.Current.Session["RenderValues"] = false; ScriptManager.RegisterClientScriptBlock(this, GetType(), "Javascript", "RenderValues();", true); } }