From 7d4846462bf5f3c7fe862c7466d0461b6c5d228f Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Fri, 20 Feb 2009 02:33:54 +0000 Subject: [PATCH] Update svn properties, add copyright headers, minor formatting cleanup. --- OpenSim/Data/NHibernate/EstateRegionLink.cs | 27 + OpenSim/Data/Tests/DataTestUtil.cs | 33 +- OpenSim/Region/Application/OpenSimBase.cs | 2 +- .../VectorRender/VectorRenderModule.cs | 92 +- .../Framework/Scenes/ChildAgentDataUpdate.cs | 1012 +++++----- .../Framework/Scenes/Scene.Inventory.cs | 1 - .../Avatar/Concierge/ConciergeModule.cs | 6 +- Prebuild/scripts/VS2008.bat | 8 +- .../src/Core/Nodes/DatabaseProjectNode.cs | 188 +- .../src/Core/Nodes/DatabaseReferenceNode.cs | 126 +- Prebuild/src/Core/Targets/VSGenericTarget.cs | 1768 ++++++++--------- 11 files changed, 1654 insertions(+), 1609 deletions(-) mode change 100644 => 100755 Prebuild/scripts/VS2008.bat diff --git a/OpenSim/Data/NHibernate/EstateRegionLink.cs b/OpenSim/Data/NHibernate/EstateRegionLink.cs index e666c3a397..4b83fa51b1 100644 --- a/OpenSim/Data/NHibernate/EstateRegionLink.cs +++ b/OpenSim/Data/NHibernate/EstateRegionLink.cs @@ -1,3 +1,30 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + using System; using System.Collections.Generic; using System.Text; diff --git a/OpenSim/Data/Tests/DataTestUtil.cs b/OpenSim/Data/Tests/DataTestUtil.cs index 37d1443a19..f781ea6e38 100644 --- a/OpenSim/Data/Tests/DataTestUtil.cs +++ b/OpenSim/Data/Tests/DataTestUtil.cs @@ -1,4 +1,31 @@ -using System; +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; using System.Collections.Generic; using System.Text; using OpenMetaverse; @@ -6,13 +33,11 @@ using NUnit.Framework; namespace OpenSim.Data.Tests { - /// /// Shared constants and methods for database unit tests. /// public class DataTestUtil { - public const uint UNSIGNED_INTEGER_MIN = uint.MinValue; public const uint UNSIGNED_INTEGER_MAX = uint.MaxValue / 2; // NHibernate does not support unsigned integer range. @@ -57,6 +82,6 @@ namespace OpenSim.Data.Tests Assert.GreaterOrEqual(actualValue, expectedValue - Math.Abs(expectedValue) * DOUBLE_PRECISSION); Assert.LessOrEqual(actualValue, expectedValue + Math.Abs(expectedValue) * DOUBLE_PRECISSION); } - } } + diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 69ff2bdca3..54822d04ab 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -437,7 +437,7 @@ namespace OpenSim private IAssetServer loadAssetServer(string id, PluginInitialiserBase pi) { - if(id != null && id != String.Empty) + if (id != null && id != String.Empty) { m_log.DebugFormat("[OPENSIMBASE] Attempting to load asset server id={0}", id); diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs index 86f836c5fb..7cee0cfe53 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs @@ -147,7 +147,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender int width = 256; int height = 256; int alpha = 255; // 0 is transparent - Color bgColour = Color.White; // Default background color + Color bgColour = Color.White; // Default background color char[] paramDelimiter = { ',' }; char[] nvpDelimiter = { ':' }; @@ -230,18 +230,17 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender } } break; - case "bgcolour": - int hex = 0; - if (Int32.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex)) - { - bgColour = Color.FromArgb(hex); - } - else - { - - bgColour = Color.FromName(value); - } - break; + case "bgcolour": + int hex = 0; + if (Int32.TryParse(value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex)) + { + bgColour = Color.FromArgb(hex); + } + else + { + bgColour = Color.FromName(value); + } + break; case "": // blank string has been passed do nothing just use defaults break; @@ -271,7 +270,6 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender } break; } - } Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); @@ -282,8 +280,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender // background color in their scripts, only do when fully opaque if (alpha == 255) { - graph.FillRectangle(new SolidBrush(bgColour), 0, 0, width, height); - + graph.FillRectangle(new SolidBrush(bgColour), 0, 0, width, height); } for (int w = 0; w < bitmap.Width; w++) @@ -294,7 +291,6 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender } } - GDIDraw(data, graph); byte[] imageJ2000 = new byte[0]; @@ -326,10 +322,8 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender } return parsed; - } - /* private void CairoDraw(string data, System.Drawing.Graphics graph) { @@ -462,38 +456,38 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender fontSize = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); myFont = new Font(fontName, fontSize); } - else if (nextLine.StartsWith("FontProp")) - { - nextLine = nextLine.Remove(0, 8); + else if (nextLine.StartsWith("FontProp")) + { + nextLine = nextLine.Remove(0, 8); nextLine = nextLine.Trim(); - string [] fprops = nextLine.Split(partsDelimiter); - foreach (string prop in fprops) { - - switch (prop) - { - case "B": - if(!(myFont.Bold)) - myFont = new Font(myFont, myFont.Style | FontStyle.Bold); - break; - case "I": - if(!(myFont.Italic)) - myFont = new Font(myFont, myFont.Style | FontStyle.Italic); - break; - case "U": - if(!(myFont.Underline)) - myFont = new Font(myFont, myFont.Style | FontStyle.Underline); - break; - case "S": - if(!(myFont.Strikeout)) - myFont = new Font(myFont, myFont.Style | FontStyle.Strikeout); - break; - case "R": - myFont = new Font(myFont, FontStyle.Regular); - break; - } - } - } + string [] fprops = nextLine.Split(partsDelimiter); + foreach (string prop in fprops) { + + switch (prop) + { + case "B": + if (!(myFont.Bold)) + myFont = new Font(myFont, myFont.Style | FontStyle.Bold); + break; + case "I": + if (!(myFont.Italic)) + myFont = new Font(myFont, myFont.Style | FontStyle.Italic); + break; + case "U": + if (!(myFont.Underline)) + myFont = new Font(myFont, myFont.Style | FontStyle.Underline); + break; + case "S": + if (!(myFont.Strikeout)) + myFont = new Font(myFont, myFont.Style | FontStyle.Strikeout); + break; + case "R": + myFont = new Font(myFont, FontStyle.Regular); + break; + } + } + } else if (nextLine.StartsWith("FontName")) { nextLine = nextLine.Remove(0, 8); diff --git a/OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs b/OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs index e181b91c1d..6bfa73bab1 100644 --- a/OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs +++ b/OpenSim/Region/Framework/Scenes/ChildAgentDataUpdate.cs @@ -1,506 +1,506 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using OpenSim.Framework; -using OpenMetaverse; -using OpenMetaverse.StructuredData; - -namespace OpenSim.Region.Framework.Scenes -{ - public interface IAgentData - { - UUID AgentID { get; set; } - - OSDMap PackUpdateMessage(); - void UnpackUpdateMessage(OSDMap map); - } - - /// - /// Replacement for ChildAgentDataUpdate. Used over RESTComms and LocalComms. - /// - public class AgentPosition : IAgentData - { - private UUID m_id; - public UUID AgentID - { - get { return m_id; } - set { m_id = value; } - } - - public ulong RegionHandle; - public uint CircuitCode; - public UUID SessionID; - - public float Far; - public Vector3 Position; - public Vector3 Velocity; - public Vector3 Center; - public Vector3 Size; - public Vector3 AtAxis; - public Vector3 LeftAxis; - public Vector3 UpAxis; - public bool ChangedGrid; - - // This probably shouldn't be here - public byte[] Throttles; - - - public OSDMap PackUpdateMessage() - { - OSDMap args = new OSDMap(); - args["message_type"] = OSD.FromString("AgentPosition"); - - args["region_handle"] = OSD.FromString(RegionHandle.ToString()); - args["circuit_code"] = OSD.FromString(CircuitCode.ToString()); - args["agent_uuid"] = OSD.FromUUID(AgentID); - args["session_uuid"] = OSD.FromUUID(SessionID); - - args["position"] = OSD.FromString(Position.ToString()); - args["velocity"] = OSD.FromString(Velocity.ToString()); - args["center"] = OSD.FromString(Center.ToString()); - args["size"] = OSD.FromString(Size.ToString()); - args["at_axis"] = OSD.FromString(AtAxis.ToString()); - args["left_axis"] = OSD.FromString(LeftAxis.ToString()); - args["up_axis"] = OSD.FromString(UpAxis.ToString()); - - args["far"] = OSD.FromReal(Far); - args["changed_grid"] = OSD.FromBoolean(ChangedGrid); - - if ((Throttles != null) && (Throttles.Length > 0)) - args["throttles"] = OSD.FromBinary(Throttles); - - return args; - } - - public void UnpackUpdateMessage(OSDMap args) - { - if (args.ContainsKey("region_handle")) - UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle); - - if (args["circuit_code"] != null) - UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode); - - if (args["agent_uuid"] != null) - AgentID = args["agent_uuid"].AsUUID(); - - if (args["session_uuid"] != null) - SessionID = args["session_uuid"].AsUUID(); - - if (args["position"] != null) - Vector3.TryParse(args["position"].AsString(), out Position); - - if (args["velocity"] != null) - Vector3.TryParse(args["velocity"].AsString(), out Velocity); - - if (args["center"] != null) - Vector3.TryParse(args["center"].AsString(), out Center); - - if (args["size"] != null) - Vector3.TryParse(args["size"].AsString(), out Size); - - if (args["at_axis"] != null) - Vector3.TryParse(args["at_axis"].AsString(), out AtAxis); - - if (args["left_axis"] != null) - Vector3.TryParse(args["left_axis"].AsString(), out AtAxis); - - if (args["up_axis"] != null) - Vector3.TryParse(args["up_axis"].AsString(), out AtAxis); - - if (args["changed_grid"] != null) - ChangedGrid = args["changed_grid"].AsBoolean(); - - if (args["far"] != null) - Far = (float)(args["far"].AsReal()); - - if (args["throttles"] != null) - Throttles = args["throttles"].AsBinary(); - } - - /// - /// Soon to be decommissioned - /// - /// - public void CopyFrom(ChildAgentDataUpdate cAgent) - { - AgentID = new UUID(cAgent.AgentID); - - // next: ??? - Size = new Vector3(); - Size.Z = cAgent.AVHeight; - - Center = new Vector3(cAgent.cameraPosition.x, cAgent.cameraPosition.y, cAgent.cameraPosition.z); - Far = cAgent.drawdistance; - Position = new Vector3(cAgent.Position.x, cAgent.Position.y, cAgent.Position.z); - RegionHandle = cAgent.regionHandle; - Throttles = cAgent.throttles; - Velocity = new Vector3(cAgent.Velocity.x, cAgent.Velocity.y, cAgent.Velocity.z); - } - - } - - public class AgentGroupData - { - public UUID GroupID; - public ulong GroupPowers; - public bool AcceptNotices; - - public AgentGroupData(UUID id, ulong powers, bool notices) - { - GroupID = id; - GroupPowers = powers; - AcceptNotices = notices; - } - - public AgentGroupData(OSDMap args) - { - UnpackUpdateMessage(args); - } - - public OSDMap PackUpdateMessage() - { - OSDMap groupdata = new OSDMap(); - groupdata["group_id"] = OSD.FromUUID(GroupID); - groupdata["group_powers"] = OSD.FromString(GroupPowers.ToString()); - groupdata["accept_notices"] = OSD.FromBoolean(AcceptNotices); - - return groupdata; - } - - public void UnpackUpdateMessage(OSDMap args) - { - if (args["group_id"] != null) - GroupID = args["group_id"].AsUUID(); - if (args["group_powers"] != null) - UInt64.TryParse((string)args["group_powers"].AsString(), out GroupPowers); - if (args["accept_notices"] != null) - AcceptNotices = args["accept_notices"].AsBoolean(); - } - } - - //public class AgentAnimationData - //{ - // public UUID Animation; - // public UUID ObjectID; - - // public AgentAnimationData(UUID anim, UUID obj) - // { - // Animation = anim; - // ObjectID = obj; - // } - - // public AgentAnimationData(OSDMap args) - // { - // UnpackUpdateMessage(args); - // } - - // public OSDMap PackUpdateMessage() - // { - // OSDMap anim = new OSDMap(); - // anim["animation"] = OSD.FromUUID(Animation); - // anim["object_id"] = OSD.FromUUID(ObjectID); - // return anim; - // } - - // public void UnpackUpdateMessage(OSDMap args) - // { - // if (args["animation"] != null) - // Animation = args["animation"].AsUUID(); - // if (args["object_id"] != null) - // ObjectID = args["object_id"].AsUUID(); - // } - //} - - public class AgentData : IAgentData - { - private UUID m_id; - public UUID AgentID - { - get { return m_id; } - set { m_id = value; } - } - public ulong RegionHandle; - public uint CircuitCode; - public UUID SessionID; - - public Vector3 Position; - public Vector3 Velocity; - public Vector3 Center; - public Vector3 Size; - public Vector3 AtAxis; - public Vector3 LeftAxis; - public Vector3 UpAxis; - public bool ChangedGrid; - - public float Far; - public float Aspect; - //public int[] Throttles; - public byte[] Throttles; - - public uint LocomotionState; - public Quaternion HeadRotation; - public Quaternion BodyRotation; - public uint ControlFlags; - public float EnergyLevel; - public Byte GodLevel; - public bool AlwaysRun; - public UUID PreyAgent; - public Byte AgentAccess; - public UUID[] AgentTextures; - public UUID ActiveGroupID; - - public AgentGroupData[] Groups; - public Animation[] Anims; - - public UUID GranterID; - public Dictionary NVPairs; - - public byte[] VisualParams; - - public string CallbackURI; - - public OSDMap PackUpdateMessage() - { - OSDMap args = new OSDMap(); - args["message_type"] = OSD.FromString("AgentData"); - - args["region_handle"] = OSD.FromString(RegionHandle.ToString()); - args["circuit_code"] = OSD.FromString(CircuitCode.ToString()); - args["agent_uuid"] = OSD.FromUUID(AgentID); - args["session_uuid"] = OSD.FromUUID(SessionID); - - args["position"] = OSD.FromString(Position.ToString()); - args["velocity"] = OSD.FromString(Velocity.ToString()); - args["center"] = OSD.FromString(Center.ToString()); - args["size"] = OSD.FromString(Size.ToString()); - args["at_axis"] = OSD.FromString(AtAxis.ToString()); - args["left_axis"] = OSD.FromString(LeftAxis.ToString()); - args["up_axis"] = OSD.FromString(UpAxis.ToString()); - - args["changed_grid"] = OSD.FromBoolean(ChangedGrid); - args["far"] = OSD.FromReal(Far); - args["aspect"] = OSD.FromReal(Aspect); - - if ((Throttles != null) && (Throttles.Length > 0)) - args["throttles"] = OSD.FromBinary(Throttles); - - args["locomotion_state"] = OSD.FromString(LocomotionState.ToString()); - args["head_rotation"] = OSD.FromString(HeadRotation.ToString()); - args["body_rotation"] = OSD.FromString(BodyRotation.ToString()); - args["control_flags"] = OSD.FromString(ControlFlags.ToString()); - - args["energy_level"] = OSD.FromReal(EnergyLevel); - args["god_level"] = OSD.FromString(GodLevel.ToString()); - args["always_run"] = OSD.FromBoolean(AlwaysRun); - args["prey_agent"] = OSD.FromUUID(PreyAgent); - args["agent_access"] = OSD.FromString(AgentAccess.ToString()); - - if ((AgentTextures != null) && (AgentTextures.Length > 0)) - { - OSDArray textures = new OSDArray(AgentTextures.Length); - foreach (UUID uuid in AgentTextures) - textures.Add(OSD.FromUUID(uuid)); - args["agent_textures"] = textures; - } - - args["active_group_id"] = OSD.FromUUID(ActiveGroupID); - - if ((Groups != null) && (Groups.Length > 0)) - { - OSDArray groups = new OSDArray(Groups.Length); - foreach (AgentGroupData agd in Groups) - groups.Add(agd.PackUpdateMessage()); - args["groups"] = groups; - } - - if ((Anims != null) && (Anims.Length > 0)) - { - OSDArray anims = new OSDArray(Anims.Length); - foreach (Animation aanim in Anims) - anims.Add(aanim.PackUpdateMessage()); - args["animations"] = anims; - } - - if ((VisualParams != null) && (VisualParams.Length > 0)) - args["visual_params"] = OSD.FromBinary(VisualParams); - - // Last few fields are still missing: granter and NVPais - - if ((CallbackURI != null) && (!CallbackURI.Equals(""))) - args["callback_uri"] = OSD.FromString(CallbackURI); - - return args; - } - - /// - /// Deserialization of agent data. - /// Avoiding reflection makes it painful to write, but that's the price! - /// - /// - public void UnpackUpdateMessage(OSDMap args) - { - if (args.ContainsKey("region_handle")) - UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle); - - if (args["circuit_code"] != null) - UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode); - - if (args["agent_uuid"] != null) - AgentID = args["agent_uuid"].AsUUID(); - - if (args["session_uuid"] != null) - SessionID = args["session_uuid"].AsUUID(); - - if (args["position"] != null) - Vector3.TryParse(args["position"].AsString(), out Position); - - if (args["velocity"] != null) - Vector3.TryParse(args["velocity"].AsString(), out Velocity); - - if (args["center"] != null) - Vector3.TryParse(args["center"].AsString(), out Center); - - if (args["size"] != null) - Vector3.TryParse(args["size"].AsString(), out Size); - - if (args["at_axis"] != null) - Vector3.TryParse(args["at_axis"].AsString(), out AtAxis); - - if (args["left_axis"] != null) - Vector3.TryParse(args["left_axis"].AsString(), out AtAxis); - - if (args["up_axis"] != null) - Vector3.TryParse(args["up_axis"].AsString(), out AtAxis); - - if (args["changed_grid"] != null) - ChangedGrid = args["changed_grid"].AsBoolean(); - - if (args["far"] != null) - Far = (float)(args["far"].AsReal()); - - if (args["aspect"] != null) - Aspect = (float)args["aspect"].AsReal(); - - if (args["throttles"] != null) - Throttles = args["throttles"].AsBinary(); - - if (args["locomotion_state"] != null) - UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState); - - if (args["head_rotation"] != null) - Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation); - - if (args["body_rotation"] != null) - Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation); - - if (args["control_flags"] != null) - UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags); - - if (args["energy_level"] != null) - EnergyLevel = (float)(args["energy_level"].AsReal()); - - if (args["god_level"] != null) - Byte.TryParse(args["god_level"].AsString(), out GodLevel); - - if (args["always_run"] != null) - AlwaysRun = args["always_run"].AsBoolean(); - - if (args["prey_agent"] != null) - PreyAgent = args["prey_agent"].AsUUID(); - - if (args["agent_access"] != null) - Byte.TryParse(args["agent_access"].AsString(), out AgentAccess); - - if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array) - { - OSDArray textures = (OSDArray)(args["agent_textures"]); - AgentTextures = new UUID[textures.Count]; - int i = 0; - foreach (OSD o in textures) - AgentTextures[i++] = o.AsUUID(); - } - - if (args["active_group_id"] != null) - ActiveGroupID = args["active_group_id"].AsUUID(); - - if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array) - { - OSDArray groups = (OSDArray)(args["groups"]); - Groups = new AgentGroupData[groups.Count]; - int i = 0; - foreach (OSD o in groups) - { - if (o.Type == OSDType.Map) - { - Groups[i++] = new AgentGroupData((OSDMap)o); - } - } - } - - if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array) - { - OSDArray anims = (OSDArray)(args["animations"]); - Anims = new Animation[anims.Count]; - int i = 0; - foreach (OSD o in anims) - { - if (o.Type == OSDType.Map) - { - Anims[i++] = new Animation((OSDMap)o); - } - } - } - - if (args["visual_params"] != null) - VisualParams = args["visual_params"].AsBinary(); - - if (args["callback_uri"] != null) - CallbackURI = args["callback_uri"].AsString(); - } - - public AgentData() - { - } - - public AgentData(Hashtable hash) - { - //UnpackUpdateMessage(hash); - } - - public void Dump() - { - System.Console.WriteLine("------------ AgentData ------------"); - System.Console.WriteLine("UUID: " + AgentID); - System.Console.WriteLine("Region: " + RegionHandle); - System.Console.WriteLine("Position: " + Position); - } - } - -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using OpenSim.Framework; +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +namespace OpenSim.Region.Framework.Scenes +{ + public interface IAgentData + { + UUID AgentID { get; set; } + + OSDMap PackUpdateMessage(); + void UnpackUpdateMessage(OSDMap map); + } + + /// + /// Replacement for ChildAgentDataUpdate. Used over RESTComms and LocalComms. + /// + public class AgentPosition : IAgentData + { + private UUID m_id; + public UUID AgentID + { + get { return m_id; } + set { m_id = value; } + } + + public ulong RegionHandle; + public uint CircuitCode; + public UUID SessionID; + + public float Far; + public Vector3 Position; + public Vector3 Velocity; + public Vector3 Center; + public Vector3 Size; + public Vector3 AtAxis; + public Vector3 LeftAxis; + public Vector3 UpAxis; + public bool ChangedGrid; + + // This probably shouldn't be here + public byte[] Throttles; + + + public OSDMap PackUpdateMessage() + { + OSDMap args = new OSDMap(); + args["message_type"] = OSD.FromString("AgentPosition"); + + args["region_handle"] = OSD.FromString(RegionHandle.ToString()); + args["circuit_code"] = OSD.FromString(CircuitCode.ToString()); + args["agent_uuid"] = OSD.FromUUID(AgentID); + args["session_uuid"] = OSD.FromUUID(SessionID); + + args["position"] = OSD.FromString(Position.ToString()); + args["velocity"] = OSD.FromString(Velocity.ToString()); + args["center"] = OSD.FromString(Center.ToString()); + args["size"] = OSD.FromString(Size.ToString()); + args["at_axis"] = OSD.FromString(AtAxis.ToString()); + args["left_axis"] = OSD.FromString(LeftAxis.ToString()); + args["up_axis"] = OSD.FromString(UpAxis.ToString()); + + args["far"] = OSD.FromReal(Far); + args["changed_grid"] = OSD.FromBoolean(ChangedGrid); + + if ((Throttles != null) && (Throttles.Length > 0)) + args["throttles"] = OSD.FromBinary(Throttles); + + return args; + } + + public void UnpackUpdateMessage(OSDMap args) + { + if (args.ContainsKey("region_handle")) + UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle); + + if (args["circuit_code"] != null) + UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode); + + if (args["agent_uuid"] != null) + AgentID = args["agent_uuid"].AsUUID(); + + if (args["session_uuid"] != null) + SessionID = args["session_uuid"].AsUUID(); + + if (args["position"] != null) + Vector3.TryParse(args["position"].AsString(), out Position); + + if (args["velocity"] != null) + Vector3.TryParse(args["velocity"].AsString(), out Velocity); + + if (args["center"] != null) + Vector3.TryParse(args["center"].AsString(), out Center); + + if (args["size"] != null) + Vector3.TryParse(args["size"].AsString(), out Size); + + if (args["at_axis"] != null) + Vector3.TryParse(args["at_axis"].AsString(), out AtAxis); + + if (args["left_axis"] != null) + Vector3.TryParse(args["left_axis"].AsString(), out AtAxis); + + if (args["up_axis"] != null) + Vector3.TryParse(args["up_axis"].AsString(), out AtAxis); + + if (args["changed_grid"] != null) + ChangedGrid = args["changed_grid"].AsBoolean(); + + if (args["far"] != null) + Far = (float)(args["far"].AsReal()); + + if (args["throttles"] != null) + Throttles = args["throttles"].AsBinary(); + } + + /// + /// Soon to be decommissioned + /// + /// + public void CopyFrom(ChildAgentDataUpdate cAgent) + { + AgentID = new UUID(cAgent.AgentID); + + // next: ??? + Size = new Vector3(); + Size.Z = cAgent.AVHeight; + + Center = new Vector3(cAgent.cameraPosition.x, cAgent.cameraPosition.y, cAgent.cameraPosition.z); + Far = cAgent.drawdistance; + Position = new Vector3(cAgent.Position.x, cAgent.Position.y, cAgent.Position.z); + RegionHandle = cAgent.regionHandle; + Throttles = cAgent.throttles; + Velocity = new Vector3(cAgent.Velocity.x, cAgent.Velocity.y, cAgent.Velocity.z); + } + + } + + public class AgentGroupData + { + public UUID GroupID; + public ulong GroupPowers; + public bool AcceptNotices; + + public AgentGroupData(UUID id, ulong powers, bool notices) + { + GroupID = id; + GroupPowers = powers; + AcceptNotices = notices; + } + + public AgentGroupData(OSDMap args) + { + UnpackUpdateMessage(args); + } + + public OSDMap PackUpdateMessage() + { + OSDMap groupdata = new OSDMap(); + groupdata["group_id"] = OSD.FromUUID(GroupID); + groupdata["group_powers"] = OSD.FromString(GroupPowers.ToString()); + groupdata["accept_notices"] = OSD.FromBoolean(AcceptNotices); + + return groupdata; + } + + public void UnpackUpdateMessage(OSDMap args) + { + if (args["group_id"] != null) + GroupID = args["group_id"].AsUUID(); + if (args["group_powers"] != null) + UInt64.TryParse((string)args["group_powers"].AsString(), out GroupPowers); + if (args["accept_notices"] != null) + AcceptNotices = args["accept_notices"].AsBoolean(); + } + } + + //public class AgentAnimationData + //{ + // public UUID Animation; + // public UUID ObjectID; + + // public AgentAnimationData(UUID anim, UUID obj) + // { + // Animation = anim; + // ObjectID = obj; + // } + + // public AgentAnimationData(OSDMap args) + // { + // UnpackUpdateMessage(args); + // } + + // public OSDMap PackUpdateMessage() + // { + // OSDMap anim = new OSDMap(); + // anim["animation"] = OSD.FromUUID(Animation); + // anim["object_id"] = OSD.FromUUID(ObjectID); + // return anim; + // } + + // public void UnpackUpdateMessage(OSDMap args) + // { + // if (args["animation"] != null) + // Animation = args["animation"].AsUUID(); + // if (args["object_id"] != null) + // ObjectID = args["object_id"].AsUUID(); + // } + //} + + public class AgentData : IAgentData + { + private UUID m_id; + public UUID AgentID + { + get { return m_id; } + set { m_id = value; } + } + public ulong RegionHandle; + public uint CircuitCode; + public UUID SessionID; + + public Vector3 Position; + public Vector3 Velocity; + public Vector3 Center; + public Vector3 Size; + public Vector3 AtAxis; + public Vector3 LeftAxis; + public Vector3 UpAxis; + public bool ChangedGrid; + + public float Far; + public float Aspect; + //public int[] Throttles; + public byte[] Throttles; + + public uint LocomotionState; + public Quaternion HeadRotation; + public Quaternion BodyRotation; + public uint ControlFlags; + public float EnergyLevel; + public Byte GodLevel; + public bool AlwaysRun; + public UUID PreyAgent; + public Byte AgentAccess; + public UUID[] AgentTextures; + public UUID ActiveGroupID; + + public AgentGroupData[] Groups; + public Animation[] Anims; + + public UUID GranterID; + public Dictionary NVPairs; + + public byte[] VisualParams; + + public string CallbackURI; + + public OSDMap PackUpdateMessage() + { + OSDMap args = new OSDMap(); + args["message_type"] = OSD.FromString("AgentData"); + + args["region_handle"] = OSD.FromString(RegionHandle.ToString()); + args["circuit_code"] = OSD.FromString(CircuitCode.ToString()); + args["agent_uuid"] = OSD.FromUUID(AgentID); + args["session_uuid"] = OSD.FromUUID(SessionID); + + args["position"] = OSD.FromString(Position.ToString()); + args["velocity"] = OSD.FromString(Velocity.ToString()); + args["center"] = OSD.FromString(Center.ToString()); + args["size"] = OSD.FromString(Size.ToString()); + args["at_axis"] = OSD.FromString(AtAxis.ToString()); + args["left_axis"] = OSD.FromString(LeftAxis.ToString()); + args["up_axis"] = OSD.FromString(UpAxis.ToString()); + + args["changed_grid"] = OSD.FromBoolean(ChangedGrid); + args["far"] = OSD.FromReal(Far); + args["aspect"] = OSD.FromReal(Aspect); + + if ((Throttles != null) && (Throttles.Length > 0)) + args["throttles"] = OSD.FromBinary(Throttles); + + args["locomotion_state"] = OSD.FromString(LocomotionState.ToString()); + args["head_rotation"] = OSD.FromString(HeadRotation.ToString()); + args["body_rotation"] = OSD.FromString(BodyRotation.ToString()); + args["control_flags"] = OSD.FromString(ControlFlags.ToString()); + + args["energy_level"] = OSD.FromReal(EnergyLevel); + args["god_level"] = OSD.FromString(GodLevel.ToString()); + args["always_run"] = OSD.FromBoolean(AlwaysRun); + args["prey_agent"] = OSD.FromUUID(PreyAgent); + args["agent_access"] = OSD.FromString(AgentAccess.ToString()); + + if ((AgentTextures != null) && (AgentTextures.Length > 0)) + { + OSDArray textures = new OSDArray(AgentTextures.Length); + foreach (UUID uuid in AgentTextures) + textures.Add(OSD.FromUUID(uuid)); + args["agent_textures"] = textures; + } + + args["active_group_id"] = OSD.FromUUID(ActiveGroupID); + + if ((Groups != null) && (Groups.Length > 0)) + { + OSDArray groups = new OSDArray(Groups.Length); + foreach (AgentGroupData agd in Groups) + groups.Add(agd.PackUpdateMessage()); + args["groups"] = groups; + } + + if ((Anims != null) && (Anims.Length > 0)) + { + OSDArray anims = new OSDArray(Anims.Length); + foreach (Animation aanim in Anims) + anims.Add(aanim.PackUpdateMessage()); + args["animations"] = anims; + } + + if ((VisualParams != null) && (VisualParams.Length > 0)) + args["visual_params"] = OSD.FromBinary(VisualParams); + + // Last few fields are still missing: granter and NVPais + + if ((CallbackURI != null) && (!CallbackURI.Equals(""))) + args["callback_uri"] = OSD.FromString(CallbackURI); + + return args; + } + + /// + /// Deserialization of agent data. + /// Avoiding reflection makes it painful to write, but that's the price! + /// + /// + public void UnpackUpdateMessage(OSDMap args) + { + if (args.ContainsKey("region_handle")) + UInt64.TryParse(args["region_handle"].AsString(), out RegionHandle); + + if (args["circuit_code"] != null) + UInt32.TryParse((string)args["circuit_code"].AsString(), out CircuitCode); + + if (args["agent_uuid"] != null) + AgentID = args["agent_uuid"].AsUUID(); + + if (args["session_uuid"] != null) + SessionID = args["session_uuid"].AsUUID(); + + if (args["position"] != null) + Vector3.TryParse(args["position"].AsString(), out Position); + + if (args["velocity"] != null) + Vector3.TryParse(args["velocity"].AsString(), out Velocity); + + if (args["center"] != null) + Vector3.TryParse(args["center"].AsString(), out Center); + + if (args["size"] != null) + Vector3.TryParse(args["size"].AsString(), out Size); + + if (args["at_axis"] != null) + Vector3.TryParse(args["at_axis"].AsString(), out AtAxis); + + if (args["left_axis"] != null) + Vector3.TryParse(args["left_axis"].AsString(), out AtAxis); + + if (args["up_axis"] != null) + Vector3.TryParse(args["up_axis"].AsString(), out AtAxis); + + if (args["changed_grid"] != null) + ChangedGrid = args["changed_grid"].AsBoolean(); + + if (args["far"] != null) + Far = (float)(args["far"].AsReal()); + + if (args["aspect"] != null) + Aspect = (float)args["aspect"].AsReal(); + + if (args["throttles"] != null) + Throttles = args["throttles"].AsBinary(); + + if (args["locomotion_state"] != null) + UInt32.TryParse(args["locomotion_state"].AsString(), out LocomotionState); + + if (args["head_rotation"] != null) + Quaternion.TryParse(args["head_rotation"].AsString(), out HeadRotation); + + if (args["body_rotation"] != null) + Quaternion.TryParse(args["body_rotation"].AsString(), out BodyRotation); + + if (args["control_flags"] != null) + UInt32.TryParse(args["control_flags"].AsString(), out ControlFlags); + + if (args["energy_level"] != null) + EnergyLevel = (float)(args["energy_level"].AsReal()); + + if (args["god_level"] != null) + Byte.TryParse(args["god_level"].AsString(), out GodLevel); + + if (args["always_run"] != null) + AlwaysRun = args["always_run"].AsBoolean(); + + if (args["prey_agent"] != null) + PreyAgent = args["prey_agent"].AsUUID(); + + if (args["agent_access"] != null) + Byte.TryParse(args["agent_access"].AsString(), out AgentAccess); + + if ((args["agent_textures"] != null) && (args["agent_textures"]).Type == OSDType.Array) + { + OSDArray textures = (OSDArray)(args["agent_textures"]); + AgentTextures = new UUID[textures.Count]; + int i = 0; + foreach (OSD o in textures) + AgentTextures[i++] = o.AsUUID(); + } + + if (args["active_group_id"] != null) + ActiveGroupID = args["active_group_id"].AsUUID(); + + if ((args["groups"] != null) && (args["groups"]).Type == OSDType.Array) + { + OSDArray groups = (OSDArray)(args["groups"]); + Groups = new AgentGroupData[groups.Count]; + int i = 0; + foreach (OSD o in groups) + { + if (o.Type == OSDType.Map) + { + Groups[i++] = new AgentGroupData((OSDMap)o); + } + } + } + + if ((args["animations"] != null) && (args["animations"]).Type == OSDType.Array) + { + OSDArray anims = (OSDArray)(args["animations"]); + Anims = new Animation[anims.Count]; + int i = 0; + foreach (OSD o in anims) + { + if (o.Type == OSDType.Map) + { + Anims[i++] = new Animation((OSDMap)o); + } + } + } + + if (args["visual_params"] != null) + VisualParams = args["visual_params"].AsBinary(); + + if (args["callback_uri"] != null) + CallbackURI = args["callback_uri"].AsString(); + } + + public AgentData() + { + } + + public AgentData(Hashtable hash) + { + //UnpackUpdateMessage(hash); + } + + public void Dump() + { + System.Console.WriteLine("------------ AgentData ------------"); + System.Console.WriteLine("UUID: " + AgentID); + System.Console.WriteLine("Region: " + RegionHandle); + System.Console.WriteLine("Position: " + Position); + } + } + +} diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index f5d7b3217b..4eb8a2837c 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -1379,7 +1379,6 @@ namespace OpenSim.Region.Framework.Scenes if (part != null) { - TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID); bool allowInventoryDrop = (part.GetEffectiveObjectFlags() & (uint)PrimFlags.AllowInventoryDrop) != 0; diff --git a/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs b/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs index 51aa8f811f..604b21d186 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Concierge/ConciergeModule.cs @@ -282,7 +282,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Concierge { m_log.DebugFormat("[Concierge]: {0} logs off from {1}", client.Name, client.Scene.RegionInfo.RegionName); RemoveFromAttendeeList(client.AgentId, client.Name, client.Scene); - lock(m_sceneAttendees) + lock (m_sceneAttendees) { AnnounceToAgentsRegion(client.Scene, String.Format(m_announceLeaving, client.Name, client.Scene.RegionInfo.RegionName, m_sceneAttendees[client.Scene].Count)); @@ -406,7 +406,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Concierge attendees.Count, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, DateTime.UtcNow.ToString("s"))); - lock(m_sceneAttendees) + lock (m_sceneAttendees) { foreach (UUID uuid in attendees) { @@ -458,7 +458,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Concierge string payload = bs.Payload; HttpWebRequest updatePost = bs.Poster; - using(StreamWriter payloadStream = new StreamWriter(updatePost.EndGetRequestStream(result))) + using (StreamWriter payloadStream = new StreamWriter(updatePost.EndGetRequestStream(result))) { payloadStream.Write(payload); payloadStream.Close(); diff --git a/Prebuild/scripts/VS2008.bat b/Prebuild/scripts/VS2008.bat old mode 100644 new mode 100755 index b4656683ab..eb51a820cb --- a/Prebuild/scripts/VS2008.bat +++ b/Prebuild/scripts/VS2008.bat @@ -1,4 +1,4 @@ -@rem Generates a solution (.sln) and a set of project files (.csproj, .vbproj, etc.) -@rem for Microsoft Visual Studio .NET 2008 -cd .. -Prebuild.exe /target vs2008 /file prebuild.xml /pause +@rem Generates a solution (.sln) and a set of project files (.csproj, .vbproj, etc.) +@rem for Microsoft Visual Studio .NET 2008 +cd .. +Prebuild.exe /target vs2008 /file prebuild.xml /pause diff --git a/Prebuild/src/Core/Nodes/DatabaseProjectNode.cs b/Prebuild/src/Core/Nodes/DatabaseProjectNode.cs index 8696a79164..27c205162a 100644 --- a/Prebuild/src/Core/Nodes/DatabaseProjectNode.cs +++ b/Prebuild/src/Core/Nodes/DatabaseProjectNode.cs @@ -1,94 +1,94 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -using Prebuild.Core.Attributes; -using Prebuild.Core.Interfaces; -using Prebuild.Core.Utilities; - -namespace Prebuild.Core.Nodes -{ - [DataNode("DatabaseProject")] - public class DatabaseProjectNode : DataNode - { - string name; - string path; - string fullpath; - Guid guid = Guid.NewGuid(); - readonly List authors = new List(); - readonly List references = new List(); - - public Guid Guid - { - get { return guid; } - } - - public string Name - { - get { return name; } - } - - public string Path - { - get { return path; } - } - - public string FullPath - { - get { return fullpath; } - } - - public IEnumerable References - { - get { return references; } - } - - public override void Parse(XmlNode node) - { - name = Helper.AttributeValue(node, "name", name); - path = Helper.AttributeValue(node, "path", name); - - try - { - fullpath = Helper.ResolvePath(path); - } - catch - { - throw new WarningException("Could not resolve Solution path: {0}", path); - } - - Kernel.Instance.CurrentWorkingDirectory.Push(); - - try - { - Helper.SetCurrentDir(fullpath); - - if (node == null) - { - throw new ArgumentNullException("node"); - } - - foreach (XmlNode child in node.ChildNodes) - { - IDataNode dataNode = Kernel.Instance.ParseNode(child, this); - - if (dataNode == null) - continue; - - if (dataNode is AuthorNode) - authors.Add((AuthorNode)dataNode); - else if (dataNode is DatabaseReferenceNode) - references.Add((DatabaseReferenceNode)dataNode); - } - } - finally - { - Kernel.Instance.CurrentWorkingDirectory.Pop(); - } - - base.Parse(node); - } - } -} +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +using Prebuild.Core.Attributes; +using Prebuild.Core.Interfaces; +using Prebuild.Core.Utilities; + +namespace Prebuild.Core.Nodes +{ + [DataNode("DatabaseProject")] + public class DatabaseProjectNode : DataNode + { + string name; + string path; + string fullpath; + Guid guid = Guid.NewGuid(); + readonly List authors = new List(); + readonly List references = new List(); + + public Guid Guid + { + get { return guid; } + } + + public string Name + { + get { return name; } + } + + public string Path + { + get { return path; } + } + + public string FullPath + { + get { return fullpath; } + } + + public IEnumerable References + { + get { return references; } + } + + public override void Parse(XmlNode node) + { + name = Helper.AttributeValue(node, "name", name); + path = Helper.AttributeValue(node, "path", name); + + try + { + fullpath = Helper.ResolvePath(path); + } + catch + { + throw new WarningException("Could not resolve Solution path: {0}", path); + } + + Kernel.Instance.CurrentWorkingDirectory.Push(); + + try + { + Helper.SetCurrentDir(fullpath); + + if (node == null) + { + throw new ArgumentNullException("node"); + } + + foreach (XmlNode child in node.ChildNodes) + { + IDataNode dataNode = Kernel.Instance.ParseNode(child, this); + + if (dataNode == null) + continue; + + if (dataNode is AuthorNode) + authors.Add((AuthorNode)dataNode); + else if (dataNode is DatabaseReferenceNode) + references.Add((DatabaseReferenceNode)dataNode); + } + } + finally + { + Kernel.Instance.CurrentWorkingDirectory.Pop(); + } + + base.Parse(node); + } + } +} diff --git a/Prebuild/src/Core/Nodes/DatabaseReferenceNode.cs b/Prebuild/src/Core/Nodes/DatabaseReferenceNode.cs index 97c3964b8e..845db24b12 100644 --- a/Prebuild/src/Core/Nodes/DatabaseReferenceNode.cs +++ b/Prebuild/src/Core/Nodes/DatabaseReferenceNode.cs @@ -1,63 +1,63 @@ -using System; -using Prebuild.Core.Attributes; -using Prebuild.Core.Utilities; - -namespace Prebuild.Core.Nodes -{ - [DataNode("DatabaseReference")] - public class DatabaseReferenceNode : DataNode - { - string name; - Guid providerId; - string connectionString; - - public string Name - { - get { return name; } - } - - public Guid ProviderId - { - get { return providerId; } - } - - public string ConnectionString - { - get { return connectionString; } - } - - public override void Parse(System.Xml.XmlNode node) - { - name = Helper.AttributeValue(node, "name", name); - - string providerName = Helper.AttributeValue(node, "providerName", string.Empty); - if (providerName != null) - { - switch (providerName) - { - // digitaljeebus: pulled from HKLM\SOFTWARE\Microsoft\VisualStudio\9.0\DataProviders\* - // Not sure if these will help other operating systems, or if there's a better way. - case "Microsoft.SqlServerCe.Client.3.5": - providerId = new Guid("7C602B5B-ACCB-4acd-9DC0-CA66388C1533"); break; - case "System.Data.OleDb": - providerId = new Guid("7F041D59-D76A-44ed-9AA2-FBF6B0548B80"); break; - case "System.Data.OracleClient": - providerId = new Guid("8F5C5018-AE09-42cf-B2CC-2CCCC7CFC2BB"); break; - case "System.Data.SqlClient": - providerId = new Guid("91510608-8809-4020-8897-FBA057E22D54"); break; - case "System.Data.Odbc": - providerId = new Guid("C3D4F4CE-2C48-4381-B4D6-34FA50C51C86"); break; - - default: - throw new ArgumentOutOfRangeException("providerName", providerName, "Could not provider name to an id."); - } - } - else - providerId = new Guid(Helper.AttributeValue(node, "providerId", Guid.Empty.ToString("B"))); - - connectionString = Helper.AttributeValue(node, "connectionString", connectionString); - - base.Parse(node); - } - } -} +using System; +using Prebuild.Core.Attributes; +using Prebuild.Core.Utilities; + +namespace Prebuild.Core.Nodes +{ + [DataNode("DatabaseReference")] + public class DatabaseReferenceNode : DataNode + { + string name; + Guid providerId; + string connectionString; + + public string Name + { + get { return name; } + } + + public Guid ProviderId + { + get { return providerId; } + } + + public string ConnectionString + { + get { return connectionString; } + } + + public override void Parse(System.Xml.XmlNode node) + { + name = Helper.AttributeValue(node, "name", name); + + string providerName = Helper.AttributeValue(node, "providerName", string.Empty); + if (providerName != null) + { + switch (providerName) + { + // digitaljeebus: pulled from HKLM\SOFTWARE\Microsoft\VisualStudio\9.0\DataProviders\* + // Not sure if these will help other operating systems, or if there's a better way. + case "Microsoft.SqlServerCe.Client.3.5": + providerId = new Guid("7C602B5B-ACCB-4acd-9DC0-CA66388C1533"); break; + case "System.Data.OleDb": + providerId = new Guid("7F041D59-D76A-44ed-9AA2-FBF6B0548B80"); break; + case "System.Data.OracleClient": + providerId = new Guid("8F5C5018-AE09-42cf-B2CC-2CCCC7CFC2BB"); break; + case "System.Data.SqlClient": + providerId = new Guid("91510608-8809-4020-8897-FBA057E22D54"); break; + case "System.Data.Odbc": + providerId = new Guid("C3D4F4CE-2C48-4381-B4D6-34FA50C51C86"); break; + + default: + throw new ArgumentOutOfRangeException("providerName", providerName, "Could not provider name to an id."); + } + } + else + providerId = new Guid(Helper.AttributeValue(node, "providerId", Guid.Empty.ToString("B"))); + + connectionString = Helper.AttributeValue(node, "connectionString", connectionString); + + base.Parse(node); + } + } +} diff --git a/Prebuild/src/Core/Targets/VSGenericTarget.cs b/Prebuild/src/Core/Targets/VSGenericTarget.cs index a05f6b3107..60cc80328b 100644 --- a/Prebuild/src/Core/Targets/VSGenericTarget.cs +++ b/Prebuild/src/Core/Targets/VSGenericTarget.cs @@ -1,884 +1,884 @@ -#region BSD License -/* -Copyright (c) 2008 Matthew Holmes (matthew@wildfiregames.com), John Anderson (sontek@gmail.com) - -Redistribution and use in source and binary forms, with or without modification, are permitted -provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this list of conditions - and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright notice, this list of conditions - and the following disclaimer in the documentation and/or other materials provided with the - distribution. -* The name of the author may not be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, -BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#endregion - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.IO; -using System.Text; - -using Prebuild.Core.Attributes; -using Prebuild.Core.Interfaces; -using Prebuild.Core.Nodes; -using Prebuild.Core.Utilities; -using System.CodeDom.Compiler; - -namespace Prebuild.Core.Targets -{ - - /// - /// - /// - public abstract class VSGenericTarget : ITarget - { - #region Fields - - readonly Hashtable tools = new Hashtable(); - Kernel kernel; - #endregion - - #region Properties - /// - /// Gets or sets the solution version. - /// - /// The solution version. - public abstract string SolutionVersion { get; } - /// - /// Gets or sets the product version. - /// - /// The product version. - public abstract string ProductVersion { get; } - /// - /// Gets or sets the schema version. - /// - /// The schema version. - public abstract string SchemaVersion { get; } - /// - /// Gets or sets the name of the version. - /// - /// The name of the version. - public abstract string VersionName { get; } - /// - /// Gets or sets the version. - /// - /// The version. - public abstract VSVersion Version { get; } - /// - /// Gets the name. - /// - /// The name. - public abstract string Name { get; } - - protected abstract string GetToolsVersionXml(FrameworkVersion version); - public abstract string SolutionTag { get; } - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - protected VSGenericTarget() - { - this.tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP", "$(MSBuildBinPath)\\Microsoft.CSHARP.Targets"); - this.tools["Database"] = new ToolInfo("Database", "{4F174C21-8C12-11D0-8340-0000F80270F8}", "dbp", "UNKNOWN"); - this.tools["Boo"] = new ToolInfo("Boo", "{45CEA7DC-C2ED-48A6-ACE0-E16144C02365}", "booproj", "Boo", "$(BooBinPath)\\Boo.Microsoft.Build.targets"); - this.tools["VisualBasic"] = new ToolInfo("VisualBasic", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic", "$(MSBuildBinPath)\\Microsoft.VisualBasic.Targets"); - this.tools["Folder"] = new ToolInfo("Folder", "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", null, null); - } - - #endregion - - #region Private Methods - - private string MakeRefPath(ProjectNode project) - { - string ret = ""; - foreach (ReferencePathNode node in project.ReferencePaths) - { - try - { - string fullPath = Helper.ResolvePath(node.Path); - if (ret.Length < 1) - { - ret = fullPath; - } - else - { - ret += ";" + fullPath; - } - } - catch (ArgumentException) - { - this.kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path); - } - } - - return ret; - } - - private static ProjectNode FindProjectInSolution(string name, SolutionNode solution) - { - SolutionNode node = solution; - - while (node.Parent is SolutionNode) - node = node.Parent as SolutionNode; - - return FindProjectInSolutionRecursively(name, node); - } - - private static ProjectNode FindProjectInSolutionRecursively(string name, SolutionNode solution) - { - if (solution.ProjectsTable.ContainsKey(name)) - return (ProjectNode)solution.ProjectsTable[name]; - - foreach (SolutionNode child in solution.Solutions) - { - ProjectNode node = FindProjectInSolutionRecursively(name, child); - if (node != null) - return node; - } - - return null; - } - - private void WriteProject(SolutionNode solution, ProjectNode project) - { - if (!tools.ContainsKey(project.Language)) - { - throw new UnknownLanguageException("Unknown .NET language: " + project.Language); - } - - ToolInfo toolInfo = (ToolInfo)tools[project.Language]; - string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension); - StreamWriter ps = new StreamWriter(projectFile); - - kernel.CurrentWorkingDirectory.Push(); - Helper.SetCurrentDir(Path.GetDirectoryName(projectFile)); - - #region Project File - using (ps) - { - ps.WriteLine("", GetToolsVersionXml(project.FrameworkVersion)); - ps.WriteLine(" "); - ps.WriteLine(" Local"); - ps.WriteLine(" {0}", this.ProductVersion); - ps.WriteLine(" {0}", this.SchemaVersion); - ps.WriteLine(" {{{0}}}", project.Guid.ToString().ToUpper()); - - // Visual Studio has a hard coded guid for the project type - if (project.Type == ProjectType.Web) - ps.WriteLine(" {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}"); - ps.WriteLine(" Debug"); - ps.WriteLine(" AnyCPU"); - ps.WriteLine(" {0}", project.AppIcon); - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(" {0}", project.AssemblyName); - foreach (ConfigurationNode conf in project.Configurations) - { - if (conf.Options.KeyFile != "") - { - ps.WriteLine(" {0}", conf.Options.KeyFile); - ps.WriteLine(" true"); - break; - } - } - ps.WriteLine(" JScript"); - ps.WriteLine(" Grid"); - ps.WriteLine(" IE50"); - ps.WriteLine(" false"); - ps.WriteLine(" {0}", project.FrameworkVersion.ToString().Replace("_", ".")); - - ps.WriteLine(" {0}", project.Type == ProjectType.Web ? ProjectType.Library.ToString() : project.Type.ToString()); - ps.WriteLine(" {0}", project.DesignerFolder); - ps.WriteLine(" {0}", project.RootNamespace); - ps.WriteLine(" {0}", project.StartupObject); - if (string.IsNullOrEmpty(project.DebugStartParameters)) - { - ps.WriteLine(" {0}", project.DebugStartParameters); - } - ps.WriteLine(" "); - ps.WriteLine(" "); - - ps.WriteLine(" "); - - foreach (ConfigurationNode conf in project.Configurations) - { - ps.Write(" ", conf.Name); - ps.WriteLine(" {0}", conf.Options["AllowUnsafe"]); - ps.WriteLine(" {0}", conf.Options["BaseAddress"]); - ps.WriteLine(" {0}", conf.Options["CheckUnderflowOverflow"]); - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(" {0}", conf.Options["CompilerDefines"]); - ps.WriteLine(" {0}", Helper.NormalizePath(conf.Options["XmlDocFile"].ToString())); - ps.WriteLine(" {0}", conf.Options["DebugInformation"]); - ps.WriteLine(" {0}", conf.Options["FileAlignment"]); - ps.WriteLine(" {0}", conf.Options["OptimizeCode"]); - if (project.Type != ProjectType.Web) - ps.WriteLine(" {0}", - Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString()))); - else - ps.WriteLine(" {0}", - Helper.EndPath(Helper.NormalizePath("bin\\"))); - - ps.WriteLine(" {0}", conf.Options["RegisterComInterop"]); - ps.WriteLine(" {0}", conf.Options["RemoveIntegerChecks"]); - ps.WriteLine(" {0}", conf.Options["WarningsAsErrors"]); - ps.WriteLine(" {0}", conf.Options["WarningLevel"]); - ps.WriteLine(" {0}", conf.Options["NoStdLib"]); - ps.WriteLine(" {0}", conf.Options["SuppressWarnings"]); - ps.WriteLine(" "); - } - - //ps.WriteLine(" "); - - List projectReferences = new List(); - List otherReferences = new List(); - - foreach (ReferenceNode refr in project.References) - { - ProjectNode projectNode = FindProjectInSolution(refr.Name, solution); - - if (projectNode == null) - otherReferences.Add(refr); - else - projectReferences.Add(projectNode); - } - // Assembly References - ps.WriteLine(" "); - - foreach (ReferenceNode refr in otherReferences) - { - ps.Write(" "); - ps.Write(" "); - ps.Write(refr.Name); - ps.WriteLine(""); - // TODO: Allow reference to *.exe files - ps.WriteLine(" {0}", refr.LocalCopy); - ps.WriteLine(" "); - } - ps.WriteLine(" "); - - //Project References - ps.WriteLine(" "); - foreach (ProjectNode projectReference in projectReferences) - { - ToolInfo tool = (ToolInfo)tools[projectReference.Language]; - if (tools == null) - throw new UnknownLanguageException(); - - string path = - Helper.MakePathRelativeTo(project.FullPath, - Helper.MakeFilePath(projectReference.FullPath, projectReference.Name, tool.FileExtension)); - ps.WriteLine(" ", path); - - // TODO: Allow reference to visual basic projects - ps.WriteLine(" {0}", projectReference.Name); - ps.WriteLine(" {0}", projectReference.Guid.ToString("B").ToUpper()); - ps.WriteLine(" {0}", tool.Guid.ToUpper()); - - ps.WriteLine(" False" ); - - ps.WriteLine(" "); - } - ps.WriteLine(" "); - - // ps.WriteLine(" "); - ps.WriteLine(" "); - - // ps.WriteLine(" "); - List list = new List(); - - foreach (string path in project.Files) - { - string lower = path.ToLower(); - if (lower.EndsWith(".resx")) - { - string codebehind = String.Format("{0}.Designer{1}", path.Substring(0, path.LastIndexOf('.')), toolInfo.LanguageExtension); - if (!list.Contains(codebehind)) - list.Add(codebehind); - } - } - - foreach (string file in project.Files) - { - // if (file == "Properties\\Bind.Designer.cs") - // { - // Console.WriteLine("Wait a minute!"); - // Console.WriteLine(project.Files.GetSubType(file).ToString()); - // } - - SubType subType = project.Files.GetSubType(file); - - if (subType != SubType.Code && subType != SubType.Settings && subType != SubType.Designer - && subType != SubType.CodeBehind) - { - ps.WriteLine(" ", file.Substring(0, file.LastIndexOf('.')) + ".resx"); - ps.WriteLine(" {0}", Path.GetFileName(file)); - ps.WriteLine(" Designer"); - ps.WriteLine(" "); - // - } - - if (subType == SubType.Designer) - { - ps.WriteLine(" ", file); - ps.WriteLine(" " + subType + ""); - ps.WriteLine(" ResXFileCodeGenerator"); - - string autogen_name = file.Substring(0, file.LastIndexOf('.')) + ".Designer.cs"; - string dependent_name = file.Substring(0, file.LastIndexOf('.')) + ".cs"; - - ps.WriteLine(" {0}", autogen_name); - - // Check for a parent .cs file with the same name as this designer file - if (File.Exists(dependent_name)) - ps.WriteLine(" {0}", Path.GetFileName(dependent_name)); - - ps.WriteLine(" "); - if (File.Exists(autogen_name)) - { - ps.WriteLine(" ", autogen_name); - ps.WriteLine(" True"); - ps.WriteLine(" True"); - - // If a parent .cs file exists, link this autogen file to it. Otherwise link - // to the designer file - if (File.Exists(dependent_name)) - ps.WriteLine(" {0}", Path.GetFileName(dependent_name)); - else - ps.WriteLine(" {0}", Path.GetFileName(file)); - - ps.WriteLine(" "); - } - list.Add(autogen_name); - } - if (subType == SubType.Settings) - { - ps.Write(" <{0} ", project.Files.GetBuildAction(file)); - ps.WriteLine("Include=\"{0}\">", file); - string fileName = Path.GetFileName(file); - if (project.Files.GetBuildAction(file) == BuildAction.None) - { - ps.WriteLine(" SettingsSingleFileGenerator"); - ps.WriteLine(" {0}", fileName.Substring(0, fileName.LastIndexOf('.')) + ".Designer.cs"); - } - else - { - ps.WriteLine(" Code"); - ps.WriteLine(" True"); - ps.WriteLine(" True"); - string fileNameShort = fileName.Substring(0, fileName.LastIndexOf('.')); - string fileNameShorter = fileNameShort.Substring(0, fileNameShort.LastIndexOf('.')); - ps.WriteLine(" {0}", Path.GetFileName(fileNameShorter + ".settings")); - } - ps.WriteLine(" ", project.Files.GetBuildAction(file)); - } - else if (subType != SubType.Designer) - { - string path = Helper.NormalizePath(file); - string path_lower = path.ToLower(); - - if (!list.Contains(file)) - { - ps.Write(" <{0} ", project.Files.GetBuildAction(path)); - - int startPos = 0; - if (project.Files.GetPreservePath(file)) - { - while ((@"./\").IndexOf(file.Substring(startPos, 1)) != -1) - startPos++; - - } - else - { - startPos = file.LastIndexOf(Path.GetFileName(path)); - } - - ps.WriteLine("Include=\"{0}\">", path); - - int last_period_index = file.LastIndexOf('.'); - string short_file_name = file.Substring(0, last_period_index); - string extension = Path.GetExtension(path); - string designer_format = string.Format(".designer{0}", extension); - - if (path_lower.EndsWith(designer_format)) - { - int designer_index = path_lower.IndexOf(designer_format); - string file_name = path.Substring(0, designer_index); - - if (File.Exists(file_name)) - ps.WriteLine(" {0}", Path.GetFileName(file_name)); - else if (File.Exists(file_name + ".resx")) - ps.WriteLine(" {0}", Path.GetFileName(file_name + ".resx")); - } - else if (subType == SubType.CodeBehind) - { - ps.WriteLine(" {0}", Path.GetFileName(short_file_name)); - } - if (project.Files.GetIsLink(file)) - { - string alias = project.Files.GetLinkPath(file); - alias += file.Substring(startPos); - alias = Helper.NormalizePath(alias); - ps.WriteLine(" {0}", alias); - } - else if (project.Files.GetBuildAction(file) != BuildAction.None) - { - if (project.Files.GetBuildAction(file) != BuildAction.EmbeddedResource) - { - ps.WriteLine(" {0}", subType); - } - } - - if (project.Files.GetCopyToOutput(file) != CopyToOutput.Never) - { - ps.WriteLine(" {0}", project.Files.GetCopyToOutput(file)); - } - - ps.WriteLine(" ", project.Files.GetBuildAction(file)); - } - } - } - - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(" "); - ps.WriteLine(""); - } - #endregion - - #region User File - - ps = new StreamWriter(projectFile + ".user"); - using (ps) - { - ps.WriteLine(""); - //ps.WriteLine( "" ); - //ps.WriteLine(" <{0}>", toolInfo.XMLTag); - //ps.WriteLine(" "); - ps.WriteLine(" "); - //ps.WriteLine(" ", MakeRefPath(project)); - ps.WriteLine(" Debug"); - ps.WriteLine(" AnyCPU"); - ps.WriteLine(" {0}", MakeRefPath(project)); - ps.WriteLine(" {0}", this.ProductVersion); - ps.WriteLine(" ProjectFiles"); - ps.WriteLine(" 0"); - ps.WriteLine(" "); - foreach (ConfigurationNode conf in project.Configurations) - { - ps.Write(" "); - } - ps.WriteLine(""); - } - #endregion - - kernel.CurrentWorkingDirectory.Pop(); - } - - private void WriteSolution(SolutionNode solution, bool writeSolutionToDisk) - { - kernel.Log.Write("Creating {0} solution and project files", this.VersionName); - - foreach (SolutionNode child in solution.Solutions) - { - kernel.Log.Write("...Creating folder: {0}", child.Name); - WriteSolution(child, false); - } - - foreach (ProjectNode project in solution.Projects) - { - kernel.Log.Write("...Creating project: {0}", project.Name); - WriteProject(solution, project); - } - - foreach (DatabaseProjectNode project in solution.DatabaseProjects) - { - kernel.Log.Write("...Creating database project: {0}", project.Name); - WriteDatabaseProject(solution, project); - } - - if (writeSolutionToDisk) // only write main solution - { - kernel.Log.Write(""); - string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln"); - - using (StreamWriter ss = new StreamWriter(solutionFile)) - { - kernel.CurrentWorkingDirectory.Push(); - Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile)); - - ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", this.SolutionVersion); - ss.WriteLine(SolutionTag); - - WriteProjectDeclarations(ss, solution, solution); - - ss.WriteLine("Global"); - - ss.WriteLine("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution"); - foreach (ConfigurationNode conf in solution.Configurations) - { - ss.WriteLine("\t\t{0}|Any CPU = {0}|Any CPU", conf.Name); - } - ss.WriteLine("\tEndGlobalSection"); - - ss.WriteLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution"); - WriteConfigurationLines(solution.Configurations, solution, ss); - ss.WriteLine("\tEndGlobalSection"); - - if (solution.Solutions.Count > 0) - { - ss.WriteLine("\tGlobalSection(NestedProjects) = preSolution"); - foreach (SolutionNode embeddedSolution in solution.Solutions) - { - WriteNestedProjectMap(ss, embeddedSolution); - } - ss.WriteLine("\tEndGlobalSection"); - } - - ss.WriteLine("EndGlobal"); - } - - kernel.CurrentWorkingDirectory.Pop(); - } - } - - private void WriteProjectDeclarations(StreamWriter writer, SolutionNode actualSolution, SolutionNode embeddedSolution) - { - foreach (SolutionNode childSolution in embeddedSolution.Solutions) - { - WriteEmbeddedSolution(writer, childSolution); - WriteProjectDeclarations(writer, actualSolution, childSolution); - } - - foreach (ProjectNode project in embeddedSolution.Projects) - { - WriteProject(actualSolution, writer, project); - } - - foreach (DatabaseProjectNode dbProject in embeddedSolution.DatabaseProjects) - { - WriteProject(actualSolution, writer, dbProject); - } - - if (actualSolution.Guid == embeddedSolution.Guid) - { - WriteSolutionFiles(actualSolution, writer); - } - } - - private static void WriteNestedProjectMap(StreamWriter writer, SolutionNode embeddedSolution) - { - foreach (ProjectNode project in embeddedSolution.Projects) - { - WriteNestedProject(writer, embeddedSolution, project.Guid); - } - - foreach (DatabaseProjectNode dbProject in embeddedSolution.DatabaseProjects) - { - WriteNestedProject(writer, embeddedSolution, dbProject.Guid); - } - - foreach (SolutionNode child in embeddedSolution.Solutions) - { - WriteNestedProject(writer, embeddedSolution, child.Guid); - WriteNestedProjectMap(writer, child); - } - } - - private static void WriteNestedProject(StreamWriter writer, SolutionNode solution, Guid projectGuid) - { - WriteNestedFolder(writer, solution.Guid, projectGuid); - } - - private static void WriteNestedFolder(StreamWriter writer, Guid parentGuid, Guid childGuid) - { - writer.WriteLine("\t\t{0} = {1}", - childGuid.ToString("B").ToUpper(), - parentGuid.ToString("B").ToUpper()); - } - - private static void WriteConfigurationLines(ICollection configurations, SolutionNode solution, StreamWriter ss) - { - foreach (ProjectNode project in solution.Projects) - { - foreach (ConfigurationNode conf in configurations) - { - ss.WriteLine("\t\t{0}.{1}|Any CPU.ActiveCfg = {1}|Any CPU", - project.Guid.ToString("B").ToUpper(), - conf.Name); - - ss.WriteLine("\t\t{0}.{1}|Any CPU.Build.0 = {1}|Any CPU", - project.Guid.ToString("B").ToUpper(), - conf.Name); - } - } - - foreach (SolutionNode child in solution.Solutions) - { - WriteConfigurationLines(configurations, child, ss); - } - } - - private void WriteSolutionFiles(SolutionNode solution, StreamWriter ss) - { - WriteProject(ss, "Folder", solution.Guid, "Solution Files", "Solution Files", solution.Files); - } - - private void WriteEmbeddedSolution(StreamWriter writer, SolutionNode embeddedSolution) - { - WriteProject(writer, "Folder", embeddedSolution.Guid, embeddedSolution.Name, embeddedSolution.Name, embeddedSolution.Files); - } - - private void WriteProject(SolutionNode solution, StreamWriter ss, ProjectNode project) - { - WriteProject(ss, solution, project.Language, project.Guid, project.Name, project.FullPath); - } - - private void WriteProject(SolutionNode solution, StreamWriter ss, DatabaseProjectNode dbProject) - { - if (solution.Files != null && solution.Files.Count > 0) - WriteProject(ss, solution, "Database", dbProject.Guid, dbProject.Name, dbProject.FullPath); - } - - private static bool ExtensionSpecified(string refName) - { - return refName.EndsWith(".dll") || refName.EndsWith(".exe"); - } - - private static string GetProjectExtension(ProjectNode project) - { - string extension = ".dll"; - if (project.Type == ProjectType.Exe) - { - extension = ".exe"; - } - return extension; - } - - const string ProjectDeclarationBeginFormat = "Project(\"{0}\") = \"{1}\", \"{2}\", \"{3}\""; - const string ProjectDeclarationEndFormat = "EndProject"; - - private void WriteProject(StreamWriter ss, SolutionNode solution, string language, Guid guid, string name, string projectFullPath) - { - if (!tools.ContainsKey(language)) - throw new UnknownLanguageException("Unknown .NET language: " + language); - - ToolInfo toolInfo = (ToolInfo)tools[language]; - - string path = Helper.MakePathRelativeTo(solution.FullPath, projectFullPath); - - path = Helper.MakeFilePath(path, name, toolInfo.FileExtension); - - WriteProject(ss, language, guid, name, path); - } - - private void WriteProject(StreamWriter writer, string language, Guid projectGuid, string name, string location) - { - WriteProject(writer, language, projectGuid, name, location, null); - } - - private void WriteProject(StreamWriter writer, string language, Guid projectGuid, string name, string location, FilesNode files) - { - if (!tools.ContainsKey(language)) - throw new UnknownLanguageException("Unknown .NET language: " + language); - - ToolInfo toolInfo = (ToolInfo)tools[language]; - - writer.WriteLine(ProjectDeclarationBeginFormat, - toolInfo.Guid, - name, - location, - projectGuid.ToString("B").ToUpper()); - - if (files != null) - { - writer.WriteLine("\tProjectSection(SolutionItems) = preProject"); - - foreach (string file in files) - writer.WriteLine("\t\t{0} = {0}", file); - - writer.WriteLine("\tEndProjectSection"); - } - - writer.WriteLine(ProjectDeclarationEndFormat); - } - - private void WriteDatabaseProject(SolutionNode solution, DatabaseProjectNode project) - { - string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "dbp"); - IndentedTextWriter ps = new IndentedTextWriter(new StreamWriter(projectFile), " "); - - kernel.CurrentWorkingDirectory.Push(); - - Helper.SetCurrentDir(Path.GetDirectoryName(projectFile)); - - using (ps) - { - ps.WriteLine("# Microsoft Developer Studio Project File - Database Project"); - ps.WriteLine("Begin DataProject = \"{0}\"", project.Name); - ps.Indent++; - ps.WriteLine("MSDTVersion = \"80\""); - // TODO: Use the project.Files property - if (ContainsSqlFiles(Path.GetDirectoryName(projectFile))) - WriteDatabaseFoldersAndFiles(ps, Path.GetDirectoryName(projectFile)); - - ps.WriteLine("Begin DBRefFolder = \"Database References\""); - ps.Indent++; - foreach (DatabaseReferenceNode reference in project.References) - { - ps.WriteLine("Begin DBRefNode = \"{0}\"", reference.Name); - ps.Indent++; - ps.WriteLine("ConnectStr = \"{0}\"", reference.ConnectionString); - ps.WriteLine("Provider = \"{0}\"", reference.ProviderId.ToString("B").ToUpper()); - //ps.WriteLine("Colorizer = 5"); - ps.Indent--; - ps.WriteLine("End"); - } - ps.Indent--; - ps.WriteLine("End"); - ps.Indent--; - ps.WriteLine("End"); - - ps.Flush(); - } - - kernel.CurrentWorkingDirectory.Pop(); - } - - private bool ContainsSqlFiles(string folder) - { - foreach (string file in Directory.GetFiles(folder, "*.sql")) - { - return true; // if the folder contains 1 .sql file, that's good enough - } - - foreach (string child in Directory.GetDirectories(folder)) - { - if (ContainsSqlFiles(child)) - return true; // if 1 child folder contains a .sql file, still good enough - } - - return false; - } - - private void WriteDatabaseFoldersAndFiles(IndentedTextWriter writer, string folder) - { - foreach (string child in Directory.GetDirectories(folder)) - { - if (ContainsSqlFiles(child)) - { - writer.WriteLine("Begin Folder = \"{0}\"", Path.GetFileName(child)); - writer.Indent++; - WriteDatabaseFoldersAndFiles(writer, child); - writer.Indent--; - writer.WriteLine("End"); - } - } - foreach (string file in Directory.GetFiles(folder, "*.sql")) - { - writer.WriteLine("Script = \"{0}\"", Path.GetFileName(file)); - } - } - - private void CleanProject(ProjectNode project) - { - kernel.Log.Write("...Cleaning project: {0}", project.Name); - - ToolInfo toolInfo = (ToolInfo)tools[project.Language]; - string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension); - string userFile = projectFile + ".user"; - - Helper.DeleteIfExists(projectFile); - Helper.DeleteIfExists(userFile); - } - - private void CleanSolution(SolutionNode solution) - { - kernel.Log.Write("Cleaning {0} solution and project files", this.VersionName, solution.Name); - - string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln"); - string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo"); - - Helper.DeleteIfExists(slnFile); - Helper.DeleteIfExists(suoFile); - - foreach (ProjectNode project in solution.Projects) - { - CleanProject(project); - } - - kernel.Log.Write(""); - } - - #endregion - - #region ITarget Members - - /// - /// Writes the specified kern. - /// - /// The kern. - public virtual void Write(Kernel kern) - { - if (kern == null) - { - throw new ArgumentNullException("kern"); - } - kernel = kern; - foreach (SolutionNode sol in kernel.Solutions) - { - WriteSolution(sol, true); - } - kernel = null; - } - - /// - /// Cleans the specified kern. - /// - /// The kern. - public virtual void Clean(Kernel kern) - { - if (kern == null) - { - throw new ArgumentNullException("kern"); - } - kernel = kern; - foreach (SolutionNode sol in kernel.Solutions) - { - CleanSolution(sol); - } - kernel = null; - } - - #endregion - } -} +#region BSD License +/* +Copyright (c) 2008 Matthew Holmes (matthew@wildfiregames.com), John Anderson (sontek@gmail.com) + +Redistribution and use in source and binary forms, with or without modification, are permitted +provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this list of conditions + and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions + and the following disclaimer in the documentation and/or other materials provided with the + distribution. +* The name of the author may not be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, +BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.IO; +using System.Text; + +using Prebuild.Core.Attributes; +using Prebuild.Core.Interfaces; +using Prebuild.Core.Nodes; +using Prebuild.Core.Utilities; +using System.CodeDom.Compiler; + +namespace Prebuild.Core.Targets +{ + + /// + /// + /// + public abstract class VSGenericTarget : ITarget + { + #region Fields + + readonly Hashtable tools = new Hashtable(); + Kernel kernel; + #endregion + + #region Properties + /// + /// Gets or sets the solution version. + /// + /// The solution version. + public abstract string SolutionVersion { get; } + /// + /// Gets or sets the product version. + /// + /// The product version. + public abstract string ProductVersion { get; } + /// + /// Gets or sets the schema version. + /// + /// The schema version. + public abstract string SchemaVersion { get; } + /// + /// Gets or sets the name of the version. + /// + /// The name of the version. + public abstract string VersionName { get; } + /// + /// Gets or sets the version. + /// + /// The version. + public abstract VSVersion Version { get; } + /// + /// Gets the name. + /// + /// The name. + public abstract string Name { get; } + + protected abstract string GetToolsVersionXml(FrameworkVersion version); + public abstract string SolutionTag { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + protected VSGenericTarget() + { + this.tools["C#"] = new ToolInfo("C#", "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "csproj", "CSHARP", "$(MSBuildBinPath)\\Microsoft.CSHARP.Targets"); + this.tools["Database"] = new ToolInfo("Database", "{4F174C21-8C12-11D0-8340-0000F80270F8}", "dbp", "UNKNOWN"); + this.tools["Boo"] = new ToolInfo("Boo", "{45CEA7DC-C2ED-48A6-ACE0-E16144C02365}", "booproj", "Boo", "$(BooBinPath)\\Boo.Microsoft.Build.targets"); + this.tools["VisualBasic"] = new ToolInfo("VisualBasic", "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "vbproj", "VisualBasic", "$(MSBuildBinPath)\\Microsoft.VisualBasic.Targets"); + this.tools["Folder"] = new ToolInfo("Folder", "{2150E333-8FDC-42A3-9474-1A3956D46DE8}", null, null); + } + + #endregion + + #region Private Methods + + private string MakeRefPath(ProjectNode project) + { + string ret = ""; + foreach (ReferencePathNode node in project.ReferencePaths) + { + try + { + string fullPath = Helper.ResolvePath(node.Path); + if (ret.Length < 1) + { + ret = fullPath; + } + else + { + ret += ";" + fullPath; + } + } + catch (ArgumentException) + { + this.kernel.Log.Write(LogType.Warning, "Could not resolve reference path: {0}", node.Path); + } + } + + return ret; + } + + private static ProjectNode FindProjectInSolution(string name, SolutionNode solution) + { + SolutionNode node = solution; + + while (node.Parent is SolutionNode) + node = node.Parent as SolutionNode; + + return FindProjectInSolutionRecursively(name, node); + } + + private static ProjectNode FindProjectInSolutionRecursively(string name, SolutionNode solution) + { + if (solution.ProjectsTable.ContainsKey(name)) + return (ProjectNode)solution.ProjectsTable[name]; + + foreach (SolutionNode child in solution.Solutions) + { + ProjectNode node = FindProjectInSolutionRecursively(name, child); + if (node != null) + return node; + } + + return null; + } + + private void WriteProject(SolutionNode solution, ProjectNode project) + { + if (!tools.ContainsKey(project.Language)) + { + throw new UnknownLanguageException("Unknown .NET language: " + project.Language); + } + + ToolInfo toolInfo = (ToolInfo)tools[project.Language]; + string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension); + StreamWriter ps = new StreamWriter(projectFile); + + kernel.CurrentWorkingDirectory.Push(); + Helper.SetCurrentDir(Path.GetDirectoryName(projectFile)); + + #region Project File + using (ps) + { + ps.WriteLine("", GetToolsVersionXml(project.FrameworkVersion)); + ps.WriteLine(" "); + ps.WriteLine(" Local"); + ps.WriteLine(" {0}", this.ProductVersion); + ps.WriteLine(" {0}", this.SchemaVersion); + ps.WriteLine(" {{{0}}}", project.Guid.ToString().ToUpper()); + + // Visual Studio has a hard coded guid for the project type + if (project.Type == ProjectType.Web) + ps.WriteLine(" {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}"); + ps.WriteLine(" Debug"); + ps.WriteLine(" AnyCPU"); + ps.WriteLine(" {0}", project.AppIcon); + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(" {0}", project.AssemblyName); + foreach (ConfigurationNode conf in project.Configurations) + { + if (conf.Options.KeyFile != "") + { + ps.WriteLine(" {0}", conf.Options.KeyFile); + ps.WriteLine(" true"); + break; + } + } + ps.WriteLine(" JScript"); + ps.WriteLine(" Grid"); + ps.WriteLine(" IE50"); + ps.WriteLine(" false"); + ps.WriteLine(" {0}", project.FrameworkVersion.ToString().Replace("_", ".")); + + ps.WriteLine(" {0}", project.Type == ProjectType.Web ? ProjectType.Library.ToString() : project.Type.ToString()); + ps.WriteLine(" {0}", project.DesignerFolder); + ps.WriteLine(" {0}", project.RootNamespace); + ps.WriteLine(" {0}", project.StartupObject); + if (string.IsNullOrEmpty(project.DebugStartParameters)) + { + ps.WriteLine(" {0}", project.DebugStartParameters); + } + ps.WriteLine(" "); + ps.WriteLine(" "); + + ps.WriteLine(" "); + + foreach (ConfigurationNode conf in project.Configurations) + { + ps.Write(" ", conf.Name); + ps.WriteLine(" {0}", conf.Options["AllowUnsafe"]); + ps.WriteLine(" {0}", conf.Options["BaseAddress"]); + ps.WriteLine(" {0}", conf.Options["CheckUnderflowOverflow"]); + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(" {0}", conf.Options["CompilerDefines"]); + ps.WriteLine(" {0}", Helper.NormalizePath(conf.Options["XmlDocFile"].ToString())); + ps.WriteLine(" {0}", conf.Options["DebugInformation"]); + ps.WriteLine(" {0}", conf.Options["FileAlignment"]); + ps.WriteLine(" {0}", conf.Options["OptimizeCode"]); + if (project.Type != ProjectType.Web) + ps.WriteLine(" {0}", + Helper.EndPath(Helper.NormalizePath(conf.Options["OutputPath"].ToString()))); + else + ps.WriteLine(" {0}", + Helper.EndPath(Helper.NormalizePath("bin\\"))); + + ps.WriteLine(" {0}", conf.Options["RegisterComInterop"]); + ps.WriteLine(" {0}", conf.Options["RemoveIntegerChecks"]); + ps.WriteLine(" {0}", conf.Options["WarningsAsErrors"]); + ps.WriteLine(" {0}", conf.Options["WarningLevel"]); + ps.WriteLine(" {0}", conf.Options["NoStdLib"]); + ps.WriteLine(" {0}", conf.Options["SuppressWarnings"]); + ps.WriteLine(" "); + } + + //ps.WriteLine(" "); + + List projectReferences = new List(); + List otherReferences = new List(); + + foreach (ReferenceNode refr in project.References) + { + ProjectNode projectNode = FindProjectInSolution(refr.Name, solution); + + if (projectNode == null) + otherReferences.Add(refr); + else + projectReferences.Add(projectNode); + } + // Assembly References + ps.WriteLine(" "); + + foreach (ReferenceNode refr in otherReferences) + { + ps.Write(" "); + ps.Write(" "); + ps.Write(refr.Name); + ps.WriteLine(""); + // TODO: Allow reference to *.exe files + ps.WriteLine(" {0}", refr.LocalCopy); + ps.WriteLine(" "); + } + ps.WriteLine(" "); + + //Project References + ps.WriteLine(" "); + foreach (ProjectNode projectReference in projectReferences) + { + ToolInfo tool = (ToolInfo)tools[projectReference.Language]; + if (tools == null) + throw new UnknownLanguageException(); + + string path = + Helper.MakePathRelativeTo(project.FullPath, + Helper.MakeFilePath(projectReference.FullPath, projectReference.Name, tool.FileExtension)); + ps.WriteLine(" ", path); + + // TODO: Allow reference to visual basic projects + ps.WriteLine(" {0}", projectReference.Name); + ps.WriteLine(" {0}", projectReference.Guid.ToString("B").ToUpper()); + ps.WriteLine(" {0}", tool.Guid.ToUpper()); + + ps.WriteLine(" False" ); + + ps.WriteLine(" "); + } + ps.WriteLine(" "); + + // ps.WriteLine(" "); + ps.WriteLine(" "); + + // ps.WriteLine(" "); + List list = new List(); + + foreach (string path in project.Files) + { + string lower = path.ToLower(); + if (lower.EndsWith(".resx")) + { + string codebehind = String.Format("{0}.Designer{1}", path.Substring(0, path.LastIndexOf('.')), toolInfo.LanguageExtension); + if (!list.Contains(codebehind)) + list.Add(codebehind); + } + } + + foreach (string file in project.Files) + { + // if (file == "Properties\\Bind.Designer.cs") + // { + // Console.WriteLine("Wait a minute!"); + // Console.WriteLine(project.Files.GetSubType(file).ToString()); + // } + + SubType subType = project.Files.GetSubType(file); + + if (subType != SubType.Code && subType != SubType.Settings && subType != SubType.Designer + && subType != SubType.CodeBehind) + { + ps.WriteLine(" ", file.Substring(0, file.LastIndexOf('.')) + ".resx"); + ps.WriteLine(" {0}", Path.GetFileName(file)); + ps.WriteLine(" Designer"); + ps.WriteLine(" "); + // + } + + if (subType == SubType.Designer) + { + ps.WriteLine(" ", file); + ps.WriteLine(" " + subType + ""); + ps.WriteLine(" ResXFileCodeGenerator"); + + string autogen_name = file.Substring(0, file.LastIndexOf('.')) + ".Designer.cs"; + string dependent_name = file.Substring(0, file.LastIndexOf('.')) + ".cs"; + + ps.WriteLine(" {0}", autogen_name); + + // Check for a parent .cs file with the same name as this designer file + if (File.Exists(dependent_name)) + ps.WriteLine(" {0}", Path.GetFileName(dependent_name)); + + ps.WriteLine(" "); + if (File.Exists(autogen_name)) + { + ps.WriteLine(" ", autogen_name); + ps.WriteLine(" True"); + ps.WriteLine(" True"); + + // If a parent .cs file exists, link this autogen file to it. Otherwise link + // to the designer file + if (File.Exists(dependent_name)) + ps.WriteLine(" {0}", Path.GetFileName(dependent_name)); + else + ps.WriteLine(" {0}", Path.GetFileName(file)); + + ps.WriteLine(" "); + } + list.Add(autogen_name); + } + if (subType == SubType.Settings) + { + ps.Write(" <{0} ", project.Files.GetBuildAction(file)); + ps.WriteLine("Include=\"{0}\">", file); + string fileName = Path.GetFileName(file); + if (project.Files.GetBuildAction(file) == BuildAction.None) + { + ps.WriteLine(" SettingsSingleFileGenerator"); + ps.WriteLine(" {0}", fileName.Substring(0, fileName.LastIndexOf('.')) + ".Designer.cs"); + } + else + { + ps.WriteLine(" Code"); + ps.WriteLine(" True"); + ps.WriteLine(" True"); + string fileNameShort = fileName.Substring(0, fileName.LastIndexOf('.')); + string fileNameShorter = fileNameShort.Substring(0, fileNameShort.LastIndexOf('.')); + ps.WriteLine(" {0}", Path.GetFileName(fileNameShorter + ".settings")); + } + ps.WriteLine(" ", project.Files.GetBuildAction(file)); + } + else if (subType != SubType.Designer) + { + string path = Helper.NormalizePath(file); + string path_lower = path.ToLower(); + + if (!list.Contains(file)) + { + ps.Write(" <{0} ", project.Files.GetBuildAction(path)); + + int startPos = 0; + if (project.Files.GetPreservePath(file)) + { + while ((@"./\").IndexOf(file.Substring(startPos, 1)) != -1) + startPos++; + + } + else + { + startPos = file.LastIndexOf(Path.GetFileName(path)); + } + + ps.WriteLine("Include=\"{0}\">", path); + + int last_period_index = file.LastIndexOf('.'); + string short_file_name = file.Substring(0, last_period_index); + string extension = Path.GetExtension(path); + string designer_format = string.Format(".designer{0}", extension); + + if (path_lower.EndsWith(designer_format)) + { + int designer_index = path_lower.IndexOf(designer_format); + string file_name = path.Substring(0, designer_index); + + if (File.Exists(file_name)) + ps.WriteLine(" {0}", Path.GetFileName(file_name)); + else if (File.Exists(file_name + ".resx")) + ps.WriteLine(" {0}", Path.GetFileName(file_name + ".resx")); + } + else if (subType == SubType.CodeBehind) + { + ps.WriteLine(" {0}", Path.GetFileName(short_file_name)); + } + if (project.Files.GetIsLink(file)) + { + string alias = project.Files.GetLinkPath(file); + alias += file.Substring(startPos); + alias = Helper.NormalizePath(alias); + ps.WriteLine(" {0}", alias); + } + else if (project.Files.GetBuildAction(file) != BuildAction.None) + { + if (project.Files.GetBuildAction(file) != BuildAction.EmbeddedResource) + { + ps.WriteLine(" {0}", subType); + } + } + + if (project.Files.GetCopyToOutput(file) != CopyToOutput.Never) + { + ps.WriteLine(" {0}", project.Files.GetCopyToOutput(file)); + } + + ps.WriteLine(" ", project.Files.GetBuildAction(file)); + } + } + } + + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(" "); + ps.WriteLine(""); + } + #endregion + + #region User File + + ps = new StreamWriter(projectFile + ".user"); + using (ps) + { + ps.WriteLine(""); + //ps.WriteLine( "" ); + //ps.WriteLine(" <{0}>", toolInfo.XMLTag); + //ps.WriteLine(" "); + ps.WriteLine(" "); + //ps.WriteLine(" ", MakeRefPath(project)); + ps.WriteLine(" Debug"); + ps.WriteLine(" AnyCPU"); + ps.WriteLine(" {0}", MakeRefPath(project)); + ps.WriteLine(" {0}", this.ProductVersion); + ps.WriteLine(" ProjectFiles"); + ps.WriteLine(" 0"); + ps.WriteLine(" "); + foreach (ConfigurationNode conf in project.Configurations) + { + ps.Write(" "); + } + ps.WriteLine(""); + } + #endregion + + kernel.CurrentWorkingDirectory.Pop(); + } + + private void WriteSolution(SolutionNode solution, bool writeSolutionToDisk) + { + kernel.Log.Write("Creating {0} solution and project files", this.VersionName); + + foreach (SolutionNode child in solution.Solutions) + { + kernel.Log.Write("...Creating folder: {0}", child.Name); + WriteSolution(child, false); + } + + foreach (ProjectNode project in solution.Projects) + { + kernel.Log.Write("...Creating project: {0}", project.Name); + WriteProject(solution, project); + } + + foreach (DatabaseProjectNode project in solution.DatabaseProjects) + { + kernel.Log.Write("...Creating database project: {0}", project.Name); + WriteDatabaseProject(solution, project); + } + + if (writeSolutionToDisk) // only write main solution + { + kernel.Log.Write(""); + string solutionFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln"); + + using (StreamWriter ss = new StreamWriter(solutionFile)) + { + kernel.CurrentWorkingDirectory.Push(); + Helper.SetCurrentDir(Path.GetDirectoryName(solutionFile)); + + ss.WriteLine("Microsoft Visual Studio Solution File, Format Version {0}", this.SolutionVersion); + ss.WriteLine(SolutionTag); + + WriteProjectDeclarations(ss, solution, solution); + + ss.WriteLine("Global"); + + ss.WriteLine("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution"); + foreach (ConfigurationNode conf in solution.Configurations) + { + ss.WriteLine("\t\t{0}|Any CPU = {0}|Any CPU", conf.Name); + } + ss.WriteLine("\tEndGlobalSection"); + + ss.WriteLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution"); + WriteConfigurationLines(solution.Configurations, solution, ss); + ss.WriteLine("\tEndGlobalSection"); + + if (solution.Solutions.Count > 0) + { + ss.WriteLine("\tGlobalSection(NestedProjects) = preSolution"); + foreach (SolutionNode embeddedSolution in solution.Solutions) + { + WriteNestedProjectMap(ss, embeddedSolution); + } + ss.WriteLine("\tEndGlobalSection"); + } + + ss.WriteLine("EndGlobal"); + } + + kernel.CurrentWorkingDirectory.Pop(); + } + } + + private void WriteProjectDeclarations(StreamWriter writer, SolutionNode actualSolution, SolutionNode embeddedSolution) + { + foreach (SolutionNode childSolution in embeddedSolution.Solutions) + { + WriteEmbeddedSolution(writer, childSolution); + WriteProjectDeclarations(writer, actualSolution, childSolution); + } + + foreach (ProjectNode project in embeddedSolution.Projects) + { + WriteProject(actualSolution, writer, project); + } + + foreach (DatabaseProjectNode dbProject in embeddedSolution.DatabaseProjects) + { + WriteProject(actualSolution, writer, dbProject); + } + + if (actualSolution.Guid == embeddedSolution.Guid) + { + WriteSolutionFiles(actualSolution, writer); + } + } + + private static void WriteNestedProjectMap(StreamWriter writer, SolutionNode embeddedSolution) + { + foreach (ProjectNode project in embeddedSolution.Projects) + { + WriteNestedProject(writer, embeddedSolution, project.Guid); + } + + foreach (DatabaseProjectNode dbProject in embeddedSolution.DatabaseProjects) + { + WriteNestedProject(writer, embeddedSolution, dbProject.Guid); + } + + foreach (SolutionNode child in embeddedSolution.Solutions) + { + WriteNestedProject(writer, embeddedSolution, child.Guid); + WriteNestedProjectMap(writer, child); + } + } + + private static void WriteNestedProject(StreamWriter writer, SolutionNode solution, Guid projectGuid) + { + WriteNestedFolder(writer, solution.Guid, projectGuid); + } + + private static void WriteNestedFolder(StreamWriter writer, Guid parentGuid, Guid childGuid) + { + writer.WriteLine("\t\t{0} = {1}", + childGuid.ToString("B").ToUpper(), + parentGuid.ToString("B").ToUpper()); + } + + private static void WriteConfigurationLines(ICollection configurations, SolutionNode solution, StreamWriter ss) + { + foreach (ProjectNode project in solution.Projects) + { + foreach (ConfigurationNode conf in configurations) + { + ss.WriteLine("\t\t{0}.{1}|Any CPU.ActiveCfg = {1}|Any CPU", + project.Guid.ToString("B").ToUpper(), + conf.Name); + + ss.WriteLine("\t\t{0}.{1}|Any CPU.Build.0 = {1}|Any CPU", + project.Guid.ToString("B").ToUpper(), + conf.Name); + } + } + + foreach (SolutionNode child in solution.Solutions) + { + WriteConfigurationLines(configurations, child, ss); + } + } + + private void WriteSolutionFiles(SolutionNode solution, StreamWriter ss) + { + WriteProject(ss, "Folder", solution.Guid, "Solution Files", "Solution Files", solution.Files); + } + + private void WriteEmbeddedSolution(StreamWriter writer, SolutionNode embeddedSolution) + { + WriteProject(writer, "Folder", embeddedSolution.Guid, embeddedSolution.Name, embeddedSolution.Name, embeddedSolution.Files); + } + + private void WriteProject(SolutionNode solution, StreamWriter ss, ProjectNode project) + { + WriteProject(ss, solution, project.Language, project.Guid, project.Name, project.FullPath); + } + + private void WriteProject(SolutionNode solution, StreamWriter ss, DatabaseProjectNode dbProject) + { + if (solution.Files != null && solution.Files.Count > 0) + WriteProject(ss, solution, "Database", dbProject.Guid, dbProject.Name, dbProject.FullPath); + } + + private static bool ExtensionSpecified(string refName) + { + return refName.EndsWith(".dll") || refName.EndsWith(".exe"); + } + + private static string GetProjectExtension(ProjectNode project) + { + string extension = ".dll"; + if (project.Type == ProjectType.Exe) + { + extension = ".exe"; + } + return extension; + } + + const string ProjectDeclarationBeginFormat = "Project(\"{0}\") = \"{1}\", \"{2}\", \"{3}\""; + const string ProjectDeclarationEndFormat = "EndProject"; + + private void WriteProject(StreamWriter ss, SolutionNode solution, string language, Guid guid, string name, string projectFullPath) + { + if (!tools.ContainsKey(language)) + throw new UnknownLanguageException("Unknown .NET language: " + language); + + ToolInfo toolInfo = (ToolInfo)tools[language]; + + string path = Helper.MakePathRelativeTo(solution.FullPath, projectFullPath); + + path = Helper.MakeFilePath(path, name, toolInfo.FileExtension); + + WriteProject(ss, language, guid, name, path); + } + + private void WriteProject(StreamWriter writer, string language, Guid projectGuid, string name, string location) + { + WriteProject(writer, language, projectGuid, name, location, null); + } + + private void WriteProject(StreamWriter writer, string language, Guid projectGuid, string name, string location, FilesNode files) + { + if (!tools.ContainsKey(language)) + throw new UnknownLanguageException("Unknown .NET language: " + language); + + ToolInfo toolInfo = (ToolInfo)tools[language]; + + writer.WriteLine(ProjectDeclarationBeginFormat, + toolInfo.Guid, + name, + location, + projectGuid.ToString("B").ToUpper()); + + if (files != null) + { + writer.WriteLine("\tProjectSection(SolutionItems) = preProject"); + + foreach (string file in files) + writer.WriteLine("\t\t{0} = {0}", file); + + writer.WriteLine("\tEndProjectSection"); + } + + writer.WriteLine(ProjectDeclarationEndFormat); + } + + private void WriteDatabaseProject(SolutionNode solution, DatabaseProjectNode project) + { + string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, "dbp"); + IndentedTextWriter ps = new IndentedTextWriter(new StreamWriter(projectFile), " "); + + kernel.CurrentWorkingDirectory.Push(); + + Helper.SetCurrentDir(Path.GetDirectoryName(projectFile)); + + using (ps) + { + ps.WriteLine("# Microsoft Developer Studio Project File - Database Project"); + ps.WriteLine("Begin DataProject = \"{0}\"", project.Name); + ps.Indent++; + ps.WriteLine("MSDTVersion = \"80\""); + // TODO: Use the project.Files property + if (ContainsSqlFiles(Path.GetDirectoryName(projectFile))) + WriteDatabaseFoldersAndFiles(ps, Path.GetDirectoryName(projectFile)); + + ps.WriteLine("Begin DBRefFolder = \"Database References\""); + ps.Indent++; + foreach (DatabaseReferenceNode reference in project.References) + { + ps.WriteLine("Begin DBRefNode = \"{0}\"", reference.Name); + ps.Indent++; + ps.WriteLine("ConnectStr = \"{0}\"", reference.ConnectionString); + ps.WriteLine("Provider = \"{0}\"", reference.ProviderId.ToString("B").ToUpper()); + //ps.WriteLine("Colorizer = 5"); + ps.Indent--; + ps.WriteLine("End"); + } + ps.Indent--; + ps.WriteLine("End"); + ps.Indent--; + ps.WriteLine("End"); + + ps.Flush(); + } + + kernel.CurrentWorkingDirectory.Pop(); + } + + private bool ContainsSqlFiles(string folder) + { + foreach (string file in Directory.GetFiles(folder, "*.sql")) + { + return true; // if the folder contains 1 .sql file, that's good enough + } + + foreach (string child in Directory.GetDirectories(folder)) + { + if (ContainsSqlFiles(child)) + return true; // if 1 child folder contains a .sql file, still good enough + } + + return false; + } + + private void WriteDatabaseFoldersAndFiles(IndentedTextWriter writer, string folder) + { + foreach (string child in Directory.GetDirectories(folder)) + { + if (ContainsSqlFiles(child)) + { + writer.WriteLine("Begin Folder = \"{0}\"", Path.GetFileName(child)); + writer.Indent++; + WriteDatabaseFoldersAndFiles(writer, child); + writer.Indent--; + writer.WriteLine("End"); + } + } + foreach (string file in Directory.GetFiles(folder, "*.sql")) + { + writer.WriteLine("Script = \"{0}\"", Path.GetFileName(file)); + } + } + + private void CleanProject(ProjectNode project) + { + kernel.Log.Write("...Cleaning project: {0}", project.Name); + + ToolInfo toolInfo = (ToolInfo)tools[project.Language]; + string projectFile = Helper.MakeFilePath(project.FullPath, project.Name, toolInfo.FileExtension); + string userFile = projectFile + ".user"; + + Helper.DeleteIfExists(projectFile); + Helper.DeleteIfExists(userFile); + } + + private void CleanSolution(SolutionNode solution) + { + kernel.Log.Write("Cleaning {0} solution and project files", this.VersionName, solution.Name); + + string slnFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "sln"); + string suoFile = Helper.MakeFilePath(solution.FullPath, solution.Name, "suo"); + + Helper.DeleteIfExists(slnFile); + Helper.DeleteIfExists(suoFile); + + foreach (ProjectNode project in solution.Projects) + { + CleanProject(project); + } + + kernel.Log.Write(""); + } + + #endregion + + #region ITarget Members + + /// + /// Writes the specified kern. + /// + /// The kern. + public virtual void Write(Kernel kern) + { + if (kern == null) + { + throw new ArgumentNullException("kern"); + } + kernel = kern; + foreach (SolutionNode sol in kernel.Solutions) + { + WriteSolution(sol, true); + } + kernel = null; + } + + /// + /// Cleans the specified kern. + /// + /// The kern. + public virtual void Clean(Kernel kern) + { + if (kern == null) + { + throw new ArgumentNullException("kern"); + } + kernel = kern; + foreach (SolutionNode sol in kernel.Solutions) + { + CleanSolution(sol); + } + kernel = null; + } + + #endregion + } +}