FileNode.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. #region BSD License
  2. /*
  3. Copyright (c) 2004-2005 Matthew Holmes ([email protected]), Dan Moorehead ([email protected])
  4. Redistribution and use in source and binary forms, with or without modification, are permitted
  5. provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice, this list of conditions
  7. and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
  9. and the following disclaimer in the documentation and/or other materials provided with the
  10. distribution.
  11. * The name of the author may not be used to endorse or promote products derived from this software
  12. without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  14. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  17. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  18. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  19. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. */
  21. #endregion
  22. using System;
  23. using System.IO;
  24. using System.Xml;
  25. using Prebuild.Core.Attributes;
  26. using Prebuild.Core.Interfaces;
  27. using Prebuild.Core.Utilities;
  28. using Prebuild.Core.Targets;
  29. namespace Prebuild.Core.Nodes
  30. {
  31. /// <summary>
  32. ///
  33. /// </summary>
  34. public enum BuildAction
  35. {
  36. /// <summary>
  37. ///
  38. /// </summary>
  39. None,
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. Compile,
  44. /// <summary>
  45. ///
  46. /// </summary>
  47. Content,
  48. /// <summary>
  49. ///
  50. /// </summary>
  51. EmbeddedResource,
  52. /// <summary>
  53. ///
  54. /// </summary>
  55. ApplicationDefinition,
  56. /// <summary>
  57. ///
  58. /// </summary>
  59. Page,
  60. /// <summary>
  61. ///
  62. /// </summary>
  63. Copy
  64. }
  65. /// <summary>
  66. ///
  67. /// </summary>
  68. public enum SubType
  69. {
  70. /// <summary>
  71. ///
  72. /// </summary>
  73. Code,
  74. /// <summary>
  75. ///
  76. /// </summary>
  77. Component,
  78. /// <summary>
  79. ///
  80. /// </summary>
  81. Designer,
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. Form,
  86. /// <summary>
  87. ///
  88. /// </summary>
  89. Settings,
  90. /// <summary>
  91. ///
  92. /// </summary>
  93. UserControl,
  94. /// <summary>
  95. ///
  96. /// </summary>
  97. CodeBehind,
  98. }
  99. public enum CopyToOutput
  100. {
  101. Never,
  102. Always,
  103. PreserveNewest
  104. }
  105. /// <summary>
  106. ///
  107. /// </summary>
  108. [DataNode("File")]
  109. public class FileNode : DataNode
  110. {
  111. #region Fields
  112. private string m_Path;
  113. private string m_ResourceName = "";
  114. private BuildAction? m_BuildAction;
  115. private bool m_Valid;
  116. private SubType? m_SubType;
  117. private CopyToOutput m_CopyToOutput = CopyToOutput.Never;
  118. private bool m_Link = false;
  119. private string m_LinkPath = string.Empty;
  120. private bool m_PreservePath = false;
  121. #endregion
  122. #region Properties
  123. /// <summary>
  124. ///
  125. /// </summary>
  126. public string Path
  127. {
  128. get
  129. {
  130. return m_Path;
  131. }
  132. }
  133. /// <summary>
  134. ///
  135. /// </summary>
  136. public string ResourceName
  137. {
  138. get
  139. {
  140. return m_ResourceName;
  141. }
  142. }
  143. /// <summary>
  144. ///
  145. /// </summary>
  146. public BuildAction BuildAction
  147. {
  148. get
  149. {
  150. if (m_BuildAction != null)
  151. return m_BuildAction.Value;
  152. else
  153. return GetBuildActionByFileName(this.Path);
  154. }
  155. }
  156. public CopyToOutput CopyToOutput
  157. {
  158. get
  159. {
  160. return this.m_CopyToOutput;
  161. }
  162. }
  163. public bool IsLink
  164. {
  165. get
  166. {
  167. return this.m_Link;
  168. }
  169. }
  170. public string LinkPath
  171. {
  172. get
  173. {
  174. return this.m_LinkPath;
  175. }
  176. }
  177. /// <summary>
  178. ///
  179. /// </summary>
  180. public SubType SubType
  181. {
  182. get
  183. {
  184. if (m_SubType != null)
  185. return m_SubType.Value;
  186. else
  187. return GetSubTypeByFileName(this.Path);
  188. }
  189. }
  190. /// <summary>
  191. ///
  192. /// </summary>
  193. public bool IsValid
  194. {
  195. get
  196. {
  197. return m_Valid;
  198. }
  199. }
  200. /// <summary>
  201. ///
  202. /// </summary>
  203. /// <param name="file"></param>
  204. /// <returns></returns>
  205. public bool PreservePath
  206. {
  207. get
  208. {
  209. return m_PreservePath;
  210. }
  211. }
  212. #endregion
  213. #region Public Methods
  214. /// <summary>
  215. ///
  216. /// </summary>
  217. /// <param name="node"></param>
  218. public override void Parse(XmlNode node)
  219. {
  220. string buildAction = Helper.AttributeValue(node, "buildAction", String.Empty);
  221. if (buildAction != string.Empty)
  222. m_BuildAction = (BuildAction)Enum.Parse(typeof(BuildAction), buildAction);
  223. string subType = Helper.AttributeValue(node, "subType", string.Empty);
  224. if (subType != String.Empty)
  225. m_SubType = (SubType)Enum.Parse(typeof(SubType), subType);
  226. Console.WriteLine("[FileNode]:BuildAction is {0}", buildAction);
  227. m_ResourceName = Helper.AttributeValue(node, "resourceName", m_ResourceName.ToString());
  228. this.m_Link = bool.Parse(Helper.AttributeValue(node, "link", bool.FalseString));
  229. if ( this.m_Link == true )
  230. {
  231. this.m_LinkPath = Helper.AttributeValue( node, "linkPath", string.Empty );
  232. }
  233. this.m_CopyToOutput = (CopyToOutput) Enum.Parse(typeof(CopyToOutput), Helper.AttributeValue(node, "copyToOutput", this.m_CopyToOutput.ToString()));
  234. this.m_PreservePath = bool.Parse( Helper.AttributeValue( node, "preservePath", bool.FalseString ) );
  235. if( node == null )
  236. {
  237. throw new ArgumentNullException("node");
  238. }
  239. m_Path = Helper.InterpolateForEnvironmentVariables(node.InnerText);
  240. if(m_Path == null)
  241. {
  242. m_Path = "";
  243. }
  244. m_Path = m_Path.Trim();
  245. m_Valid = true;
  246. if(!File.Exists(m_Path))
  247. {
  248. m_Valid = false;
  249. Kernel.Instance.Log.Write(LogType.Warning, "File does not exist: {0}", m_Path);
  250. }
  251. if (System.IO.Path.GetExtension(m_Path) == ".settings")
  252. {
  253. m_SubType = SubType.Settings;
  254. m_BuildAction = BuildAction.None;
  255. }
  256. }
  257. #endregion
  258. }
  259. }