public string DownloadFile(OutputParametersViewModel analysisResults)
        {
            var analysisDictionary = new AnalysisDictionary();

            this.GetValuesFromProperty(analysisResults.CommonResults, analysisDictionary);
            this.GetValuesFromProperty(analysisResults.NightWatchmanResults, analysisDictionary);

            // Generate Shopping included and excluded files
            var excludedFilename = Path.Combine(ApplicationSettings.OutputFolderPath, "Shopping Excluded Programs.txt");
            var includedFilename = Path.Combine(ApplicationSettings.OutputFolderPath, "Shopping Included Programs.txt");
            Exclusions.ExclusionFilter = (string)EnvironmentSettings.GetConfigSectionValues("Shopping")["ShoppingDefaultExclusions"];
            Exclusions.GenerateIncludedAndExcludedFiles(includedFilename, excludedFilename);

            // Create zip file
            var filesToZip = new List<ZipFileEntry>
                {
                    new ZipFileEntry(NightWatchmanController.GenerateReport(analysisResults, ReportType.Word)),
                    new ZipFileEntry(NightWatchmanController.GenerateReport(analysisResults, ReportType.Pdf)),
                    new ZipFileEntry(ShoppingController.GenerateReport(analysisResults, ReportType.Word)),
                    new ZipFileEntry(ShoppingController.GenerateReport(analysisResults, ReportType.Pdf)),
                    new ZipFileEntry(excludedFilename),
                    new ZipFileEntry(includedFilename)
                };

            var zipFileName = string.Format("{0}_Results_{1}.zip", analysisResults.CommonResults.CompanyName, DateTime.UtcNow.ToString("yyyy_MM_dd_hh_m_ss"));

            const string ZipPassword = "";

            ZipPackage.PackageFiles(
                filesToZip, Path.Combine(ApplicationSettings.OutputFolderPath, zipFileName), ZipPassword);

            return zipFileName;
        }
        public string DownloadFile(OutputParametersViewModel analysisResults)
        {
            var analysisDictionary = new AnalysisDictionary();

            this.GetValuesFromProperty(analysisResults.CommonResults, analysisDictionary);
            this.GetValuesFromProperty(analysisResults.NightWatchmanResults, analysisDictionary);

            // Generate Shopping included and excluded files
            var excludedFilename = Path.Combine(ApplicationSettings.OutputFolderPath, "Shopping Excluded Programs.txt");
            var includedFilename = Path.Combine(ApplicationSettings.OutputFolderPath, "Shopping Included Programs.txt");

            Exclusions.ExclusionFilter = (string)EnvironmentSettings.GetConfigSectionValues("Shopping")["ShoppingDefaultExclusions"];
            Exclusions.GenerateIncludedAndExcludedFiles(includedFilename, excludedFilename);

            // Create zip file
            var filesToZip = new List <ZipFileEntry>
            {
                new ZipFileEntry(NightWatchmanController.GenerateReport(analysisResults, ReportType.Word)),
                new ZipFileEntry(NightWatchmanController.GenerateReport(analysisResults, ReportType.Pdf)),
                new ZipFileEntry(ShoppingController.GenerateReport(analysisResults, ReportType.Word)),
                new ZipFileEntry(ShoppingController.GenerateReport(analysisResults, ReportType.Pdf)),
                new ZipFileEntry(excludedFilename),
                new ZipFileEntry(includedFilename)
            };

            var zipFileName = string.Format("{0}_Results_{1}.zip", analysisResults.CommonResults.CompanyName, DateTime.UtcNow.ToString("yyyy_MM_dd_hh_m_ss"));

            const string ZipPassword = "";

            ZipPackage.PackageFiles(
                filesToZip, Path.Combine(ApplicationSettings.OutputFolderPath, zipFileName), ZipPassword);

            return(zipFileName);
        }
        public ViewResult Download(OutputParametersViewModel analysisResults)
        {
            var httpCookie = this.HttpContext.Request.Cookies[ApplicationSettings.SelectedFileName];

            if (httpCookie != null)
            {
                var shoppingProgramListModel = new ShoppingProgramListModel(analysisResults.CommonResults.FileName);
                analysisResults.ShoppingProgramListResults = new ShoppingProgramListViewModel
                {
                    ProgramList = shoppingProgramListModel.Build(analysisResults.ShoppingResults)
                }; 
                
                var filname = httpCookie.Value;

                var packageFile = this.DownloadFile(analysisResults);

                var cleanup = new CleanupDb(AnalysisManager.CleanupAnalysisManager);

                IAsyncResult ar = cleanup.BeginInvoke(filname, ApplicationSettings.DatabaseConnectionString, null, null);

                this.DownloadFile(ApplicationSettings.OutputFolderPath, packageFile);
                Log.InfoFormat("{0} downloaded to {1}", packageFile, ApplicationSettings.OutputFolderPath);
            }

            return this.View();
        }
