/// <summary>
        /// Clones this object
        /// </summary>
        /// <remarks>This is a shallow clone, avoiding copying the image data</remarks>
        /// <returns>A shallow clone of this object</returns>
        public object Clone()
        {
            var clone = new WebCamSensorState();

            this.CopyTo(clone);
            return(clone);
        }
        /// <summary>
        /// Helper function for the Replace message.
        /// This posts a replace message to the port.
        /// </summary>
        /// <param name="state">The state to replace.</param>
        /// <returns>The response port for the replace message.</returns>
        public DsspResponsePort <DefaultReplaceResponseType> Replace(WebCamSensorState state)
        {
            var replace = new Replace(state);

            Post(replace);

            return(replace.ResponsePort);
        }
        /// <summary>
        /// Provides a standard implementation of HttpGet
        /// </summary>
        /// <param name="get">The HttpGet message to process</param>
        /// <param name="state">The webcam state</param>
        /// <param name="transform">The embedded resource to use as the XSLT transform</param>
        public void HttpGetHelper(HttpGet get, WebCamSensorState state, string transform)
        {
            var copy = state.Clone() as WebCamSensorState;

            copy.Data = null;

            get.ResponsePort.Post(
                new HttpResponseType(
                    HttpStatusCode.OK,
                    copy,
                    transform));
        }
        /// <summary>
        /// Initialize webcam state.
        /// </summary>
        private void DoInitializeWebcamAlternate()
        {
            this.cachedProcessedFrames.VisibleImage =
                new byte[this.kinectSensor.ColorStream.FrameWidth * this.kinectSensor.ColorStream.FrameHeight
                         * 3];

            this.webCamState = new webcam.WebCamSensorState
            {
                DeviceName = "Kinect",
                Width      = this.kinectSensor.ColorStream.FrameWidth,
                Height     = this.kinectSensor.ColorStream.FrameHeight
            };

            this.utilitiesPort = DsspHttpUtilitiesService.Create(Environment);
        }
 /// <summary>
 /// Initializing constructor
 /// </summary>
 /// <param name="body">The initial body value</param>
 public Replace(WebCamSensorState body)
     : base(body)
 {
 }
        /// <summary>
        /// Provides a standard implementation of HttpQuery
        /// </summary>
        /// <param name="query">The HttpQuery message to process</param>
        /// <param name="state">The webcam state</param>
        /// <param name="transform">The embedded resource to use as the XSLT transform</param>
        /// <param name="utilitiesPort">The utilities port used to stream images</param>
        /// <returns>Stanard CCR iterator</returns>
        public IEnumerator <ITask> HttpQueryHelper(HttpQuery query, WebCamSensorState state, string transform, DsspHttpUtilitiesPort utilitiesPort)
        {
            var type      = query.Body.Query[QueryType];
            var mediaType = string.Empty;
            var format    = default(sdi.ImageFormat);

            switch (type.ToLowerInvariant())
            {
            case Jpeg:
                format    = sdi.ImageFormat.Jpeg;
                mediaType = MediaTypeNames.Image.Jpeg;
                break;

            case Gif:
                format    = sdi.ImageFormat.Gif;
                mediaType = MediaTypeNames.Image.Gif;
                break;

            case Png:
                format    = sdi.ImageFormat.Png;
                mediaType = MediaPng;
                break;

            case Bmp:
                format    = sdi.ImageFormat.Bmp;
                mediaType = MediaBmp;
                break;

            default:
                var copy = state.Clone() as WebCamSensorState;
                copy.Data = null;

                query.ResponsePort.Post(
                    new HttpResponseType(
                        HttpStatusCode.OK,
                        copy,
                        transform));
                yield break;
            }

            if (state.Data == null || state.Data.Length == 0)
            {
                query.ResponsePort.Post(
                    new HttpResponseType(
                        HttpStatusCode.OK,
                        state,
                        transform));
                yield break;
            }

            using (var image = state.Bitmap)
            {
                using (var mem = new MemoryStream())
                {
                    image.Save(mem, format);
                    mem.Position = 0;

                    var response = new WriteResponseFromStream(
                        query.Body.Context,
                        mem,
                        mediaType);

                    utilitiesPort.Post(response);

                    yield return(response.ResultPort.Choice());
                }
            }
        }