Пример #1
0
        private static void WriteDvnrReportFile(ReportFileType reportType, string dvnrFilePath, DvnrReport report)
        {
            try
            {
                string filePath = Path.Combine(Environment.CurrentDirectory, dvnrFilePath);
                File.Delete(filePath);

                using (var file = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    using (var sw = new StreamWriter(file))
                    {
                        if (reportType == ReportFileType.Xml)
                        {
                            PrintReportXml(report, sw);
                        }
                        if (reportType == ReportFileType.Json)
                        {
                            PrintReportJson(report, sw);
                        }
                        if (reportType == ReportFileType.Text)
                        {
                            PrintReportText(report, sw);
                        }

                        Console.WriteLine("Report was written to: {0}", filePath);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Could not save report file. Error: {0}", ex.ToString());
                Console.WriteLine("Could not save report file");
            }
        }
Пример #2
0
        public ReportFile(
            [NotNull] string title,
            [NotNull] string fileName,
            [NotNull] string rawHtml,
            [NotNull] byte[] content,
            ReportFileType reportFileType)
        {
            if (title == null)
            {
                throw new ArgumentNullException(nameof(title));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            FileName = fileName;

            Content = content.ToArray();

            RawHtml = rawHtml;

            ReportFileType = reportFileType;

            Title = title;
        }
Пример #3
0
        public ReportFile Build(
            long reportId,
            long userId,
            IReadOnlyDictionary <string, object> parameters,
            ReportFileType reportFileType)
        {
            using (var telemetryScope = _telemetryScopeProvider.Create <Reports>(TelemetryOperationNames.Report.Generate))
            {
                try
                {
                    var report = GetReport(reportId);

                    telemetryScope.SetEntity(report);

                    var reportBundle = GetReportBundle(userId, parameters, report);

                    var reportFile = TranslateReport(reportFileType, reportBundle);

                    SaveReportFileInTempStorage(userId, reportBundle, reportFile);

                    telemetryScope.WriteSuccess();

                    return(reportFile);
                }
                catch (Exception ex)
                {
                    telemetryScope.WriteException(ex);

                    throw;
                }
            }
        }
Пример #4
0
        private static DvnrReport GenerateReportFromExisting(string fromFilename, ReportFileType reportType)
        {
            if (reportType == ReportFileType.Unknown || reportType == ReportFileType.Text)
            {
                throw new ArgumentException("Unsupported report type", nameof(reportType));
            }

            if (!File.Exists(fromFilename))
            {
                Trace.TraceError("Could not find specified from file at {0}", fromFilename);
                Console.WriteLine("Could not find specified from file at {0}", fromFilename);
                return(null);
            }

            string dvnrReportText;

            using (var fileStream = File.Open(fromFilename, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader streamReader = new StreamReader(fileStream, true))
                {
                    dvnrReportText = streamReader.ReadToEnd();
                }
            }

            if (reportType == ReportFileType.Xml)
            {
                Console.WriteLine("Parsing XML report from {0}.", fromFilename);
                return(XmlUtils.XmlDeserializeFromString <DvnrReport>(dvnrReportText));
            }
            // TODO: support json file

            return(null);
        }
Пример #5
0
        public BuildReportQuery(long reportId, IReadOnlyDictionary <string, string> parameters, ReportFileType reportFileType)
        {
            ReportId = reportId;

            Parameters = parameters;

            ReportFileType = reportFileType;
        }
        public IReportTranslator GetTranslator(ReportFileType reportFileType)
        {
            var reportFileTypeString = reportFileType.ToString();

            var reportTranslator = _unityContainer.Resolve <IReportTranslator>(reportFileTypeString);

            return(reportTranslator);
        }
Пример #7
0
        public bool SendByEmail(ReportFileType fileType, string email)
        {
            if (fileType == ReportFileType.TXT)
            {
                GetTxtReport();
            }
            var taskEmailSender = Task.Run(() => SendEmailAsync(email));

            return(true);
        }
Пример #8
0
        public static IReportParser Create(ReportFileType reportFileType, DataDictionary dataDictionary, TextWriter errorWriter)
        {
            switch (reportFileType)
            {
            case ReportFileType.EastMoneyPlainHtml:
                return(new EastMoneyPlainHtmlReportParser(dataDictionary, errorWriter));

            default:
                throw new NotImplementedException();
            }
        }
        private string GetReportFileName(ReportBundle reportBundle, ReportFileType reportFileType)
        {
            var currentDateUtc = _timeService.GetUtc();

            const string dateMask = "yyyy-MM-dd hh-mm-ss-ffff";

            var reportFileExtension = _reportFileExtensionProvider.Get(reportFileType);

            var validFileName = reportBundle.Title.ToValidPath();

            var fileName = $"{validFileName} {currentDateUtc.ToString(dateMask)}.{reportFileExtension}";

            return(fileName);
        }
        public static string Get(ReportFileType value)
        {
            var type = value.GetType();

            var memInfo = type.GetMember(value.ToString()).SingleOrDefault();

            var attribute = memInfo.GetCustomAttribute <ReportFileTypeExtensionAttribute>();

            if (attribute == null)
            {
                throw new ArgumentException(nameof(value));
            }

            return(attribute._extension);
        }
        public ReportFile Translate([NotNull] ReportBundle reportBundle, ReportFileType reportFileType)
        {
            if (reportBundle == null)
            {
                throw new ArgumentNullException(nameof(reportBundle));
            }

            var translator = _reportTranslatorFabric.GetTranslator(reportFileType);

            var reportFileContent = translator.Translate(reportBundle.BodyHtml);

            var reportTitle = GetReportFileName(reportBundle, reportFileType);

            return(new ReportFile(reportBundle.Title, reportTitle, reportBundle.BodyHtml, reportFileContent, reportFileType));
        }
        public void ShouldGenerateReport()
        {
            const int reportId = 234234;

            var report = new Reports
            {
                Id = reportId
            };

            _reportStorage
            .Setup(_ => _.Get(reportId))
            .Returns(report);

            const int userId = 2342342;

            var parameters = new Dictionary <string, object>
            {
                { "Halo", "No" }
            };

            var reportBundle = new ReportBundle();

            _reportGenerationPipelineManager
            .Setup(_ => _.Generate(report, userId, parameters))
            .Returns(reportBundle);

            const ReportFileType reportFileType = ReportFileType.Html;

            var reportFile = new ReportFile("Title", "Repo", "<div></div>", Guid.NewGuid().ToByteArray(), reportFileType);

            _reportTranslationManager
            .Setup(_ => _.Translate(reportBundle, reportFileType))
            .Returns(reportFile);

            var result = _target.Build(reportId, userId, parameters, reportFileType);

            _repositoryLogger.Verify(_ => _.SaveReportFile(reportBundle, reportFile, userId), Times.Once);

            result.ShouldBeEquivalentTo(reportFile);
        }
Пример #13
0
 private ReportFile TranslateReport(ReportFileType reportFileType, ReportBundle reportBundle) =>
 _reportTranslationManager.Translate(reportBundle, reportFileType);
        public void ShouldGetReportFileExtension(ReportFileType reportFileType, string extension)
        {
            var result = ReportFileTypeExtensionAttribute.Get(reportFileType);

            result.ShouldBeEquivalentTo(extension);
        }
 public static IUnityContainer RegisterTranslator <T>(this IUnityContainer container,
                                                      ReportFileType reportFileType,
                                                      ReuseScope reuseScope)
     where T : IReportTranslator => container.RegisterType <IReportTranslator, T>(reportFileType.ToString(), reuseScope);
Пример #16
0
        public static void Main(string[] args)
        {
            if (AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                // RazorEngine cannot clean up from the default appdomain...
                //Console.WriteLine("Switching to second AppDomain...");
                AppDomainSetup adSetup = new AppDomainSetup();
                adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                var current = AppDomain.CurrentDomain;
                // You only need to add strongnames when your appdomain is not a full trust environment.
                var strongNames = new StrongName[0];

                var domain = AppDomain.CreateDomain(
                    "MyMainDomain", null,
                    current.SetupInformation, new PermissionSet(PermissionState.Unrestricted),
                    strongNames);
                try
                {
                    domain.ExecuteAssembly(Assembly.GetExecutingAssembly().Location, args);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error executing ContrastDvnr: " + ex.Message);
                    Trace.TraceError("Error executing ContrastDvnr: " + ex);
                    return;
                }
                return;
            }

            var traceOutput = new DvnrTraceListener("ContrastDvnr.log", "tracelog");

            Trace.Listeners.Add(traceOutput);
            Trace.AutoFlush = true;

            var arguments = new Docopt().Apply(usage, args, version: "ContrastDvnr 1.0", exit: true);

            Trace.TraceInformation("ContrastDvnr executed with arguments [{0}]", string.Join(" ", args));

            // ensure IIS is installed and we can use ServerManager
            if (!Reporting.PreFlightCheck())
            {
                return;
            }

            bool isXml  = arguments["xml"].IsTrue;
            bool isJson = arguments["json"].IsTrue;
            bool isText = arguments["text"].IsTrue;

            ReportFileType reportType = ReportFileType.Unknown;

            // default to xml if no format is specified
            if (!isXml && !isJson && !isText)
            {
                reportType = ReportFileType.Xml;
            }
            else if (isXml)
            {
                reportType = ReportFileType.Xml;
            }
            else if (isJson)
            {
                reportType = ReportFileType.Json;
            }
            else if (isText)
            {
                reportType = ReportFileType.Text;
            }

            string fileName = "report.xml";

            if (reportType == ReportFileType.Xml)
            {
                fileName = "report.xml";
            }
            else if (reportType == ReportFileType.Json)
            {
                fileName = "report.json";
            }
            else if (reportType == ReportFileType.Text)
            {
                fileName = "report.txt";
            }


            DvnrReport report;
            string     fromFilename = arguments.ContainsKey("--from") ? arguments["--from"]?.ToString() : "";

            if (!string.IsNullOrEmpty(fromFilename))
            {
                report = GenerateReportFromExisting(fromFilename, reportType);
            }
            else
            {
                report = GenerateReportFromCurrentMachine();
            }

            string directory = CreateOutputDirectory();

            if (arguments["--screen"].IsTrue)   // write to screen instead of file
            {
                if (reportType == ReportFileType.Xml)
                {
                    PrintReportXml(report, Console.Out);
                }
                if (reportType == ReportFileType.Json)
                {
                    PrintReportJson(report, Console.Out);
                }
                if (reportType == ReportFileType.Text)
                {
                    PrintReportText(report, Console.Out);
                }
            }
            else
            {   // write to file
                string dvnrReportPath = Path.Combine(directory, fileName);
                Console.WriteLine("Writing DVNR report.");
                WriteDvnrReportFile(reportType, dvnrReportPath, report);

                string compatReportPath = Path.Combine(directory, "compatSummary.md");
                Console.WriteLine("Writing compatibility report.");
                WriteCompatSummary(report, compatReportPath);
            }

            Trace.TraceInformation("ContrastDvnr exited");
            Trace.Flush();
        }
Пример #17
0
        public string Get(ReportFileType reportFileType)
        {
            var fileExtension = ReportFileTypeExtensionAttribute.Get(reportFileType);

            return(fileExtension);
        }
Пример #18
0
        static void Main(string[] args)
        {
            if (args == null || (args.Length != 1 && args.Length != 10))
            {
                return;
            }

            ReportFileType fileType = ReportFileType.Report;

            DataSet dsDataset = null;

            if (args.Length == 1)
            {
                string filename = args[0];

                if (filename.IndexOf("\n") > 0)
                {
                    args = filename.Split("\n".ToCharArray());

                    if (args.Length != 10)
                    {
                        return;
                    }
                }
                else if (filename.EndsWith(".wmks"))
                {
                    wmksFileManager.WriteFile(filename);

                    return;
                }
                else if (filename.EndsWith(".repx"))
                {
                    string Inwfilename = filename.Replace(".repx", ".inw");

                    args = InwManager.ReadInwFile(Inwfilename);

                    fileType = ReportFileType.InwFile;

                    if (args == null)
                    {
                        args = ConfigFileManager.ReadDataConfig(filename);

                        fileType = ReportFileType.BaseXmlFile;
                    }
                }
                else if (filename.EndsWith(".repw"))
                {
                    string Inwfilename = filename.Replace(".repw", ".inw");

                    args = InwManager.ReadInwFile(Inwfilename);

                    fileType = ReportFileType.InwFile;

                    if (args == null)
                    {
                        args = ConfigFileManager.ReadDataConfig(filename);

                        fileType = ReportFileType.BaseXmlFile;
                    }
                }
                else if (filename.EndsWith(".inw"))
                {
                    args = InwManager.ReadInwFile(filename);

                    fileType = ReportFileType.InwFile;
                }
                else if (filename.EndsWith(".wrdf"))
                {
                    WrdfFileManager.ReadDataConfig(filename, out dsDataset, out args);

                    fileType = ReportFileType.WebbDataFile;
                }
                else
                {
                    return;
                }
                if (args == null)
                {
                    return;
                }
            }

            if (args[3] == "DBConn:" && args[8] == @"Files:")
            {
                return;
            }

            Webb.Utility.CurReportMode = 1;             //set browser mode

            ThreadStart ts = new ThreadStart(LoadingThreadProc);

            Thread thread = new Thread(ts);

            thread.Start();

            CommandManager m_CmdManager = new CommandManager(args);

            //Calculate data source
            if (thread.IsAlive)
            {
                LoadingForm.MessageText = "Loading Data Source...";
            }

            DBSourceConfig m_Config = m_CmdManager.CreateDBConfig();

            if (m_Config.Templates.Count == 0)
            {
                if (thread.IsAlive)
                {
                    LoadingForm.Close();

                    thread.Abort();
                }

                Webb.Utilities.TopMostMessageBox.ShowMessage("Invalid template report name!", MessageBoxButtons.OK);

                Environment.Exit(0);
            }


            if (m_CmdManager.PrintDirectly)
            {
                if (PrinterSettings.InstalledPrinters.Count == 0)
                {
                    if (thread.IsAlive)
                    {
                        LoadingForm.Close();

                        thread.Abort();
                    }

                    Webb.Utilities.TopMostMessageBox.ShowMessage("No printer driver is installed!", MessageBoxButtons.OK);

                    Environment.Exit(0);
                }
            }

            WebbDataProvider m_DBProvider = new WebbDataProvider(m_Config);

            WebbDataSource m_DBSource = new WebbDataSource();

            if (fileType == ReportFileType.WebbDataFile && dsDataset == null)
            {
                m_DBSource.DataSource = dsDataset.Copy();
            }
            else
            {
                m_DBProvider.GetDataSource(m_Config, m_DBSource);
            }

            ArrayList m_Fields = new ArrayList();

            foreach (System.Data.DataColumn m_col in m_DBSource.DataSource.Tables[0].Columns)
            {
                if (m_col.Caption == "{EXTENDCOLUMNS}" && m_col.ColumnName.StartsWith("C_"))
                {
                    continue;
                }

                m_Fields.Add(m_col.ColumnName);
            }


            Webb.Reports.DataProvider.VideoPlayBackManager.PublicDBProvider = m_DBProvider;

            Webb.Data.PublicDBFieldConverter.SetAvailableFields(m_Fields);

            Webb.Reports.DataProvider.VideoPlayBackManager.LoadAdvScFilters();  //Modified at 2009-1-19 13:48:30@Scott

            Webb.Reports.DataProvider.VideoPlayBackManager.ReadPictureDirFromRegistry();

            m_DBProvider.UpdateEFFDataSource(m_DBSource);

            Webb.Reports.DataProvider.VideoPlayBackManager.DataSource = m_DBSource.DataSource;  //Set dataset for click event


            //Loading report template
            if (thread.IsAlive)
            {
                LoadingForm.MessageText = "Loading Report Template...";
            }

            #region Modified Area
            ArrayList printedReports = new ArrayList();

            ArrayList invalidateReports = new ArrayList();

            bool unionprint = m_CmdManager.UnionPrint;

            #endregion                    //End Modify at 2008-10-10 14:29:49@Simon


            FilterInfoCollection filterInfos = m_DBSource.Filters;            //2009-7-1 11:09:08@Simon Add this Code  For Union Print

            if (filterInfos == null)
            {
                filterInfos = new FilterInfoCollection();
            }

            string printerName = m_CmdManager.PrinterName;

            foreach (string strTemplate in m_Config.Templates)
            {
                string strTemplateName = m_CmdManager.GetTemplateName(strTemplate, '@');                //Modified at 2009-2-3 9:17:34@Scott

                WebbReport m_Report = null;

                try
                {
                    m_Report = m_CmdManager.CreateReport(Application.ExecutablePath, strTemplateName);                          //1 //create report with template

                    //09-01-2011@Scott
                    if (m_Config.WebbDBType == WebbDBTypes.WebbPlaybook)
                    {
                        SetReportHeader(m_Config, m_Report, m_Config.HeaderName);  //Add this code at 2011-7-28 16:23:41@simon
                    }
                    else
                    {
                        string strHeader = m_CmdManager.GetAttachedHeader(strTemplate, '@');

                        SetReportHeader(m_Config, m_Report, strHeader);
                    }
                    //End
                }
                catch (Exception ex)
                {
                    Webb.Utilities.TopMostMessageBox.ShowMessage("Error", "Can't load report template!\r\n" + ex.Message, MessageBoxButtons.OK);

                    m_Report = new WebbReport();
                }

                bool Canopen = CheckedUserRight(m_Report.LicenseLevel, m_Config.WebbDBType);

                string filename = System.IO.Path.GetFileNameWithoutExtension(strTemplateName);

                if (!Canopen)
                {
                    invalidateReports.Add(filename);
                }
                else
                {
                    //Add attached filter here
                    #region Modified Area

                    m_DBSource.Filters = filterInfos.Copy();                     //2009-7-1 11:09:04@Simon Add this Code  For Union Print

                    string strFilterName = m_CmdManager.GetAttachedFilter(strTemplate, '@');

                    if (strFilterName != string.Empty)                   //2009-7-1 11:09:04@Simon For display Filternames In GameListInfo
                    {
                        if (!m_DBProvider.DBSourceConfig.Filters.Contains(strFilterName))
                        {
                            FilterInfo filterInfo = new FilterInfo();

                            filterInfo.FilterName = strFilterName;

                            m_DBSource.Filters.Add(filterInfo);
                        }
                    }

                    ScAFilter          scaFilter = Webb.Reports.DataProvider.VideoPlayBackManager.AdvReportFilters.GetFilter(strFilterName);            //Modified at 2009-1-19 14:25:30@Scott
                    AdvFilterConvertor convertor = new AdvFilterConvertor();
                    DBFilter           AdvFilter = convertor.GetReportFilter(scaFilter).Filter;

                    if (AdvFilter != null || AdvFilter.Count > 0)               //2009-5-6 9:38:37@Simon Add this Code
                    {
                        AdvFilter.Add(m_Report.Template.Filter);
                        m_Report.Template.Filter = AdvFilter;
                    }

                    SectionFilterCollection sectionFilter = m_Report.Template.SectionFilters.Copy();

                    if (m_Report.Template.ReportScType == ReportScType.Custom)
                    {
                        m_Report.Template.SectionFilters = AdvFilterConvertor.GetCustomFilters(Webb.Reports.DataProvider.VideoPlayBackManager.AdvReportFilters, sectionFilter);
                    }

                    #endregion                            //Modify at 2008-11-24 16:04:05@Scott

                    //Set data source
                    if (thread.IsAlive)
                    {
                        LoadingForm.MessageText = "Set Data Source...";
                        LoadingForm.ProcessText = Webb.Utility.GetCurFileName();
                    }

                    m_Report.LoadAdvSectionFilters(m_Config.UserFolder);

                    m_Report.SetWatermark(m_Config.WartermarkImagePath);                        //06-19-2008@Scott

                    m_Report.SetDataSource(m_DBSource);
                }

                if (m_CmdManager.PrintDirectly)
                {
                    if (!Canopen)
                    {
                        if (!unionprint)
                        {
                            Webb.Utilities.TopMostMessageBox.ShowMessage("LicenseLevel Error", "This report is not designed for your Webb application!" + "", MessageBoxButtons.OK);
                        }
                        continue;
                    }
                    else
                    {
                        printedReports.Add(m_Report);
                    }

                    #region Modified Area
                    if (unionprint)
                    {
                        continue;                                       //Modified at 2008-10-10 10:04:37@Simon
                    }
                    //Print
                    if (Webb.Utility.CancelPrint)
                    {
                        if (thread.IsAlive)
                        {
                            LoadingForm.Close();

                            thread.Join();
                        }

                        return;
                    }

                    if (thread.IsAlive)
                    {
                        LoadingForm.MessageText = "Printing...";
                    }

                    if (printerName != string.Empty)
                    {
                        if (!PrinterExist(printerName))
                        {
                            Webb.Utilities.TopMostMessageBox.ShowMessage("Failed to Print", "WRB Cann't Find The Printer '" + printerName + "' in you system,please check the printer setting!",
                                                                         MessageBoxButtons.OK);
                            Environment.Exit(-1);
                        }
                        m_Report.Print(printerName);
                    }
                    else
                    {
                        m_Report.Print();
                    }
                    #endregion                            //End Modify at 2008-10-9 16:54:58@Simon
                }
                else
                {                //Browser
                    //Create report
                    if (thread.IsAlive)
                    {
                        LoadingForm.MessageText = "Creating Report Browser...";
                    }

                    WebbRepBrowser m_Browser = new WebbRepBrowser();

                    //m_Browser.LoadReport(new WebbReport[]{m_Report,m_Report});	//multiply report

                    if (m_Config.WebbDBType.ToString().ToLower().StartsWith("webbvictory"))
                    {
                        m_Browser.TopMost = true;
                    }
                    else
                    {
                        m_Browser.TopMost = false;
                    }
                    if (Canopen)
                    {
                        m_Browser.LoadReport(m_Report);
                    }

                    if (thread.IsAlive)
                    {
                        LoadingForm.Close();

                        thread.Join();
                    }

                    Webb.Reports.DataProvider.VideoPlayBackManager.PublicBrowser = m_Browser;                           //05-04-2008@Scott

                    if (!Canopen)
                    {
                        m_Browser.ReportName = filename;

                        m_Browser.InvertZorder();
//						Webb.Utilities.TopMostMessageBox.ShowMessage("LicenseLevel Error", "This report is not designed for your Webb application!\n So it would not open" + "", MessageBoxButtons.OK);
                    }

                    Application.Run(m_Browser);
                }
            }
            //add these codes for join all reports to print in only one document
            #region Modified Area

            WebbReport[] AllReportsToPrint = new WebbReport[printedReports.Count];

            for (int i = 0; i < printedReports.Count; i++)
            {
                AllReportsToPrint[i] = printedReports[i] as WebbReport;
            }

            if (m_CmdManager.PrintDirectly && unionprint)
            {
                if (AllReportsToPrint.Length == 0)
                {
                    Webb.Utilities.TopMostMessageBox.ShowMessage("No document", "No document could be print!",
                                                                 MessageBoxButtons.OK);
                }
                else
                {
                    if (thread.IsAlive)
                    {
                        LoadingForm.MessageText = "Printing...";

                        LoadingForm.ProcessText = "Union Printing Documents";
                    }

                    if (invalidateReports.Count > 0)
                    {
                        Webb.Utilities.AutoClosedMessageBox.ShowMessage(invalidateReports);
                    }
                    if (printerName != string.Empty)
                    {
                        if (!PrinterExist(printerName))
                        {
                            Webb.Utilities.TopMostMessageBox.ShowMessage("Failed to Print", "WRB Cann'i Find The Printer '" + printerName + "' in you system,\nplease check the printer setting!",
                                                                         MessageBoxButtons.OK);
                            Environment.Exit(-1);
                        }

                        WebbReport.Print(printerName, AllReportsToPrint);
                    }
                    else
                    {
                        WebbReport.Print(AllReportsToPrint);
                    }
                }
            }
            #endregion                    //End Modify at 2008-10-10 9:42:07@Simon

            if (thread.IsAlive)
            {
                LoadingForm.Close();

                thread.Join();
            }
        }