Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Removed the MergeWorkspace() method from StructurizrClient. PutWorksp…
Browse files Browse the repository at this point in the history
…ace() now merges layout information by default. You can disable this by setting the MergeFromRemote property to false.
  • Loading branch information
simonbrowndotje committed Nov 21, 2016
1 parent 4a71710 commit e6df978
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
33 changes: 22 additions & 11 deletions Structurizr.Core/Client/StructurizrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class StructurizrClient

public EncryptionStrategy EncryptionStrategy { get; set; }

public bool MergeFromRemote { get; set; }

public StructurizrClient(string apiKey, string apiSecret) : this("https://api.structurizr.com", apiKey, apiSecret)
{
}
Expand All @@ -33,6 +35,7 @@ public StructurizrClient(string apiUrl, string apiKey, string apiSecret)
this.ApiSecret = apiSecret;

this.WorkspaceArchiveLocation = new DirectoryInfo(".");
this.MergeFromRemote = true;
}

public Workspace GetWorkspace(long workspaceId)
Expand Down Expand Up @@ -69,6 +72,25 @@ public Workspace GetWorkspace(long workspaceId)

public void PutWorkspace(long workspaceId, Workspace workspace)
{
if (workspace == null)
{
throw new ArgumentException("A workspace must be supplied");
}
else if (workspaceId <= 0)
{
throw new ArgumentException("The workspace ID must be set");
}

if (MergeFromRemote)
{
Workspace remoteWorkspace = GetWorkspace(workspaceId);
if (remoteWorkspace != null)
{
workspace.Views.CopyLayoutInformationFrom(remoteWorkspace.Views);
workspace.Views.Configuration.CopyConfigurationFrom(remoteWorkspace.Views.Configuration);
}
}

workspace.Id = workspaceId;

using (WebClient webClient = new WebClient())
Expand Down Expand Up @@ -109,17 +131,6 @@ public void PutWorkspace(long workspaceId, Workspace workspace)
}
}

public void MergeWorkspace(long workspaceId, Workspace workspace)
{
Workspace remoteWorkspace = GetWorkspace(workspaceId);
if (remoteWorkspace != null)
{
workspace.Views.CopyLayoutInformationFrom(remoteWorkspace.Views);
workspace.Views.Configuration.CopyConfigurationFrom(remoteWorkspace.Views.Configuration);
}
PutWorkspace(workspaceId, workspace);
}

private void AddHeaders(WebClient webClient, string httpMethod, string path, string content, string contentType)
{
webClient.Encoding = Encoding.UTF8;
Expand Down
2 changes: 1 addition & 1 deletion Structurizr.Examples/ClientSideEncryptedWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)

StructurizrClient structurizrClient = new StructurizrClient("key", "secret");
structurizrClient.EncryptionStrategy = new AesEncryptionStrategy("password");
structurizrClient.MergeWorkspace(41, workspace);
structurizrClient.PutWorkspace(41, workspace);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Structurizr.Examples/FinancialRiskSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static void Main(string[] args)

// and upload the model to structurizr.com
StructurizrClient structurizrClient = new StructurizrClient("key", "secret");
structurizrClient.MergeWorkspace(9481, workspace);
structurizrClient.PutWorkspace(9481, workspace);
}
}
}
2 changes: 1 addition & 1 deletion Structurizr.Examples/WidgetsLimited.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void Main(string[] args)
styles.Add(new ElementStyle(InternalSoftwareSystemTag) { Background = "#B60037" });

StructurizrClient structurizrClient = new StructurizrClient("key", "secret");
structurizrClient.MergeWorkspace(14471, workspace);
structurizrClient.PutWorkspace(14471, workspace);
}

}
Expand Down
11 changes: 1 addition & 10 deletions docs/api-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,9 @@ By default, a copy of the workspace (as JSON) is archived to the current working

### 2. PutWorkspace

This allows you to overwrite an existing workspace.
This allows you to overwrite an existing workspace. If the ```MergeFromRemote``` property (on the ```StructurizrClient``` instance) is set to ```true``` (this is the default), any layout information (i.e. the location of boxes on diagrams) is preserved where possible (i.e. where diagram elements haven't been renamed).

```c#
structurizrClient.PutWorkspace(1234, workspace);
```

### 3. MergeWorkspace

This is the same as ```PutWorkspace``` except that any layout information (i.e. the location of boxes on diagrams) is preserved where possible (i.e. where diagram elements haven't been renamed).

```c#
structurizrClient.MergeWorkspace(1234, workspace);
```

Under the covers, this operation calls ```GetWorkspace``` followed by ```PutWorkspace```. If the merge doesn't work as expected, you still have the previous version of the workspace (as JSON) in the archive location.

0 comments on commit e6df978

Please sign in to comment.