public static void Validate(TextReader sokResponseTextReader, Sok sok, List <string> validationErrors) { Sokeresultat sokResponse = null; try { sokResponse = (Sokeresultat) new XmlSerializer(typeof(Sokeresultat)).Deserialize( sokResponseTextReader); } catch (Exception e) { validationErrors.Add(string.Format(ValidationErrorMessages.CouldNotParseSokeresultat, "utvidet")); return; } if (sokResponse == null) { validationErrors.Add(ValidationErrorMessages.SokeresultatIsNull); return; } // Too many responses. Doesnt match Take request. if (sokResponse.ResultatListe.Count > sok.Take) { validationErrors.Add(string.Format( ValidationErrorMessages.TooLongResultListAccordingToTakeParameter, sok.Take, sokResponse.ResultatListe.Count)); } foreach (var parameter in sok.Parameter) { switch (parameter.Operator) { case OperatorType.Equal: if (parameter.Felt == SokFelt.MappePeriodTittel) { ValidateMappePeriodTittelEqual(sok, sokResponse, validationErrors, parameter); } break; case OperatorType.Between: if (isDateSokeFelt(parameter.Felt)) { var listOfDates = GetDateResults(sokResponse, parameter.Felt, validationErrors); foreach (var dateTimeValue in listOfDates) { ValidateBetweenDates(dateTimeValue, parameter.Parameterverdier.Datevalues[0], parameter.Parameterverdier.Datevalues[1], validationErrors); } } break; } } }
static void Main(string[] args) { Console.WriteLine("\n----------------------------------------------------------"); Console.WriteLine("\t\t***PICA***"); Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("\n\tSokovi (svi po 10cl): \n\tFanta, Djus, Coca-Cola\n\n\tZestina (kraci: 1 cl, dupli: 2cl): \n\tVodka, Rum, Tekila, Dzin"); Console.WriteLine("\n----------------------------------------------------------"); Console.WriteLine("\t\t***NARUCENA PICA***"); Console.WriteLine("----------------------------------------------------------"); Sok s1 = new Sok("Djus"); s1.Sipaj(); s1.ShowDetails(); Sok s2 = new Sok("Fanta"); s2.Sipaj(); s2.ShowDetails(); Sok s3 = new Sok("Coca-cola"); s3.Sipaj(); s3.ShowDetails(); Zestina z1 = new Zestina("Vodka", 2); z1.Sipaj(); z1.ShowDetails(); Zestina z2 = new Zestina("Rum", 1); z2.Sipaj(); z2.ShowDetails(); Console.WriteLine("\n\t\t***KOKTELI***"); Console.WriteLine("----------------------------------------------------------"); Koktel k1 = new Koktel("Blue Lagoon"); k1.Koktel_1(s2, z1); Koktel k2 = new Koktel("Cuba Libre"); k2.Koktel_2(s1, s2, z2); Koktel k3 = new Koktel("Fruity"); k3.Koktel_3(s3, s2, s1); }
//Söker i databas: protected void button_sok_Click(object sender, EventArgs e) { //Leta upp kontroller: UserControl grdResult_UCtrl = (UserControl)Page.FindControl("grdResult_UCtrl"); GridView grdResult = (GridView)grdResult_UCtrl.FindControl("grdResult"); //Skapar instans av objekt för delayvärde och sök-anrop Sok sk = new Sok(); //Anger antal sekunder som sökningen skall vara i cache-objektet: sk.Delay = 120; try { sk.button_sok(grdResult, this.Page, display, text3_Artist, text4_Album, text5_Format, text6_Press, text8_ar, text7_Kommentar); } catch (FormatException err) { //Rensar display från text och gridviews clr.Clean_surfaces(this.Page); string mess = "<h2>[Page]Skivor.Sok:FormatException</h2>"; mess += "<h2>Felmeddelande: " + err.Message + "</h2>"; display.InnerHtml = mess; } catch (MySqlException err) { //Rensar display från text och gridviews clr.Clean_surfaces(this.Page); string mess = "<h2>[Page]Skivor.Sok:MySqlException</h2>"; mess += "<h2>Felmeddelande: " + err.Message + "</h2>"; display.InnerHtml = mess; } catch (System.Exception err) { //Rensar display från text och gridviews clr.Clean_surfaces(this.Page); string mess = "<h2>[Page]Skivor.Sok:System.Exception</h2>"; mess += "<h2>Felmeddelande: " + err.Message + "</h2>"; display.InnerHtml = mess; } }
//Söker i databas: protected void button_sok_Click(object sender, EventArgs e) { //Leta upp kontroller: GridView grdResult_Artist = (GridView)grdResult_Artist_UCtrl.FindControl("grdResult_Artist"); //Skapar instans av objekt för delayvärde och sök-anrop: Sok sk = new Sok(); //Anger antal sekunder som sökningen skall vara i cache-objektet: sk.Delay = 20; try { sk.button_sok(grdResult_Artist, this.Page, display, text3_Artist, text9_VPfr, text10_VPtill, text11_Ursland, text12_Ursstad, text13_Musiktyp, text14_Kortbio); } catch (FormatException err) { //Rensar display från text och gridviews clr.Clean_surfaces_Artist(this.Page); string mess = "<h2>[Page]Artist.Sok_Artist:FormatException</h2>"; mess += "<h2>Felmeddelande: " + err.Message + "</h2>"; display.InnerHtml = mess; } catch (MySqlException err) { //Rensar display från text och gridviews clr.Clean_surfaces_Artist(this.Page); string mess = "<h2>[Page]Artist.Sok_Artist:MySqlException</h2>"; mess += "<h2>Felmeddelande: " + err.Message + "</h2>"; display.InnerHtml = mess; } catch (System.Exception err) { //Rensar display från text och gridviews clr.Clean_surfaces_Artist(this.Page); string mess = "<h2>[Page]Artist.Sok:System.Exception</h2>"; mess += "<h2>Felmeddelande: " + err.Message + "</h2>"; display.InnerHtml = mess; } }
private static void ValidateMappePeriodTittelEqual(Sok sok, SokeresultatMinimum sokResponse, List <string> validationErrors, Parameter parameter) { var notFoundExpectedRespons = false; foreach (var resultatMinimum in sokResponse.ResultatListe) { var searchText = parameter.Parameterverdier.Stringvalues.First(); //TODO skal vi støtte * var searchTextStripped = searchText.Replace("*", string.Empty); if (sok.Respons == Respons.Mappe) { if (resultatMinimum.Mappe == null && !notFoundExpectedRespons) { validationErrors.Add(string.Format(ValidationErrorMessages.FoundUnexpectedResultTypeAccordingToRespons, sok.Respons.ToString())); notFoundExpectedRespons = true; //Only show this validation message once. Else it will overflow the list. } if (resultatMinimum.Mappe != null && !resultatMinimum.Mappe.Tittel.Contains(searchTextStripped)) { validationErrors.Add(string.Format(ValidationErrorMessages.ResultDontMatchSearchText, parameter.Felt, resultatMinimum.Mappe.Tittel, searchText)); } } else if (sok.Respons == Respons.Saksmappe) { if (resultatMinimum.Saksmappe == null && !notFoundExpectedRespons) { validationErrors.Add(string.Format(ValidationErrorMessages.FoundUnexpectedResultTypeAccordingToRespons, sok.Respons.ToString())); notFoundExpectedRespons = true; //Only show this validation message once. Else it will overflow the list. } if (resultatMinimum.Saksmappe != null && !resultatMinimum.Saksmappe.Tittel.Contains(searchTextStripped)) { validationErrors.Add(string.Format(ValidationErrorMessages.ResultDontMatchSearchText, parameter.Felt, resultatMinimum.Mappe.Tittel, searchText)); } } } }