Ejemplo n.º 1
0
            public MainBranch(ORMGeneratorSelectionControl parent
#if VISUALSTUDIO_15_0
                              , IServiceProvider serviceProvider
#endif
                              )
            {
                SortedList <string, OutputFormatBranch> branches = new SortedList <string, OutputFormatBranch>(StringComparer.OrdinalIgnoreCase);
                List <OutputFormatBranch> modifiers            = null;
                int modifierAsGeneratorCount                   = 0;
                IDictionary <string, IORMGenerator> generators =
#if VISUALSTUDIO_15_0
                    ORMCustomTool.GetORMGenerators(serviceProvider);
#else
                    ORMCustomTool.ORMGenerators;
#endif
                foreach (IORMGenerator ormGenerator in generators.Values)
                {
                    string             outputFormatName = ormGenerator.ProvidesOutputFormat;
                    OutputFormatBranch formatBranch;
                    if (ormGenerator.IsFormatModifier)
                    {
                        // Track modifiers separately
                        if (modifiers == null)
                        {
                            modifiers = new List <OutputFormatBranch>();
                        }
                        formatBranch = new OutputFormatBranch(this);
                        formatBranch.ORMGenerators.Add(ormGenerator);
                        OutputFormatBranch primaryFormatBranch;
                        if (branches.TryGetValue(outputFormatName, out primaryFormatBranch))
                        {
                            if (primaryFormatBranch.IsModifier)
                            {
                                if (primaryFormatBranch.ORMGenerators[0].FormatModifierPriority <= ormGenerator.FormatModifierPriority)
                                {
                                    primaryFormatBranch.NextModifier = formatBranch;
                                }
                                else
                                {
                                    formatBranch.NextModifier  = primaryFormatBranch;
                                    branches[outputFormatName] = formatBranch;
                                }
                            }
                            else
                            {
                                primaryFormatBranch.NextModifier = formatBranch;
                            }
                        }
                        else
                        {
                            // We don't have a branch yet for a primary generator, track
                            // the modifier by adding it here. We will verify later that
                            // all modifiers have a non-modifier primary generator.
                            branches.Add(outputFormatName, formatBranch);
                            ++modifierAsGeneratorCount;
                        }
                        modifiers.Add(formatBranch);
                    }
                    else
                    {
                        if (branches.TryGetValue(outputFormatName, out formatBranch))
                        {
                            if (formatBranch.IsModifier)
                            {
                                OutputFormatBranch modifierBranch = formatBranch;
                                formatBranch = new OutputFormatBranch(this);
                                formatBranch.NextModifier  = modifierBranch;
                                branches[outputFormatName] = formatBranch;
                                --modifierAsGeneratorCount;
                            }
                        }
                        else
                        {
                            formatBranch = new OutputFormatBranch(this);
                            branches.Add(outputFormatName, formatBranch);
                        }
                        formatBranch.ORMGenerators.Add(ormGenerator);
                    }
                }
                if (modifierAsGeneratorCount != 0)
                {
                    // A modifier with no associated generator does not
                    // make sense, but is currently stored as a branch.
                    // Pull it out of the list.
                    for (int i = modifiers.Count - 1; i >= 0; --i)
                    {
                        OutputFormatBranch testBranch;
                        string             outputFormat = modifiers[i].ORMGenerators[0].ProvidesOutputFormat;
                        if (!branches.TryGetValue(outputFormat, out testBranch) ||
                            testBranch.IsModifier)
                        {
                            if (testBranch != null)
                            {
                                branches.Remove(outputFormat);
                            }
                            modifiers.RemoveAt(i);
                        }
                    }
                }
                _parent   = parent;
                _branches = branches;
                int modifierCount;
                if (modifiers != null && 0 != (modifierCount = modifiers.Count))
                {
                    if (modifierCount > 1)
                    {
                        modifiers.Sort(delegate(OutputFormatBranch left, OutputFormatBranch right)
                        {
                            return(string.Compare(left.ORMGenerators[0].DisplayName, right.ORMGenerators[0].DisplayName));
                        });
                    }
                    _modifiers = modifiers;
                }
            }
Ejemplo n.º 2
0
			public MainBranch(ORMGeneratorSelectionControl parent)
			{
				SortedList<string, OutputFormatBranch> branches = new SortedList<string, OutputFormatBranch>(StringComparer.OrdinalIgnoreCase);
				List<OutputFormatBranch> modifiers = null;
				int modifierAsGeneratorCount = 0;
				foreach (IORMGenerator ormGenerator in ORMCustomTool.ORMGenerators.Values)
				{
					string outputFormatName = ormGenerator.ProvidesOutputFormat;
					OutputFormatBranch formatBranch;
					if (ormGenerator.IsFormatModifier)
					{
						// Track modifiers separately
						if (modifiers == null)
						{
							modifiers = new List<OutputFormatBranch>();
						}
						formatBranch = new OutputFormatBranch(this);
						formatBranch.ORMGenerators.Add(ormGenerator);
						OutputFormatBranch primaryFormatBranch;
						if (branches.TryGetValue(outputFormatName, out primaryFormatBranch))
						{
							if (primaryFormatBranch.IsModifier)
							{
								if (primaryFormatBranch.ORMGenerators[0].FormatModifierPriority <= ormGenerator.FormatModifierPriority)
								{
									primaryFormatBranch.NextModifier = formatBranch;
								}
								else
								{
									formatBranch.NextModifier = primaryFormatBranch;
									branches[outputFormatName] = formatBranch;
								}
							}
							else
							{
								primaryFormatBranch.NextModifier = formatBranch;
							}
						}
						else
						{
							// We don't have a branch yet for a primary generator, track
							// the modifier by adding it here. We will verify later that
							// all modifiers have a non-modifier primary generator.
							branches.Add(outputFormatName, formatBranch);
							++modifierAsGeneratorCount;
						}
						modifiers.Add(formatBranch);
					}
					else
					{
						if (branches.TryGetValue(outputFormatName, out formatBranch))
						{
							if (formatBranch.IsModifier)
							{
								OutputFormatBranch modifierBranch = formatBranch;
								formatBranch = new OutputFormatBranch(this);
								formatBranch.NextModifier = modifierBranch;
								branches[outputFormatName] = formatBranch;
								--modifierAsGeneratorCount;
							}
						}
						else
						{
							formatBranch = new OutputFormatBranch(this);
							branches.Add(outputFormatName, formatBranch);
						}
						formatBranch.ORMGenerators.Add(ormGenerator);
					}
				}
				if (modifierAsGeneratorCount != 0)
				{
					// A modifier with no associated generator does not
					// make sense, but is currently stored as a branch.
					// Pull it out of the list.
					for (int i = modifiers.Count - 1; i >= 0; --i)
					{
						OutputFormatBranch testBranch;
						string outputFormat = modifiers[i].ORMGenerators[0].ProvidesOutputFormat;
						if (!branches.TryGetValue(outputFormat, out testBranch) ||
							testBranch.IsModifier)
						{
							if (testBranch != null)
							{
								branches.Remove(outputFormat);
							}
							modifiers.RemoveAt(i);
						}
					}
				}
				_parent = parent;
				_branches = branches;
				int modifierCount;
				if (modifiers != null && 0 != (modifierCount = modifiers.Count))
				{
					if (modifierCount > 1)
					{
						modifiers.Sort(delegate(OutputFormatBranch left, OutputFormatBranch right)
						{
							return string.Compare(left.ORMGenerators[0].DisplayName, right.ORMGenerators[0].DisplayName);
						});
					}
					_modifiers = modifiers;
				}
			}