void LoadMonoDevelopConfigurationProperties (string configName, SlnSection sec, Solution sln, ProgressMonitor monitor)
		{
			SolutionConfiguration config = sln.Configurations [configName];
			if (config == null)
				return;
			sln.ReadConfigurationData (monitor, sec.Properties, config);
		}
		void LoadNestedProjects (SlnSection sec, IDictionary<string, SolutionFolderItem> entries, ProgressMonitor monitor)
		{
			if (sec == null || sec.SectionType != SlnSectionType.PreProcess)
				return;

			foreach (var kvp in sec.Properties) {
				// Guids should be upper case for VS compatibility
				var pair = new KeyValuePair<string, string> (kvp.Key.ToUpper (), kvp.Value.ToUpper ());

				SolutionFolderItem folderItem;
				SolutionFolderItem item;
				
				if (!entries.TryGetValue (pair.Value, out folderItem)) {
					//Container not found
					LoggingService.LogWarning (GettextCatalog.GetString ("Project with guid '{0}' not found.", pair.Value));
					continue;
				}
				
				SolutionFolder folder = folderItem as SolutionFolder;
				if (folder == null) {
					LoggingService.LogWarning (GettextCatalog.GetString ("Item with guid '{0}' is not a folder.", pair.Value));
					continue;
				}

				if (!entries.TryGetValue (pair.Key, out item)) {
					//Containee not found
					LoggingService.LogWarning (GettextCatalog.GetString ("Project with guid '{0}' not found.", pair.Key));
					continue;
				}

				folder.Items.Add (item);
			}
		}
		void WriteNestedProjects (SolutionFolder folder, SolutionFolder root, SlnSection sec)
		{
			foreach (SolutionFolderItem ce in folder.Items)
				sec.Properties.SetValue (ce.ItemId, folder.ItemId);
		}
