Exemple #1
0
        public void Execute()
        {
            if (trackingDataView.Points == null)
            {
                throw new Exception("Tracking data not found");
            }

            if (string.IsNullOrWhiteSpace(trackingDataView.CipherKey))
            {
                throw new Exception("Cipher key not found");
            }

            var user = repository.User.Find(x => x.FirstName == trackingDataView.FirstName && x.LastName == trackingDataView.LastName)
                       .ToList().FirstOrDefault();

            if (user == null)
            {
                user = new User()
                {
                    FirstName = trackingDataView.FirstName, LastName = trackingDataView.LastName, Age = trackingDataView.Age
                };
                repository.User.Add(user);
                repository.Save();
            }

            if (user == null)
            {
                throw new Exception("User not added");
            }

            foreach (var item in trackingDataView.Points)
            {
                string point = string.Join(" ", item.X, item.Y);
                repository.TrackingData.Add(new TrackingData()
                {
                    CipherPoints = XorCipher.Encrypt(point, trackingDataView.CipherKey), User = user
                });
                repository.Save();
            }
        }
Exemple #2
0
        public virtual void Execute()
        {
            List <TrackingDataView> result = new List <TrackingDataView>();

            try
            {
                foreach (var item in Users)
                {
                    var points = new List <Point>();
                    foreach (var trackingData in item.Tracking)
                    {
                        Point point = new Point();
                        try
                        {
                            string[] nums = XorCipher.Decrypt(trackingData.CipherPoints, TrackingDataView.CipherKey).Split(' ');
                            point.X = Convert.ToDouble(nums[0]);
                            point.Y = Convert.ToDouble(nums[1]);
                        }
                        catch
                        {
                            throw;
                        }
                        points.Add(point);
                    }
                    result.Add(new TrackingDataView()
                    {
                        FirstName = item.FirstName, LastName = item.LastName, Age = item.Age, Points = points
                    });
                }
            }
            catch
            {
                Console.WriteLine("Проверьте правильно ли введен ключ.");
            }

            TrackingResult = result;
        }