Beispiel #1
0
        void onPointingUpdatedAsynch(PointingRelationEventArgs args)
        {
            if (!this.stopRecording)
            {
                if (args != null && args.DefaultPointer != null && args.DefaultPointer.DisplayPoint != null && args.DefaultPointer.PointsAt)
                {
                    //lock (listLock)
                    //{
                    //    queue.Enqueue(args);
                    //    Monitor.Pulse(listLock);
                    //}

                    /*using (FileStream stream = new FileStream(this.output, FileMode.Append))
                     * {
                     *   using (BinaryWriter writer = new BinaryWriter(stream))
                     *   {
                     *       //header
                     *       writer.Write(1);
                     *       writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceA).FullName)));
                     *       writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceB).FullName)));
                     *       writer.Write((DateTime.Now - startTime).TotalSeconds);
                     *       //writer.Write(DateTime.Now.ToString() + '|');
                     *
                     *       //content
                     *       writer.Write(args.DefaultPointer.Distance);
                     *       writer.Write(args.DefaultPointer.DisplayPoint.X);
                     *       writer.Write(args.DefaultPointer.DisplayPoint.Y);
                     *       writer.Write(args.DefaultPointer.Intersection.X);
                     *       writer.Write(args.DefaultPointer.Intersection.Y);
                     *       writer.Write(args.DefaultPointer.Intersection.Z);
                     *       writer.Write(args.DefaultPointer.IsTouching);
                     *       writer.Write(args.DefaultPointer.PointsAt);
                     *       writer.Write(args.DefaultPointer.PointsToward);
                     *   }
                     * }*/

                    this.array.Add(args);
                    this.times.Add((DateTime.Now - startTime).TotalSeconds);
                }
            }
        }
Beispiel #2
0
        private void ConsumerJob()
        {
            /*while (true)
             * {
             *  lock (listLock)
             *  {
             *      Object o = null;
             *
             *      if (!queue.TryDequeue(out o))
             *      {
             *          Console.WriteLine("No object to dequeue, waiting...");
             *
             *          if (this.stopRecording)
             *          {
             *              this.relationsList.Clear();
             *
             *              foreach (RelationPair temp in relations)
             *              {
             *                  temp.OnPointingUpdatedAsynch -= onPointingUpdatedAsynch;
             *                  temp.OnLocationUpdatedAsynch -= onLocationUpdatedAsynch;
             *                  temp.OnMotionUpdatedAsynch -= onMotionUpdatedAsynch;
             *                  temp.OnDirectionUpdatedAsynch-= onDirectionUpdatedAsynch;
             *              }
             *
             *              relations.Clear();
             *
             *              System.Windows.Application.Current.Dispatcher.Invoke(new System.Action(() => {
             *                  this.recording.Hide();
             *                  this.recording.label1.Content = "Recording...";
             *              }));
             *
             *              this.stopRecording = false;
             *          }
             *
             *          // Threads will wait here and only one will be released when .Pulse()d
             *          Monitor.Wait(listLock);
             *          o = queue.Take(1);
             *      }*/

            for (int x = 0; x < this.array.Count; x++)
            {
                var o = array[x];

                if (o != null)
                {
                    using (FileStream stream = new FileStream(this.output, FileMode.Append))
                    {
                        using (BinaryWriter writer = new BinaryWriter(stream))
                        {
                            if (o is PointingRelationEventArgs)
                            {
                                PointingRelationEventArgs args = (PointingRelationEventArgs)o;

                                //header
                                writer.Write(1);
                                writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceA).FullName)));
                                writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceB).FullName)));
                                writer.Write(this.times[x]);
                                //writer.Write(DateTime.Now.ToString("hh:mm:ss"));

                                //content
                                writer.Write(args.DefaultPointer.Distance);
                                writer.Write(args.DefaultPointer.DisplayPoint.X);
                                writer.Write(args.DefaultPointer.DisplayPoint.Y);
                                writer.Write(args.DefaultPointer.Intersection.X);
                                writer.Write(args.DefaultPointer.Intersection.Y);
                                writer.Write(args.DefaultPointer.Intersection.Z);
                                writer.Write(args.DefaultPointer.IsTouching);
                                writer.Write(args.DefaultPointer.PointsAt);
                                writer.Write(args.DefaultPointer.PointsToward);
                            }

                            if (o is DirectionRelationEventArgs)
                            {
                                DirectionRelationEventArgs args = (DirectionRelationEventArgs)o;

                                //header
                                writer.Write(2);
                                writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceA).FullName)));
                                writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceB).FullName)));
                                writer.Write(this.times[x]);
                                //writer.Write(DateTime.Now.ToString() + '|');

                                //content
                                writer.Write(args.PresenceA.Location.X);
                                writer.Write(args.PresenceA.Location.Y);
                                writer.Write(args.PresenceA.Location.Z);
                                writer.Write(args.PresenceB.Location.X);
                                writer.Write(args.PresenceB.Location.Y);
                                writer.Write(args.PresenceB.Location.Z);
                                writer.Write(args.AFromB);
                                writer.Write(args.BFromA);
                                writer.Write(args.ATowardsB);
                                writer.Write(args.BTowardsA);
                                writer.Write(args.Parallel);
                                writer.Write(args.Purpendicular);
                            }

                            if (o is LocationRelationEventArgs)
                            {
                                LocationRelationEventArgs args = (LocationRelationEventArgs)o;

                                //header
                                writer.Write(3);
                                writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceA).FullName)));
                                writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceB).FullName)));
                                writer.Write(this.times[x]);
                                //writer.Write(DateTime.Now.ToString("hh:mm:ss"));

                                //content
                                writer.Write(args.PresenceA.Location.X);
                                writer.Write(args.PresenceA.Location.Y);
                                writer.Write(args.PresenceA.Location.Z);
                                writer.Write(args.PresenceB.Location.X);
                                writer.Write(args.PresenceB.Location.Y);
                                writer.Write(args.PresenceB.Location.Z);
                                writer.Write(args.Distance);
                                writer.Write(args.AFromB);
                                writer.Write(args.BFromA);
                                writer.Write(args.ATowardsB);
                                writer.Write(args.BTowardsA);
                                writer.Write(args.IsAMoving);
                                writer.Write(args.IsBMoving);
                                writer.Write(args.Parallel);
                                writer.Write(args.Purpendicular);
                            }

                            if (o is MotionRelationEventArgs)
                            {
                                MotionRelationEventArgs args = (MotionRelationEventArgs)o;

                                //header
                                writer.Write(4);
                                writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceA).FullName)));
                                writer.Write(this.entities.IndexOf(this.truncate(((PresenceBase)args.PresenceB).FullName)));
                                writer.Write(this.times[x]);
                                //writer.Write(DateTime.Now.ToString("hh:mm:ss"));

                                //content
                                writer.Write(args.IsAMoving);
                                writer.Write(args.IsBMoving);
                                writer.Write(args.VelocityDifference);
                                writer.Write(args.XAccelerationAgrees);
                                writer.Write(args.XVelocityAgrees);
                                writer.Write(args.YAccelerationAgrees);
                                writer.Write(args.YVelocAgrees);
                                writer.Write(args.ZAccelerationAgrees);
                                writer.Write(args.ZVelocAgrees);
                            }
                        }
                    }
                }
            }

            /*
             * }*/
        }