Ejemplo n.º 1
0
        private static void SynchronizeResxFilesInner(CustomTraceLog customTraceLog, ref XmlDocument sourceXmlDoc, ref XmlDocument destinationXmlDoc, DateTime now, ref bool hasErrors, ref bool hasConflicts, ref bool leftFileChanged, ref bool rightFileChanged, ref List <string> processedKeys)
        {
            XmlNodeList nodes = sourceXmlDoc.SelectNodes("/root/data");

            for (int n = nodes.Count - 1; n >= 0; n--)
            {
                XmlNode node = nodes[n];

                ResxItem sourceResxItem = new ResxItem();
                sourceResxItem.Key     = node.Attributes["name"].Value;
                sourceResxItem.Value   = node["value"].InnerText;
                sourceResxItem.Comment = node["comment"] == null ? null : node["comment"].InnerText;
                sourceResxItem.MoveTimestampsFromCommentToProperties();                //sourceResxItem.Comment!=null && sourceResxItem.Comment.Contains("min pass size")

                if (!processedKeys.Contains(sourceResxItem.Key))
                {
                    processedKeys.Add(sourceResxItem.Key);

                    ResxItem destinationResxItem  = null;
                    XmlNode  pairInDestinationXml =
                        destinationXmlDoc.SelectSingleNode("/root/data[@name='" + node.Attributes["name"].Value + "']");
                    if (pairInDestinationXml != null)
                    {
                        destinationResxItem         = new ResxItem();
                        destinationResxItem.Key     = pairInDestinationXml.Attributes["name"].Value;
                        destinationResxItem.Value   = pairInDestinationXml["value"].InnerText;
                        destinationResxItem.Comment = pairInDestinationXml["comment"] == null
                                                                                                                ? null
                                                                                                                : pairInDestinationXml["comment"].InnerText;
                        destinationResxItem.MoveTimestampsFromCommentToProperties();
                    }

                    bool           hasC;
                    CustomTraceLog tLog = new CustomTraceLog(string.Empty);
                    bool           hasE = SynchronizeResxItems(ref sourceResxItem, ref destinationResxItem, tLog, now, out hasC);
                    hasErrors    = hasErrors || hasE;
                    hasConflicts = hasConflicts || hasC;

                    if (sourceResxItem.Changed || destinationResxItem.Changed || hasE || hasC)
                    {
                        customTraceLog.ExtendLastLine(node.Attributes["name"].Value.PadRight(80, ' ') + ": ");
                        customTraceLog.ExtendLastLine(tLog.ToString());
                    }
                    if (sourceResxItem.Changed)
                    {
                        if (sourceResxItem.Deleted)
                        {
                            sourceResxItem.DeleteNode(ref sourceXmlDoc, sourceResxItem.Key);
                            leftFileChanged = true;
                        }
                        else
                        {
                            sourceResxItem.ReapplyDatesToComment();
                            sourceResxItem.CopyToNode(ref sourceXmlDoc, ref node);
                            leftFileChanged = true;
                        }
                    }
                    if (destinationResxItem.Changed)
                    {
                        if (destinationResxItem.Deleted)
                        {
                            destinationResxItem.DeleteNode(ref destinationXmlDoc, destinationResxItem.Key);
                            rightFileChanged = true;
                        }
                        else
                        {
                            destinationResxItem.ReapplyDatesToComment();
                            destinationResxItem.CopyToNode(ref destinationXmlDoc, ref pairInDestinationXml);
                            rightFileChanged = true;
                        }
                    }
                    if (sourceResxItem.Changed || destinationResxItem.Changed)
                    {
                        customTraceLog.AddLine("");
                    }
                }
            }
        }