Exemplo n.º 4
0
        public static string GenerateReport(OutputParametersViewModel analysisResults, ReportType reportType)
        {
            var reportViewer = new ReportViewer();

            reportViewer.LocalReport.ReportEmbeddedResource = "SavingsAnalysis.Web.Reports.Shopping.rdlc";

            // Program list
            var dataSetShoppingProgramList = CreateDataSource(analysisResults.ShoppingProgramListResults.ProgramList, "DataSetShoppingProgramList");

            reportViewer.LocalReport.DataSources.Add(dataSetShoppingProgramList);

            reportViewer.LocalReport.SetParameters(
                new[]
            {
                // Common
                new ReportParameter("CompanyName", analysisResults.CommonResults.CompanyName),
                new ReportParameter("CurrencySymbol", analysisResults.CommonResults.CurrencySymbol),

                // Shopping
                new ReportParameter("CostPerRequest", analysisResults.ShoppingResults.CostPerRequest.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("EndDate", analysisResults.ShoppingResults.ShopEndDate.ToString(CultureInfo.CurrentCulture.DateTimeFormat)),
                new ReportParameter("NumberOfActiveMachines", analysisResults.ShoppingResults.NumberOfActiveMachines.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("Period", analysisResults.ShoppingResults.Period.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("StartDate", analysisResults.ShoppingResults.ShopStartDate.ToString(CultureInfo.CurrentCulture.DateTimeFormat)),
                new ReportParameter("Threshold", analysisResults.ShoppingResults.Threshold.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("TotalNumberOfOneOffRequests", analysisResults.ShoppingResults.TotalNumberOfOneOffRequests.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("TotalNumberOfRequests", analysisResults.ShoppingResults.TotalNumberOfRequests.ToString(CultureInfo.InvariantCulture))
            });

            var filename = DetermineFilename("Shopping", reportType);

            SaveReport(filename, reportType, reportViewer);

            return(filename);
        }
        public ViewResult Download(OutputParametersViewModel analysisResults)
        {
            var httpCookie = this.HttpContext.Request.Cookies[ApplicationSettings.SelectedFileName];

            if (httpCookie != null)
            {
                var shoppingProgramListModel = new ShoppingProgramListModel(analysisResults.CommonResults.FileName);
                analysisResults.ShoppingProgramListResults = new ShoppingProgramListViewModel
                {
                    ProgramList = shoppingProgramListModel.Build(analysisResults.ShoppingResults)
                };

                var filname = httpCookie.Value;

                var packageFile = this.DownloadFile(analysisResults);

                var cleanup = new CleanupDb(AnalysisManager.CleanupAnalysisManager);

                IAsyncResult ar = cleanup.BeginInvoke(filname, ApplicationSettings.DatabaseConnectionString, null, null);

                this.DownloadFile(ApplicationSettings.OutputFolderPath, packageFile);
                Log.InfoFormat("{0} downloaded to {1}", packageFile, ApplicationSettings.OutputFolderPath);
            }

            return(this.View());
        }
        public ActionResult AnalysisResults()
        {
            InputParametersViewModel input = null;

            if (this.TempData.ContainsKey("input"))
            {
                input = (InputParametersViewModel)this.TempData["input"];
            }

            if (input != null && input.Common != null)
            {
                ViewBag.SelectedFile = input.Common.FileName;
            }

            var shoppingAnalysis        = new ShoppingAnalysisModel(input.Shopping, input.Common);
            var shoppingAnalysisResults = shoppingAnalysis.Build();

            var nightWatchmanAnalysisModel   = new NightWatchmanAnalysisModel(input.NightWatchman, input.Common);
            var nightWatchmanAnalysisResults = nightWatchmanAnalysisModel.Build();

            var model = new OutputParametersViewModel
            {
                CommonResults        = input.Common,
                NightWatchmanResults = nightWatchmanAnalysisResults,
                ShoppingResults      = shoppingAnalysisResults
            };

            return(this.View(model));
        }
        public ActionResult AnalysisResults(OutputParametersViewModel input)
        {
            ViewBag.SelectedFile = input.CommonResults.FileName;
            if (!ModelState.IsValid)
            {
                return(this.View(input));
            }

            return(this.View(input));
        }
        public void AnalysisResultPostTest()
        {
            var shoppingProgramListViewModel = new ShoppingProgramListViewModel
            {
                ProgramList = new List <ShoppingProgram>()
            };

            for (int i = 1; i < 20; i++)
            {
                shoppingProgramListViewModel.ProgramList.Add(
                    new ShoppingProgram
                {
                    AttributeValue = string.Format("Test{0}", i),
                    PackageName    = string.Format("PackageName{0}", i),
                    ProgramName    = string.Format("ProgramName{0}", i),
                    TotalCount     = i * 1111
                });
            }

            var analysisParameters = new OutputParametersViewModel
            {
                CommonResults =
                    new CommonInputParameterViewModel
                {
                    CurrencySymbol = "$",
                    FileName       = Path.Combine(EnvironmentSettings.GetInstance().DataUploadPath, CsvFileName)
                },
                NightWatchmanResults       = new NightWatchmanAnalysisResultsViewModel(),
                ShoppingResults            = new ShoppingAnalysisViewModel(),
                ShoppingProgramListResults = shoppingProgramListViewModel
            };

            var result = new SavingsAnalysisController().DownloadFile(analysisParameters);

            result = Path.Combine(EnvironmentSettings.GetInstance().OutputFolderPath, result);


            try
            {
                if (File.Exists(result))
                {
                    Assert.Pass("Report createded successfully ");
                }
                else
                {
                    Assert.Fail("Report not created");
                }
            }
            catch (SuccessException)
            {
            }
        }
        public void ReportParametersPostTest()
        {
            var analysisParameters = new OutputParametersViewModel()
                {
                    CommonResults = new CommonInputParameterViewModel
                            { FileName = Path.Combine(EnvironmentSettings.GetInstance().DataUploadPath, CsvFileName) },

                    NightWatchmanResults  = new NightWatchmanAnalysisResultsViewModel(),
                    ShoppingResults = new ShoppingAnalysisViewModel()
                };
            var result = new SavingsAnalysisController().AnalysisResults(analysisParameters) as ViewResult;
            Assert.AreEqual(Path.Combine(EnvironmentSettings.GetInstance().DataUploadPath, CsvFileName), result.ViewBag.SelectedFile);
        }
        public void ReportParametersPostTest()
        {
            var analysisParameters = new OutputParametersViewModel()
            {
                CommonResults = new CommonInputParameterViewModel
                {
                    FileName = Path.Combine(EnvironmentSettings.GetInstance().DataUploadPath, CsvFileName)
                },

                NightWatchmanResults = new NightWatchmanAnalysisResultsViewModel(),
                ShoppingResults      = new ShoppingAnalysisViewModel()
            };
            var result = new SavingsAnalysisController().AnalysisResults(analysisParameters) as ViewResult;

            Assert.AreEqual(Path.Combine(EnvironmentSettings.GetInstance().DataUploadPath, CsvFileName), result.ViewBag.SelectedFile);
        }
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var model = new OutputParametersViewModel
            {
                CommonResults =
                    base.BindModel(
                        controllerContext,
                        new ModelBindingContext()
                {
                    ModelMetadata =
                        ModelMetadataProviders.Current.GetMetadataForType(
                            () => new CommonInputParameterViewModel(), typeof(CommonInputParameterViewModel)),
                    ModelState    = bindingContext.ModelState,
                    ValueProvider = bindingContext.ValueProvider
                }) as CommonInputParameterViewModel,
                NightWatchmanResults =
                    base.BindModel(
                        controllerContext,
                        new ModelBindingContext()
                {
                    ModelMetadata =
                        ModelMetadataProviders.Current.GetMetadataForType(
                            () => new NightWatchmanAnalysisResultsViewModel(),
                            typeof(NightWatchmanAnalysisResultsViewModel)),
                    ModelState    = bindingContext.ModelState,
                    ValueProvider = bindingContext.ValueProvider
                }) as NightWatchmanAnalysisResultsViewModel,
                ShoppingResults =
                    base.BindModel(
                        controllerContext,
                        new ModelBindingContext()
                {
                    ModelMetadata =
                        ModelMetadataProviders.Current.GetMetadataForType(
                            () => new ShoppingAnalysisViewModel(), typeof(ShoppingAnalysisViewModel)),
                    ModelState    = bindingContext.ModelState,
                    ValueProvider = bindingContext.ValueProvider
                }) as ShoppingAnalysisViewModel
            };


            return(model);
        }
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var model = new OutputParametersViewModel
                {
                    CommonResults = 
                        base.BindModel(
                            controllerContext,
                            new ModelBindingContext()
                                {
                                    ModelMetadata =
                                        ModelMetadataProviders.Current.GetMetadataForType(
                                            () => new CommonInputParameterViewModel(), typeof(CommonInputParameterViewModel)),
                                    ModelState = bindingContext.ModelState,
                                    ValueProvider = bindingContext.ValueProvider
                                }) as CommonInputParameterViewModel,
                    NightWatchmanResults =
                        base.BindModel(
                            controllerContext,
                            new ModelBindingContext()
                                {
                                    ModelMetadata =
                                        ModelMetadataProviders.Current.GetMetadataForType(
                                            () => new NightWatchmanAnalysisResultsViewModel(),
                                            typeof(NightWatchmanAnalysisResultsViewModel)),
                                    ModelState = bindingContext.ModelState,
                                    ValueProvider = bindingContext.ValueProvider
                                }) as NightWatchmanAnalysisResultsViewModel,
                    ShoppingResults =
                        base.BindModel(
                            controllerContext,
                            new ModelBindingContext()
                                {
                                    ModelMetadata =
                                        ModelMetadataProviders.Current.GetMetadataForType(
                                            () => new ShoppingAnalysisViewModel(), typeof(ShoppingAnalysisViewModel)),
                                    ModelState = bindingContext.ModelState,
                                    ValueProvider = bindingContext.ValueProvider
                                }) as ShoppingAnalysisViewModel
                };


            return model;
        }
        public static string GenerateReport(OutputParametersViewModel analysisResults, ReportType reportType)
        {
            var reportViewer = new ReportViewer();

            reportViewer.LocalReport.ReportEmbeddedResource = "SavingsAnalysis.Web.Reports.NightWatchman.rdlc";

            // Power State
            var dataSetShoppingProgramList = CreateDataSource("DataSetNightwatchmanOvernightPowerState");

            reportViewer.LocalReport.DataSources.Add(dataSetShoppingProgramList);

            reportViewer.LocalReport.SetParameters(
                new[]
            {
                // Common
                new ReportParameter("CompanyName", analysisResults.CommonResults.CompanyName),
                new ReportParameter("CurrencySymbol", analysisResults.CommonResults.CurrencySymbol),

                // Nightwatchman
                new ReportParameter("NumberOfDesktops", analysisResults.NightWatchmanResults.NumberOfDesktops.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("NumberOfLaptops", analysisResults.NightWatchmanResults.NumberOfLaptops.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("PassengerCars", analysisResults.NightWatchmanResults.PassengerCars.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("Period", analysisResults.NightWatchmanResults.Period.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("PotentialYearlyCO2Savings", analysisResults.NightWatchmanResults.PotentialYearlyCO2Savings.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("PotentialYearlyKwhSavings", analysisResults.NightWatchmanResults.PotentialYearlyKwhSavings.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("PowerStateOff", analysisResults.NightWatchmanResults.PowerStateOff.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("PowerStateOn", analysisResults.NightWatchmanResults.PowerStateOn.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("ShowCars", analysisResults.NightWatchmanResults.ShowCars.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("ShowNuclear", analysisResults.NightWatchmanResults.ShowNuclear.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("ShowStars", analysisResults.NightWatchmanResults.ShowStars.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("ShowTrees", analysisResults.NightWatchmanResults.ShowTrees),
                new ReportParameter("ShowZ", analysisResults.NightWatchmanResults.ShowZ.ToString(CultureInfo.InvariantCulture)),
                new ReportParameter("StartDate", analysisResults.NightWatchmanResults.NWStartDate.ToString("dd MMM yyyy")),
                new ReportParameter("YearlyCostSavings", analysisResults.NightWatchmanResults.YearlyCostSavings.ToString(CultureInfo.InvariantCulture)),
            });

            var filename = DetermineFilename("NightWatchmanNew", reportType);

            SaveReport(filename, reportType, reportViewer);

            return(filename);
        }
        public ActionResult AnalysisResults(OutputParametersViewModel input)
        {
            ViewBag.SelectedFile = input.CommonResults.FileName;
            if (!ModelState.IsValid)
            {
                return this.View(input);
            }

            return this.View(input);
        }
        public ActionResult AnalysisResults()
        {
            InputParametersViewModel input = null;
            if (this.TempData.ContainsKey("input"))
            {
                input = (InputParametersViewModel)this.TempData["input"];
            }

            if(input != null && input.Common != null) ViewBag.SelectedFile = input.Common.FileName;

            var shoppingAnalysis = new ShoppingAnalysisModel(input.Shopping, input.Common);
            var shoppingAnalysisResults = shoppingAnalysis.Build();

            var nightWatchmanAnalysisModel = new NightWatchmanAnalysisModel(input.NightWatchman, input.Common);
            var nightWatchmanAnalysisResults = nightWatchmanAnalysisModel.Build();

            var model = new OutputParametersViewModel
                            {
                                CommonResults = input.Common,
                                NightWatchmanResults = nightWatchmanAnalysisResults,
                                ShoppingResults = shoppingAnalysisResults
                            };

            return this.View(model);
        }
        public void AnalysisResultPostTest()
        {
            var shoppingProgramListViewModel = new ShoppingProgramListViewModel
                {
                    ProgramList = new List<ShoppingProgram>()
                };

            for (int i = 1; i < 20; i++)
            {
                shoppingProgramListViewModel.ProgramList.Add(
                    new ShoppingProgram
                        {
                            AttributeValue = string.Format("Test{0}", i),
                            PackageName = string.Format("PackageName{0}", i),
                            ProgramName = string.Format("ProgramName{0}", i),
                            TotalCount = i * 1111
                        });
            }

            var analysisParameters = new OutputParametersViewModel
                {
                    CommonResults =
                        new CommonInputParameterViewModel
                            {
                                CurrencySymbol = "$",
                                FileName = Path.Combine(EnvironmentSettings.GetInstance().DataUploadPath, CsvFileName)
                            }, 
                    NightWatchmanResults = new NightWatchmanAnalysisResultsViewModel(), 
                    ShoppingResults = new ShoppingAnalysisViewModel(),
                    ShoppingProgramListResults = shoppingProgramListViewModel
                };

            var result = new SavingsAnalysisController().DownloadFile(analysisParameters);
            result = Path.Combine(EnvironmentSettings.GetInstance().OutputFolderPath, result);


            try
            {
                if (File.Exists(result))
                {
                    Assert.Pass("Report createded successfully ");
                }
                else
                {
                    Assert.Fail("Report not created");
                }
            }
            catch (SuccessException)
            {
            }
        }