Ejemplo n.º 1
0
        private async Task UpdateTournament(object o)
        {
            if ((Tournament.TournamentKey < 0) || string.IsNullOrEmpty(Tournament.Name))
            {
                MessageBox.Show("Please select a tournament to update");
                return;
            }

            // cancelled password input
            if (string.IsNullOrEmpty(Credentials.LoginPassword))
            {
                return;
            }

            if (Tournament.ScgaQualifier && Tournament.TeamSize != 2)
            {
                MessageBox.Show("SCGA qualifier requires team size to be set to 2.");
                return;
            }

            if(Tournament.MemberGuest && Tournament.TeamSize != 2)
            {
                MessageBox.Show("Member/guest requires team size to be set to 2.");
                return;
            }

            Tournament.TournamentDescriptionKey = TournamentDescription.TournamentDescriptionKey;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(WebAddresses.BaseAddress);

                var values = Tournament.ToKeyValuePairs();

                values.Add(new KeyValuePair<string, string>("Login", Credentials.LoginName));
                values.Add(new KeyValuePair<string, string>("Password", Credentials.LoginPassword));

                values.Add(new KeyValuePair<string, string>("Action", "Update"));

                var content = new FormUrlEncodedContent(values);

                string responseString;
                using (new WaitCursor())
                {
                    var response = await client.PostAsync(WebAddresses.ScriptFolder + WebAddresses.SubmitTournament, content);
                    responseString = await response.Content.ReadAsStringAsync();
                }

                if (!responseString.StartsWith("Success", StringComparison.InvariantCultureIgnoreCase))
                {
                    Credentials.CheckForInvalidPassword(responseString);
                    Logging.Log(WebAddresses.ScriptFolder + WebAddresses.SubmitTournament, responseString);

                    HtmlDisplayWindow displayWindow = new HtmlDisplayWindow();
                    displayWindow.WebBrowser.NavigateToString(responseString);
                    displayWindow.Owner = Application.Current.MainWindow;
                    displayWindow.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Tournament updated");
                }
            }
        }
Ejemplo n.º 2
0
        private async Task TournamentSelectionChanged(int selectedIndex)
        {
            if (selectedIndex < 0)
            {
                return;
            }

            if (TournamentNames.Count == 0)
            {
                return;
            }

            TournamentName tournamentName = TournamentNames[selectedIndex];

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(WebAddresses.BaseAddress);

                using (new WaitCursor())
                {
                    var values = new List<KeyValuePair<string, string>>();

                    values.Add(new KeyValuePair<string, string>("TournamentKey", tournamentName.TournamentKey.ToString()));

                    var content = new FormUrlEncodedContent(values);

                    var response = await client.PostAsync(WebAddresses.ScriptFolder + WebAddresses.GetTournament, content);
                    var responseString = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        LoadTournamentFromWebResponse(responseString);
                    }
                    else
                    {
                        Logging.Log(WebAddresses.ScriptFolder + WebAddresses.GetTournament, responseString);

                        HtmlDisplayWindow displayWindow = new HtmlDisplayWindow();
                        if (!string.IsNullOrEmpty(responseString))
                        {
                            displayWindow.WebBrowser.NavigateToString(responseString);
                            displayWindow.Owner = App.Current.MainWindow;
                            displayWindow.ShowDialog();
                        }
                    }
                }
            }

            if (TournamentDescriptionNames.Count == 0)
            {
                GetTournamentDescriptions(false);
            }

            SelectCurrentDescription();

            TournamentChairmenSelectedIndex = -1;
        }
