Esempio n. 1
0
        private static void CheckAutomation(IEnumerable <IAutomationSettingsSchema> automationSettings,
                                            string indentation)
        {
            // commands
            var allSettingsByName = automationSettings.ToDictionary(s => s.Name, s => s);

            foreach (
                var commandAutomationName in
                allSettingsByName.Where(kvp => kvp.Value.AutomationType == "Command")
                .Select(kvp => kvp.Key)
                .OrderBy(k => k))
            {
                var match = v4NameRegex.Match(commandAutomationName);
                if (match.Success)
                {
                    var v4Settings = allSettingsByName[commandAutomationName].As <ICommandSettings>();

                    // find matching v5 command
                    var v5Name = match.Groups["before_version"].Value + match.Groups["version"].Value + "5" +
                                 match.Groups["after_version"].Value;

                    IAutomationSettingsSchema v5SettingsSchema;
                    if (!allSettingsByName.TryGetValue(v5Name, out v5SettingsSchema))
                    {
                        Console.WriteLine("{0}  Command {1}: does not have matching v5 version", indentation,
                                          commandAutomationName);
                        continue;
                    }

                    var v5Settings = v5SettingsSchema.As <ICommandSettings>();
                    // check type id
                    if (v4Settings.TypeId != v5Settings.TypeId)
                    {
                        Console.WriteLine(
                            "{0}  Command {1}: v5 version does not match command type {2} vs {3}",
                            indentation,
                            commandAutomationName,
                            v4Settings.TypeId,
                            v5Settings.TypeId);
                        continue;
                    }

                    // check properties
                    Console.WriteLine("{0}  Command {1}", indentation, commandAutomationName);
                    if (!v4Settings.TypeId.Contains("AggregatorCommand"))
                    {
                        foreach (var v4Property in v4Settings.Properties.Where(p => p.Name != "TemplateAuthoringUri"))
                        {
                            var v4Value = v4Property.Value;
                            var v5Value = v5Settings.Properties.First(p => p.Name == v4Property.Name).Value;

                            if (v4Value != v5Value)
                            {
                                Console.WriteLine("{0}    {1} (v4) = {2}", indentation, v4Property.Name,
                                                  v4Property.Value);
                                Console.WriteLine("{0}    {1} (v5) = {2}", indentation, v4Property.Name, v5Value);
                            }
                        }
                    }
                    else
                    {
                        var referencesV4 =
                            JsonConvert.DeserializeObject <Collection <CommandReference> >(
                                v4Settings.Properties.First(p => p.Name == "CommandReferenceList").Value);
                        var referencesV5 =
                            JsonConvert.DeserializeObject <Collection <CommandReference> >(
                                v5Settings.Properties.First(p => p.Name == "CommandReferenceList").Value);

                        if (referencesV4.Count != referencesV5.Count)
                        {
                            Console.WriteLine("{0}    Aggregate count doesn't match", indentation);
                        }
                        else
                        {
                            for (int i = 0; i < referencesV4.Count; i++)
                            {
                                Console.WriteLine(
                                    "{0}    {2} (v4): {1}",
                                    indentation,
                                    allSettingsByName.Where(kvp => kvp.Value.AutomationType == "Command").First(kvp => kvp.Value.As <ICommandSettings>().Id == referencesV4[i].CommandId).Key,
                                    i);
                                Console.WriteLine(
                                    "{0}    {2} (v5): {1}",
                                    indentation,
                                    allSettingsByName.Where(kvp => kvp.Value.AutomationType == "Command").First(kvp => kvp.Value.As <ICommandSettings>().Id == referencesV5[i].CommandId).Key,
                                    i);
                            }
                        }
                    }
                }
            }

            // launch points
            foreach (var settingKvp in
                     allSettingsByName
                     .Where(kvp => kvp.Value.AutomationType != "Command")
                     .OrderBy(kvp => kvp.Key + "|" + kvp.Value.AutomationType))
            {
                var match = v4NameRegex.Match(settingKvp.Key);
                if (match.Success)
                {
                    // find matching v5 launch point
                    var v5Name = match.Groups["before_version"].Value + match.Groups["version"].Value + "5" +
                                 match.Groups["after_version"].Value;

                    IAutomationSettingsSchema v5SettingsSchema;
                    if (!allSettingsByName.TryGetValue(v5Name, out v5SettingsSchema))
                    {
                        Console.WriteLine("{0}  Launchpoint {1}: does not have matching v5 version", indentation,
                                          settingKvp.Key);
                        continue;
                    }

                    // check type id
                    if (settingKvp.Value.AutomationType != v5SettingsSchema.AutomationType)
                    {
                        Console.WriteLine(
                            "{0}  Launchpoint {1}: v5 version does not match launchpoint type {2} vs {3}",
                            indentation,
                            settingKvp.Key,
                            settingKvp.Value.AutomationType,
                            v5SettingsSchema.AutomationType);
                        continue;
                    }

                    var v4Settings = settingKvp.Value.As <IAutomationSettings>();
                    var v5Settings = v5SettingsSchema.As <IAutomationSettings>();

                    var v4me             = (ModelElement)v4Settings;
                    var v4CommandIdProp  = v4me.GetDomainClass().FindDomainProperty("CommandId", true);
                    var v4CommandId      = v4CommandIdProp != null ? (Guid)v4CommandIdProp.GetValue(v4me) : Guid.Empty;
                    var v4EventIdProp    = v4me.GetDomainClass().FindDomainProperty("EventId", true);
                    var v4EventId        = v4EventIdProp != null ? (string)v4EventIdProp.GetValue(v4me) : null;
                    var v4ConditionsProp = v4me.GetDomainClass().FindDomainProperty("Conditions", true);
                    var v4Conditions     = v4ConditionsProp != null ? (string)v4ConditionsProp.GetValue(v4me) : null;

                    var v5me             = (ModelElement)v5Settings;
                    var v5CommandIdProp  = v5me.GetDomainClass().FindDomainProperty("CommandId", true);
                    var v5CommandId      = v5CommandIdProp != null ? (Guid)v5CommandIdProp.GetValue(v5me) : Guid.Empty;
                    var v5EventIdProp    = v5me.GetDomainClass().FindDomainProperty("EventId", true);
                    var v5EventId        = v5EventIdProp != null ? (string)v5EventIdProp.GetValue(v5me) : null;
                    var v5ConditionsProp = v5me.GetDomainClass().FindDomainProperty("Conditions", true);
                    var v5Conditions     = v5ConditionsProp != null ? (string)v5ConditionsProp.GetValue(v5me) : null;

                    if (v4EventId != v5EventId)
                    {
                        Console.WriteLine(
                            "{0}  Launchpoint: {1} does not match event id: {2} vs {3}",
                            indentation,
                            settingKvp.Key,
                            v4EventId,
                            v5EventId);

                        continue;
                    }

                    Console.WriteLine(
                        "{0}  Launchpoint: {1}({4}) {2}-{3}",
                        indentation,
                        settingKvp.Key,
                        allSettingsByName.Where(kvp => kvp.Value.AutomationType == "Command").First(kvp => kvp.Value.As <ICommandSettings>().Id == v4CommandId).Key,
                        allSettingsByName.Where(kvp => kvp.Value.AutomationType == "Command").First(kvp => kvp.Value.As <ICommandSettings>().Id == v5CommandId).Key,
                        v4EventId);
                    if (!string.IsNullOrEmpty(v4Conditions) && !string.IsNullOrEmpty(v5Conditions))
                    {
                        Console.WriteLine("{0}    Conditions v4: ", indentation);
                        foreach (var conditionLine in (v4Conditions ?? "").Split('\n', '\r').Where(s => !string.IsNullOrEmpty(s)))
                        {
                            Console.WriteLine("{0}      {1}", indentation, conditionLine);
                        }
                        Console.WriteLine("{0}    Conditions v5: ", indentation);
                        foreach (var conditionLine in (v5Conditions ?? "").Split('\n', '\r').Where(s => !string.IsNullOrEmpty(s)))
                        {
                            Console.WriteLine("{0}      {1}", indentation, conditionLine);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private static void DumpAutomation(IEnumerable <IAutomationSettingsSchema> automationSettings, string indentation)
        {
            var allCommands =
                automationSettings
                .Where(s => s.AutomationType == "Command")
                .Select(s => s.As <ICommandSettings>())
                .ToList();
            var allCommandsById = allCommands.ToDictionary(c => c.Id, c => c);

            var interestingCommands = new HashSet <Guid>();

            foreach (var commandSetting in allCommands.Where(cs => !cs.TypeId.Contains("AggregatorCommand")).OrderBy(cs => cs.Name))
            {
                var marker = "";

                if (commandSetting.TypeId.Contains("GenerateComponentCodeCommand") ||
                    commandSetting.TypeId.Contains("GenerateProductCodeCommandCustom") ||
                    commandSetting.TypeId.Contains("GenerateProductCodeCommand"))
                {
                    interestingCommands.Add(commandSetting.Id);
                    marker = " (*)";
                }

                Console.WriteLine("{0}  Command{3}: {1} ({2})", indentation, commandSetting.Name, commandSetting.TypeId, marker);
                foreach (var property in commandSetting.Properties)
                {
                    Console.WriteLine("{0}    {1} = {2}", indentation, property.Name, property.Value);
                }
            }

            // aggregates
            var  aggregatorCommands = allCommands.Where(cs => cs.TypeId.Contains("AggregatorCommand")).ToList();
            bool aggregatorAdded;

            do
            {
                aggregatorAdded = false;
                foreach (var aggregatorCommand in aggregatorCommands)
                {
                    var references =
                        JsonConvert.DeserializeObject <Collection <CommandReference> >(
                            aggregatorCommand.Properties.First(p => p.Name == "CommandReferenceList").Value);

                    if (references.Any(r => interestingCommands.Contains(r.CommandId)))
                    {
                        aggregatorAdded = interestingCommands.Add(aggregatorCommand.Id);
                    }
                }
            } while (aggregatorAdded);

            foreach (var aggregatorCommand in aggregatorCommands.OrderBy(ac => ac.Name))
            {
                Console.WriteLine(
                    "{0}  Aggregate{2}: {1}",
                    indentation,
                    aggregatorCommand.Name,
                    interestingCommands.Contains(aggregatorCommand.Id) ? " (*)" : "");

                var i = 0;
                foreach (var reference in
                         JsonConvert.DeserializeObject <Collection <CommandReference> >(
                             aggregatorCommand.Properties.First(p => p.Name == "CommandReferenceList").Value))
                {
                    var command = allCommandsById[reference.CommandId];
                    Console.WriteLine(
                        "{0}    {3}: {1}{2}",
                        indentation,
                        command.Name,
                        interestingCommands.Contains(reference.CommandId) ? " (*)" : "",
                        i++);
                }
            }

            // launch points

            foreach (var setting in
                     automationSettings
                     .Where(s => s.AutomationType != "Command")
                     .OrderBy(s => s.AutomationType + "|" + s.Name))
            {
                var automation = setting.As <IAutomationSettings>();

                var me   = (ModelElement)automation;
                var prop = me.GetDomainClass().FindDomainProperty("CommandId", true);
                if (prop != null)
                {
                    var eventIdProp = me.GetDomainClass().FindDomainProperty("EventId", true);

                    var commandId = (Guid)prop.GetValue(me);
                    Console.WriteLine(
                        "{0}  Launch{4}: {1} ({2}) -> {3}",
                        indentation,
                        automation.Name,
                        setting.AutomationType + (eventIdProp != null ? " - " + eventIdProp.GetValue(me) : ""),
                        allCommandsById.ContainsKey(commandId) ? allCommandsById[commandId].Name : "MISSING!",
                        interestingCommands.Contains(commandId) ? " (*)" : "");

                    var conditionProp = me.GetDomainClass().FindDomainProperty("Conditions", true);
                    if (conditionProp != null)
                    {
                        var conditions = (string)conditionProp.GetValue(me);
                        if (!string.IsNullOrEmpty(conditions))
                        {
                            Console.WriteLine("{0}    Conditions: ", indentation);
                            foreach (var conditionLine in conditions.Split('\n', '\r').Where(s => !string.IsNullOrEmpty(s)))
                            {
                                Console.WriteLine("{0}      {1}", indentation, conditionLine);
                            }
                        }
                    }
                }
            }
        }