|
// Written by Shai Raiten: http://blogs.microsoft.co.il/blogs/shair/
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using KinectReception.Enums;
using KinectReception.Objects;
using KinectReception.Helpers;
using Microsoft.Research.Kinect.Nui;
using System.ComponentModel;
namespace KinectReception.Managers
{
public class AuthenticManager : INotifyPropertyChanged
{
public delegate void IsAuthenticHandler(int score, string result);
public event IsAuthenticHandler IsAuthentic;
private ObservableCollection<RuleObject> _rules;
private int _goal;
private int _score = 0;
public int Score
{
get { return _score; }
set
{
if (value == this._score) return;
_score = value;
NotifyPropertyChanged("Score");
}
}
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public AuthenticManager()
{
_rules = ConfigurationManager.Load();
_goal = Properties.Settings.Default.Goal;
}
public void ChecksForAuthentic(JointsCollection joints)
{
if (_rules.Count == 0) return;
var fixJoints =
joints.Cast<Joint>().Where(
joint => joint.Position.W >= 0.6f &&
joint.TrackingState == JointTrackingState.Tracked).ToList();
var sb = new StringBuilder();
for (var index = 0; index < _rules.Count; index++)
{
var rule = _rules[index];
var s = (from j in fixJoints.Where(joint => joint.ID == rule.Source) select j).
DefaultIfEmpty(new Joint() { TrackingState = JointTrackingState.NotTracked }).
Single();
var t = (from j in fixJoints.Where(joint => joint.ID == rule.Target) select j).
DefaultIfEmpty(new Joint() { TrackingState = JointTrackingState.NotTracked }).
Single();
if (s.TrackingState == JointTrackingState.NotTracked ||
t.TrackingState == JointTrackingState.NotTracked) break;
var sv = s.ToFloat(rule.SourceVector);
var tv = t.ToFloat(rule.TargetVector);
if (rule.Operator == Operators.Bigger && sv > tv)
{
Score = Score + rule.Score;
sb.AppendLine(string.Format("Bigger -> Source: {0}, Target:{1} , Vector:{2}",
rule.Source, rule.Target, rule.SourceVector));
}
else if (rule.Operator == Operators.Smaller && sv < tv)
{
Score = Score + rule.Score;
sb.AppendLine(string.Format("Smaller -> Source: {0}, Target:{1} , Vector:{2}",
rule.Source, rule.Target, rule.SourceVector));
}
}
if (Score >= _goal)
IsAuthentic(Score, sb.ToString());
}
public void Reset()
{
_goal = Properties.Settings.Default.Goal;
_rules = ConfigurationManager.Load();
Score = 0;
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Shai Raiten is VS ALM MVP, currently working for Sela Group as a ALM senior consultant and trainer specializes in Microsoft technologies especially Team System and .NET technology. He is currently consulting in various enterprises in Israel, planning and analysis Load and performance problems using Team System, building Team System customizations and adjusts ALM processes for enterprises. Shai is known as one of the top Team System experts in Israel. He conducts lectures and workshops for developers\QA and enterprises who want to specialize in Team System.
My Blog: http://blogs.microsoft.co.il/blogs/shair/