Browse files

Fix lane deletion when there are dependent lanes.

  • Loading branch information...
1 parent d0fd209 commit d7c085b9d4cd0a497d879612be8d9d2b02072dc7 @rolfbjarne rolfbjarne committed Oct 1, 2013
View
27 MonkeyWrench.DataClasses/Logic/FindLaneWithDependenciesResponse.cs
@@ -0,0 +1,27 @@
+/*
+ * FindLaneWithDependenciesResponse.cs
+ *
+ * Authors:
+ * Rolf Bjarne Kvinge (rolf@xamarin.com)
+ *
+ * Copyright 2013 Xamarin Inc. (http://www.xamarin.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using MonkeyWrench;
+
+namespace MonkeyWrench.DataClasses.Logic
+{
+ public class FindLaneWithDependenciesResponse : WebServiceResponse
+ {
+ public DBLane lane;
+ public List<DBLane> dependencies;
+ }
+}
View
2 MonkeyWrench.DataClasses/MonkeyWrench.DataClasses.csproj 100755 → 100644
@@ -183,6 +183,7 @@
<Compile Include="Utilities.cs" />
<Compile Include="WebServices.cs" />
<Compile Include="WebServices.Generated.cs" />
+ <Compile Include="Logic\FindLaneWithDependenciesResponse.cs" />
</ItemGroup>
<ItemGroup>
<None Include="CustomTypes.sql" />
@@ -223,4 +224,3 @@
</Target>
-->
</Project>
-
View
26 MonkeyWrench.DataClasses/WebServices.Generated.cs
@@ -1005,7 +1005,31 @@ public partial class WebServices : System.Web.Services.Protocols.SoapHttpClientP
object[] results = this.EndInvoke(asyncResult);
return ((FindLaneResponse)(results[0]));
}
-
+
+ /// <remarks/>
+ [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://monkeywrench.novell.com/FindLaneWithDependencies", RequestNamespace="http://monkeywrench.novell.com/", ResponseNamespace="http://monkeywrench.novell.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
+ public FindLaneWithDependenciesResponse FindLaneWithDependencies(WebServiceLogin login, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] System.Nullable<int> lane_id, string lane) {
+ object[] results = this.Invoke("FindLaneWithDependencies", new object[] {
+ login,
+ lane_id,
+ lane});
+ return ((FindLaneWithDependenciesResponse)(results[0]));
+ }
+
+ /// <remarks/>
+ public System.IAsyncResult BeginFindLaneWitDependencies(WebServiceLogin login, System.Nullable<int> lane_id, string lane, System.AsyncCallback callback, object asyncState) {
+ return this.BeginInvoke("FindLane", new object[] {
+ login,
+ lane_id,
+ lane}, callback, asyncState);
+ }
+
+ /// <remarks/>
+ public FindLaneWithDependenciesResponse EndFindLaneWithDependencies(System.IAsyncResult asyncResult) {
+ object[] results = this.EndInvoke(asyncResult);
+ return ((FindLaneWithDependenciesResponse)(results[0]));
+ }
+
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://monkeywrench.novell.com/EditLane", RequestNamespace="http://monkeywrench.novell.com/", ResponseNamespace="http://monkeywrench.novell.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public void EditLane(WebServiceLogin login, DBLane lane) {
View
17 MonkeyWrench.Database/Extensions/DBLane_Extensions.cs
@@ -114,8 +114,8 @@ public static void Delete (DB db, int lane_id)
DELETE FROM HostLane WHERE lane_id = @id;
DELETE FROM EnvironmentVariable WHERE lane_id = @id;
DELETE FROM LaneDeletionDirective WHERE lane_id = @id;
-DELETE FROM Lane WHERE id = @id;
DELETE FROM LaneDependency WHERE lane_id = @id OR dependent_lane_id = @id;
+DELETE FROM Lane WHERE id = @id;
";
DB.CreateParameter (cmd, "id", lane_id);
cmd.ExecuteNonQuery ();
@@ -138,6 +138,21 @@ public static List<DBLaneDependency> GetDependencies (this DBLane me, DB db)
return result;
}
+ public static List<DBLane> GetDependentLanes (this DBLane me, DB db)
+ {
+ var result = new List<DBLane> ();
+ using (IDbCommand cmd = db.CreateCommand ()) {
+ cmd.CommandText = "SELECT Lane.* FROM Lane INNER JOIN LaneDependency ON LaneDependency.lane_id = Lane.id WHERE LaneDependency.dependent_lane_id = @lane_id ORDER BY Lane.lane;";
+ DB.CreateParameter (cmd, "lane_id", me.id);
+ using (IDataReader reader = cmd.ExecuteReader ()) {
+ while (reader.Read ())
+ result.Add (new DBLane (reader));
+ }
+ }
+ Logger.Log ("*** * *** GetDependentLanes for {0}: {1} results\n", me.id, result.Count);
+ return result;
+ }
+
public static DBRevision FindRevision (this DBLane me, DB db, string revision)
{
using (IDbCommand cmd = db.CreateCommand ()) {
View
15 MonkeyWrench.Web.UI/Delete.aspx.cs
@@ -39,9 +39,18 @@ protected void Page_Load (object sender, EventArgs e)
return;
}
- FindLaneResponse lane = Master.WebService.FindLane (Master.WebServiceLogin, lane_id, null);
-
- lblMessage.Text = string.Format ("Are you sure you want to delete the lane '{0}' (ID: {1})?", lane.lane.lane, lane.lane.id);
+ var lane = Master.WebService.FindLaneWithDependencies (Master.WebServiceLogin, lane_id, null);
+ var text = new System.Text.StringBuilder ();
+
+ text.AppendFormat ("Are you sure you want to delete the lane '{0}' (ID: {1}) Count: {2}?<br/>", lane.lane.lane, lane.lane.id, lane.dependencies == null ? "N/A" : lane.dependencies.Count.ToString ());
+ if (lane.dependencies != null && lane.dependencies.Count > 0) {
+ text.AppendFormat ("<br/>There are {0} other lane(s) depending on this lane:<br/>", lane.dependencies.Count);
+ foreach (var dl in lane.dependencies) {
+ text.AppendFormat ("<a href=EditLane.aspx?lane_id={0}>{1}</a><br/>", dl.id, dl.lane);
+ }
+ text.AppendFormat ("<br/>These dependencies will also be removed.<br/>");
+ }
+ lblMessage.Text = text.ToString ();
cmdConfirm.Enabled = true;
break;
}
View
18 MonkeyWrench.Web.WebService/WebServices.asmx.cs
@@ -896,6 +896,24 @@ public FindLaneResponse FindLane (WebServiceLogin login, int? lane_id, string la
}
[WebMethod]
+ public FindLaneWithDependenciesResponse FindLaneWithDependencies (WebServiceLogin login, int? lane_id, string lane)
+ {
+ var response = new FindLaneWithDependenciesResponse ();
+
+ using (DB db = new DB ()) {
+ Authenticate (db, login, response);
+
+ response.lane = FindLane (db, lane_id, lane);
+ if (response.lane != null)
+ response.dependencies = response.lane.GetDependentLanes (db);
+
+ Logger.Log ("*** * *** FindLaneWithDependencies for {0}: {1} results\n", response.lane.id, response.dependencies.Count);
+
+ return response;
+ }
+ }
+
+ [WebMethod]
public void EditLane (WebServiceLogin login, DBLane lane)
{
//WebServiceResponse response = new WebServiceResponse ();
View
59 MonkeyWrench.Web.WebService/WebServices.wsdl
@@ -87,6 +87,7 @@
<xs:element minOccurs="1" maxOccurs="1" name="parent_lane_id" nillable="true" type="xs:int" />
<xs:element minOccurs="0" maxOccurs="1" name="commit_filter" type="xs:string" />
<xs:element minOccurs="1" maxOccurs="1" name="traverse_merge" type="xs:boolean" />
+ <xs:element minOccurs="1" maxOccurs="1" name="enabled" type="xs:boolean" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
@@ -734,6 +735,16 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
+ <xs:complexType name="FindLaneWithDependenciesResponse">
+ <xs:complexContent mixed="false">
+ <xs:extension base="s0:WebServiceResponse">
+ <xs:sequence>
+ <xs:element minOccurs="0" maxOccurs="1" name="lane" type="s0:DBLane" />
+ <xs:element minOccurs="0" maxOccurs="1" name="dependencies" type="s0:ArrayOfDBLaneDependency" />
+ </xs:sequence>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
<xs:complexType name="GetViewLaneDataResponse">
<xs:complexContent mixed="false">
<xs:extension base="s0:WebServiceResponse">
@@ -1674,6 +1685,22 @@
</xs:sequence>
</xs:complexType>
</xs:element>
+ <xs:element name="FindLaneWithDependencies">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" maxOccurs="1" name="login" type="s0:WebServiceLogin" />
+ <xs:element minOccurs="1" maxOccurs="1" name="lane_id" nillable="true" type="xs:int" />
+ <xs:element minOccurs="0" maxOccurs="1" name="lane" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="FindLaneWithDependenciesResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" maxOccurs="1" name="FindLaneWithDependenciesResult" type="s0:FindLaneWithDependenciesResponse" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
<xs:element name="EditLane">
<xs:complexType>
<xs:sequence>
@@ -3028,6 +3055,12 @@
<message name="FindLaneSoapOut">
<part name="parameters" element="s0:FindLaneResponse" />
</message>
+ <message name="FindLaneWithDependenciesSoapIn">
+ <part name="parameters" element="s0:FindLaneWithDependencies" />
+ </message>
+ <message name="FindLaneWithDependenciesSoapOut">
+ <part name="parameters" element="s0:FindLaneWithDependenciesResponse" />
+ </message>
<message name="EditLaneSoapIn">
<part name="parameters" element="s0:EditLane" />
</message>
@@ -3665,6 +3698,10 @@
<input message="s0:FindLaneSoapIn" />
<output message="s0:FindLaneSoapOut" />
</operation>
+ <operation name="FindLaneWithDependencies">
+ <input message="s0:FindLaneWithDependenciesSoapIn" />
+ <output message="s0:FindLaneWithDependenciesSoapOut" />
+ </operation>
<operation name="EditLane">
<input message="s0:EditLaneSoapIn" />
<output message="s0:EditLaneSoapOut" />
@@ -4135,6 +4172,10 @@
<input message="s0:FindLaneSoapIn" />
<output message="s0:FindLaneSoapOut" />
</operation>
+ <operation name="FindLaneWithDependencies">
+ <input message="s0:FindLaneWithDependenciesSoapIn" />
+ <output message="s0:FindLaneWithDependenciesSoapOut" />
+ </operation>
<operation name="EditLane">
<input message="s0:EditLaneSoapIn" />
<output message="s0:EditLaneSoapOut" />
@@ -4841,6 +4882,15 @@
<soap:body use="literal" />
</output>
</operation>
+ <operation name="FindLaneWithDependencies">
+ <soap:operation soapAction="http://monkeywrench.novell.com/FindLaneWithDependencies" style="document" />
+ <input>
+ <soap:body use="literal" />
+ </input>
+ <output>
+ <soap:body use="literal" />
+ </output>
+ </operation>
<operation name="EditLane">
<soap:operation soapAction="http://monkeywrench.novell.com/EditLane" style="document" />
<input>
@@ -5897,6 +5947,15 @@
<soap12:body use="literal" />
</output>
</operation>
+ <operation name="FindLaneWithDependencies">
+ <soap12:operation soapAction="http://monkeywrench.novell.com/FindLaneWithDependencies" style="document" />
+ <input>
+ <soap12:body use="literal" />
+ </input>
+ <output>
+ <soap12:body use="literal" />
+ </output>
+ </operation>
<operation name="EditLane">
<soap12:operation soapAction="http://monkeywrench.novell.com/EditLane" style="document" />
<input>

0 comments on commit d7c085b

Please sign in to comment.