コード例 #1
0
 private static void RequireRebuild(CustomTraceLog customTraceLog)
 {
     customTraceLog.ExtendLastLine("Rebuild is required.");
 }
コード例 #2
0
 private static void AddDates(ref ResxItem L, ref ResxItem R, CustomTraceLog customTraceLog, DateTime now)
 {
     L.LastSynchronizationDate = L.LastModificationDate = R.LastSynchronizationDate = R.LastModificationDate = now;
     customTraceLog.ExtendLastLine("Dates updated.");
 }
コード例 #3
0
 private static void CopyToLeft(ref ResxItem L, ref ResxItem R, CustomTraceLog customTraceLog)
 {
     L.Value   = R.Value;
     L.Comment = R.Comment;
     customTraceLog.ExtendLastLine("Copied to Left.");
 }
コード例 #4
0
 private static void CopyToRight(ref ResxItem L, ref ResxItem R, CustomTraceLog customTraceLog)
 {
     R.Value   = L.Value;
     R.Comment = L.Comment;
     customTraceLog.ExtendLastLine("Copied to right.");
 }
コード例 #5
0
        /// <summary>
        /// See Resolution matrix in ReadMe.txt!
        /// </summary>
        /// <param name="L"></param>
        /// <param name="R"></param>
        /// <param name="customTraceLog"></param>
        /// <returns></returns>
        private static bool SynchronizeResxItems(ref ResxItem L, ref ResxItem R, CustomTraceLog customTraceLog, DateTime now, out bool hasConflicts)
        {
            bool hasErrors = false;

            hasConflicts = false;

            //See Resolution matrix in ReadMe.txt!
            if (L == null && R != null && R.Value != null &&
                R.LastSynchronizationDate == null)
            {
                L     = new ResxItem();
                L.Key = R.Key;
                CopyToLeft(ref L, ref R, customTraceLog);
                AddDates(ref L, ref R, customTraceLog, now);
                RequireRebuild(customTraceLog);
                L.Changed = true;
                R.Changed = true;
                L.Created = true;
            }
            else
            if (L == null && R != null && R.Value != null &&
                R.LastSynchronizationDate != null)
            {
                customTraceLog.ExtendLastLine("Deleted right.");
                RequireRebuild(customTraceLog);
                L         = new ResxItem();
                L.Key     = R.Key;
                L.Deleted = true;
                R.Changed = true;
                L.Changed = true;
                R.Deleted = true;
            }
            else
            if (R == null && L != null && L.Value != null &&
                L.LastSynchronizationDate == null)
            {
                R     = new ResxItem();
                R.Key = L.Key;
                CopyToRight(ref L, ref R, customTraceLog);
                AddDates(ref L, ref R, customTraceLog, now);
                RequireRebuild(customTraceLog);
                R.Changed = true;
                L.Changed = true;
                R.Created = true;
            }
            else
            if (R == null && L != null && L.Value != null &&
                L.LastSynchronizationDate != null)
            {
                customTraceLog.ExtendLastLine("Deleted left.");
                RequireRebuild(customTraceLog);
                R         = new ResxItem();
                R.Key     = L.Key;
                R.Deleted = true;
                L.Changed = true;
                R.Changed = true;
                L.Deleted = true;
            }
            else
            if (L.LastSynchronizationDate != null && R.LastSynchronizationDate != null &&
                L.LastSynchronizationDate != R.LastSynchronizationDate)
            {
                customTraceLog.ExtendLastLine("Error: Last sync dates does not match. Are you syncing right versions of resx folders?!");
                hasErrors = true;
                L.Changed = false;
                R.Changed = false;
            }
            else
            if (
                L.Value != null && R.Value != null && L.Value == R.Value &&
                (L.LastModificationDate == null || L.LastSynchronizationDate == null || R.LastModificationDate == null || R.LastSynchronizationDate == null ||
                 (L.LastModificationDate != L.LastSynchronizationDate || R.LastSynchronizationDate != R.LastModificationDate))
                )
            {
                AddDates(ref L, ref R, customTraceLog, now);
                L.Changed = true;
                R.Changed = true;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate == null && L.LastModificationDate == null &&
                R.Value == null && R.LastSynchronizationDate == null && R.LastModificationDate == null)
            {
                CopyToRight(ref L, ref R, customTraceLog);
                AddDates(ref L, ref R, customTraceLog, now);
                RequireRebuild(customTraceLog);
                L.Changed = true;
                R.Changed = true;
            }
            else
            if (L.Value == null && L.LastSynchronizationDate == null && L.LastModificationDate == null &&
                R.Value != null && R.LastSynchronizationDate == null && R.LastModificationDate == null)
            {
                CopyToLeft(ref L, ref R, customTraceLog);
                AddDates(ref L, ref R, customTraceLog, now);
                RequireRebuild(customTraceLog);
                L.Changed = true;
                R.Changed = true;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate != null && L.LastModificationDate != null &&
                R.Value != null && R.LastSynchronizationDate == null && R.LastModificationDate == null &&
                L.Value != R.Value && L.LastSynchronizationDate == L.LastModificationDate)
            {
                CopyToLeft(ref L, ref R, customTraceLog);
                AddDates(ref L, ref R, customTraceLog, now);
                L.Changed = true;
                R.Changed = true;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate == null && L.LastModificationDate == null &&
                R.Value != null && R.LastSynchronizationDate != null && R.LastModificationDate != null &&
                L.Value != R.Value && R.LastSynchronizationDate == R.LastModificationDate)
            {
                CopyToRight(ref L, ref R, customTraceLog);
                AddDates(ref L, ref R, customTraceLog, now);
                L.Changed = true;
                R.Changed = true;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate != null && L.LastModificationDate != null &&
                R.Value != null && R.LastSynchronizationDate == null && R.LastModificationDate == null &&
                L.Value != R.Value && L.LastSynchronizationDate != L.LastModificationDate)
            {
                customTraceLog.ExtendLastLine("Conflict. None changed.");
                hasConflicts = true;
                L.Changed    = false;
                R.Changed    = false;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate == null && L.LastModificationDate == null &&
                R.Value != null && R.LastSynchronizationDate != null && R.LastModificationDate != null &&
                L.Value != R.Value && R.LastSynchronizationDate != R.LastModificationDate)
            {
                customTraceLog.ExtendLastLine("Conflict. None changed.");
                hasConflicts = true;
                L.Changed    = false;
                R.Changed    = false;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate != null && L.LastModificationDate != null &&
                R.Value != null && R.LastSynchronizationDate != null && R.LastModificationDate != null &&
                L.Value == R.Value && L.LastModificationDate == R.LastModificationDate)
            {
                //customTraceLog.ExtendLastLine("None changed.");
                L.Changed = false;
                R.Changed = false;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate != null && L.LastModificationDate != null &&
                R.Value != null && R.LastSynchronizationDate != null && R.LastModificationDate != null &&
                L.Value != R.Value && L.LastSynchronizationDate == L.LastModificationDate && R.LastSynchronizationDate == R.LastModificationDate)
            {
                customTraceLog.ExtendLastLine("Error: Sync and modifications dates are same but text is different.");
                hasErrors = true;
                L.Changed = false;
                R.Changed = false;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate != null && L.LastModificationDate != null &&
                R.Value != null && R.LastSynchronizationDate != null && R.LastModificationDate != null &&
                L.Value != R.Value && L.LastSynchronizationDate != L.LastModificationDate && R.LastSynchronizationDate == R.LastModificationDate)
            {
                CopyToRight(ref L, ref R, customTraceLog);
                AddDates(ref L, ref R, customTraceLog, now);
                L.Changed = true;
                R.Changed = true;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate != null && L.LastModificationDate != null &&
                R.Value != null && R.LastSynchronizationDate != null && R.LastModificationDate != null &&
                L.Value != R.Value && L.LastSynchronizationDate == L.LastModificationDate && R.LastSynchronizationDate != R.LastModificationDate)
            {
                CopyToLeft(ref L, ref R, customTraceLog);
                AddDates(ref L, ref R, customTraceLog, now);
                L.Changed = true;
                R.Changed = true;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate != null && L.LastModificationDate != null &&
                R.Value != null && R.LastSynchronizationDate != null && R.LastModificationDate != null &&
                L.Value != R.Value && L.LastSynchronizationDate != L.LastModificationDate && R.LastSynchronizationDate != R.LastModificationDate)
            {
                customTraceLog.ExtendLastLine("Conflict. None changed.");
                hasConflicts = true;
                L.Changed    = false;
                R.Changed    = false;
            }
            else
            if (L.Value != null && L.LastSynchronizationDate == null && L.LastModificationDate == null &&
                R.Value != null && R.LastSynchronizationDate == null && R.LastModificationDate == null &&
                L.Value != R.Value)
            {
                customTraceLog.ExtendLastLine("Conflict. None changed.");
                hasConflicts = true;
                L.Changed    = false;
                R.Changed    = false;
            }
            else
            {
                customTraceLog.ExtendLastLine(string.Format("Error: Unsupported case happened.Send log to devel to exemine.\r\nLeft:\r\n{0}\r\nRight:\r\n{1}", L.ToString(), R.ToString()));
                hasErrors = true;
                L.Changed = false;
                R.Changed = false;
            }

            return(hasErrors);
        }
コード例 #6
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("");
                    }
                }
            }
        }