Beispiel #1
0
        public ViewResult Snapshot(string userName)
        {
            SnapshotViewModel viewModel = new SnapshotViewModel
            {
                User = repository.Users.Where(u => u.Name == userName).First()
            };

            return(View(viewModel));
        }
Beispiel #2
0
        public IActionResult Index()
        {
            if (_configuration["EnvironmentName"].EndsWith("PROD", StringComparison.InvariantCultureIgnoreCase))
            {
                return(RedirectToAction("Index", "Dashboard"));
            }

            var viewmodel = new SnapshotViewModel();

            return(View("~/Views/Roatp/Apply/Snapshot/Index.cshtml", viewmodel));
        }
Beispiel #3
0
        /// <summary>
        ///  Sets the data context for snapshot view.
        /// </summary>
        /// <returns> Snapshot view </returns>
        public SnapshotView GetSnapshotView()
        {
            if (snapshotViewModel == null)
            {
                snapshotViewModel = new SnapshotViewModel(GetSnapshotModel());
                snapshotView      = new SnapshotView()
                {
                    DataContext = snapshotViewModel
                };
            }

            return(snapshotView);
        }
Beispiel #4
0
        public void Snapshot(SnapshotViewModel model)
        {
            var player = PlayerService.GetPlayer(Request.Cookies);

            if (player == null)
            {
                return;
            }

            var game           = App.GetGame(model.GameId);
            var cleansedBase64 = model.Base64.Substring(model.Base64.IndexOf("base64,") + 7);

            game.SetSnapshot(player, cleansedBase64);
        }
