internal static IEnumerable <Patch> GetModulePatches(ISystemOperations so, ISession session, ISessionSettings sessionSettings, ILocateModules folderModuleLocator, IList <KeyValuePair <string, Tuple <string, ModuleType> > > folderModules, ILocateModules fileModuleLocator, IList <KeyValuePair <string, Tuple <string, ModuleType> > > fileModules) { IList <KeyValuePair <string, Tuple <string, ModuleType> > > oldModules; IList <KeyValuePair <string, Tuple <string, ModuleType> > > newModules; ILocateModules oldModuleLocator; ILocateModules newModuleLocator; if (session.Action == ActionType.Extract) { oldModules = folderModules; newModules = fileModules; oldModuleLocator = folderModuleLocator; newModuleLocator = fileModuleLocator; } else { oldModules = fileModules; newModules = folderModules; oldModuleLocator = fileModuleLocator; newModuleLocator = folderModuleLocator; } if (sessionSettings.IgnoreEmpty) { oldModules = oldModules.Where(kvp => ModuleProcessing.HasCode(kvp.Value.Item1)).ToList(); newModules = newModules.Where(kvp => ModuleProcessing.HasCode(kvp.Value.Item1)).ToList(); } // find modules which aren't in both lists and record them as new/deleted var patches = new List <Patch>(); patches.AddRange(GetDeletedModuleChanges(oldModules, newModules, session.Action, sessionSettings.DeleteDocumentsFromFile)); patches.AddRange(GetNewModuleChanges(oldModules, newModules, session.Action, sessionSettings.AddNewDocumentsToFile)); // this also filters the new/deleted modules from the last step var sideBySide = (from o in oldModules join n in newModules on o.Key equals n.Key select new SideBySideArgs { Name = o.Key, OldType = o.Value.Item2, NewType = n.Value.Item2, OldText = o.Value.Item1, NewText = n.Value.Item1 }).ToArray(); patches.AddRange(GetFrxChanges(so, oldModuleLocator, newModuleLocator, sideBySide.Where(x => x.NewType == ModuleType.Form).Select(x => x.Name))); sideBySide = sideBySide.Where(sxs => sxs.OldText != sxs.NewText).ToArray(); foreach (var sxs in sideBySide) { patches.AddRange(Patch.CompareSideBySide(sxs)); } return(patches); }
private static IEnumerable <Patch> GetFrxChanges(ISystemOperations fo, ILocateModules oldModuleLocator, ILocateModules newModuleLocator, IEnumerable <string> frmModules) { foreach (var modName in frmModules) { var oldFrxPath = oldModuleLocator.GetFrxPath(modName); var newFrxPath = newModuleLocator.GetFrxPath(modName); if (string.IsNullOrEmpty(oldFrxPath) && string.IsNullOrEmpty(newFrxPath)) { } else if (!string.IsNullOrEmpty(oldFrxPath) && string.IsNullOrEmpty(newFrxPath)) { yield return(Patch.MakeFrxDeletion(modName)); } else if (string.IsNullOrEmpty(oldFrxPath) && !string.IsNullOrEmpty(newFrxPath)) { yield return(Patch.MakeFrxChange(modName)); } else if (FrxFilesAreDifferent(fo, oldFrxPath, newFrxPath, out var explain)) { yield return(Patch.MakeFrxChange(modName)); } } }