Exemplo n.º 4
0
        public void Generate(bool ForceRegenerate)
        {
            var s = new SlnFile();

            s.FullPath = OutputDirectory / (SolutionName + ".sln");
            using (var sr = new StringReader(SlnTemplateText))
            {
                s.Read(sr);
            }

            s.Projects.Clear();
            s.SolutionConfigurationsSection.Clear();
            s.ProjectConfigurationsSection.Clear();

            foreach (var ConfigurationType in Enum.GetValues(typeof(ConfigurationType)).Cast <ConfigurationType>())
            {
                var ConfigurationTypeAndArchitecture = $"{ConfigurationType}|{GetArchitectureString(TargetOperatingSystem, TargetArchitecture)}";
                s.SolutionConfigurationsSection.SetValue(ConfigurationTypeAndArchitecture, ConfigurationTypeAndArchitecture);
            }

            SlnSection NestedProjects = null;

            foreach (var Section in s.Sections.Where(Section => Section.Id == "NestedProjects"))
            {
                Section.Clear();
                NestedProjects = Section;
            }

            if (NestedProjects == null)
            {
                NestedProjects = new SlnSection
                {
                    Id = "NestedProjects"
                };
                s.Sections.Add(NestedProjects);
            }

            var Filters = new Dictionary <String, String>(StringComparer.OrdinalIgnoreCase);

            foreach (var Project in ProjectReferences)
            {
                var Dir = Project.VirtualDir.ToString(PathStringStyle.Windows);
                if (!Filters.ContainsKey(Dir))
                {
                    var CurrentDir       = Dir.AsPath();
                    var CurrentDirFilter = CurrentDir.ToString(PathStringStyle.Windows);
                    while ((CurrentDirFilter != ".") && !Filters.ContainsKey(CurrentDirFilter))
                    {
                        var g = Guid.ParseExact(Hash.GetHashForPath(CurrentDirFilter, 32), "N").ToString().ToUpper();
                        Filters.Add(CurrentDirFilter, g);
                        CurrentDir       = CurrentDir.Parent;
                        CurrentDirFilter = CurrentDir.ToString(PathStringStyle.Windows);
                        if (CurrentDirFilter != ".")
                        {
                            var gUpper = Guid.ParseExact(Hash.GetHashForPath(CurrentDirFilter, 32), "N").ToString().ToUpper();
                            NestedProjects.Properties.SetValue("{" + g + "}", "{" + gUpper + "}");
                        }
                    }
                }

                s.Projects.Add(new SlnProject
                {
                    TypeGuid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}",
                    Name     = Project.Name,
                    FilePath = Project.FilePath.FullPath.RelativeTo(OutputDirectory).ToString(PathStringStyle.Windows),
                    Id       = "{" + Project.Id + "}"
                });

                var conf = new SlnPropertySet("{" + Project.Id + "}");
                foreach (var c in s.SolutionConfigurationsSection)
                {
                    var Value = TargetOperatingSystem == OperatingSystemType.Windows ? c.Value.Replace("|x86", "|Win32") : c.Value;
                    conf.SetValue(c.Key + ".ActiveCfg", Value);
                    conf.SetValue(c.Key + ".Build.0", Value);
                }
                s.ProjectConfigurationsSection.Add(conf);

                if (Dir != ".")
                {
                    NestedProjects.Properties.SetValue("{" + Project.Id + "}", "{" + Filters[Dir] + "}");
                }
            }

            foreach (var f in Filters)
            {
                s.Projects.Add(new SlnProject
                {
                    TypeGuid = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}",
                    Name     = f.Key.AsPath().FileName,
                    FilePath = f.Key.AsPath().FileName,
                    Id       = "{" + f.Value + "}"
                });
            }

            foreach (var Section in s.Sections.Where(Section => Section.Id == "ExtensibilityGlobals"))
            {
                Section.Properties.SetValue("SolutionGuid", "{" + SolutionId.ToUpper() + "}");
            }

            String Text;

            using (var sw = new StringWriter())
            {
                s.Write(sw);
                Text = sw.ToString();
            }
            TextFile.WriteToFile(s.FullPath, Text, Encoding.UTF8, !ForceRegenerate);
        }
		static DataItem ReadDataItem (SlnSection pset, Dictionary<DataNode,int> ids)
		{
			DataItem it = new DataItem ();

			var lines = pset.GetContent ().ToArray ();

			int lineNum = 0;
			int lastLine = lines.Length - 1;
			while (lineNum <= lastLine) {
				if (!ReadDataNode (it, lines, lastLine, "", ids, ref lineNum))
					lineNum++;
			}
			return it;
		}
		static DataItem ReadDataItem (SlnSection pset)
		{
			return ReadDataItem (pset, null);
		}
		static void WriteDataItem (SlnSection pset, DataItem item)
		{
			HashSet<DataItem> removedItems = new HashSet<DataItem> ();
			Dictionary<DataNode,int> ids = new Dictionary<DataNode, int> ();

			// First of all read the existing data item, since we want to keep data that has not been modified
			// The ids collection is filled with a map of items and their ids
			var currentItem = ReadDataItem (pset, ids);

			// UpdateFromItem will add new data to the item, it will remove the data that has been removed, and
			// will ignore unknown data that has not been set or removed
			currentItem.UpdateFromItem (item, removedItems);

			// List of IDs that are not used anymore and can be reused when writing the item
			var unusedIds = new Queue<int> (removedItems.Select (it => ids[it]).OrderBy (i => i));

			// Calculate the next free id, to be used when adding new items
			var usedIds = ids.Where (p => !removedItems.Contains (p.Key)).Select (p => p.Value).ToArray ();
			int nextId = usedIds.Length > 0 ? usedIds.Max () + 1 : 0;

			var newSet = new List<KeyValuePair<string, string>> ();

			foreach (DataNode val in currentItem.ItemData)
				WriteDataNode (newSet, "", val, ids, unusedIds, ref nextId);
			
			pset.SetContent (newSet);
		}