Beispiel #5
0
        public async Task Start()
        {
            var primaryScreenBounds = Screen.PrimaryScreen.Bounds;
            var primaryScreenWidth  = primaryScreenBounds.Width;
            var primaryScreenHeight = primaryScreenBounds.Height;
            var destinationX        = 0;
            var destinationY        = 0;

            using (var bitmapScreenCapture = new Bitmap(primaryScreenWidth, primaryScreenHeight))
            {
                using (var graphics = Graphics.FromImage(bitmapScreenCapture))
                {
                    while (this.isRunning)
                    {
                        graphics.CopyFromScreen(
                            primaryScreenBounds.X,
                            primaryScreenBounds.Y,
                            destinationX,
                            destinationY,
                            bitmapScreenCapture.Size,
                            CopyPixelOperation.SourceCopy);

                        var imageAsByteArray = ConvertionOperations.ImageToByteArray(bitmapScreenCapture);

                        try
                        {
                            var model = new SnapshotViewModel
                            {
                                SessionId           = this.SessionId,
                                SnapshotAsByteArray = imageAsByteArray
                            };

                            await this.HttpService.SendAsBson(model, this.Settings.RequestUrl);
                        }
                        catch (Exception exc)
                        {
                            // TODO: Log the exception cause
                        }

                        Thread.Sleep(this.Settings.SnapshotDelayInMilliseconds);
                    }
                }
            }
        }
        public IHttpActionResult PostSnapshot(SnapshotViewModel model)
        {
            var currentDate = DateTime.Now;
            var year        = currentDate.Year;
            var month       = currentDate.ToString("MMMM");
            var mm          = currentDate.ToString("MMM");
            var day         = currentDate.Day;

            var timeOfDay = currentDate.TimeOfDay;
            var hours     = timeOfDay.Hours.ToTimeString();
            var minutes   = timeOfDay.Minutes.ToTimeString();
            var seconds   = timeOfDay.Seconds.ToTimeString();

            var image        = ConvertionOperations.ImageFromByteArray(model.SnapshotAsByteArray);
            var fileName     = $"{year}-{month}-{day}-{hours}-{minutes}-{seconds}.jpeg";
            var filePath     = $@"{this.BasePath}Sessions\{model.SessionId}";
            var fullFilePath = $@"{filePath}\{fileName}";

            this.CreateDirectory(filePath);

            image.Save(fullFilePath);

            return(this.Ok());
        }
        public ActionResult Snapshot()
        {
            var weeklyAppsList = new List <JPApplication>();

            var weeklyHiresList = new List <JPHire>();

            var newJpStudentsList = new List <JPStudent>();

            var jpStudentCount          = 0;
            var jpStudentCount_Portland = 0;
            var jpStudentCount_Denver   = 0;
            var jpStudentCount_Seattle  = 0;
            var jpStudentCount_Remote   = 0;

            int unhiredGradCount          = 0;
            int unhiredGradCount_Portland = 0;
            int unhiredGradCount_Denver   = 0;
            int unhiredGradCount_Seattle  = 0;
            int unhiredGradCount_Remote   = 0;

            int totalDaysInJP = 0, avgDaysInJP = 0, totalStudents = 0;
            int startDateDay = 0, startDateMonth = 0, startDateYear = 0, todayDateDay = 0, todayDateMonth = 0, todayDateYear = 0;

            foreach (var student in db.JPStudents)
            {
                int id = student.JPStudentId;

                startDateDay   = student.JPStartDate.Day;                /* ----------------PB--------------- */
                startDateMonth = student.JPStartDate.Month;
                startDateYear  = student.JPStartDate.Year;
                todayDateDay   = DateTime.Today.Day;
                todayDateMonth = DateTime.Today.Month;
                todayDateYear  = DateTime.Today.Year;

                if (student.JPHired == true)
                {
                    if (startDateDay > todayDateDay)                         // checks if the start day was in a previous month
                    {                                                        // if so adjust day count for days in the previous month
                        if (todayDateMonth == 3)
                        {
                            todayDateDay += 28;
                        }
                        else if (todayDateMonth == 10 || todayDateMonth == 5 || todayDateMonth == 7 || todayDateMonth == 12)
                        {
                            todayDateDay += 30;
                        }
                        else
                        {
                            todayDateDay += 31;
                        }
                    }

                    totalDaysInJP += (todayDateDay - startDateDay);
                    totalStudents++;
                }

                var apps = db.JPApplications.Where(a => a.ApplicationUserId == student.ApplicationUserId).ToList();
                if (student.JPHired == true)
                {
                    var hire = db.JPHires.Where(a => a.ApplicationUserId == student.ApplicationUserId).FirstOrDefault();
                    if (hire.IsHiredWithinOneWeekOfCurrentDate == true)
                    {
                        weeklyHiresList.Add(hire);
                    }
                }

                else if (student.JPHired == false && student.JPGraduated == false)
                {
                    if ((student.JPStudentLocation == JPStudentLocation.PortlandLocal) || (student.JPStudentLocation == JPStudentLocation.PortlandRemote))
                    {
                        jpStudentCount_Portland++;
                    }
                    if ((student.JPStudentLocation == JPStudentLocation.DenverLocal) || (student.JPStudentLocation == JPStudentLocation.DenverRemote))
                    {
                        jpStudentCount_Denver++;
                    }
                    if ((student.JPStudentLocation == JPStudentLocation.SeattleLocal) || (student.JPStudentLocation == JPStudentLocation.SeattleRemote))
                    {
                        jpStudentCount_Seattle++;
                    }
                    if ((student.JPStudentLocation == JPStudentLocation.Remote) || (student.JPStudentLocation == JPStudentLocation.PortlandLocal))
                    {
                        jpStudentCount_Remote++;
                    }
                    jpStudentCount++;
                    if (student.IsStartDateWithinOneWeekOfCurrentDate == true)
                    {
                        newJpStudentsList.Add(student);
                    }
                }

                else if (student.JPHired == false && student.JPGraduated == true)
                {
                    if ((student.JPStudentLocation == JPStudentLocation.PortlandLocal) || (student.JPStudentLocation == JPStudentLocation.PortlandRemote))
                    {
                        unhiredGradCount_Portland++;
                    }
                    if ((student.JPStudentLocation == JPStudentLocation.DenverLocal) || (student.JPStudentLocation == JPStudentLocation.DenverRemote))
                    {
                        unhiredGradCount_Denver++;
                    }
                    if ((student.JPStudentLocation == JPStudentLocation.SeattleLocal) || (student.JPStudentLocation == JPStudentLocation.SeattleRemote))
                    {
                        unhiredGradCount_Seattle++;
                    }
                    if (student.JPStudentLocation == JPStudentLocation.Remote)
                    {
                        unhiredGradCount_Remote++;
                    }
                    unhiredGradCount++;
                }

                foreach (var app in apps)
                {
                    if (app.IsAppliedDateWithinOneWeekOfCurrentDate == true)
                    {
                        weeklyAppsList.Add(app);
                    }
                }
            }

            var newJpStudentsList_Portland = newJpStudentsList.Where(x => (x.JPStudentLocation == JPStudentLocation.PortlandLocal) || (x.JPStudentLocation == JPStudentLocation.PortlandRemote)).ToList();
            var newJpStudentsList_Denver   = newJpStudentsList.Where(x => (x.JPStudentLocation == JPStudentLocation.DenverLocal) || (x.JPStudentLocation == JPStudentLocation.DenverRemote)).ToList();
            var newJpStudentsList_Seattle  = newJpStudentsList.Where(x => (x.JPStudentLocation == JPStudentLocation.SeattleLocal) || (x.JPStudentLocation == JPStudentLocation.SeattleRemote)).ToList();
            var newJpStudentsList_Remote   = newJpStudentsList.Where(x => x.JPStudentLocation == JPStudentLocation.Remote).ToList();

            var weeklyHiresList_Portland = weeklyHiresList.Where(x => (x.JPStudentLocation == JPStudentLocation.PortlandLocal) || (x.JPStudentLocation == JPStudentLocation.PortlandRemote)).ToList();
            var weeklyHiresList_Denver   = weeklyHiresList.Where(x => (x.JPStudentLocation == JPStudentLocation.DenverLocal) || (x.JPStudentLocation == JPStudentLocation.DenverRemote)).ToList();
            var weeklyHiresList_Seattle  = weeklyHiresList.Where(x => (x.JPStudentLocation == JPStudentLocation.SeattleLocal) || (x.JPStudentLocation == JPStudentLocation.SeattleRemote)).ToList();
            var weeklyHiresList_Remote   = weeklyHiresList.Where(x => x.JPStudentLocation == JPStudentLocation.Remote).ToList();

            int totalWeeklyHires          = weeklyHiresList.Count();
            int totalWeeklyHires_Portland = weeklyHiresList.Where(x => (x.JPStudentLocation == JPStudentLocation.PortlandLocal) || (x.JPStudentLocation == JPStudentLocation.PortlandLocal)).Count();
            int totalWeeklyHires_Denver   = weeklyHiresList.Where(x => (x.JPStudentLocation == JPStudentLocation.DenverLocal) || (x.JPStudentLocation == JPStudentLocation.DenverRemote)).Count();
            int totalWeeklyHires_Seattle  = weeklyHiresList.Where(x => (x.JPStudentLocation == JPStudentLocation.SeattleLocal) || (x.JPStudentLocation == JPStudentLocation.SeattleRemote)).Count();
            int totalWeeklyHires_Remote   = weeklyHiresList.Where(x => x.JPStudentLocation == JPStudentLocation.Remote).Count();

            avgDaysInJP = (totalDaysInJP / totalStudents);              // PB ---------------------------------------

            int totalWeeklyApps          = weeklyAppsList.Count();
            int totalWeeklyApps_Portland = weeklyAppsList.Where(x => x.JPCompanyCity == "Portland").Count();
            int totalWeeklyApps_Denver   = weeklyAppsList.Where(x => x.JPCompanyCity == "Denver").Count();
            int totalWeeklyApps_Seattle  = weeklyAppsList.Where(x => x.JPCompanyCity == "Seattle").Count();
            int totalWeeklyApps_Remote   = weeklyAppsList.Where(x => x.JPCompanyCity == "Remote").Count();


            var snapshotStats = new SnapshotViewModel(newJpStudentsList, weeklyHiresList, totalWeeklyApps, totalWeeklyHires, jpStudentCount, unhiredGradCount,
                                                      newJpStudentsList_Portland, weeklyHiresList_Portland, totalWeeklyApps_Portland, totalWeeklyHires_Portland, jpStudentCount_Portland, unhiredGradCount_Portland,
                                                      newJpStudentsList_Denver, weeklyHiresList_Denver, totalWeeklyApps_Denver, totalWeeklyHires_Denver, jpStudentCount_Denver, unhiredGradCount_Denver,
                                                      newJpStudentsList_Seattle, weeklyHiresList_Seattle, totalWeeklyApps_Seattle, totalWeeklyHires_Seattle, jpStudentCount_Seattle, unhiredGradCount_Seattle,
                                                      newJpStudentsList_Remote, weeklyHiresList_Remote, totalWeeklyApps_Remote, totalWeeklyHires_Remote, jpStudentCount_Remote, unhiredGradCount_Remote, avgDaysInJP, totalDaysInJP
                                                      );

            //weeklyApps is 3x what it should be (it was 54 today (8/30), but it should be 18) because there are 3 copies of each seed student. Without duplicate seed data this should work fine.)

            return(View(snapshotStats));
        }
