Example #1
0
 /// <summary>
 /// Raises the RemoteUnitTypeChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnRemoteUnitTypeChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.RemoteUnitTypeChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #2
0
 /// <summary>
 /// Raises the PositiveFlowInChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnPositiveFlowInChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.PositiveFlowInChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #3
0
 /// <summary>
 /// Raises the TargetElementChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnTargetElementChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.TargetElementChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #4
0
 /// <summary>
 /// Raises the PowerSystemResourceChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnPowerSystemResourceChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.PowerSystemResourceChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #5
0
 /// <summary>
 /// Raises the SwitchControlChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnSwitchControlChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.SwitchControlChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #6
0
 /// <summary>
 /// Raises the AccumulatorChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnAccumulatorChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler<ValueChangedEventArgs> handler = this.AccumulatorChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #7
0
 /// <summary>
 /// Raises the PointOfReceiptForChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnPointOfReceiptForChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.PointOfReceiptForChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #8
0
 /// <summary>
 /// Raises the CogenerationPlantChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnCogenerationPlantChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.CogenerationPlantChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #9
0
 /// <summary>
 /// Raises the ParallelPathFlagChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnParallelPathFlagChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.ParallelPathFlagChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #10
0
 /// <summary>
 /// Raises the TotalTransferCapabilityChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnTotalTransferCapabilityChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.TotalTransferCapabilityChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #11
0
 /// <summary>
 /// Raises the TreeForZeroChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnTreeForZeroChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.TreeForZeroChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #12
0
 /// <summary>
 /// Raises the GeneratingUnitChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnGeneratingUnitChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.GeneratingUnitChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #13
0
 /// <summary>
 /// Raises the IsNetGrossPChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnIsNetGrossPChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.IsNetGrossPChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #14
0
 /// <summary>
 /// Raises the WorkEquipmentAssetChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnWorkEquipmentAssetChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.WorkEquipmentAssetChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #15
0
 /// <summary>
 /// Raises the SPAccountingFunctionChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnSPAccountingFunctionChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.SPAccountingFunctionChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #16
0
 /// <summary>
 /// Raises the FixedPortionChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnFixedPortionChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.FixedPortionChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #17
0
 /// <summary>
 /// Raises the EContainingClassChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnEContainingClassChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.EContainingClassChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #18
0
 /// <summary>
 /// Raises the ControlledByChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnControlledByChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.ControlledByChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #19
0
 /// <summary>
 /// Raises the DeclaringTypeChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnDeclaringTypeChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.DeclaringTypeChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #20
0
 /// <summary>
 /// Raises the ApplicationChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnApplicationChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.ApplicationChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #21
0
 /// <summary>
 /// Raises the ConductingEquipmentChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnConductingEquipmentChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.ConductingEquipmentChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #22
0
 /// <summary>
 /// Raises the MicroplateChanged event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnMicroplateChanged(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.MicroplateChanged;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
