Lauda

Untitled

Dec 10th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 22.03 KB | None | 0 0
  1. // Decompiled with JetBrains decompiler
  2. // Type: ImageEditor.util.SCKolokvijum2014
  3. // Assembly: ImageEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  4. // MVID: 898CD58A-25C2-45D2-B6C8-07901E3DDD0B
  5. // Assembly location: F:\Downloads\SC vezba7 - priprema za kolokvijum-Dabic\SC vezba7 - priprema za kolokvijum-Dabic\SC vezba7 - priprema2\src\lib\ImageEditor.dll
  6.  
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Linq;
  9. using StringMatching;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Drawing;
  13. using System.Drawing.Drawing2D;
  14. using System.IO;
  15. using System.Net;
  16. using System.Windows.Forms;
  17.  
  18. namespace ImageEditor.util
  19. {
  20.   public class SCKolokvijum2014
  21.   {
  22.     private int w = 1680;
  23.     private int h = 480;
  24.     private string _test = "";
  25.     private int _duzinaReda = 10;
  26.     private int _minBrojReci = 2;
  27.     private int _maxBrojReci = 3;
  28.     private int _minBrojRedova = 2;
  29.     private int _maxBrojRedova = 3;
  30.     private double prag = 0.0;
  31.     private int uspeh = 0;
  32.     private DateTime start = DateTime.Now;
  33.     private Dictionary<string, string> _alfabeti = new Dictionary<string, string>();
  34.     private Dictionary<string, HashSet<string>> _recnici = new Dictionary<string, HashSet<string>>();
  35.     private Dictionary<string, List<string>> _recenice = new Dictionary<string, List<string>>();
  36.     private Dictionary<string, bool> _inverzno = new Dictionary<string, bool>();
  37.     private Dictionary<string, int> _brojRedova = new Dictionary<string, int>();
  38.     private Dictionary<string, Color> _bojaSlova = new Dictionary<string, Color>();
  39.     private Dictionary<string, Color> _bojaPozadine = new Dictionary<string, Color>();
  40.     private string _serverUrl = "http://localhost/Mvc4WebApi/";
  41.     private Font f1 = new Font("Verdana", 30f, FontStyle.Bold);
  42.     private Font f2 = new Font("Comic Sans MS", 25f, FontStyle.Bold);
  43.     private Font f3 = new Font("Courier New", 35f, FontStyle.Bold);
  44.     private Random rnd = new Random();
  45.     private bool _generateRandom = false;
  46.     public List<SCKolokvijum2014Rez> rezultati = new List<SCKolokvijum2014Rez>();
  47.     private FrmKolokvijumRezultati frm = (FrmKolokvijumRezultati) null;
  48.     private string _putanjaObucavajuciSkup;
  49.     private string _putanjaTestiranje;
  50.  
  51.     public int Uspeh
  52.     {
  53.       get
  54.       {
  55.         return this.uspeh;
  56.       }
  57.     }
  58.  
  59.     public Dictionary<string, string> Alfabeti
  60.     {
  61.       get
  62.       {
  63.         return this._alfabeti;
  64.       }
  65.     }
  66.  
  67.     public Dictionary<string, HashSet<string>> Recnici
  68.     {
  69.       get
  70.       {
  71.         return this._recnici;
  72.       }
  73.     }
  74.  
  75.     public SCKolokvijum2014(string putanjaObucavajuciSkup, string putanjaTestiranje, string serverUrl)
  76.     {
  77.       this._putanjaObucavajuciSkup = putanjaObucavajuciSkup;
  78.       this._putanjaTestiranje = putanjaTestiranje;
  79.       this._serverUrl = serverUrl;
  80.       string str1 = System.IO.File.ReadAllText(this._putanjaObucavajuciSkup).Trim();
  81.       string[] strArray1 = System.IO.File.ReadAllLines(this._putanjaTestiranje);
  82.       string[] strArray2 = new string[1]
  83.       {
  84.         "1"
  85.       };
  86.       foreach (string index in strArray2)
  87.       {
  88.         int num = 0;
  89.         List<string> list = new List<string>();
  90.         string[] strArray3 = (string[]) null;
  91.         switch (index)
  92.         {
  93.           case "1":
  94.             strArray3 = new string[2]
  95.             {
  96.               "a",
  97.               "รค"
  98.             };
  99.             this._inverzno.Add(index, false);
  100.             num = 0;
  101.             this._brojRedova.Add(index, 2);
  102.             break;
  103.         }
  104.         if (!this._inverzno[index])
  105.           this._bojaPozadine.Add(index, Color.FromArgb((int) byte.MaxValue, 180, 180, 180));
  106.         if (num == 0)
  107.           this._bojaSlova.Add(index, !this._inverzno[index] ? Color.FromArgb((int) byte.MaxValue, 240, 170, 110) : Color.FromArgb((int) byte.MaxValue, 140, 30, 10));
  108.         string str2 = str1.Replace(", ", "").Replace(strArray3[0], strArray3[1]);
  109.         this._alfabeti.Add(index, str2);
  110.         foreach (string str3 in strArray1)
  111.         {
  112.           string str4 = str3.Substring(str3.LastIndexOf('}') + 1).ToLower().Replace(strArray3[0], strArray3[1]).Replace("!", "").Replace("?", "").Replace(".", "").Replace(",", "").Replace("'", "").Replace("-", "").Replace(":", "");
  113.           list.Add(str4);
  114.         }
  115.         this._recenice.Add(index, list);
  116.         this._recnici.Add(index, this.GenerisiRecnik(index));
  117.       }
  118.     }
  119.  
  120.     private HashSet<string> GenerisiRecnik(string sifra)
  121.     {
  122.       HashSet<string> hashSet = new HashSet<string>();
  123.       foreach (string str1 in this._recenice[sifra])
  124.       {
  125.         string str2 = str1.Replace("|", " ");
  126.         char[] chArray = new char[1]
  127.         {
  128.           ' '
  129.         };
  130.         foreach (string str3 in str2.Split(chArray))
  131.         {
  132.           if (!hashSet.Contains(str3))
  133.           {
  134.             if (str3.Contains(Environment.NewLine))
  135.               Console.WriteLine(str3);
  136.             hashSet.Add(str3);
  137.           }
  138.         }
  139.       }
  140.       return hashSet;
  141.     }
  142.  
  143.     public string GetAlfabetServer(string sifra)
  144.     {
  145.       WebRequest webRequest = WebRequest.Create(this._serverUrl + "api/alphabets?sifra=" + sifra);
  146.       webRequest.Method = "GET";
  147.       WebResponse response = webRequest.GetResponse();
  148.       Console.WriteLine(((HttpWebResponse) response).StatusDescription);
  149.       Stream responseStream = response.GetResponseStream();
  150.       StreamReader streamReader = new StreamReader(responseStream);
  151.       JObject jobject = (JObject) JsonConvert.DeserializeObject(streamReader.ReadToEnd());
  152.       streamReader.Close();
  153.       responseStream.Close();
  154.       response.Close();
  155.       return (string) jobject.GetValue("Alphabet");
  156.     }
  157.  
  158.     public string GetAlfabet(string sifra)
  159.     {
  160.       return this._alfabeti[sifra];
  161.     }
  162.  
  163.     public HashSet<string> GetRecnikServer(string sifra)
  164.     {
  165.       WebRequest webRequest = WebRequest.Create(this._serverUrl + "api/dictionaries?sifra=" + sifra);
  166.       webRequest.Method = "GET";
  167.       WebResponse response = webRequest.GetResponse();
  168.       Console.WriteLine(((HttpWebResponse) response).StatusDescription);
  169.       Stream responseStream = response.GetResponseStream();
  170.       StreamReader streamReader = new StreamReader(responseStream);
  171.       JObject jobject = (JObject) JsonConvert.DeserializeObject(streamReader.ReadToEnd());
  172.       streamReader.Close();
  173.       responseStream.Close();
  174.       response.Close();
  175.       HashSet<string> hashSet = new HashSet<string>();
  176.       foreach (JValue jvalue in (IEnumerable<JToken>) Extensions.AsJEnumerable((IEnumerable<JToken>) jobject.GetValue("Dictionary")))
  177.         hashSet.Add(((object) jvalue).ToString());
  178.       return hashSet;
  179.     }
  180.  
  181.     public HashSet<string> GetRecnik(string sifra)
  182.     {
  183.       return this._recnici[sifra];
  184.     }
  185.  
  186.     public Bitmap SlikaZaObucavanjeServer(string indeks, string ime, string prezime, ZaOcenu zaOcenu, string sifra)
  187.     {
  188.       using (WebClient webClient = new WebClient())
  189.       {
  190.         int num = zaOcenu == ZaOcenu.Sest ? 0 : (zaOcenu == ZaOcenu.Sedam ? 1 : 2);
  191.         Stream stream = webClient.OpenRead(this._serverUrl + (object) "api/images?indeks=" + indeks + "&ime=" + ime + "&prezime=" + prezime + "&tezina=" + (string) (object) num + "&sifra=" + sifra + "&obuka=true");
  192.         Bitmap bitmap = new Bitmap(stream);
  193.         stream.Flush();
  194.         stream.Close();
  195.         Console.WriteLine(webClient.ResponseHeaders.Get("uuid"));
  196.         webClient.Dispose();
  197.         return bitmap;
  198.       }
  199.     }
  200.  
  201.     public Bitmap SlikaZaObucavanje(string sifra)
  202.     {
  203.       Bitmap bitmap = new Bitmap(this.w, this.h);
  204.       Graphics gr = Graphics.FromImage((Image) bitmap);
  205.       Color[] colorArray = this.BojeSlova(sifra);
  206.       if (!this._inverzno[sifra])
  207.       {
  208.         this.Pozadina(gr, sifra);
  209.       }
  210.       else
  211.       {
  212.         colorArray = this.BojeSlovaInv(sifra);
  213.         this.PozadinaInv(gr, sifra);
  214.       }
  215.       int num1 = 30;
  216.       int num2 = 30;
  217.       int num3 = 0;
  218.       SizeF sizeF;
  219.       for (int index = 0; index < this._alfabeti[sifra].Length; ++index)
  220.       {
  221.         string text = string.Concat((object) this._alfabeti[sifra][index]);
  222.         sizeF = gr.MeasureString(text, this.f1);
  223.         int num4 = (int) sizeF.Width;
  224.         num3 = (int) sizeF.Height;
  225.         SolidBrush solidBrush = new SolidBrush(colorArray[index % 30]);
  226.         gr.DrawString(text ?? "", this.f1, (Brush) solidBrush, (float) num1, (float) num2);
  227.         num1 += num4 + 5;
  228.       }
  229.       int num5 = 30;
  230.       int num6 = num2 + (num3 + 20);
  231.       for (int index = 0; index < this._alfabeti[sifra].Length; ++index)
  232.       {
  233.         string text = string.Concat((object) this._alfabeti[sifra][index]);
  234.         sizeF = gr.MeasureString(text, this.f2);
  235.         int num4 = (int) sizeF.Width;
  236.         num3 = (int) sizeF.Height;
  237.         SolidBrush solidBrush = new SolidBrush(colorArray[index % 30]);
  238.         gr.DrawString(text ?? "", this.f2, (Brush) solidBrush, (float) num5, (float) num6);
  239.         num5 += num4 + 5;
  240.       }
  241.       int num7 = 30;
  242.       int num8 = num6 + (num3 + 20);
  243.       for (int index = 0; index < this._alfabeti[sifra].Length; ++index)
  244.       {
  245.         string text = string.Concat((object) this._alfabeti[sifra][index]);
  246.         sizeF = gr.MeasureString(text, this.f3);
  247.         int num4 = (int) sizeF.Width;
  248.         SolidBrush solidBrush = new SolidBrush(colorArray[index % 30]);
  249.         gr.DrawString(text ?? "", this.f3, (Brush) solidBrush, (float) num7, (float) num8);
  250.         num7 += num4 + 5;
  251.       }
  252.       this.UbaciShum(gr, sifra);
  253.       gr.Dispose();
  254.       return bitmap;
  255.     }
  256.  
  257.     protected void Pozadina(Graphics gr, string sifra)
  258.     {
  259.       int alpha = (int) byte.MaxValue;
  260.       Color color = this._bojaPozadine[sifra];
  261.       int red = (int) color.R + this.rnd.Next(30) - 15;
  262.       color = this._bojaPozadine[sifra];
  263.       int green = (int) color.G + this.rnd.Next(30) - 15;
  264.       color = this._bojaPozadine[sifra];
  265.       int blue = (int) color.B + this.rnd.Next(30) - 15;
  266.       Color color2 = Color.FromArgb(alpha, red, green, blue);
  267.       LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new Point(0, 0), new Point(this.w, this.h), this._bojaPozadine[sifra], color2);
  268.       Pen pen = new Pen((Brush) linearGradientBrush);
  269.       gr.FillRectangle((Brush) linearGradientBrush, 0, 0, this.w, this.h);
  270.     }
  271.  
  272.     protected void PozadinaInv(Graphics gr, string sifra)
  273.     {
  274.       int alpha = (int) byte.MaxValue;
  275.       Color color = this._bojaPozadine[sifra];
  276.       int red = (int) color.R + this.rnd.Next(30) - 15;
  277.       color = this._bojaPozadine[sifra];
  278.       int green = (int) color.G + this.rnd.Next(30) - 15;
  279.       color = this._bojaPozadine[sifra];
  280.       int blue = (int) color.B + this.rnd.Next(30) - 15;
  281.       Color color2 = Color.FromArgb(alpha, red, green, blue);
  282.       LinearGradientBrush linearGradientBrush = new LinearGradientBrush(new Point(0, 0), new Point(this.w, this.h), this._bojaPozadine[sifra], color2);
  283.       Pen pen = new Pen((Brush) linearGradientBrush);
  284.       gr.FillRectangle((Brush) linearGradientBrush, 0, 0, this.w, this.h);
  285.     }
  286.  
  287.     protected Color[] BojeSlova(string sifra)
  288.     {
  289.       Color[] colorArray = new Color[30];
  290.       for (int index = 0; index < 30; ++index)
  291.       {
  292.         this.rnd.Next(100);
  293.         int num = index % 3;
  294.         int alpha = (int) byte.MaxValue;
  295.         Color color1 = this._bojaSlova[sifra];
  296.         int red = (int) color1.R + this.rnd.Next(20) - 10;
  297.         color1 = this._bojaSlova[sifra];
  298.         int green = (int) color1.G + this.rnd.Next(20) - 10;
  299.         color1 = this._bojaSlova[sifra];
  300.         int blue = (int) color1.B + this.rnd.Next(20) - 10;
  301.         Color color2 = Color.FromArgb(alpha, red, green, blue);
  302.         colorArray[index] = color2;
  303.       }
  304.       return colorArray;
  305.     }
  306.  
  307.     protected Color[] BojeSlovaInv(string sifra)
  308.     {
  309.       return this.BojeSlova(sifra);
  310.     }
  311.  
  312.     protected void UbaciShum(Graphics gr, string sifra)
  313.     {
  314.       Random random = new Random();
  315.       int num = 200;
  316.       for (int index = 0; index < num; ++index)
  317.       {
  318.         int x = random.Next(this.w - 1);
  319.         int y = random.Next(this.h - 1);
  320.         if (!this._inverzno[sifra])
  321.           gr.DrawRectangle(Pens.Brown, x, y, 1, 1);
  322.         else
  323.           gr.DrawRectangle(Pens.Yellow, x, y, 1, 1);
  324.       }
  325.     }
  326.  
  327.     public Bitmap SlikaZaTestServer(string indeks, string ime, string prezime, ZaOcenu zaOcenu, string sifra, out string uuid)
  328.     {
  329.       using (WebClient webClient = new WebClient())
  330.       {
  331.         int num = zaOcenu == ZaOcenu.Sest ? 0 : (zaOcenu == ZaOcenu.Sedam ? 1 : 2);
  332.         Stream stream = webClient.OpenRead(this._serverUrl + (object) "api/images?indeks=" + indeks + "&ime=" + ime + "&prezime=" + prezime + "&tezina=" + (string) (object) num + "&sifra=" + sifra + "&obuka=false");
  333.         Bitmap bitmap = new Bitmap(stream);
  334.         stream.Flush();
  335.         stream.Close();
  336.         webClient.Dispose();
  337.         uuid = webClient.ResponseHeaders.Get("uuid");
  338.         return bitmap;
  339.       }
  340.     }
  341.  
  342.     public Bitmap SlikaZaTest(string indeks, string ime, string prezime, string sifra, ZaOcenu tezina)
  343.     {
  344.       Bitmap bitmap = new Bitmap(this.w, this.h);
  345.       Graphics gr = Graphics.FromImage((Image) bitmap);
  346.       gr.InterpolationMode = InterpolationMode.High;
  347.       Color[] colorArray = this.BojeSlova(sifra);
  348.       if (!this._inverzno[sifra])
  349.       {
  350.         this.Pozadina(gr, sifra);
  351.       }
  352.       else
  353.       {
  354.         colorArray = this.BojeSlovaInv(sifra);
  355.         this.PozadinaInv(gr, sifra);
  356.       }
  357.       Font font = this.f1;
  358.       switch (this.rnd.Next(3))
  359.       {
  360.         case 0:
  361.           font = this.f1;
  362.           break;
  363.         case 1:
  364.           font = this.f2;
  365.           break;
  366.         case 2:
  367.           font = this.f3;
  368.           break;
  369.       }
  370.       int num1 = 20;
  371.       float angle = 0.5f + (float) this.rnd.Next(2);
  372.       gr.RotateTransform(angle);
  373.       int num2 = 1;
  374.       int num3 = 70;
  375.       if (!this._generateRandom)
  376.       {
  377.         string str1 = "";
  378.         while (true)
  379.         {
  380.           string str2;
  381.           string str3;
  382.           char[] chArray;
  383.           do
  384.           {
  385.             int num4;
  386.             if (str1.Length >= 25)
  387.               num4 = str1.Split('|').Length < this._brojRedova[sifra] ? 1 : 0;
  388.             else
  389.               num4 = 1;
  390.             if (num4 != 0)
  391.             {
  392.               str2 = this._recenice[sifra][this.rnd.Next(this._recenice[sifra].Count - 1)].Split('|')[0];
  393.               str3 = str2;
  394.               chArray = new char[1]
  395.               {
  396.                 ' '
  397.               };
  398.             }
  399.             else
  400.               goto label_15;
  401.           }
  402.           while (str3.Split(chArray).Length < 3);
  403.           str1 = !(str1 == "") ? str1 + "|" + str2 : str2;
  404.         }
  405. label_15:
  406.         string str4 = "";
  407.         string[] strArray1 = str1.Split('|');
  408.         int num5 = strArray1.Length;
  409.         for (int index = 0; index < this._brojRedova[sifra]; ++index)
  410.           str4 = str4 + strArray1[index] + "|";
  411.         string str5 = str4.Substring(0, str4.Length - 1);
  412.         if (tezina == ZaOcenu.Sest)
  413.         {
  414.           this._test = str5.Split('|')[0].Replace("|", " ").Replace(" ", "");
  415.           num5 = 1;
  416.         }
  417.         else if (tezina == ZaOcenu.Sedam)
  418.         {
  419.           this._test = str5.Split('|')[0].Replace("|", " ");
  420.           num5 = 1;
  421.         }
  422.         else if (tezina == ZaOcenu.Osam)
  423.         {
  424.           this._test = str5;
  425.           num5 = this._test.Split("|".ToCharArray()).Length;
  426.         }
  427.         string[] strArray2 = this._test.Split("|".ToCharArray());
  428.         for (int index1 = 0; index1 < num5; ++index1)
  429.         {
  430.           int num4 = 30;
  431.           int num6 = index1 * num3;
  432.           string str2 = strArray2[index1].Trim();
  433.           int num7 = this.rnd.Next(str2.Length);
  434.           string[] strArray3 = str2.Split(' ');
  435.           int num8 = 6;
  436.           int num9 = -1;
  437.           for (int index2 = 0; index2 < strArray3.Length; ++index2)
  438.           {
  439.             if (strArray3[index2].Length > num8)
  440.             {
  441.               num9 = str2.IndexOf(strArray3[index2]);
  442.               num8 = strArray3[index2].Length;
  443.             }
  444.           }
  445.           for (int index2 = 0; index2 < str2.Length; ++index2)
  446.           {
  447.             char ch = str2[index2];
  448.             if (tezina == ZaOcenu.Osam && (int) str2[index2] != 32 && (num9 != -1 && index2 > num9) && index2 < num9 + num8 && this.rnd.Next(15) == 1)
  449.               ch = this._alfabeti[sifra][this.rnd.Next(this._alfabeti[sifra].Length - 1)];
  450.             string text = string.Concat((object) ch);
  451.             SizeF sizeF = gr.MeasureString(text, font);
  452.             int num10 = (int) sizeF.Width;
  453.             int num11 = (int) sizeF.Height;
  454.             SolidBrush solidBrush = new SolidBrush(colorArray[index2 % 30]);
  455.             gr.DrawString(text ?? "", font, (Brush) solidBrush, (float) num4, (float) (num1 + num6));
  456.             if (index2 == num7)
  457.               gr.DrawLine(new Pen(this._bojaSlova[sifra]), new Point(num4, num1 + num6), new Point(num4 + num10, num1 + num11 + num6));
  458.             if ((int) str2[index2] == 32)
  459.               num4 += num10 / 2 + 35;
  460.             else
  461.               num4 += num10 / 2 + 20;
  462.           }
  463.           int x = this.rnd.Next(num4);
  464.           gr.DrawEllipse(new Pen(this._bojaSlova[sifra]), x, num1 + num6, 65, 30);
  465.         }
  466.       }
  467.       else
  468.       {
  469.         if (tezina == ZaOcenu.Osam)
  470.           num2 = this.rnd.Next(this._minBrojRedova, this._maxBrojRedova + 1);
  471.         for (int index1 = 0; index1 < num2; ++index1)
  472.         {
  473.           int num4 = 30;
  474.           this._test = "";
  475.           int num5 = index1 * num3;
  476.           for (int index2 = 0; index2 < this._duzinaReda; ++index2)
  477.           {
  478.             int index3 = this.rnd.Next(this._alfabeti[sifra].Length);
  479.             SCKolokvijum2014 scKolokvijum2014 = this;
  480.             string str = scKolokvijum2014._test + (object) this._alfabeti[sifra][index3];
  481.             scKolokvijum2014._test = str;
  482.           }
  483.           int num6 = this.rnd.Next(this._duzinaReda);
  484.           List<int> list = new List<int>();
  485.           if (tezina == ZaOcenu.Sedam || tezina == ZaOcenu.Osam)
  486.           {
  487.             int num7 = this.rnd.Next(this._minBrojReci, this._maxBrojReci + 1);
  488.             for (int index2 = 0; index2 < num7; ++index2)
  489.             {
  490.               int num8 = this.rnd.Next(1, this._duzinaReda);
  491.               if (list.Contains(num8))
  492.                 --index2;
  493.               else
  494.                 list.Add(num8);
  495.             }
  496.           }
  497.           for (int index2 = 0; index2 < this._duzinaReda; ++index2)
  498.           {
  499.             string text = string.Concat((object) this._test[index2]);
  500.             SizeF sizeF = gr.MeasureString(text, font);
  501.             int num7 = (int) sizeF.Width;
  502.             int num8 = (int) sizeF.Height;
  503.             SolidBrush solidBrush = new SolidBrush(colorArray[index2 % 30]);
  504.             gr.DrawString(text ?? "", font, (Brush) solidBrush, (float) num4, (float) (num1 + num5));
  505.             if (index2 == num6)
  506.               gr.DrawLine(Pens.Green, new Point(num4, num1 + num5), new Point(num4 + num7, num1 + num8 + num5));
  507.             if (list.Contains(index2))
  508.               num4 += num7 / 2 + 30;
  509.             else
  510.               num4 += num7 / 2 + 5;
  511.           }
  512.           int x = this.rnd.Next(num4);
  513.           if (!this._inverzno[sifra])
  514.             gr.DrawEllipse(Pens.Green, x, num1 + num5, 65, 30);
  515.           else
  516.             gr.DrawEllipse(Pens.YellowGreen, x, num1 + num5, 65, 30);
  517.         }
  518.       }
  519.       this.UbaciShum(gr, sifra);
  520.       gr.Dispose();
  521.       this.start = DateTime.Now;
  522.       return bitmap;
  523.     }
  524.  
  525.     public double ProveraServer(string uuid, string text)
  526.     {
  527.       WebRequest webRequest = WebRequest.Create(this._serverUrl + "api/images?uuid=" + uuid + "&text=" + text);
  528.       webRequest.Method = "POST";
  529.       webRequest.ContentLength = 0L;
  530.       WebResponse response = webRequest.GetResponse();
  531.       Console.WriteLine(((HttpWebResponse) response).StatusDescription);
  532.       Stream responseStream = response.GetResponseStream();
  533.       StreamReader streamReader = new StreamReader(responseStream);
  534.       JObject jobject = (JObject) JsonConvert.DeserializeObject(streamReader.ReadToEnd());
  535.       double num1 = (double) jobject.GetValue("Success");
  536.       double num2 = (double) jobject.GetValue("Time");
  537.       string str = (string) jobject.GetValue("Text");
  538.       streamReader.Close();
  539.       responseStream.Close();
  540.       response.Close();
  541.       this.rezultati.Add(new SCKolokvijum2014Rez()
  542.       {
  543.         test = str,
  544.         prepoznato = text,
  545.         totalms = num2,
  546.         r = num1
  547.       });
  548.       ++this.uspeh;
  549.       if (this.frm == null)
  550.       {
  551.         this.frm = new FrmKolokvijumRezultati(this);
  552.         ((Control) this.frm).Show();
  553.       }
  554.       else if (this.frm.IsDisposed)
  555.       {
  556.         this.frm = new FrmKolokvijumRezultati(this);
  557.         ((Control) this.frm).Show();
  558.       }
  559.       else
  560.         this.frm.osveziRezultate();
  561.       return num1;
  562.     }
  563.  
  564.     public double Provera(string pp, ZaOcenu tezina)
  565.     {
  566.       pp = pp.Replace("\n", "|").Replace("\r", "");
  567.       if (tezina == ZaOcenu.Sest)
  568.         pp = pp.Replace(" ", "");
  569.       double totalMilliseconds = (DateTime.Now - this.start).TotalMilliseconds;
  570.       double num = 1.0 - (double) Levenshtein.LevenshteinDistance(this._test, pp) / (double) Math.Max(this._test.Length, pp.Length);
  571.       if (num >= this.prag)
  572.       {
  573.         this.rezultati.Add(new SCKolokvijum2014Rez()
  574.         {
  575.           test = this._test,
  576.           prepoznato = pp,
  577.           totalms = totalMilliseconds,
  578.           r = num
  579.         });
  580.         ++this.uspeh;
  581.         if (this.frm == null)
  582.         {
  583.           this.frm = new FrmKolokvijumRezultati(this);
  584.           ((Control) this.frm).Show();
  585.         }
  586.         else if (this.frm.IsDisposed)
  587.         {
  588.           this.frm = new FrmKolokvijumRezultati(this);
  589.           ((Control) this.frm).Show();
  590.         }
  591.         else
  592.           this.frm.osveziRezultate();
  593.       }
  594.       return num;
  595.     }
  596.   }
  597. }
Advertisement
Add Comment
Please, Sign In to add comment