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); }
void WriteNestedProjects(SolutionFolder folder, SolutionFolder root, SlnSection sec) { foreach (SolutionFolderItem ce in folder.Items) { sec.Properties.SetValue(ce.ItemId, folder.ItemId); } }
internal void Read(TextReader reader, string line, ref int curLineNum) { Line = curLineNum; int n = 0; FindNext(curLineNum, line, ref n, '('); n++; FindNext(curLineNum, line, ref n, '"'); int n2 = n + 1; FindNext(curLineNum, line, ref n2, '"'); TypeGuid = line.Substring(n + 1, n2 - n - 1); n = n2 + 1; FindNext(curLineNum, line, ref n, ')'); FindNext(curLineNum, line, ref n, '='); FindNext(curLineNum, line, ref n, '"'); n2 = n + 1; FindNext(curLineNum, line, ref n2, '"'); Name = line.Substring(n + 1, n2 - n - 1); n = n2 + 1; FindNext(curLineNum, line, ref n, ','); FindNext(curLineNum, line, ref n, '"'); n2 = n + 1; FindNext(curLineNum, line, ref n2, '"'); FilePath = line.Substring(n + 1, n2 - n - 1); n = n2 + 1; FindNext(curLineNum, line, ref n, ','); FindNext(curLineNum, line, ref n, '"'); n2 = n + 1; FindNext(curLineNum, line, ref n2, '"'); Id = line.Substring(n + 1, n2 - n - 1); while ((line = reader.ReadLine()) != null) { curLineNum++; line = line.Trim(); if (line == "EndProject") { return; } if (line.StartsWith("ProjectSection", StringComparison.Ordinal)) { if (sections == null) { sections = new SlnSectionCollection(); } var sec = new SlnSection(); sections.Add(sec); sec.Read(reader, line, ref curLineNum); } } throw new InvalidSolutionFormatException(curLineNum, "Project section not closed"); }
public static void ReadObjectProperties(this SlnSection pset, object ob) { DataSerializer ser = new DataSerializer(solutionDataContext); ser.SerializationContext.BaseFile = pset.ParentFile.FileName; var data = ReadDataItem(pset); ser.Deserialize(ob, data); }
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); }
public static void WriteObjectProperties(this SlnSection pset, object ob) { DataSerializer ser = new DataSerializer(solutionDataContext); ser.SerializationContext.BaseFile = pset.ParentFile.FileName; ser.SerializationContext.IncludeDeletedValues = true; var data = ser.Serialize(ob, ob.GetType()) as DataItem; if (data != null) { WriteDataItem(pset, data); } }
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); }
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); } }
public void Read(TextReader reader) { string line; int curLineNum = 0; bool globalFound = false; bool productRead = false; while ((line = reader.ReadLine()) != null) { curLineNum++; line = line.Trim(); if (line.StartsWith("Microsoft Visual Studio Solution File", StringComparison.Ordinal)) { int i = line.LastIndexOf(' '); if (i == -1) { throw new InvalidSolutionFormatException(curLineNum); } FormatVersion = line.Substring(i + 1); prefixBlankLines = curLineNum - 1; } if (line.StartsWith("# ", StringComparison.Ordinal)) { if (!productRead) { productRead = true; ProductDescription = line.Substring(2); } } else if (line.StartsWith("Project", StringComparison.Ordinal)) { SlnProject p = new SlnProject(); p.Read(reader, line, ref curLineNum); projects.Add(p); } else if (line == "Global") { if (globalFound) { throw new InvalidSolutionFormatException(curLineNum, "Global section specified more than once"); } globalFound = true; while ((line = reader.ReadLine()) != null) { curLineNum++; line = line.Trim(); if (line == "EndGlobal") { break; } else if (line.StartsWith("GlobalSection", StringComparison.Ordinal)) { var sec = new SlnSection(); sec.Read(reader, line, ref curLineNum); sections.Add(sec); } else // Ignore text that's out of place { continue; } } if (line == null) { throw new InvalidSolutionFormatException(curLineNum, "Global section not closed"); } } else if (line.IndexOf('=') != -1) { metadata.ReadLine(line, curLineNum); } } if (FormatVersion == null) { throw new InvalidSolutionFormatException(curLineNum, "File header is missing"); } }
internal SlnPropertySetCollection(SlnSection parentSection) { this.parentSection = parentSection; }
static DataItem ReadDataItem(SlnSection pset) { return(ReadDataItem(pset, null)); }