Ejemplo n.º 1
0
        public void create(vault vault)
        {
            using (var db = new DataContext())
            {
                bool dbexist = db.Database.Exists();
                if (dbexist == true)
                {
                    if (vault.gymnast != null)
                    {
                        db.gymnast.Attach(vault.gymnast);
                    }

                    if (vault.location != null)
                    {
                        db.location.Attach(vault.location);
                    }

                    if (vault.vaultkind != null)
                    {
                        db.vaultkind.Attach(vault.vaultkind);
                    }

                    if (vault.vaultnumber != null)
                    {
                        db.vaultnumber.Attach(vault.vaultnumber);
                    }

                    db.vault.Add(vault);

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void ShowVideoPlaybackView(vault selectedVault)
 {
     VideoPlaybackViewModel videoPlaybackViewModel = new VideoPlaybackViewModel(this);
     _setContent(videoPlaybackViewModel);
     videoPlaybackViewModel.setVaultToPlay(selectedVault);
 }
Ejemplo n.º 3
0
 public void setVaultToPlay(vault selectedVault)
 {
     this.selectedVault = selectedVault;
     // Set ReplayVideo
     VideoView = new VideoViewModel(_app, this, null, selectedVault.videopath);
     GraphView.insertGraphData(selectedVault.graphdata);
 }
Ejemplo n.º 4
0
        public void createVault(List<Bitmap> captureBuffer, List<String> writeBuffer, vault vault)
        {
            List<Bitmap> frames = new List<Bitmap>();

            foreach (Bitmap bmp in captureBuffer)
            {
                frames.Add((Bitmap)bmp.Clone());
            }

            Thread createThread = new Thread(() =>
            {
                vault vaultThread = vault;
                // Create the filepath, add date stamp to filename
                String fileName = "LC_Video_" + vault.timestamp.ToString("yyyy_MM_dd_HH-mm-ss") + ".avi";

                if (!Directory.Exists(App.filePath))
                {
                    Directory.CreateDirectory(App.filePath);
                }

                String videoFilePath = Path.Combine(App.filePath, fileName);

                //create the lasercamera string
                String graphdata = "";
                foreach (String s in writeBuffer)
                {
                    graphdata += s;
                }

                if (graphdata.Length > 0)
                {
                    vault.graphdata = graphdata.Remove(graphdata.Length - 1); //Laatste komma weghalen
                }

                //generate thumbnail
                try
                {
                    BitmapImage bImage = bmpToBitmapImage(frames[20]);
                    byte[] data = null;
                    JpegBitmapEncoder encoder = new JpegBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(bImage));
                    using (MemoryStream ms = new MemoryStream())
                    {
                        encoder.Save(ms);
                        data = ms.ToArray();
                        vault.thumbnail = data;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                // Save the new vault and include the video path.
                vault.videopath = fileName;

                if (App.IsOfflineMode)
                {
                    if (!Directory.Exists(App.syncPath))
                    {
                        Directory.CreateDirectory(App.syncPath);
                    }
                    SerializeService.Serialize<vault>(vault, Path.Combine(App.syncPath, String.Format("Vault_{0}.dat", Guid.NewGuid())));
                }
                else
                {
                    create(vault);
                }

                // Send vault back to view, for thumbnail list
                Application.Current.Dispatcher.Invoke(() =>
                {
                    OnVaultCreated(vault);
                });

                // Create a new thread to save the video
                Worker workerObject = new Worker(videoFilePath, fileName, frames);
                Thread workerThread = new Thread(workerObject.DoWork);

                // Start the thread.
                workerThread.Start();
            });
            createThread.Start();
        }
Ejemplo n.º 5
0
 protected virtual void OnVaultCreated(vault createdVault)
 {
     EventHandler<vault> handler = VaultCreated;
     if (handler != null)
     {
         handler(this, createdVault);
     }
 }
Ejemplo n.º 6
0
        public void update(vault vault)
        {
            using (var db = new DataContext())
            {
                bool dbexist = db.Database.Exists();
                if (dbexist == true)
                {
                    var query = (from qVault in db.vault
                                 where qVault.vault_id == vault.vault_id
                                 select qVault).First();

                    query.gymnast_id = vault.gymnast_id;
                    query.timestamp = vault.timestamp;
                    query.vault_id = vault.vault_id;
                    query.location_id = vault.location_id;
                    query.vaultkind_id = vault.vaultkind_id;
                    query.vaultnumber_id = vault.vaultnumber_id;
                    query.rating_star = vault.rating_star;
                    query.rating_official_D = vault.rating_official_D;
                    query.rating_official_E = vault.rating_official_E;
                    query.penalty = vault.penalty;

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {

                        Console.WriteLine(e);
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public vault read(int id)
 {
     using (var db = new DataContext())
     {
         bool dbexist = db.Database.Exists();
         if (dbexist == true)
         {
             var query = (from qVault in db.vault.Include("gymnast").Include("vaultnumber").Include("location").Include("vaultkind")
                          where qVault.vault_id == id
                          select qVault).FirstOrDefault();
             return query;
         }
         vault v = new vault();
         return v;
     }
 }
Ejemplo n.º 8
0
        private void vaultCreated(object sender, vault receivedVault)
        {
            // Add vault to thumbnail list.
            ThumbnailViewModel vaultThumb = new ThumbnailViewModel(_app);
            vaultThumb.Vault = receivedVault;

            // Add to collection
            thumbnailCollection.Insert(1, vaultThumb);
            vaultSaved = true;
        }
Ejemplo n.º 9
0
        private void stopMeasuring()
        {
            vaultSaved = false;
            ThumbnailViewModel liveThumbnail = ThumbnailCollection[0];
            vault newVault = liveThumbnail.Vault;

            RatingViewModel ratingVM = (RatingViewModel)RatingControl;
            newVault.rating_star = ratingVM.getScore();

            newVault.timestamp = DateTime.Now;

            List<String> writeBuffer = portController.stopMeasurement();
            videoCameraController.StopCapture();
            cameraModule.createVault(videoCameraController.RecordedVideo, writeBuffer, newVault);
            videoCameraController.Close();

            // Create new vault for the live thumbnail
            vault newLiveVault = new vault();
            liveThumbnail.Vault = newLiveVault;
            SelectedThumbnail = liveThumbnail;

            // Clear fields, keep data if checked
            // Send the just created vault with it so the checked fields can be kept
            clearFields(newVault);
        }
Ejemplo n.º 10
0
        public MeasurementViewModel(IApplicationController app, PortController portController, VideoCameraController videoCameraController)
            : base()
        {
            _app = app;
            Measuring = false;
            RatingViewModel ratingVM = new RatingViewModel(_app);
            RatingControl = ratingVM;

            RectangleColor = "White";

            gymnastList     = vaultModule.getGymnasts();
            vaultNumberList = vaultModule.getVaultNumbers();
            vaultKindList   = vaultModule.getVaultKinds();
            locationsList   = vaultModule.getLocations();

            // Set PortController
            this.portController = portController;

            // Set VideoCamera
            CameraView = new CameraViewModel(_app);
            VideoCameraController = videoCameraController;

            ManualModeChecked = true;

            //Turn pilotlaser off if it is on
            if (portController.PilotLaser != 0)
            {
                portController.PilotLaser = 0;
            }

            // Set Graph
            GraphViewModel graphVM = new GraphViewModel(_app, this, true, 1500);
            GraphViewMeasurement = graphVM;

            // Set validation
            SetValidationRules();

            // Set vault handler
            cameraModule.VaultCreated += vaultCreated;

            // Set thumbnail collection
            thumbnailCollection = new ObservableCollection<ThumbnailViewModel>();

            // Create empty vault
            vault newVault = new vault();
            newVault.timestamp = DateTime.Now;
            selectedVault = newVault;

            // Add empty thumbnail for live and set selected
            ThumbnailViewModel liveThumbnail = new ThumbnailViewModel(_app);
            liveThumbnail.setLive(true);
            liveThumbnail.Vault = newVault;
            thumbnailCollection.Add(liveThumbnail);
            SelectedThumbnail = liveThumbnail;
        }
Ejemplo n.º 11
0
        private void clearFields(vault savedVault)
        {
            if (!VaultKindChecked)
            {
                VaultKind = "";
            }
            else
            {
                VaultKind = savedVault.vaultkind.name;
            }

            if (!LocationChecked)
            {
                Location = "";
            }
            else
            {
                Location = savedVault.location.name;
            }

            if (!GymnastChecked)
            {
                Gymnast = "";
            }
            else
            {
                Gymnast = savedVault.gymnast.name + (savedVault.gymnast.surname_prefix != null ? " " + savedVault.gymnast.surname_prefix : "") + " " + savedVault.gymnast.surname;
            }

            if (!VaultNumberChecked)
            {
                VaultNumber = "";
            }
            else
            {
                VaultNumber = savedVault.vaultnumber.code;
            }

            RatingViewModel ratingView = new RatingViewModel(_app);
            ratingView.OnRatingChanged += setVaultRating;
            RatingControl = ratingView;
            if (RatingChecked)
            {
                ratingView.RatingValue = (int)savedVault.rating_star;
            }

            if (!DscoreChecked)
            {
                Dscore = "";
            }
            else
            {
                Dscore = savedVault.rating_official_D.ToString();
            }

            if (!EscoreChecked)
            {
                Escore = "";
            }
            else
            {
                Escore = savedVault.rating_official_E.ToString();
            }

            if (!PenaltyChecked)
            {
                Penalty = "";
            }
            else
            {
                Penalty = savedVault.penalty.ToString();
            }
        }
Ejemplo n.º 12
0
        private void setVaultLabels(vault setVault, String side)
        {
            Type classType = this.GetType();

            String fullName = "Unknown gymnast";
            if (setVault.gymnast != null)
            {
                fullName = setVault.gymnast.name + (!String.IsNullOrWhiteSpace(setVault.gymnast.surname_prefix) ? " " +
                                                    setVault.gymnast.surname_prefix + " " : " ") + setVault.gymnast.surname;
            }
            classType.GetProperty(side + "FullName").SetValue(this, fullName);

            String date = "Unknown date";
            if (setVault.timestamp != null && !String.IsNullOrWhiteSpace(setVault.timestamp.ToShortDateString()))
            {
                date = setVault.timestamp.ToString("dd/MM/yyyy HH:mm:ss");
            }
            classType.GetProperty(side + "Date").SetValue(this, date);

            String vaultnumber = "Vault Number undefined";
            if (setVault.vaultnumber != null && setVault.vaultnumber.code != null)
            {
                vaultnumber = setVault.vaultnumber.code;
            }
            classType.GetProperty(side + "VaultNumber").SetValue(this, vaultnumber);

            decimal totalScore = setVault.rating_official_E.GetValueOrDefault() + setVault.rating_official_D.GetValueOrDefault() - setVault.penalty.GetValueOrDefault();
            classType.GetProperty(side + "TotalScore").SetValue(this, totalScore.ToString("0.000"));
        }