public async Task <IHttpActionResult> QueueReplay(HttpRequestMessage request)
        {
            string jsonString = await request.Content.ReadAsStringAsync();

            JArray matches = JArray.Parse(jsonString);

            List <DotaMatch> newMatches = new List <DotaMatch>();

            /*
             * Add each match sent.
             */
            foreach (JToken matchToken in matches)
            {
                MatchReplayProgress match = matchToken.ToObject <MatchReplayProgress>();
                //Get the duration so we can monitor replay progress
                MatchDetails md = await MatchesController.GetDetailsFromMatch(match.MatchId);

                match.Duration = md.Duration;
                ReplayCreator.Instance.addMatch(match);
            }
            return(Ok());
        }
        public void MakeReplays()
        {
            if (!IsBusy && Matches.Count > 0)
            {
                IsBusy = true;

                Task T = Task.Factory.StartNew(() =>
                {
                    CurrentMatch        = Matches.Dequeue();
                    CurrentMatch.Status = "Replay In Progress";
                    string imagePath    = HttpRuntime.AppDomainAppPath + "Images\\";
                    using (ISikuliSession session = Sikuli.CreateSession())
                    {
                        //session.Click(Patterns.FromFile(imagePath + "CloseButton.PNG"));
                        WaitAndClick(session, imagePath + "WatchButton.PNG");
                        WaitAndClick(session, imagePath + "WatchButton.PNG");
                        WaitAndClick(session, imagePath + "ReplaysButton.PNG");
                        WaitAndClick(session, imagePath + "MatchIds.PNG");
                        session.Type(CurrentMatch.MatchId);
                        WaitAndClick(session, imagePath + "SearchButton.PNG");
                        WaitAndClick(session, imagePath + "DownloadReplayButton.PNG");
                        WaitAndClick(session, imagePath + "MatchIdText.PNG");
                        WaitAndClick(session, imagePath + "WatchReplayButton.PNG", .9F);
                        StartStopRecording();

                        WaitAndClick(session, imagePath + "CollapseButton.PNG", .7f, 300);
                        //Wait 2 hours at most
                        //session.Wait(Patterns.FromFile(imagePath + "WatchReplayButton.PNG"), 7200);
                        try
                        {
                            session.Wait(Patterns.FromFile(imagePath + "WatchReplayButton.PNG"), 60);
                        }
                        catch { };
                        StartStopRecording();
                        //Wait 1 second for the sake of shadowplay's save
                        Thread.Sleep(1000);
                    }
                    //Cleanup Replay File
                    File.Delete(@"D:\Program Files (x86)\Steam\steamapps\common\dota 2 beta\game\dota\replays\" + CurrentMatch.MatchId + ".DEM");
                    CurrentMatch.Done = true;
                    CurrentMatch.ProgressPercentage = 100;
                    LastCompletedMatch  = CurrentMatch;
                    CurrentMatch        = null;
                    IsBusy              = false;
                    CurrentMatch.Status = "Replay Uploading";
                    YoutubeUploader.UploadToYoutube();
                    MakeReplays();
                });
            }

            //Task to give a rough idea of replay progress
            Task progressUpdator = Task.Factory.StartNew(() =>
            {
                DateTime startTime = DateTime.Now;
                while (CurrentMatch != null && !CurrentMatch.Done)
                {
                    CurrentMatch.ProgressPercentage = DateTime.Now.Subtract(startTime).Seconds / int.Parse(CurrentMatch.Duration);
                    Thread.Sleep(2000);
                }
            });
        }
 public void addMatch(MatchReplayProgress match)
 {
     Matches.Enqueue(match);
     MakeReplays();
 }