コード例 #1
0
        public void Publish()
        {
            try
            {
                // if report file already exists then delete it
                if (File.Exists(ReportFile))
                {
                    File.Delete(ReportFile);
                }

                string directory = Path.GetDirectoryName(ReportFile);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string settingsPath = Path.Combine(directory, m_wizardInfo.WorkItemGenerator.SelectedWorkItemTypeName + "-settings.xml");
                m_wizardInfo.SaveSettings(settingsPath);

                try
                {
                    m_reportBook.SaveAs(ReportFile, XlFileFormat.xlExcel8);
                }
                catch (COMException)
                {
                    m_reportBook.SaveAs(ReportFile);
                }


                // Close the workbook after save
                m_reportBook.Close();
            }
            // throw WorkitemMigratorexception of publish report failure in case of any exception
            catch (COMException comEx)
            {
                throw new WorkItemMigratorException(Resources.PublisReportError,
                                                    comEx.Message,
                                                    comEx.InnerException != null ? comEx.InnerException.Message : string.Empty);
            }
            catch (InvalidCastException icEx)
            {
                throw new WorkItemMigratorException(Resources.PublisReportError,
                                                    icEx.Message,
                                                    icEx.InnerException != null ? icEx.InnerException.Message : string.Empty);
            }
        }
コード例 #2
0
        /// <summary>
        /// Publishes the report with the style sheet
        /// </summary>
        public void Publish()
        {
            string directory = Path.GetDirectoryName(ReportFile);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            m_wizardInfo.SaveSettings(Path.Combine(directory, m_wizardInfo.WorkItemGenerator.SelectedWorkItemTypeName + "-settings.xml"));

            var listOfPassedWorkItemsFilePath  = Path.Combine(directory, ListOfPassedWorkItemsFileName);
            var listOfWarningWorkItemsFilePath = Path.Combine(directory, ListOfWarningWorkItemsFileName);
            var listOfFailedWorkItemsFilePath  = Path.Combine(directory, ListOfFailedWorkItemsFileName);

            SaveList(listOfPassedWorkItemsFilePath, m_passedWorkItemSourceFiles);
            SaveList(listOfWarningWorkItemsFilePath, m_warningWorkItemSourceFiles);
            SaveList(listOfFailedWorkItemsFilePath, m_failedWorkItemSourceFiles);

            var passedWorkItemsNode = m_document.CreateElement(PassedWorkItemsNodeName);

            Utilities.AppendAttribute(passedWorkItemsNode, FileAttributeName, listOfPassedWorkItemsFilePath);
            Utilities.AppendAttribute(passedWorkItemsNode, CountAttributeName, m_passedWorkItemsCount.ToString(System.Globalization.CultureInfo.CurrentCulture));
            m_summaryNode.AppendChild(passedWorkItemsNode);

            var warningWorkItemsNode = m_document.CreateElement(WarningWorkItemsNodeName);

            Utilities.AppendAttribute(warningWorkItemsNode, FileAttributeName, listOfWarningWorkItemsFilePath);
            Utilities.AppendAttribute(warningWorkItemsNode, CountAttributeName, m_warningWorkItemsCount.ToString(System.Globalization.CultureInfo.CurrentCulture));
            m_summaryNode.AppendChild(warningWorkItemsNode);

            var failedWorkItemsNode = m_document.CreateElement(FailedWorkItemsNodeName);

            Utilities.AppendAttribute(failedWorkItemsNode, FileAttributeName, listOfFailedWorkItemsFilePath);
            Utilities.AppendAttribute(failedWorkItemsNode, CountAttributeName, m_failedWorkItemsCount.ToString(System.Globalization.CultureInfo.CurrentCulture));
            m_summaryNode.AppendChild(failedWorkItemsNode);

            try
            {
                Assembly assembly        = Assembly.GetExecutingAssembly();
                string   fullProcessPath = assembly.Location;
                string   processDir      = Path.GetDirectoryName(fullProcessPath);
                string   XSLFilePath     = Path.Combine(processDir, XSLFileName);

                if (File.Exists(XSLFilePath))
                {
                    string destination = Path.Combine(directory, XSLFileName);
                    if (File.Exists(destination))
                    {
                        File.Delete(destination);
                    }
                    File.Copy(XSLFilePath, destination);
                }
            }
            catch (IOException)
            { }
            catch (UnauthorizedAccessException)
            { }

            if (!string.IsNullOrEmpty(m_wizardInfo.CommandUsed))
            {
                var commandUsedNode = m_document.CreateElement(CommandUsedNodeName);
                commandUsedNode.InnerXml = m_wizardInfo.CommandUsed;
                m_document.LastChild.AppendChild(commandUsedNode);
            }
            m_document.Save(ReportFile);
        }