Stumps.Server.Data.DataAccess.StumpCreate C# (CSharp) Method

StumpCreate() public method

Creates a new T:Stumps.Server.Data.StumpEntity for an existing Stumps server.
/// is null. /// or /// is null. ///
public StumpCreate ( string serverId, StumpEntity entity, byte originalRequestBody, byte originalResponseBody, byte responseBody ) : StumpEntity
serverId string The unique identifier for the Stumps server.
entity StumpEntity The to persist.
originalRequestBody byte The array of bytes representing the original request's HTTP body.
originalResponseBody byte The array of bytes representing the original response's HTTP body.
responseBody byte The array of bytes returned as the HTTP body in response to the stump.
return StumpEntity
        public StumpEntity StumpCreate(string serverId, StumpEntity entity, byte[] originalRequestBody, byte[] originalResponseBody, byte[] responseBody)
        {
            if (string.IsNullOrWhiteSpace(serverId))
            {
                throw new ArgumentNullException("serverId");
            }

            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            var stumpsPath = Path.Combine(_storagePath, serverId, DataAccess.StumpsPathName);

            var stumpFileName = Path.Combine(stumpsPath, entity.StumpId + DataAccess.StumpFileExtension);
            var originalRequestFileName = entity.StumpId + DataAccess.OriginalRequestBodyFileExtension;
            var originalResponseFileName = entity.StumpId + DataAccess.OriginalResponseBodyFileExtension;
            var responseFileName = entity.StumpId + DataAccess.ResponseBodyFileExtension;

            if (originalRequestBody != null && originalRequestBody.Length > 0)
            {
                entity.OriginalRequest.BodyResourceName = originalRequestFileName;

                var file = Path.Combine(stumpsPath, originalRequestFileName);
                File.WriteAllBytes(file, originalRequestBody);
            }

            if (originalResponseBody != null && originalResponseBody.Length > 0)
            {
                entity.OriginalResponse.BodyResourceName = originalResponseFileName;

                var file = Path.Combine(stumpsPath, originalResponseFileName);
                File.WriteAllBytes(file, originalResponseBody);
            }

            if (responseBody != null && responseBody.Length > 0)
            {
                entity.Response.BodyResourceName = responseFileName;

                var file = Path.Combine(stumpsPath, responseFileName);
                File.WriteAllBytes(file, responseBody);
            }

            JsonUtility.SerializeToFile(entity, stumpFileName);

            return entity;
        }