Beispiel #8
0
        public async Task <IActionResult> PerformSnapshot(SnapshotViewModel vm)
        {
            if (_configuration["EnvironmentName"].EndsWith("PROD", StringComparison.InvariantCultureIgnoreCase))
            {
                return(RedirectToAction("Index", "Dashboard"));
            }

            var application = await _applyApiClient.GetApplication(vm.ApplicationId ?? Guid.NewGuid());

            if (vm.ApplicationId is null)
            {
                ModelState.AddModelError("ApplicationId", "Please enter Application Id");
            }
            else if (application is null)
            {
                ModelState.AddModelError("ApplicationId", "Application not found");
            }

            if (ModelState.IsValid)
            {
                var snapshotResponse = await _qnaApiClient.SnapshotApplication(application.ApplicationId);

                var allSnapshotSequences = await _qnaApiClient.GetAllApplicationSequences(snapshotResponse.ApplicationId);

                var allSnapshotSections = await _qnaApiClient.GetAllApplicationSections(snapshotResponse.ApplicationId);

                var applySequences = application.ApplyData.Sequences;

                // must update all ids!
                foreach (var sequence in applySequences)
                {
                    var snapshotSequence = allSnapshotSequences.FirstOrDefault(seq => seq.SequenceNo == sequence.SequenceNo);
                    if (snapshotSequence != null)
                    {
                        sequence.SequenceId = snapshotSequence.Id;

                        foreach (var section in sequence.Sections)
                        {
                            var snapshotSection = allSnapshotSections.FirstOrDefault(sec => sec.SequenceNo == sequence.SequenceNo && sec.SectionNo == section.SectionNo);

                            if (snapshotSection != null)
                            {
                                section.SectionId = snapshotSection.Id;
                            }
                        }
                    }
                }

                var applySnapshotResponse = await _applyApiClient.SnapshotApplication(application.ApplicationId, snapshotResponse.ApplicationId, applySequences);

                if (applySnapshotResponse != Guid.Empty)
                {
                    vm.SnapshotApplicationId = applySnapshotResponse;
                    vm.SnapshotSuccessful    = true;
                }
                else
                {
                    vm.SnapshotSuccessful = false;
                }
            }

            return(View("~/Views/Roatp/Apply/Snapshot/Index.cshtml", vm));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SnapshotWindow"/> class.
 /// </summary>
 /// <param name="viewModel">The view model to inject.</param>
 /// <remarks>
 /// This constructor can be used to use view-model injection.
 /// </remarks>
 public SnapshotWindow(SnapshotViewModel viewModel)
     : base(viewModel)
 {
     InitializeComponent();
 }
Beispiel #10
0
        //Runs when snapshots page is opened
        public ActionResult Snapshots()
        {
            string username = Session["SkyscapeUsername"] as string;
            string password = Session["SkyscapePassword"] as string;
            var    api      = new APIMethods();

            //Authentication details passed through from config class
            var authenticate = api.authenticateSkyscape(username, password);
            var accounts     = api.getAccounts();

            SnapshotViewModel snapshotViewModel = new SnapshotViewModel();

            snapshotViewModel.skyscapeAccounts = new List <Account>();
            snapshotViewModel.Vms            = new List <QueryResultRecords>();
            snapshotViewModel.vCloudAccounts = new Dictionary <int, Account>();
            int vmId = 0;

            //Deserializes JSON string into account objects
            snapshotViewModel.skyscapeAccounts = JsonConvert.DeserializeObject <List <Account> >(accounts.Content);

            //Loop through deserialized accounts
            foreach (Account account in snapshotViewModel.skyscapeAccounts)
            {
                Account vCloudAccount = new Account();
                {
                    vCloudAccount.vCloudCredentials = new List <Dictionary <string, vCloudIdentifiers> >();
                    vCloudAccount.vCloudToken       = new Dictionary <string, int>();
                    var vCloudCredentialObject = (JsonConvert.DeserializeObject <Dictionary <string, vCloudIdentifiers> >(api.getVCloudCreds(account.id).Content));
                    vCloudAccount.id = account.id;
                    vCloudAccount.vCloudCredentials.Add(vCloudCredentialObject);
                    foreach (var vCloudCredential in vCloudAccount.vCloudCredentials)
                    {
                        foreach (var key in vCloudCredential.Keys)
                        {
                            if (key.Contains("-" + account.id.ToString() + "-"))
                            {
                                byte[] credentialsAsBytes = System.Text.Encoding.ASCII.GetBytes(vCloudCredential[key].username.ToString() + ":" + password);
                                string encodedCredentials = Convert.ToBase64String(credentialsAsBytes);
                                string token = api.authenticateVCloud(encodedCredentials);
                                if (token != null)
                                {
                                    vCloudAccount.vCloudToken.Add(token, account.id);
                                }
                                else
                                {
                                    //Variable used to show non authenticated accounts in snapshot view
                                    account.hasAccess = false;
                                }
                            }
                        }
                    }
                }
                //Match the account id and the vcloud account in the dictionary
                snapshotViewModel.vCloudAccounts.Add(account.id, vCloudAccount);
            }
            foreach (var vCloudAccount in snapshotViewModel.vCloudAccounts.Values)
            {
                foreach (string vCloudToken in vCloudAccount.vCloudToken.Keys)
                {
                    //pass vCloudToken into API call to get VMs
                    var vmsXml = api.getVCloudVms(vCloudToken).GetResponseStream();

                    //To create snapshot objects, must loop through the different levels of XML using a streamreader
                    var vmSerializer = new XmlSerializer(typeof(QueryResultRecords));
                    using (var vmStreamReader = new StreamReader(vmsXml))
                    {
                        //Deserialize XML into VMs
                        QueryResultRecords Vms = (QueryResultRecords)vmSerializer.Deserialize(vmStreamReader);
                        Vms.vCloudId = vCloudAccount.id;
                        snapshotViewModel.Vms.Add(Vms);
                        foreach (var vm in Vms.VMRecord)
                        {
                            if (vm.CatalogName == null)
                            {
                                //if no catalog name for VM
                                var snapshotXml        = api.getVCloudVmsSnapshots(vm.Href, vCloudToken).GetResponseStream();
                                var snapshotSerializer = new XmlSerializer(typeof(SnapshotSection));
                                using (var snapshotStreamReader = new StreamReader(snapshotXml))
                                {
                                    SnapshotSection snapshot = (SnapshotSection)snapshotSerializer.Deserialize(snapshotStreamReader);
                                    if (snapshot.Snapshot != null)
                                    {
                                        //set up snapshot object if snapshot exists
                                        vm.unofficialId = vmId;
                                        vmId++;
                                        vm.Snapshot = snapshot;
                                        vm.Snapshot.Snapshot.SizeInGB  = long.Parse(vm.Snapshot.Snapshot.Size) / 1073741824;
                                        vm.Snapshot.Snapshot.accountId = vCloudAccount.vCloudToken[vCloudToken];
                                        if (vm.Snapshot.Snapshot.Created.AddDays(3) < DateTime.Now.Date) //check if snapshot is older than 3 days
                                        {
                                            foreach (var account in snapshotViewModel.skyscapeAccounts)
                                            {
                                                if (account.id == vCloudAccount.id)
                                                {
                                                    //add 1 to count of old snapshots for this account
                                                    account.numberOldSnapshots++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(View(snapshotViewModel));
        }
Beispiel #11
0
    public SnapshotViewModelControllerChanges()
    {
        int totalDaysInJP = 0, portlandDaysInJP = 0, denverDaysInJP = 0, seattleDaysInJP = 0, remoteDaysInJP = 0;
        int totalStudents = 0, portlandStudents = 0, denverStudents = 0, seattleStudents = 0, remoteStudents = 0;
        int avgDaysInJP = 0, portlandAvgDaysInJP = 0, denverAvgDaysInJP = 0, seattleAvgDaysInJP = 0, remoteAvgDaysInJP = 0;

        foreach (var student in db.JPStudents)
        {
            int id = student.JPStudentId;

            if (student.JPHired == true)
            {
                if ((student.JPStudentLocation == JPStudentLocation.PortlandLocal) || (student.JPStudentLocation == JPStudentLocation.PortlandRemote))
                {
                    portlandDaysInJP += (int)(DateTime.Now - student.JPStartDate).TotalDays;
                    portlandStudents++;
                }
                if ((student.JPStudentLocation == JPStudentLocation.DenverLocal) || (student.JPStudentLocation == JPStudentLocation.DenverRemote))
                {
                    denverDaysInJP += (int)(DateTime.Now - student.JPStartDate).TotalDays;
                    denverStudents++;
                }
                if ((student.JPStudentLocation == JPStudentLocation.SeattleLocal) || (student.JPStudentLocation == JPStudentLocation.SeattleRemote))
                {
                    seattleDaysInJP += (int)(DateTime.Now - student.JPStartDate).TotalDays;
                    seattleStudents++;
                }
                if ((student.JPStudentLocation == JPStudentLocation.Remote))
                {
                    remoteDaysInJP += (int)(DateTime.Now - student.JPStartDate).TotalDays;
                    remoteStudents++;
                }
                totalDaysInJP += (int)(DateTime.Now - student.JPStartDate).TotalDays;
                totalStudents++;
            }
        }

        if (portlandStudents > 0)
        {
            portlandAvgDaysInJP = (portlandDaysInJP / portlandStudents);
        }
        if (denverStudents > 0)
        {
            denverAvgDaysInJP = (denverDaysInJP / denverStudents);
        }
        if (seattleStudents > 0)
        {
            seattleAvgDaysInJP = (seattleDaysInJP / seattleStudents);
        }
        if (remoteStudents > 0)
        {
            remoteAvgDaysInJP = (remoteDaysInJP / remoteStudents);
        }
        avgDaysInJP = (totalDaysInJP / totalStudents);

        var snapshotStats = new SnapshotViewModel(newJpStudentsList, weeklyHiresList, totalWeeklyApps, totalWeeklyHires, jpStudentCount, unhiredGradCount,
                                                  newJpStudentsList_Portland, weeklyHiresList_Portland, totalWeeklyApps_Portland, totalWeeklyHires_Portland, jpStudentCount_Portland, unhiredGradCount_Portland,
                                                  newJpStudentsList_Denver, weeklyHiresList_Denver, totalWeeklyApps_Denver, totalWeeklyHires_Denver, jpStudentCount_Denver, unhiredGradCount_Denver,
                                                  newJpStudentsList_Seattle, weeklyHiresList_Seattle, totalWeeklyApps_Seattle, totalWeeklyHires_Seattle, jpStudentCount_Seattle, unhiredGradCount_Seattle,
                                                  newJpStudentsList_Remote, weeklyHiresList_Remote, totalWeeklyApps_Remote, totalWeeklyHires_Remote, jpStudentCount_Remote, unhiredGradCount_Remote,
                                                  avgDaysInJP, portlandAvgDaysInJP, denverAvgDaysInJP, seattleAvgDaysInJP, remoteAvgDaysInJP, totalDaysInJP, portlandDaysInJP, denverDaysInJP, seattleDaysInJP, remoteDaysInJP
                                                  );
    }