Exemplo n.º 1
0
        public Workspace GetWorkspace(long workspaceId)
        {
            using (HttpClient httpClient = createHttpClient())
            {
                string httpMethod = "GET";
                string path       = WorkspacePath + workspaceId;

                AddHeaders(httpClient, httpMethod, new Uri(Url + path).AbsolutePath, "", "");

                var responseMessage = httpClient.GetAsync(Url + path);
                if (responseMessage.Result.StatusCode != HttpStatusCode.OK)
                {
                    throw new StructurizrClientException(responseMessage.Result.Content.ReadAsStringAsync().Result);
                }

                string response = responseMessage.Result.Content.ReadAsStringAsync().Result;
                ArchiveWorkspace(workspaceId, response);

                StringReader stringReader = new StringReader(response);
                if (EncryptionStrategy == null)
                {
                    return(new JsonReader().Read(stringReader));
                }
                else
                {
                    EncryptedWorkspace encryptedWorkspace = new EncryptedJsonReader().Read(stringReader);
                    encryptedWorkspace.EncryptionStrategy.Passphrase = this.EncryptionStrategy.Passphrase;
                    return(encryptedWorkspace.Workspace);
                }
            }
        }
Exemplo n.º 2
0
        public Workspace GetWorkspace(long workspaceId)
        {
            using (WebClient webClient = new WebClient())
            {
                try
                {
                    string httpMethod = "GET";
                    string path       = WorkspacePath + workspaceId;

                    AddHeaders(webClient, httpMethod, path, "", "");

                    string response = webClient.DownloadString(this.Url + path);
                    ArchiveWorkspace(workspaceId, response);

                    StringReader stringReader = new StringReader(response);
                    if (EncryptionStrategy == null)
                    {
                        return(new JsonReader().Read(stringReader));
                    }
                    else
                    {
                        EncryptedWorkspace encryptedWorkspace = new EncryptedJsonReader().Read(stringReader);
                        encryptedWorkspace.EncryptionStrategy.Passphrase = this.EncryptionStrategy.Passphrase;
                        return(encryptedWorkspace.Workspace);
                    }
                }
                catch (Exception e)
                {
                    throw new StructurizrClientException("There was an error getting the workspace: " + e.Message, e);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the workspace with the given ID.
        /// </summary>
        /// <param name="workspaceId">The workspace ID.</param>
        /// <returns>A Workspace object.</returns>
        public Workspace GetWorkspace(long workspaceId)
        {
            if (workspaceId <= 0)
            {
                throw new ArgumentException("The workspace ID must be a positive integer.");
            }

            using (HttpClient httpClient = createHttpClient())
            {
                string httpMethod = "GET";
                string path       = WorkspacePath + workspaceId;

                AddHeaders(httpClient, httpMethod, new Uri(Url + path).AbsolutePath, "", "");

                var response = httpClient.GetAsync(Url + path);
                if (response.Result.StatusCode != HttpStatusCode.OK)
                {
                    string      jsonResponse = response.Result.Content.ReadAsStringAsync().Result;
                    ApiResponse apiResponse  = ApiResponse.Parse(jsonResponse);
                    throw new StructurizrClientException(apiResponse.Message);
                }

                string json = response.Result.Content.ReadAsStringAsync().Result;
                ArchiveWorkspace(workspaceId, json);

                if (EncryptionStrategy == null)
                {
                    JsonReader jsonReader = new JsonReader();
                    jsonReader.IdGenerator = IdGenerator;
                    return(jsonReader.Read(new StringReader(json)));
                }
                else
                {
                    EncryptedWorkspace encryptedWorkspace = new EncryptedJsonReader().Read(new StringReader(json));
                    if (encryptedWorkspace.EncryptionStrategy != null)
                    {
                        encryptedWorkspace.EncryptionStrategy.Passphrase = this.EncryptionStrategy.Passphrase;
                        return(encryptedWorkspace.Workspace);
                    }
                    else
                    {
                        // this workspace isn't encrypted, even though the client has an encryption strategy set
                        JsonReader jsonReader = new JsonReader();
                        jsonReader.IdGenerator = IdGenerator;
                        return(jsonReader.Read(new StringReader(json)));
                    }
                }
            }
        }