コード例 #1
0
        public void Compare(string iOriginalPath,
                            string iNewPath,
                            string iFileType,
                            string iOutputPath,
                            bool iShowAlert = false)
        {
            CLog log = CLog.CreateInstance();

            log.Flush();
            bool flag = CompareXml(iOriginalPath, iNewPath, iFileType);

            GenerateReport(iOriginalPath, iNewPath, iFileType, iOutputPath, iShowAlert);
        }
コード例 #2
0
        public static bool operator ==(CXmlFileNodeImp node1, CXmlFileNodeImp node2)
        {
            bool mattributesFlag, textFlag, childNodesFlag;

            #region compair the text of the node

            /**********************************************************************************
            * compair the text of the node
            **********************************************************************************/
            textFlag = (node1.text == node2.text) ? true : false;
            if (!textFlag)
            {
                CLog loger = CLog.CreateInstance();
                loger.Append(XmlSettingRptDicCategory.ChangedNodeText.ToString(),
                             node2.name,
                             node2.key,
                             node2.xPath,
                             "Inner Xml Text",
                             node1.text,
                             node2.text);
            }
            #endregion

            #region compair the attributes of the nodes

            /**********************************************************************************
            * compair the attributes of the node
            **********************************************************************************/
            mattributesFlag = true;
            // Union the two Node m_mattributes by key,
            //    if the value is different for the key, keep the first Node attribute
            IEnumerable <KeyValuePair <string, string> > attrUnion = node1.m_attributes.
                                                                     Union <KeyValuePair <string, string> >(node2.m_attributes,
                                                                                                            ProjectionEqualityComparer <KeyValuePair <string, string> > .Create(a => a.Key));
            foreach (KeyValuePair <string, string> tempKeyValPair in attrUnion)
            {
                // find the new added attributes
                if (!node1.m_attributes.Keys.Any <string>((string temKey) => temKey == tempKeyValPair.Key))
                {
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.AddedAttribute.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 tempKeyValPair.Key,
                                 "[New Added]",
                                 tempKeyValPair.Value);
                    mattributesFlag = false;
                }

                // find the deleted attribute and changed attributes
                if (!node2.m_attributes.Keys.Any <string>((string temKey) => temKey == tempKeyValPair.Key))
                {
                    //deleted attribute
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.DeletedAttribute.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 tempKeyValPair.Key,
                                 tempKeyValPair.Value,
                                 "[Deleted]");
                    mattributesFlag = false;
                }
                else if (node2.m_attributes[tempKeyValPair.Key] != tempKeyValPair.Value)
                {
                    //changed attribute
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.ChangedAttribute.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 tempKeyValPair.Key,
                                 node1.m_attributes[tempKeyValPair.Key],
                                 node2.m_attributes[tempKeyValPair.Key]);
                    mattributesFlag = false;
                }
            }
            #endregion

            #region compair the child nodes of the nodes
            childNodesFlag = true;

            IEnumerable <KeyValuePair <string, IXmlFileNode> > childUnion = node1.m_childNodes.
                                                                            Union <KeyValuePair <string, IXmlFileNode> >(node2.m_childNodes,
                                                                                                                         ProjectionEqualityComparer <KeyValuePair <string, IXmlFileNode> > .Create(a => a.Key));
            foreach (KeyValuePair <string, IXmlFileNode> tempKeyValPair in childUnion)
            {
                // find the new added child nodes
                if (!node1.m_childNodes.Keys.Any <string>((string temKey) => temKey == tempKeyValPair.Key))
                {
                    // new nodes
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.AddedChildNode.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 "[Child Notes]",
                                 "[New Added]",
                                 tempKeyValPair.Key);
                    childNodesFlag = false;
                }
                // find the deleted child nodes and changed child nodes
                if (!node2.m_childNodes.Keys.Any <string>((string temKey) => temKey == tempKeyValPair.Key))
                {
                    // deleted nodes
                    CLog loger = CLog.CreateInstance();
                    loger.Append(XmlSettingRptDicCategory.DeletedChildNode.ToString(),
                                 node2.name,
                                 node2.key,
                                 node2.xPath,
                                 "[Child Notes]",
                                 tempKeyValPair.Key,
                                 "[Deleted]");
                    childNodesFlag = false;
                }
                else
                {
                    CXmlFileNodeImp tmpNode1 = (CXmlFileNodeImp)tempKeyValPair.Value;
                    CXmlFileNodeImp tmpNode2 = (CXmlFileNodeImp)node2.m_childNodes[tempKeyValPair.Key];
                    if (!(tmpNode1 == tmpNode2))
                    {
                        childNodesFlag = false;
                    }
                }
            }
            #endregion

            if (mattributesFlag && textFlag && childNodesFlag)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        private void GenerateReport(string fn1, string fn2, string xmlType, string outputDir, bool showAlert)
        {
            CLog               log           = CLog.CreateInstance();
            List <CLogRec>     logList       = log.GetLogs();
            List <CSummaryRec> logSummary    = log.GetSummary();
            string             strReportName = "CmpReport_ " +
                                               System.IO.Path.GetFileName(fn2).Split('.').First() + "_" +
                                               DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") +
                                               ".xlsx";
            string strLogName = "CmpLog_" +
                                DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") +
                                ".txt";

            if (logList.Count > 0)
            {
                List <IXmlSettingReportDictionary> dicList = new List <IXmlSettingReportDictionary>();
                IXmlSetting currentSetting =
                    m_SettingFactory.ReadSettingCollection(m_ToolSetting.GetXmlSettingFilePath().Value)
                    .GetSetting(xmlType);
                foreach (List <IXmlSettingReportDictionary> tmpList
                         in from IXmlSettingNode tmp
                         in currentSetting.GetNodes
                         select tmp.GetDictionarys)
                {
                    dicList.AddRange(tmpList);
                }

                Microsoft.Office.Interop.Excel.Application objExcel     = null;
                Microsoft.Office.Interop.Excel.Workbook    objWorkbook  = null;
                Microsoft.Office.Interop.Excel.Worksheet   objWorksheet = null;
                try
                {
                    objExcel = new Microsoft.Office.Interop.Excel.Application();

                    objExcel.Visible             = false;
                    objExcel.SheetsInNewWorkbook = 3;
                    objWorkbook = objExcel.Workbooks.Add();

                    //write report issue dictionary
                    objWorksheet      = objWorkbook.Worksheets[1];
                    objWorksheet.Name = "Report Dictionary";

                    string[] aTitle = new[] { "Issue Source",
                                              "Issue Category",
                                              "Issue Instruction" };
                    int intLineNo = 1;
                    List <CXmlSettingRptDicRep> listOfRptDic =
                        (from tmp in dicList
                         select new CXmlSettingRptDicRep
                    {
                        source = tmp.issue_source,
                        category = tmp.issue_category,
                        instruction = tmp.issue_instruction
                    }
                        ).ToList();
                    SaifeiAsm.ExcelHelper.WriteData(objWorksheet,
                                                    ref intLineNo,
                                                    SaifeiAsm.ExcelHelper.ObjectParseMethord.UsingFields,
                                                    listOfRptDic,
                                                    aTitle);
                    intLineNo = intLineNo + 2;
                    objWorksheet.Cells[intLineNo, 2] = "General Notes:";
                    foreach (string strGeneralNote in currentSetting.GeneralNotes)
                    {
                        objWorksheet.Cells[intLineNo, 3] = strGeneralNote;
                        intLineNo = intLineNo + 1;
                    }
                    //write report summary
                    objWorksheet      = objWorkbook.Worksheets[2];
                    objWorksheet.Name = "Report Summary";
                    aTitle            = new[] { "Section",
                                                "Attribute Name",
                                                "Count" };
                    intLineNo = 1;
                    SaifeiAsm.ExcelHelper.WriteData <CSummaryRec>(objWorksheet,
                                                                  ref intLineNo,
                                                                  SaifeiAsm.ExcelHelper.ObjectParseMethord.UsingFields,
                                                                  logSummary,
                                                                  aTitle);
                    //write report content
                    objWorksheet      = objWorkbook.Worksheets[3];
                    objWorksheet.Name = "Compare Report";
                    aTitle            = new[] { "TimeStamp",
                                                "Category",
                                                "Source",
                                                "Indentifier",
                                                "Path",
                                                "Attribute Name",
                                                "Old Attribute Name",
                                                "New Attribute Name" };
                    intLineNo = 1;
                    SaifeiAsm.ExcelHelper.WriteData <CLogRec>(objWorksheet,
                                                              ref intLineNo,
                                                              SaifeiAsm.ExcelHelper.ObjectParseMethord.UsingFields,
                                                              logList,
                                                              aTitle);
                    objWorkbook.SaveAs(outputDir + "\\" + strReportName);
                    objWorkbook.Close();
                    objExcel.Visible = true;
                    objExcel.Quit();
                    objWorksheet = null;
                    objWorkbook  = null;
                    objExcel     = null;
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show("Error happened: '"
                                                   + e.Message
                                                   + "' Report could not be generated.");
                }
                finally
                {
                    if (objWorksheet != null)
                    {
                        objWorksheet = null;
                    }
                    if (objWorkbook != null)
                    {
                        objWorkbook.Close();
                        objWorkbook = null;
                    }
                    if (objExcel != null)
                    {
                        objExcel.Quit();
                        objExcel = null;
                    }
                }
            }

            if (showAlert && logList.Count > 0)
            {
                System.Windows.MessageBox.Show("Compare Report is Generated.\n" +
                                               "Please Check Folder '" + outputDir + "'.");
            }
            else if (logList.Count > 0)
            {
                RecordTextLog(outputDir + "\\" + strLogName,
                              "Differents is found between '" + fn1 + "' and '" + fn2
                              + "'. Please check compare report " + outputDir + "\\" + strReportName);
            }
            else
            {
                RecordTextLog(outputDir + "\\" + strLogName,
                              "Files '" + fn1 + "' and '" + fn2
                              + "' are identical per compare setting.");
            }
        }