Example #1
0
 /// <summary>
 /// Validate that the GUID in the <see cref="Calibration"/> instance that refers to the calibration
 /// image set matches the GUID in the <see cref="ImageSetBlob"/> that contains the iamges.
 /// An exception is throw if they do not match.
 /// If they match, the method simply returns.
 /// </summary>
 /// <param name="calibration">a <see cref="Calibration"/> instance that contains all the properties
 ///		of the calibration</param>
 /// <param name="calibrationImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
 ///		image set and the GUID that identifies the set</param>
 /// <exception cref="InvalidArgumentException">if the GUIDs do not match as required</exception>
 private static void ValidateGuids(Calibration calibration, ImageSetBlob calibrationImageSet)
 {
     if (calibration.ImageSetGuid != calibrationImageSet.Guid)
     {
         throw new InvalidArgumentException("Two GUIDs for the calibration and its image set do not match");
     }
 }
Example #2
0
        /// <summary>
        /// <para>
        /// Add an image set to the server's central database.
        /// The image set is specified as a <see cref="ImageSetBlob"/> instance which provides a
        /// way to retrieve the binary data for the images and the GUID that uniquely identifies
        /// the image set.
        /// </para><para>
        /// This method will first invoke the <see cref="GetId"/> method to determine if an image
        /// set with the GUID in the <code>ImageSetBlob</code> already exists in the central
        /// database.
        /// If it exists, the database's ID for the image set will be returned and the upload of
        /// the binary data will not be done.
        /// If it doesn't exist, the upload will proceed.
        /// The binary data for the images is large, so there is no need to upload it if the image
        /// set is already present in the database.
        /// </para>
        /// </summary>
        /// <param name="imageSet">an <see cref="ImageSetBlob"/> instance that contains the image
        ///		set to add</param>
        /// <returns>a long containing the ID of the image set on the server</returns>
        /// <exception cref="HttpInvocationException">thrown when any HTTP status code other than
        ///		200 is returned by the server; fields in the exception hold the status code and
        ///		error message returned</exception>
        /// <exception cref="InvocationException">thrown when an error occurs invoking the service
        ///		on the server, prior to the service running</exception>
        /// <exception cref="MalformedUriException">thrown when a valid URI cannot be constructed
        ///		from the base URI and additional relative path</exception>
        public long Add(ImageSetBlob imageSet)
        {
            // See if the image set is already on the server. Exception will result if it isn't.
            try
            {
                return(GetId(imageSet.Guid));
            }
            catch (HttpInvocationException e)
            {
                // If any exception except "not found" occurred, re-throw it. Otherwise, continue below.
                if (e.StatusCode != HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            // Get here if the image set isn't on the server. Get the stream for reading the image set
            // and build the request. A checksum is computed over the image set data and provided as a
            // parameter along with the GUID.
            Stream         imageStream = imageSet.GetReadStream();
            HttpWebRequest request     = GetRequest("POST", string.Format("/guid={0}/checksum={1}", imageSet.Guid, Checksum.Compute(imageStream)));

            // Checksum calculation read the stream. Seek back to the beginning to send it.
            imageStream.Seek(0, SeekOrigin.Begin);

            try
            {
                // Configure request with data size and type.
                request.ContentLength = imageStream.Length;
                request.ContentType   = "application/octet-stream";

                // Send the image set data by copying it to the request's stream.
                using (Stream requestStream = request.GetRequestStream())
                    imageStream.CopyTo(requestStream);

                // Get the server's response and return it.
                return(GetResponse(request, GetResponse <long>));
            }
            catch (InvocationException)
            {
                // Any InvocationException exception is just re-thrown.
                throw;
            }
            catch (Exception e)
            {
                // Most likely I/O error. All others are programming issues.
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(string.Format("Error writing request Content: {0}, POST method, likely I/O error", request.RequestUri), e);
                }

                throw new InvocationException("Request transmission error", e);
            }
        }
Example #3
0
        /// <summary>
        /// <para>
        /// Add a treatment to the central database.
        /// Use this method to add a treatment when the patient associated with the treatment has
        /// not be sent to the server but the calibration associated with the treatment has
        /// already been successfully sent to the server.
        /// </para><para>
        /// A treatment consists of a <see cref="Treatment"/> instance that defines the properties of
        /// the treatment record and two image sets, an energized image set and a finger image set.
        /// Each image set is encapsulated as an <see cref="ImageSetBlob"/> instance which provides a
        /// way to read the binary data of the image set and the GUID that identifies the image set.
        /// This method also accepts a <see cref="Patient"/> instance that defines the patient
        /// associated with the treatment.
        /// It will be sent to the server to create the patient record before the treatment is sent.
        /// </para><para>
        /// Before attempting to send a request to the server, this method will validate that the
        /// GUIDs in the <code>Treatment</code> instance that refer to the energized image set and
        /// the finger image set match the corresponding GUIDs in the <code>ImageSetBlob</code>s.
        /// It will also validate that the GUID in the <code>Treatment</code> that refers to the patient
        /// matches the GUID in the <code>Patient</code> instance.
        /// If the GUIDs do not match as expected, an exception is thrown.
        /// If they match, each of the image sets is sent to the server and then the treatment
        /// record is sent.
        /// </para>
        /// </summary>
        /// <param name="treatment">a <see cref="Treatment"/> instance that contains all the properties
        ///		that define the treatment</param>
        /// <param name="patient">a <see cref="Patient"/> instance that contains all the properties
        ///		that define the patient</param>
        /// <param name="energizedImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		energized image set and the GUID that identifies the set</param>
        /// <param name="fingerImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		finger image set and the GUID that identifies the set</param>
        /// <returns>the ID of the treatment record from the server's database</returns>
        /// <exception cref="InvalidArgumentException">if either of the sets of GUIDs do not match as
        ///		required</exception>
        /// <exception cref="HttpInvocationException">when any HTTP status code other than 200 (OK)
        ///		is returned by the server; fields in the exception hold the status code and error
        ///		message returned</exception>
        /// <exception cref="InvocationException">when an error occurs invoking the service on the
        ///		server, prior to the service running</exception>
        /// <exception cref="MalformedUriException">thrown when a valid URI cannot be constructed from
        ///		the base URI and additional relative path</exception>
        public long Add(Treatment treatment, Patient patient, ImageSetBlob energizedImageSet, ImageSetBlob fingerImageSet)
        {
            ValidateGuids(treatment, patient);
            ValidateGuids(treatment, energizedImageSet, fingerImageSet);

            PatientService patientService = Gateway.GetService <PatientService>();

            patientService.Add(patient);

            return(Add(treatment, energizedImageSet, fingerImageSet));
        }
Example #4
0
        /// <summary>
        /// <para>
        /// Add a treatment to the central database.
        /// Use this method to add a treatment when the calibration associated with the treatment has
        /// not be sent to the server but the patient associated with the treatment has already been
        /// successfully sent to the server.
        /// </para><para>
        /// A treatment consists of a <see cref="Treatment"/> instance that defines the properties of
        /// the treatment record and two image sets, an energized image set and a finger image set.
        /// Each image set is encapsulated as an <see cref="ImageSetBlob"/> instance which provides a
        /// way to read the binary data of the image set and the GUID that identifies the image set.
        /// This method also accepts a <see cref="Calibration"/> instance that defines the calibration
        /// associated with the treatment.
        /// It will be sent to the server to create the calibration record before the treatment is sent.
        /// </para><para>
        /// Before attempting to send a request to the server, this method will validate that the
        /// GUIDs in the <code>Treatment</code> instance that refer to the energized image set and
        /// the finger image set match the corresponding GUIDs in the <code>ImageSetBlob</code>s.
        /// It will also validate that the GUID in the <code>Calibration</code> that refers to the
        /// calibration matches the GUID in the <code>Calibration</code> instance and that the GUID in
        /// the <see cref="Calibration"/> that refers to the calibration image set matches the GUID in
        /// the corresponding <code>ImageSetBlob</code> that contains the calibration image set.
        /// If the GUIDs do not match as expected, an exception is thrown.
        /// If they match, each of the image sets is sent to the server and then the treatment
        /// record is sent.
        /// </para>
        /// </summary>
        /// <param name="treatment">a <see cref="Treatment"/> instance that contains all the properties
        ///		that define the treatment</param>
        /// <param name="calibration">a <see cref="Calibration"/> instance that contains all the properties
        ///		of the calibration</param>
        /// <param name="calibrationImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		image set and the GUID that identifies the set</param>
        /// <param name="energizedImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		energized image set and the GUID that identifies the set</param>
        /// <param name="fingerImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		finger image set and the GUID that identifies the set</param>
        /// <returns>the ID of the treatment record from the server's database</returns>
        /// <exception cref="InvalidArgumentException">if either of the sets of GUIDs do not match as
        ///		required</exception>
        /// <exception cref="HttpInvocationException">when any HTTP status code other than 200 (OK)
        ///		is returned by the server; fields in the exception hold the status code and error
        ///		message returned</exception>
        /// <exception cref="InvocationException">when an error occurs invoking the service on the
        ///		server, prior to the service running</exception>
        /// <exception cref="MalformedUriException">thrown when a valid URI cannot be constructed from
        ///		the base URI and additional relative path</exception>
        public long Add(Treatment treatment, Calibration calibration, ImageSetBlob calibrationImageSet, ImageSetBlob energizedImageSet, ImageSetBlob fingerImageSet)
        {
            ValidateGuids(treatment, calibration);
            ValidateGuids(calibration, calibrationImageSet);
            ValidateGuids(treatment, energizedImageSet, fingerImageSet);

            CalibrationService calibrationService = Gateway.GetService <CalibrationService>();

            calibrationService.Add(calibration, calibrationImageSet);

            return(Add(treatment, energizedImageSet, fingerImageSet));
        }
Example #5
0
        /// <summary>
        /// <para>
        /// Add a treatment to the central database.
        /// Use this method to add a treatment when the patient and calibration associated with the
        /// treatment have already been successfully sent to the server.
        /// </para><para>
        /// A treatment consists of a <see cref="Treatment"/> instance that defines the properties of
        /// the treatment record and two image sets, an energized image set and a finger image set.
        /// Each image set is encapsulated as an <see cref="ImageSetBlob"/> instance which provides a
        /// way to read the binary data of the image set and the GUID that identifies the image set.
        /// The finger image set is optional; if there is none, the input parameter will be null and
        /// the corresponding GUID parameter in the <code>Treatment</code> must be null.
        /// </para><para>
        /// Before attempting to send a request to the server, this method will validate that the
        /// GUIDs in the <code>Treatment</code> instance that refer to the energized image set and
        /// the finger image set match the corresponding GUIDs in the <code>ImageSetBlob</code>s.
        /// If the GUIDs do not match as expected, an exception is thrown.
        /// If they match, each of the image sets is sent to the server and then the treatment
        /// record is sent.
        /// </para>
        /// </summary>
        /// <param name="treatment">a <see cref="Treatment"/> instance that contains all the properties
        ///		that define the treatment</param>
        /// <param name="energizedImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		energized image set and the GUID that identifies the set</param>
        /// <param name="fingerImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		finger image set and the GUID that identifies the set</param>
        /// <returns>the ID of the treatment record from the server's database</returns>
        /// <exception cref="InvalidArgumentException">if either of the sets of GUIDs do not match as
        ///		required</exception>
        /// <exception cref="HttpInvocationException">when any HTTP status code other than 200 (OK)
        ///		is returned by the server; fields in the exception hold the status code and error
        ///		message returned</exception>
        /// <exception cref="InvocationException">when an error occurs invoking the service on the
        ///		server, prior to the service running</exception>
        /// <exception cref="MalformedUriException">thrown when a valid URI cannot be constructed from
        ///		the base URI and additional relative path</exception>
        public long Add(Treatment treatment, ImageSetBlob energizedImageSet, ImageSetBlob fingerImageSet)
        {
            ValidateGuids(treatment, energizedImageSet, fingerImageSet);

            ImageService imageService = Gateway.GetService <ImageService>();

            imageService.Add(energizedImageSet);
            if (fingerImageSet != null)
            {
                imageService.Add(fingerImageSet);
            }

            return(Invoke <Treatment, long>("POST", "/", treatment));
        }
Example #6
0
        /// <summary>
        /// <para>
        /// Validate that the GUIDs in the <see cref="Treatment"/> instance that refer to the
        /// energized and finger image sets match the GUIDs in the corresponding <see cref="ImageSetBlob"/>
        /// instances that containing the image sets.
        /// An exception will be thrown if the GUIDs do not match as expected.
        /// If they match, the method simply returns.
        /// </para><para>
        /// The finger image set is optional.
        /// If there is no finger image set, both the input <code>ImageSetBlob</code> for the finger
        /// image set and the corresponding GUID in the <code>Treatment</code> must be null.
        /// </para>
        /// </summary>
        /// <param name="treatment">a <see cref="Treatment"/> instance that contains all the properties
        ///		that define the treatment</param>
        /// <param name="energizedImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		energized image set and the GUID that identifies the set</param>
        /// <param name="fingerImageSet">an <see cref="ImageSetBlob"/> that contains the images of the
        ///		finger image set and the GUID that identifies the set</param>
        /// <exception cref="InvalidArgumentException">if either of the sets of GUIDs do not match as
        ///		required</exception>
        private static void ValidateGuids(Treatment treatment, ImageSetBlob energizedImageSet, ImageSetBlob fingerImageSet)
        {
            if (treatment.EnergizedImageSetGuid != energizedImageSet.Guid)
            {
                throw new InvalidArgumentException("Two GUIDs for the energized image set do not match");
            }

            if (fingerImageSet == null && treatment.FingerImageSetGuid == null)
            {
                return;
            }

            if (fingerImageSet == null || treatment.FingerImageSetGuid != fingerImageSet.Guid)
            {
                throw new InvalidArgumentException("Two GUIDs for the finger image set do not match");
            }
        }
Example #7
0
        /// <summary>
        /// <para>
        /// Add a calibration record to the central database.
        /// The calibration is defined by a <see cref="Calibration"/> instance which contains a
        /// GUID reference to an image set containing the set of images for the calibration.
        /// That set of images must be provided as an <see cref="ImageSetBlob"/> to this method.
        /// The GUIDs in the <code>ImageSetBlob</code> and the <code>Calibration</code> must match.
        /// </para><para>
        /// The image set will be uploaded to the server first.
        /// If that operation is successful, the <code>Calibration</code> will then be sent to the
        /// server.
        /// All failures result in an exception being thrown.
        /// </para>
        /// </summary>
        /// <param name="calibration">a <see cref="Calibration"/> instance that specifies the
        ///		calibration</param>
        /// <param name="calibrationImageSet">an <see cref="ImageSetBlob"/> that contains the set
        ///		of images for the calibration</param>
        /// <returns>a long containing the ID of the calibration on the server</returns>
        /// <exception cref="HttpInvocationException">thrown when any HTTP status code other than
        ///		200 is returned by the server; fields in the exception hold the status code and
        ///		error message returned</exception>
        /// <exception cref="InvocationException">thrown when an error occurs invoking the service
        ///		on the server, prior to the service running</exception>
        /// <exception cref="MalformedUriException">thrown when a valid URI cannot be constructed
        ///		from the base URI and additional relative path</exception>
        /// <exception cref="InvalidArgumentException">thrown when the GUID of the image set in the
        ///		<code>ImageSetBlob</code> does not match the GUID reference to the image set in the
        ///		<code>Calibration</code></exception>
        public long Add(Calibration calibration, ImageSetBlob calibrationImageSet)
        {
            // Be sure the GUID in the calibration references the image set provided.
            if (calibration.ImageSetGuid != calibrationImageSet.Guid)
            {
                throw new InvalidArgumentException("Two GUIDs for the image set do not match");
            }

            // First, upload the image set using the image service.
            ImageService imageService = Gateway.GetService <ImageService>();

            imageService.Add(calibrationImageSet);

            // Second, send the calibration. The service will return a Calibration; just return the
            // ID of the record on the server.
            calibration = Invoke <Calibration, Calibration>("POST", "/", calibration);
            return(calibration.CalibrationId);
        }