public VendorSampleRelocator(ReverseConditionTable optionalConditionTableForFrameworkMapping = null)
 {
     if (optionalConditionTableForFrameworkMapping != null)
     {
         _ConditionMatcher = new ReverseFileConditionMatcher(optionalConditionTableForFrameworkMapping);
     }
 }
        static Dictionary <string, RequestedConfiguration> TranslateObjectList(ReverseConditionTable table, IEnumerable <ObjectEntry> list, Dictionary <string, string> optionalDictionary = null)
        {
            Dictionary <string, RequestedConfiguration> result = new Dictionary <string, RequestedConfiguration>();

            foreach (var entry in list)
            {
                var cfg = new RequestedConfiguration {
                    Framework = table.Frameworks[entry.OneBasedFrameworkIndex - 1]
                };
                if (entry.OneBasedConfigurationFragmentIndex != 0)
                {
                    cfg.Configuration = table.ConditionTable[entry.OneBasedConfigurationFragmentIndex - 1].RequestedConfiguration;
                }

                string key = entry.ObjectName;
                if (optionalDictionary != null && optionalDictionary.TryGetValue(key, out var val))
                {
                    key = val;
                }

                result[key] = cfg;
            }

            return(result);
        }
        public void SaveIfConsistent(string outputDir, PropertyDictionary2 renamedFileTable, bool throwIfInconsistent, ConfigurationFixSampleReference[] cfgFixSamples = null)
        {
            if (Warnings != ReverseFileConditionWarning.None)
            {
                if (throwIfInconsistent)
                {
                    throw new Exception("Reverse file conditions are inconsistent! Please recheck the rules.");
                }
                else
                {
                    return;
                }
            }

            Dictionary <ConditionHandle, int> conditionIndicies = new Dictionary <ConditionHandle, int>();

            var allFrameworkHandles = new[] { RootHandle }.Concat(_HandlesByFramework.Values).ToArray();
            ReverseConditionTable result = new ReverseConditionTable
            {
                Frameworks              = allFrameworkHandles.Select(h => h.ToFrameworkDefinition()).ToArray(),
                RenamedFileTable        = renamedFileTable,
                ConfigurationFixSamples = cfgFixSamples,
            };

            for (int i = 0; i < allFrameworkHandles.Length; i++)
            {
                ConvertObjectConditions(allFrameworkHandles[i].ConditionsPerFile, result.ConditionTable, result.FileTable, conditionIndicies, i);
                ConvertObjectConditions(allFrameworkHandles[i].ConditionsPerMacro, result.ConditionTable, result.MacroTable, conditionIndicies, i);
                ConvertObjectConditions(allFrameworkHandles[i].IncludeDirs, result.ConditionTable, result.IncludeDirectoryTable, conditionIndicies, i);

                foreach (var kv in allFrameworkHandles[i].FreeformMacros)
                {
                    result.FreeFormMacros.Add(new ReverseConditionTable.FreeFormMacroEntry
                    {
                        Regex          = kv.Key,
                        Value          = kv.Value,
                        FrameworkIndex = i,
                    });
                }
            }

            using (var fs = File.Create(Path.Combine(outputDir, ReverseConditionListFileName + ".gz")))
                using (var gs = new GZipStream(fs, CompressionMode.Compress))
                {
                    XmlTools.SaveObjectToStream(result, gs);
                }
        }
        public ReverseFileConditionMatcher(ReverseConditionTable table)
        {
            var fileDict = PropertyDictionary2.ReadPropertyDictionary(table.RenamedFileTable);

            _ConfigurationByFile  = TranslateObjectList(table, table.FileTable, fileDict);
            _ConfigurationByMacro = TranslateObjectList(table, table.MacroTable);

            foreach (var macro in table.FreeFormMacros)
            {
                _FreeFormMacros.Add(new FreeFormMacro
                {
                    Framework    = table.Frameworks[macro.FrameworkIndex],
                    Regex        = new Regex(macro.Regex),
                    VariableName = macro.Value
                });
            }
        }