Ejemplo n.º 3
0
        private async Task AddTournament(object o)
        {
            if(string.IsNullOrEmpty(Tournament.Name))
            {
                MessageBox.Show("Please fill in the tournament name");
                return;
            }

            // cancelled password input
            if (string.IsNullOrEmpty(Credentials.LoginPassword))
            {
                return;
            }

            foreach(var t in TournamentNames)
            {
                if((string.Compare(t.Name, Tournament.Name, true) == 0) && (t.StartDate == Tournament.StartDate))
                {
                    MessageBox.Show(Tournament.Name + " on " + Tournament.StartDate.ToShortDateString() + " matches an existing tournament.  Did you mean to update instead?");
                    return;
                }
            }

            if(Tournament.ScgaQualifier && Tournament.TeamSize != 2)
            {
                MessageBox.Show("SCGA qualifier requires team size to be set to 2.");
                return;
            }

            Tournament.TournamentDescriptionKey = TournamentDescription.TournamentDescriptionKey;
            bool success = false;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(WebAddresses.BaseAddress);

                var values = Tournament.ToKeyValuePairs();

                values.Add(new KeyValuePair<string, string>("Login", Credentials.LoginName));
                values.Add(new KeyValuePair<string, string>("Password", Credentials.LoginPassword));

                values.Add(new KeyValuePair<string, string>("Action", "Insert"));

                var content = new FormUrlEncodedContent(values);

                string responseString;
                using (new WaitCursor())
                {
                    var response = await client.PostAsync(WebAddresses.ScriptFolder + WebAddresses.SubmitTournament, content);
                    responseString = await response.Content.ReadAsStringAsync();
                }

                if (!responseString.StartsWith("Success", StringComparison.InvariantCultureIgnoreCase))
                {
                    Credentials.CheckForInvalidPassword(responseString);
                    Logging.Log(WebAddresses.ScriptFolder + WebAddresses.SubmitTournament, responseString);

                    HtmlDisplayWindow displayWindow = new HtmlDisplayWindow();
                    displayWindow.WebBrowser.NavigateToString(responseString);
                    displayWindow.Owner = Application.Current.MainWindow;
                    displayWindow.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Tournament added");
                    success = true;
                }
            }

            if (success)
            {
                GetTournaments(null);
                Tournament.Reset();
            }
        }
Ejemplo n.º 4
0
        private async Task<bool> SubmitResultsCsv(List<KeyValuePair<string, string>> kvpList, string result, bool clearResult)
        {
            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            //sw.Start();

            // cancelled password input
            if (string.IsNullOrEmpty(Credentials.LoginPassword))
            {
                return false;
            }

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(WebAddresses.BaseAddress);

                using (var multipartFormDataContent = new MultipartFormDataContent())
                {
                    var values = new[]
                            {
                                new KeyValuePair<string, string>("Login", Credentials.LoginName),
                                new KeyValuePair<string, string>("Password", Credentials.LoginPassword),
                                new KeyValuePair<string, string>("TournamentKey", TournamentNames[TournamentNameIndex].TournamentKey.ToString()),
                                new KeyValuePair<string, string>("Action", "Submit")
                            };

                    

                    foreach (var keyValuePair in values)
                    {
                        multipartFormDataContent.Add(new StringContent(keyValuePair.Value),
                            String.Format("\"{0}\"", keyValuePair.Key));
                    }

                    if (clearResult)
                    {
                        multipartFormDataContent.Add(new StringContent(result),
                            String.Format("\"{0}\"", "Clear"));
                    }

                    foreach(var keyValuePair in kvpList)
                    {
                        multipartFormDataContent.Add(new StringContent(keyValuePair.Value),
                            String.Format("\"{0}\"", keyValuePair.Key));
                    }

                    var requestUri = WebAddresses.ScriptFolder + WebAddresses.SubmitResultsCsv;

                    string responseString;
                    using (new WaitCursor())
                    {
                        try
                        {
                            Status.Message = "Submitting " + result + " results ...";
                            var response = client.PostAsync(requestUri, multipartFormDataContent).Result;
                            responseString = await response.Content.ReadAsStringAsync();
                            System.Diagnostics.Debug.WriteLine(responseString);
                        }
                        finally
                        {
                            Status.Message = string.Empty;
                        }
                    }

                    if (responseString.StartsWith("Success", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //sw.Stop();
                        //System.Diagnostics.Debug.WriteLine("Submit took " + sw.ElapsedMilliseconds + "ms");
                        return true;
                    }

                    Credentials.CheckForInvalidPassword(responseString);
                    Logging.Log(requestUri, responseString);

                    HtmlDisplayWindow displayWindow = new HtmlDisplayWindow();
                    displayWindow.WebBrowser.NavigateToString(responseString);
                    displayWindow.Owner = App.Current.MainWindow;
                    displayWindow.ShowDialog();
                }
            }
            return false;
        }
