Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Solution.cs
Go to the documentation of this file.
1 #region License
2 
3 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
4 // This file is distributed under MIT License. See LICENSE.md for details.
5 //
6 // SLNTools
7 // Copyright (c) 2009
8 // by Christian Warren
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
12 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
13 // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
16 // of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23 
24 #endregion
25 
26 using System.Collections.Generic;
27 using System.Diagnostics;
28 using System.IO;
29 using System.Linq;
30 
31 namespace SiliconStudio.Core.VisualStudio
32 {
33  /// <summary>
34  /// A VisualStudio solution.
35  /// </summary>
36  [DebuggerDisplay("Projects = [{Projects.Count}]")]
37  public class Solution
38  {
39  private readonly SectionCollection globalSections;
40  private readonly List<string> headers;
41  private readonly ProjectCollection projects;
42 
43  /// <summary>
44  /// Initializes a new instance of the <see cref="Solution"/> class.
45  /// </summary>
46  public Solution()
47  {
48  FullPath = null;
49  headers = new List<string>();
50  projects = new ProjectCollection(this);
51  globalSections = new SectionCollection();
52  Properties = new PropertyItemCollection();
53  }
54 
55  private Solution(Solution original)
56  : this(original.FullPath, original.Headers, original.Projects, original.GlobalSections, original.Properties)
57  {
58  }
59 
60  /// <summary>
61  /// Initializes a new instance of the <see cref="Solution" /> class.
62  /// </summary>
63  /// <param name="fullpath">The fullpath.</param>
64  /// <param name="headers">The headers.</param>
65  /// <param name="projects">The projects.</param>
66  /// <param name="globalSections">The global sections.</param>
67  /// <param name="properties">The properties.</param>
68  public Solution(string fullpath, IEnumerable<string> headers, IEnumerable<Project> projects, IEnumerable<Section> globalSections, IEnumerable<PropertyItem> properties)
69  {
70  FullPath = fullpath;
71  this.headers = new List<string>(headers);
72  this.projects = new ProjectCollection(this, projects);
73  this.globalSections = new SectionCollection(globalSections);
74  this.Properties = new PropertyItemCollection(properties);
75  }
76 
77  /// <summary>
78  /// Gets or sets the full path.
79  /// </summary>
80  /// <value>The full path.</value>
81  public string FullPath { get; set; }
82 
83  /// <summary>
84  /// Gets all projects that are not folders.
85  /// </summary>
86  /// <value>The children.</value>
87  public IEnumerable<Project> Children
88  {
89  get
90  {
91  return projects.Where(project => project.ParentProject == null);
92  }
93  }
94 
95  /// <summary>
96  /// Gets the global sections.
97  /// </summary>
98  /// <value>The global sections.</value>
99  public SectionCollection GlobalSections
100  {
101  get
102  {
103  return globalSections;
104  }
105  }
106 
107  /// <summary>
108  /// Gets the headers.
109  /// </summary>
110  /// <value>The headers.</value>
111  public List<string> Headers
112  {
113  get
114  {
115  return headers;
116  }
117  }
118 
119  /// <summary>
120  /// Gets all projects.
121  /// </summary>
122  /// <value>The projects.</value>
123  public ProjectCollection Projects
124  {
125  get
126  {
127  return projects;
128  }
129  }
130 
131  /// <summary>
132  /// Gets the properties.
133  /// </summary>
134  /// <value>The properties.</value>
135  public PropertyItemCollection Properties { get; private set; }
136 
137  /// <summary>
138  /// Clones this instance.
139  /// </summary>
140  /// <returns>Solution.</returns>
141  public Solution Clone()
142  {
143  return new Solution(this);
144  }
145 
146  /// <summary>
147  /// Saves this instance to the <see cref="FullPath"/> path.
148  /// </summary>
149  public void Save()
150  {
151  SaveAs(FullPath);
152  }
153 
154  /// <summary>
155  /// Saves this instance to the specified path.
156  /// </summary>
157  /// <param name="solutionPath">The solution path.</param>
158  public void SaveAs(string solutionPath)
159  {
160  using (var writer = new SolutionWriter(solutionPath))
161  {
162  writer.WriteSolutionFile(this);
163  }
164  }
165 
166  /// <summary>
167  /// Loads the solution from the specified file.
168  /// </summary>
169  /// <param name="solutionFullPath">The solution full path.</param>
170  /// <returns>Solution.</returns>
171  public static Solution FromFile(string solutionFullPath)
172  {
173  using (var reader = new SolutionReader(solutionFullPath))
174  {
175  var solution = reader.ReadSolutionFile();
176  solution.FullPath = solutionFullPath;
177  return solution;
178  }
179  }
180 
181  /// <summary>
182  /// Loads the solution from the specified stream.
183  /// </summary>
184  /// <param name="solutionFullPath">The solution full path.</param>
185  /// <param name="stream">The stream.</param>
186  /// <returns>Solution.</returns>
187  public static Solution FromStream(string solutionFullPath, Stream stream)
188  {
189  using (var reader = new SolutionReader(stream))
190  {
191  var solution = reader.ReadSolutionFile();
192  solution.FullPath = solutionFullPath;
193  return solution;
194  }
195  }
196  }
197 }
Solution Clone()
Clones this instance.
Definition: Solution.cs:141
void SaveAs(string solutionPath)
Saves this instance to the specified path.
Definition: Solution.cs:158
Solution()
Initializes a new instance of the Solution class.
Definition: Solution.cs:46
static Solution FromStream(string solutionFullPath, Stream stream)
Loads the solution from the specified stream.
Definition: Solution.cs:187
A VisualStudio solution.
Definition: Solution.cs:37
void Save()
Saves this instance to the FullPath path.
Definition: Solution.cs:149
static Solution FromFile(string solutionFullPath)
Loads the solution from the specified file.
Definition: Solution.cs:171
Solution(string fullpath, IEnumerable< string > headers, IEnumerable< Project > projects, IEnumerable< Section > globalSections, IEnumerable< PropertyItem > properties)
Initializes a new instance of the Solution class.
Definition: Solution.cs:68