Example #23
0
 /// <summary>
 /// Raises the MovedElementChanging event
 /// </summary>
 /// <param name="eventArgs">The event data</param>
 protected virtual void OnMovedElementChanging(ValueChangedEventArgs eventArgs)
 {
     System.EventHandler <ValueChangedEventArgs> handler = this.MovedElementChanging;
     if ((handler != null))
     {
         handler.Invoke(this, eventArgs);
     }
 }
 private void OnQueryCompleted(object state)
 {
     System.EventHandler <QueryCompletedEventArgs> handler = this.QueryCompleted;
     if ((handler != null))
     {
         InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
         handler(this, new QueryCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
     }
 }
Example #25
0
 /// <summary>
 /// 填充接收/发送对象实例
 /// </summary>
 public void FillSendAndRecvAsyncData(System.EventHandler <SocketAsyncEventArgs> eventHandler)
 {
     sendEventArg = new SocketAsyncEventArgs();
     sendEventArg.SetBuffer(sendBuff, 0, bufferSize);
     sendEventArg.Completed += eventHandler;
     recvEventArg            = new SocketAsyncEventArgs();
     recvEventArg.SetBuffer(recvBuff, 0, bufferSize);
     recvEventArg.Completed += eventHandler;
 }
Example #26
0
        public static void Raise <T>(this System.EventHandler <T> evento, object sender, T args) where T : EventArgs
        {
            var handler = evento;

            if (handler != null)
            {
                handler(sender, args);
            }
        }
Example #27
0
        private void CollectData()
        {
            double previousTime = GetUnixTimestampForNow();
            double elapsedTime  = 0;

            double startTime = 0;
            double endTime   = 0;

            int numFixations = 0;

            double lastFixationStartTime      = 0;
            double fixationLengthRunningTotal = 0;

            // Increment the number of fixations each time we receive data from the eye tracker.
            fixationDataStream = eyeXHost.CreateFixationDataStream(FixationDataMode.Sensitive);
            System.EventHandler <FixationEventArgs> inc = delegate(object s, FixationEventArgs e) {
                if (e.EventType == FixationDataEventType.Begin)
                {
                    numFixations++;
                    lastFixationStartTime = e.Timestamp;
                }
                if (e.EventType == FixationDataEventType.End)
                {
                    fixationLengthRunningTotal += e.Timestamp - lastFixationStartTime;
                }
            };

            fixationDataStream.Next += inc;

            // Keep collecting the data until we tell it not to.
            while (!shouldEndCollection)
            {
                if (elapsedTime < instanceLength)
                {
                    elapsedTime += GetUnixTimestampForNow() - previousTime;
                    previousTime = GetUnixTimestampForNow();
                }
                else
                {
                    endTime = GetUnixTimestampForNow();
                    double fixationsPerSecond   = numFixations / (instanceLength / 1000);
                    double meanLengthOfFixation = fixationLengthRunningTotal / numFixations;

                    Instance instance = new Instance(startTime, endTime, numFixations, fixationsPerSecond, meanLengthOfFixation, instanceClass);
                    collectedInstances.Add(instance);

                    startTime    = GetUnixTimestampForNow();
                    numFixations = 0;
                    fixationLengthRunningTotal = 0;

                    elapsedTime  = 0;
                    previousTime = GetUnixTimestampForNow();
                }
            }
        }
 /// <summary>
 /// Check if Remote Config has fetched successfully. If yes, return callback immediately, else add in to delegate to wait for callback
 /// </summary>
 public static void CheckAndHandleFetchConfig(System.EventHandler <bool> callback)
 {
     if (initSuccess.HasValue)
     {
         callback(null, InitSuccessValue);
     }
     else
     {
         onFetchComplete += callback;
     }
 }
Example #29
0
        public bool RequestShowRewardVideo(System.Action <Reward> rewardCallback, System.Action <string> timeoutCallback, float _timeoutSeconds = 5.0f)
        {
            this.RewardVideoRequestInit();

            if (this.onRewardEventList == null)
            {
                this.onRewardEventList = new List <EventHandler <Reward> > ();
            }

            foreach (var item in this.onRewardEventList)
            {
                this.rewardBasedVideo.OnAdRewarded -= item;
            }
            this.onRewardEventList.Clear();

            System.EventHandler <Reward> _rewardCallback = (object sender, Reward e) =>
            {
                rewardCallback(e);
            };

            this.rewardBasedVideo.OnAdRewarded += _rewardCallback;
            this.onRewardEventList.Add(_rewardCallback);

            float _startTime = Time.realtimeSinceStartup;
            bool  _isLoaded  = false;
            bool  _isTimeout = false;

            _isLoaded  = this.rewardBasedVideo.IsLoaded();
            _isTimeout = (Time.realtimeSinceStartup - _startTime) > _timeoutSeconds;

            while (true)
            {
                _isLoaded  = this.rewardBasedVideo.IsLoaded();
                _isTimeout = (Time.realtimeSinceStartup - _startTime) > _timeoutSeconds;

                if (_isLoaded || _isTimeout)
                {
                    break;
                }
            }

            if (_isLoaded)
            {
                Debug.Log("rewardBasedVideo _isLoaded");
                this.rewardBasedVideo.Show();
                return(true);
            }
            else
            {
                timeoutCallback("Reward video loading time out");
                return(false);
            }
        }
Example #30
0
 protected override bool Dispose(bool explicitDispose)
 {
     if (!base.Dispose(explicitDispose))
     {
         return(false);
     }
     if (explicitDispose)
     {
         _Handler = null;
     }
     return(true);
 }
        public void testConstructor()
        {
            EventHandler<IgraphGenerateEvent> handler = new System.EventHandler<IgraphGenerateEvent>(this.gen_graph_call_back);
            EventHandler<statusEventHandler> handler2 = new System.EventHandler<statusEventHandler>(this.get_network_call_back);
            DB_Manager db = new DB_Manager("networkvis");
            NetworkID UI_1 = new NetworkID(db, handler);
            GenerateGraph UI_2 = new GenerateGraph(db, handler);
            AskNetWorkID UI_3 = new AskNetWorkID(handler2);

            Assert.AreEqual(true, UI_1 != null);
            Assert.AreEqual(true, UI_2 != null);
            Assert.AreEqual(true, UI_3 != null);
        }
 private void ask_for_network()
 {
     EventHandler<statusEventHandler> handler = new System.EventHandler<statusEventHandler>(this.select_network);
     AskNetWorkID ask = new AskNetWorkID(handler);
     ask.ShowDialog(this);
 }
        private void color(KinectSensor sensor, Image image)
        {
            {
                sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                var colorPixels = new byte[sensor.ColorStream.FramePixelDataLength];
                var colorBitmap = new WriteableBitmap(sensor.ColorStream.FrameWidth, sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                image.Source = colorBitmap;
                ColorReady = new System.EventHandler<ColorImageFrameReadyEventArgs>((o, arg) =>
                {
                    using (ColorImageFrame colorFrame = arg.OpenColorImageFrame())
                    {
                        if (colorFrame != null)
                        {
                            // Copy the pixel data from the image to a temporary array
                            colorFrame.CopyPixelDataTo(colorPixels);
                            // Write the pixel data into our bitmap
                            colorBitmap.WritePixels(
                                new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                                colorPixels,
                                colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
                                0);
                        }
                    }
                });
                sensor.ColorFrameReady += ColorReady;
            }

            {
                sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);

                // Allocate space to put the depth pixels we'll receive
                var depthPixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];
                var colorPixels = new byte[sensor.DepthStream.FramePixelDataLength * sizeof(int)];
                var colorPoints = new ColorImagePoint[640 * 480];
                var colorBitmap = new WriteableBitmap(sensor.DepthStream.FrameWidth, sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

                var drawingGroup = new DrawingGroup();
                var imageSource = new DrawingImage(drawingGroup);
                DisplayAxes.Source = imageSource;

                DisplayHelp.Source = colorBitmap;
                DepthReady = (o, arg) =>
                {
                    using (DepthImageFrame frame = arg.OpenDepthImageFrame())
                    {
                        if (frame != null)
                        {
                            frame.CopyDepthImagePixelDataTo(depthPixels);
                            sensor.CoordinateMapper.MapDepthFrameToColorFrame(DepthImageFormat.Resolution640x480Fps30, depthPixels, ColorImageFormat.RgbResolution640x480Fps30, colorPoints);
                            Array.Clear(colorPixels, 0, colorPixels.Length);
                            for (var i = 0; i < depthPixels.Length; i++)
                            {
                                    var cp = colorPoints[i];
                                    var idx = (cp.X + cp.Y * 640) * 4;

                                    if (idx + 3 < colorPixels.Length)
                                    {
                                        if (depthPixels[i].IsKnownDepth)
                                        {
                                            colorPixels[idx] = 0;
                                            colorPixels[idx + 1] = 0;
                                            colorPixels[idx + 2] = 0;
                                        }
                                        else
                                        {
                                            colorPixels[idx] = 0;
                                            colorPixels[idx + 1] = 0;
                                            colorPixels[idx + 2] = 150;
                                        }
                                    }

                            }
                            // Write the pixel data into our bitmap
                            colorBitmap.WritePixels(
                                new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                                colorPixels,
                                colorBitmap.PixelWidth * sizeof(int),
                                0);

                            if (pRed != null)
                            {
                                var idx = FindDepthIndex(colorPoints, pRed);
                                dRed = FindDepth(sensor, depthPixels, pRed, idx);
                            }
                            if (pBlue != null)
                            {
                                var idx = FindDepthIndex(colorPoints, pBlue);
                                dBlue = FindDepth(sensor, depthPixels, pBlue, idx);
                            }
                            if (pYellow != null)
                            {
                                var idx = FindDepthIndex(colorPoints, pYellow);
                                dYellow = FindDepth(sensor, depthPixels, pYellow, idx);
                            }
                            ColorToggle(Pred, pRed, dRed);
                            ColorToggle(Pblue, pBlue, dBlue);
                            ColorToggle(Pyellow, pYellow, dYellow);
                            IsValid = false;
                            if (dBlue.HasValue && dRed.HasValue && dYellow.HasValue)
                                computeTransform();
                            using (var dc = drawingGroup.Open())
                            {
                                drawAxes(sensor, dc);
                            }
                        }
                    }
                };
                sensor.DepthFrameReady += DepthReady;
            }
        }
 private void generateFromDBToolStripMenuItem_Click(object sender, EventArgs e)
 {
     EventHandler<IgraphGenerateEvent> handler = new System.EventHandler<IgraphGenerateEvent>(this.SetAndShowGraph);
     DB_Manager dbm = new DB_Manager("networkvis");
     GenerateGraph genGraph = new GenerateGraph(dbm, handler);
     genGraph.Show(this);
 }
 private void loadFromDBToolStripMenuItem_Click(object sender, EventArgs e)
 {
     EventHandler<IgraphGenerateEvent> handler = new System.EventHandler<IgraphGenerateEvent>(this.SetAndShowGraph);
     DB_Manager dbm = new DB_Manager("networkvis");
     NetworkID nid = new NetworkID(dbm, handler);
     nid.Show(this);
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var sensors = KinectSensor.KinectSensors.Where(row => row.Status == KinectStatus.Connected);
            var sensor = sensors.FirstOrDefault();
            if (sensor == null)
                return;
            Action clean = null;
            sensor.Start();
            Action setDepth = () =>
                {
                    DepthImagePixel[] depthPixels;
                    byte[] colorPixels;
                    WriteableBitmap colorBitmap;
                    // Turn on the depth stream to receive depth frames
                    sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);

                    // Allocate space to put the depth pixels we'll receive
                    depthPixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];

                    // Allocate space to put the color pixels we'll create
                    colorPixels = new byte[sensor.DepthStream.FramePixelDataLength * sizeof(int)];

                    // This is the bitmap we'll display on-screen
                    colorBitmap = new WriteableBitmap(sensor.DepthStream.FrameWidth, sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

                    // Set the image we display to point to the bitmap where we'll put the image data
                    Image.Source = colorBitmap;

                    var ready = new System.EventHandler<DepthImageFrameReadyEventArgs>((o, arg) =>
                    {
                        using (DepthImageFrame depthFrame = arg.OpenDepthImageFrame())
                        {
                            if (depthFrame == null)
                                return;
                            // Copy the pixel data from the image to a temporary array
                            depthFrame.CopyDepthImagePixelDataTo(depthPixels);

                            // Get the min and max reliable depth for the current frame
                            int minDepth = depthFrame.MinDepth;
                            int maxDepth = depthFrame.MaxDepth;

                            // Convert the depth to RGB
                            int colorPixelIndex = 0;
                            for (int i = 0; i < depthPixels.Length; ++i)
                            {
                                // Get the depth for this pixel
                                short depth = depthPixels[i].Depth;

                                byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);

                                colorPixels[colorPixelIndex++] = intensity;

                                colorPixels[colorPixelIndex++] = intensity;

                                colorPixels[colorPixelIndex++] = intensity;

                                ++colorPixelIndex;
                            }

                            // Write the pixel data into our bitmap
                            colorBitmap.WritePixels(
                                new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                                colorPixels,
                                colorBitmap.PixelWidth * sizeof(int),
                                0);
                        }
                    });
                    sensor.DepthFrameReady += ready;
                    clean = () => sensor.DepthFrameReady -= ready;
                };
            Action setInfra = () =>
                {
                    sensor.ColorStream.Enable(ColorImageFormat.InfraredResolution640x480Fps30);
                    var colorPixels = new byte[sensor.ColorStream.FramePixelDataLength];
                    var colorBitmap = new WriteableBitmap(sensor.ColorStream.FrameWidth, sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Gray16, null);
                    Image.Source = colorBitmap;
                    var ready = new System.EventHandler<ColorImageFrameReadyEventArgs>((o, arg) =>
                    {
                        using (ColorImageFrame colorFrame = arg.OpenColorImageFrame())
                        {
                            if (colorFrame != null)
                            {
                                // Copy the pixel data from the image to a temporary array
                                colorFrame.CopyPixelDataTo(colorPixels);

                                // Write the pixel data into our bitmap
                                colorBitmap.WritePixels(
                                    new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                                    colorPixels,
                                    colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
                                    0);
                            }
                        }
                    });
                    sensor.ColorFrameReady += ready;
                    clean = () => sensor.ColorFrameReady -= ready;
                };
            Action setColor = () =>
            {
                sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                var colorPixels = new byte[sensor.ColorStream.FramePixelDataLength];
                var colorBitmap = new WriteableBitmap(sensor.ColorStream.FrameWidth, sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                Image.Source = colorBitmap;
                var ready = new System.EventHandler<ColorImageFrameReadyEventArgs>((o, arg) =>
                {
                    using (ColorImageFrame colorFrame = arg.OpenColorImageFrame())
                    {
                        if (colorFrame != null)
                        {
                            // Copy the pixel data from the image to a temporary array
                            colorFrame.CopyPixelDataTo(colorPixels);

                            // Write the pixel data into our bitmap
                            colorBitmap.WritePixels(
                                new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                                colorPixels,
                                colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
                                0);
                        }
                    }
                });
                sensor.ColorFrameReady += ready;
                clean = () => sensor.ColorFrameReady -= ready;
            };
            setColor();
            ColorButton.Click += (o, arg) =>
                {
                    if (clean != null)
                        clean();
                    setColor();
                };
            InfraButton.Click += (o, arg) =>
            {
                if (clean != null)
                    clean();
                setInfra();
            };
            DepthButton.Click += (o, arg) =>
            {
                if (clean != null)
                    clean();
                setDepth();
            };
            SaveButton.Click += (o, arg) =>
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.AddExtension = true;
                sfd.FileName = DateTime.Now.ToString("ddMMyyhhmmss");
                sfd.DefaultExt = "png";
                sfd.Filter = "Image files (*.png)|*.png";
                if (sfd.ShowDialog() == true)
                {
                    using (FileStream stream5 = new FileStream(sfd.FileName, FileMode.Create))
                    {
                        PngBitmapEncoder encoder5 = new PngBitmapEncoder();
                        encoder5.Frames.Add(BitmapFrame.Create((WriteableBitmap)Image.Source));
                        encoder5.Save(stream5);
                        stream5.Close();
                    }

                }
            };
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var sensors = KinectSensor.KinectSensors.Where(row => row.Status == KinectStatus.Connected);
            var sensor = sensors.FirstOrDefault();
                DepthImagePixel[] depthPixels;
            if (sensor == null)
                return;
            {
                byte[] colorPixels;
                WriteableBitmap colorBitmap;
                // Turn on the depth stream to receive depth frames
                sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);

                // Allocate space to put the depth pixels we'll receive
                depthPixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];

                // Allocate space to put the color pixels we'll create
                colorPixels = new byte[sensor.DepthStream.FramePixelDataLength * sizeof(int)];
                var colorPixelsRight = new byte[sensor.DepthStream.FramePixelDataLength * sizeof(int)];

                // This is the bitmap we'll display on-screen
                colorBitmap = new WriteableBitmap(sensor.DepthStream.FrameWidth, sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                var colorBitmapRight = new WriteableBitmap(sensor.DepthStream.FrameWidth, sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

                // Set the image we display to point to the bitmap where we'll put the image data
                BackImage.Source = colorBitmap;
                BackImageRight.Source = colorBitmapRight;
                var colorPoints = new ColorImagePoint[640 * 480];
                var depthPoints = new DepthImagePoint[640 * 480];

                var ready = new System.EventHandler<DepthImageFrameReadyEventArgs>((o, arg) =>
                {
                    using (DepthImageFrame depthFrame = arg.OpenDepthImageFrame())
                    {
                        if (depthFrame == null)
                            return;
                        // Copy the pixel data from the image to a temporary array
                        depthFrame.CopyDepthImagePixelDataTo(depthPixels);

                        // Get the min and max reliable depth for the current frame
                        int minDepth = depthFrame.MinDepth;
                        int maxDepth = depthFrame.MaxDepth;

                        sensor.CoordinateMapper.MapDepthFrameToColorFrame(DepthImageFormat.Resolution640x480Fps30, depthPixels, ColorImageFormat.RgbResolution640x480Fps30, colorPoints);

                        // Convert the depth to RGB
                        int colorPixelIndex = 0;
                        for (int i = 0; i < depthPixels.Length; ++i)
                        {
                            // Get the depth for this pixel
                            short depth = depthPixels[i].Depth;
                            var cp = colorPoints[i];
                            byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
                            var idx = (cp.X + cp.Y * 640) * 4;

                            if (idx + 3 < colorPixels.Length)
                            {
                                if (!depthPixels[i].IsKnownDepth)
                                {
                                    colorPixelsRight[idx] = 0;
                                    colorPixelsRight[idx + 1] = 0;
                                    colorPixelsRight[idx + 2] = 150;
                                }
                                else
                                {
                                    colorPixelsRight[idx] = intensity;
                                    colorPixelsRight[idx + 1] = intensity;
                                    colorPixelsRight[idx + 2] = intensity;
                                }
                            }
                            if (!depthPixels[i].IsKnownDepth)
                            {
                                colorPixels[colorPixelIndex++] = 0;
                                colorPixels[colorPixelIndex++] = 0;
                                colorPixels[colorPixelIndex++] = 150;
                            }
                            else
                            {
                                colorPixels[colorPixelIndex++] = intensity;
                                colorPixels[colorPixelIndex++] = intensity;
                                colorPixels[colorPixelIndex++] = intensity;
                            }

                            ++colorPixelIndex;
                        }

                        // Write the pixel data into our bitmap
                        colorBitmap.WritePixels(
                            new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                            colorPixels,
                            colorBitmap.PixelWidth * sizeof(int),
                            0);
                        colorBitmapRight.WritePixels(
                            new Int32Rect(0, 0, colorBitmapRight.PixelWidth, colorBitmapRight.PixelHeight),
                            colorPixelsRight,
                            colorBitmapRight.PixelWidth * sizeof(int),
                            0);
                    }
                });
                sensor.DepthFrameReady += ready;
            }

            {
                sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                var colorPixels = new byte[sensor.ColorStream.FramePixelDataLength];
                var colorBitmap = new WriteableBitmap(sensor.ColorStream.FrameWidth, sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                var colorBitmapRight = new WriteableBitmap(sensor.ColorStream.FrameWidth, sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                ForeImage.Source = colorBitmap;
                ForeImageRight.Source = colorBitmapRight;
                var ready = new System.EventHandler<ColorImageFrameReadyEventArgs>((o, arg) =>
                {
                    using (ColorImageFrame colorFrame = arg.OpenColorImageFrame())
                    {
                        if (colorFrame != null)
                        {
                            // Copy the pixel data from the image to a temporary array
                            colorFrame.CopyPixelDataTo(colorPixels);
                            // Write the pixel data into our bitmap
                            colorBitmap.WritePixels(
                                new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                                colorPixels,
                                colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
                                0);
                            colorBitmapRight.WritePixels(
                                 new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
                                 colorPixels,
                                 colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
                                 0);
                        }
                    }
                });
                sensor.ColorFrameReady += ready;
            }
            sensor.Start();
        }