Ejemplo n.º 5
0
        private async Task UploadToWeb(object o)
        {
            PaymentsDue = 0;
            PaymentsMade = 0;

            List<TeeTimeRequest> modifiedEntries = new List<TeeTimeRequest>();
            foreach (var teeTimeRequest in TeeTimeRequests)
            {
                if(!teeTimeRequest.Paid && teeTimeRequest.ModifiedPaid)
                {
                    modifiedEntries.Add(teeTimeRequest);
                    teeTimeRequest.PaymentMade = teeTimeRequest.PaymentDue;
                    teeTimeRequest.Paid = teeTimeRequest.ModifiedPaid;
                }
                if(teeTimeRequest.Paid && !teeTimeRequest.ModifiedPaid)
                {
                    modifiedEntries.Add(teeTimeRequest);
                    teeTimeRequest.PaymentMade = 0;
                    teeTimeRequest.Paid = teeTimeRequest.ModifiedPaid;
                }

                PaymentsDue += teeTimeRequest.PaymentDue;
                PaymentsMade += teeTimeRequest.PaymentMade;
            }

            if (modifiedEntries.Count == 0)
            {
                MessageBox.Show("No entries were changed");
                return;
            }

            // cancelled password input
            if (string.IsNullOrEmpty(Credentials.LoginPassword))
            {
                return;
            }

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(WebAddresses.BaseAddress);

                var values = new List<KeyValuePair<string, string>>();

                values.Add(new KeyValuePair<string, string>("Login", Credentials.LoginName));
                values.Add(new KeyValuePair<string, string>("Password", Credentials.LoginPassword));
                values.Add(new KeyValuePair<string, string>("Action", "UpdatePaymentMade"));

                values.Add(new KeyValuePair<string, string>("TournamentKey",
                        TournamentNames[TournamentNameIndex].TournamentKey.ToString(CultureInfo.InvariantCulture)));

                for (int i = 0; i < modifiedEntries.Count; i++)
                {
                    values.Add(new KeyValuePair<string, string>(
                        string.Format("Signup[{0}][SignupKey]", i),
                        modifiedEntries[i].SignupKey.ToString(CultureInfo.InvariantCulture)));

                    values.Add(new KeyValuePair<string, string>(
                        string.Format("Signup[{0}][PaymentMade]", i),
                        modifiedEntries[i].PaymentMade.ToString(CultureInfo.InvariantCulture)));
                }

                var content = new FormUrlEncodedContent(values);

                using (new WaitCursor())
                {
                    var response = await client.PostAsync(WebAddresses.ScriptFolder + WebAddresses.SubmitSignUps, content);
                    var responseString = await response.Content.ReadAsStringAsync();

                    if (responseString.StartsWith("Success", StringComparison.InvariantCultureIgnoreCase))
                    {
                        MessageBox.Show("Updated " + modifiedEntries.Count + " signups");
                    }
                    else
                    {
                        Credentials.CheckForInvalidPassword(responseString);
                        Logging.Log(WebAddresses.ScriptFolder + WebAddresses.SubmitWaitingList, responseString);

                        HtmlDisplayWindow displayWindow = new HtmlDisplayWindow();
                        displayWindow.WebBrowser.NavigateToString(responseString);
                        displayWindow.Owner = Application.Current.MainWindow;
                        displayWindow.ShowDialog();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        protected async Task<bool> HttpSend(
            HttpClient client,
            HtmlRequestType requestType,
            List<KeyValuePair<string, string>> values,
            string url)
        {
            string responseString;

            using (new WaitCursor())
            {
                var content = new FormUrlEncodedContent(values);

                HttpResponseMessage response = null;

                switch(requestType)
                {
                    case HtmlRequestType.Get:
                        break;
                    case HtmlRequestType.Put:
                        break;
                    case HtmlRequestType.Post:
                        response = await client.PostAsync(url, content);
                        break;
                    case HtmlRequestType.Delete:
                        response = await client.DeleteAsync(url);
                        break;
                }

                responseString = await response.Content.ReadAsStringAsync();
                System.Diagnostics.Debug.WriteLine(responseString);
            }

            if (responseString.StartsWith("Success", StringComparison.InvariantCultureIgnoreCase))
            {
                return true;
            }
            else
            {
                TabViewModelBase.Credentials.CheckForInvalidPassword(responseString);
                Logging.Log(url, responseString);

                HtmlDisplayWindow displayWindow = new HtmlDisplayWindow();
                if (!string.IsNullOrEmpty(responseString))
                {
                    displayWindow.WebBrowser.NavigateToString(responseString);
                    displayWindow.Owner = App.Current.MainWindow;
                    displayWindow.ShowDialog();
                }
                else
                {
                    System.Windows.MessageBox.Show("Reponse was an empty string");
                }
            }

            return false;

        }
Ejemplo n.º 7
0
        private async Task SubmitWaitingList(object s)
        {
            var waitingList = LoadWaitingList(Options.WaitListFileName);

            // cancelled password input
            if (string.IsNullOrEmpty(Credentials.LoginPassword))
            {
                return;
            }

            if ((waitingList != null) && (waitingList.Count > 0))
            {
                using (new WaitCursor())
                {
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(WebAddresses.BaseAddress);

                        var values = new List<KeyValuePair<string, string>>();

                        values.Add(new KeyValuePair<string, string>("Login", Credentials.LoginName));
                        values.Add(new KeyValuePair<string, string>("Password", Credentials.LoginPassword));

                        for (int i = 0; i < waitingList.Count; i++)
                        {
                            values.Add(new KeyValuePair<string, string>(
                                string.Format("WaitingList[{0}][Position]", i),
                                waitingList[i].Position.ToString()));

                            values.Add(new KeyValuePair<string, string>(
                                string.Format("WaitingList[{0}][Name]", i),
                                 waitingList[i].Name));

                            values.Add(new KeyValuePair<string, string>(
                                string.Format("WaitingList[{0}][DateAdded]", i),
                                 waitingList[i].DateAdded.ToString("yyyy-MM-dd")));

                        }

                        var content = new FormUrlEncodedContent(values);

                        var response = await client.PostAsync(WebAddresses.ScriptFolder + WebAddresses.SubmitWaitingList, content);
                        var responseString = await response.Content.ReadAsStringAsync();
                        System.Diagnostics.Debug.WriteLine(responseString);

                        if (responseString.StartsWith("Success", StringComparison.InvariantCultureIgnoreCase))
                        {
                            MessageBox.Show("Waiting list uploaded");
                        }
                        else
                        {
                            Credentials.CheckForInvalidPassword(responseString);
                            Logging.Log(WebAddresses.ScriptFolder + WebAddresses.SubmitWaitingList, responseString);

                            HtmlDisplayWindow displayWindow = new HtmlDisplayWindow();
                            displayWindow.WebBrowser.NavigateToString(responseString);
                            displayWindow.Owner = App.Current.MainWindow;
                            displayWindow.ShowDialog();
                        }
                    }
                }
            }
        }