public string GetHtmlCode(string _link)
 {
     try
     {
         WebRequest request = WebRequest.Create(_link);
         using (WebResponse response = request.GetResponse())
         {
             using (Stream dataStream = response.GetResponseStream())
                 using (StreamReader reader = new StreamReader(dataStream))
                 {
                     _responseFromServer = "";
                     _responseFromServer = reader.ReadToEnd();
                 }
             response.Close();
         }
     }
     catch (WebException e)
     {
         _errorSend.SendMail(_link + " " + e.Message);
     }
     catch (UriFormatException e)
     {
         Console.WriteLine(e.Message);
         _errorSend.SendMail(e.Message);
     }
     return(_responseFromServer);
 }
        public void AddCategory(string categoryTitle)
        {
            SqlParameter ct            = new SqlParameter("@Category", categoryTitle);
            string       sqlExpression = "SELECT id FROM Category WHERE Title = @Category";

            try
            {
                using (SqlConnection connection = new SqlConnection(_connectionString))
                {
                    connection.Open();
                    SqlCommand    command = new SqlCommand(sqlExpression, connection);
                    SqlDataReader reader  = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        Console.WriteLine("Error! That {0} category exists in database", categoryTitle);
                        return;
                    }

                    sqlExpression = "INSERT INTO Category (Title, Enabled) VALUES ('@Category', 1)";
                    command       = new SqlCommand(sqlExpression, connection);
                    int number = command.ExecuteNonQuery();

                    if (number > 0)
                    {
                        _sender.SendMail("Added new category is " + categoryTitle);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occured when try to add new category Info: {0}", ex);
            }
        }
Ejemplo n.º 3
0
        private void FileCheker(string path, string name)
        {
            int t = 0;

            if (File.Exists(path + "\\" + name + ConfigurationManager.AppSettings["fileformat"]))
            {
                while (File.Exists(path + "\\" + name + t.ToString() + ConfigurationManager.AppSettings["fileformat"]))
                {
                    t++;
                }
                _filepath = path + "\\" + name + t.ToString() + ConfigurationManager.AppSettings["fileformat"];
                try
                {
                    using (FileStream fs = File.Create(_filepath)) { }
                }
                catch (Exception ex)
                {
                    _errorSend.SendMail(ex.Message);
                    DisplayInfo.ShowInfo(ex.Message.ToString());
                }
            }
            else
            {
                _filepath = path + "\\" + name + ConfigurationManager.AppSettings["fileformat"];
                try
                {
                    using (FileStream fs = File.Create(_filepath)) { }
                }
                catch (Exception ex)
                {
                    _errorSend.SendMail(ex.Message);
                    DisplayInfo.ShowInfo(ex.Message.ToString());
                }
            }
        }
Ejemplo n.º 4
0
 public void ProcessSendingMessage(FaceAttributes[] faceAttributeses, string userMail, string userName)
 {
     if (FaceValidating(faceAttributeses))
     {
         this.emotionStrategy = emotionStrategyFactory.CreatEmotionStrategy(faceAttributeses[0]);
         smtpSender.SendMail(userMail, newProfilePictureSubject, GenerateMessage(emotionStrategy, userName));
     }
 }
        public void Parse(ref List <LinkInfo> parts, string link)
        {
            Match  m;
            int    code;
            string backlnk, responseFromServer = _net.GetHtmlCode(link), pattern = "(?:href|src)\\s*=\\s*(?:[\"'](?<1>[^\"']*)[\"']|(?<1>\\S+))";

            if (responseFromServer == "")
            {
                return;
            }
            try
            {
                m = Regex.Match(responseFromServer, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled, TimeSpan.FromSeconds(1));
                while (m.Success)
                {
                    backlnk = Cheker(link, m.Groups[1].ToString());
                    if (backlnk != "")
                    {
                        code = _net.GetStatusCode(backlnk);
                        parts.Add(new LinkInfo()
                        {
                            Url = backlnk, Code = code
                        });
                        DisplayInfo.ShowLink(backlnk, code, parts.Count);
                    }
                    m = m.NextMatch();
                }
            }
            catch (RegexMatchTimeoutException e)
            {
                _errorSend.SendMail(e.Message);
                DisplayInfo.ShowInfo("The matching operation timed out.");
            }

            catch (ArgumentNullException e)
            {
                _errorSend.SendMail(e.Message);
                DisplayInfo.ShowInfo(e.Message.ToString());
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> UploadPicture(IFormFile file)
        {
            var user = await this._userManager.GetUserAsync(HttpContext.User);

            string currentUserEmail = user.Email;
            string userId           = user.Id;

            using (var stream = new MemoryStream())
            {
                await file.CopyToAsync(stream);

                await this.blobStorageService.UploadAsync(user.Id, blobContainer, stream.ToArray());
            }


            var pictureUri = await this.blobStorageService.GetAsync(userId, blobContainer);

            user.ProfilePictureUrl = pictureUri.Url.ToString();
            var updated = await this._userManager.UpdateAsync(user);

            var faceAtributes = await faceService.DetectFaceAtribytesAsync(blobStorageService.GetAsync(userId, blobContainer).Result.Url);

            try
            {
                smtpSender.SendMail(user.Email, GenerateMessageByEmotion(faceAtributes[0], user.UserName));
            }
            catch (IndexOutOfRangeException e)
            {
                smtpSender.SendMail(currentUserEmail, "No face on picture");
            }

            StatusMessage = "Your profile picture has been updated. Check your email!";
            var model = new IndexViewModel {
                StatusMessage = StatusMessage
            };

            return(RedirectToAction(nameof(Index)));
        }
        public void Start()
        {
            Console.WriteLine("\t\t\rTop 3 Started!");
            for (;;)
            {
                // Console.WriteLine(_net.GetHtmlCode(_link));
                List <Top3> top3 = new List <Top3>();

                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(_net.GetHtmlCode(@"http://www.stoloto.ru/top3/archive"));
                var el = doc.DocumentNode.Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("elem"));
                foreach (HtmlNode node in el)
                {
                    var top = new Top3();

                    var znach = node.Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("draw_date"));
                    var zn    = node.Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("draw"));
                    foreach (HtmlNode b in znach)
                    {
                        var znach2 = node.Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("container cleared"));

                        top.date = b.InnerText;
                        // Console.Write(b.InnerText + " ");
                        foreach (HtmlNode f in znach2)
                        {
                            Regex rgx = new Regex(@"[^\d]");
                            top.numbers += (rgx.Replace(f.InnerText, ""));
                        }
                    }
                    foreach (HtmlNode b in zn)
                    {
                        var tt = b.Descendants("a");
                        foreach (HtmlNode bb in tt)
                        {
                            top.date = bb.InnerHtml;
                        }
                    }

                    top3.Add(top);
                }
                int           limit     = Settings.top3Count;
                int           sequence  = Settings.top3Seq;
                int           Nsequence = Settings.top3NSeq;
                int[]         chisla    = { 0, 0, 0 };
                int[]         chisla2   = { 0, 0, 0 };
                int           counter   = 0;
                List <string> list      = new List <string>();
                List <string> Nlist     = new List <string>();
                List <string> points    = new List <string>();
                List <string> Npoints   = new List <string>();
                foreach (Top3 t in top3)
                {
                    if (counter == limit)
                    {
                        break;
                    }

                    int j = 0;
                    foreach (char v in t.numbers)
                    {
                        int mbr = -1;
                        int.TryParse(v.ToString(), out mbr);
                        if (mbr != -1)
                        {
                            if (sequence > 0 && Nsequence > 0)
                            {
                                if ((mbr % 2) == 0)
                                {
                                    chisla[j]++;

                                    if (chisla[j] >= sequence)
                                    {
                                        list.Add((j + 1) + "." + chisla[j].ToString());
                                        points.Add(t.date);//end;
                                        chisla[j] = 0;
                                    }

                                    if (chisla2[j] >= Nsequence)
                                    {
                                        Nlist.Add((j + 1) + "." + chisla2[j].ToString());
                                        Npoints.Add(t.date);//end;
                                        chisla2[j] = 0;
                                    }
                                    else
                                    {
                                        chisla2[j] = 0;
                                    }
                                }
                                else
                                {
                                    chisla2[j]++;

                                    if (chisla2[j] >= Nsequence)
                                    {
                                        Nlist.Add((j + 1) + "." + chisla2[j].ToString());
                                        Npoints.Add(t.date);//end;
                                        chisla2[j] = 0;
                                    }

                                    if (chisla[j] >= sequence)
                                    {
                                        list.Add((j + 1) + "." + chisla[j].ToString());
                                        points.Add(t.date);//end;
                                        chisla[j] = 0;
                                    }
                                    else
                                    {
                                        chisla[j] = 0;
                                    }
                                }
                            }
                        }
                        j++;
                    }
                    // Console.Write(t.date + " " + t.numbers+" ");
                    // Console.WriteLine("\n");
                    counter++;
                }

                /* if (list.Count == 0 && Nlist.Count == 0)
                 * {
                 *   Console.WriteLine("\t\t\rFor TOP 3 No data...");
                 *   continue;
                 * }*/

                string lastFile = Settings.lastFile;

                string     result = "";
                FileWriter fl     = new FileWriter("TOP3");
                int        index  = 0;
                fl.Write("<html><head></head><body><h2>Четные</h2><table><tr><td>Ряд</td><td>Подряд (раз)</td><td>Тираж</td></tr>");
                foreach (string str in list)
                {
                    string outer = "<tr> ";
                    foreach (char c in str)
                    {
                        if (c == '.')
                        {
                            continue;
                        }
                        outer += "<td>" + c.ToString() + "</td>";
                    }
                    int aqq;
                    int.TryParse(points[index], out aqq);
                    outer += " " + "<td>" + (aqq + Settings.top3Seq - 1) + "</td></tr>";
                    fl.Write(outer);
                    result += outer;
                    index++;
                }
                result = "<h2>Четные</h2><table><tr><td>Ряд</td><td>Подряд (раз)</td><td>Тираж</td></tr>" + result + "</table><br>";

                fl.Write("</table><br><h2>Нечетные</h2><table><tr><td>Ряд</td><td>Подряд (раз)</td><td>Тираж</td></tr>");

                index = 0;
                string result2 = "";
                foreach (string str in Nlist)
                {
                    string outer = "<tr> ";

                    foreach (char c in str)
                    {
                        if (c == '.')
                        {
                            continue;
                        }
                        outer += "<td>" + c.ToString() + "</td>";
                    }
                    int aqq;
                    int.TryParse(Npoints[index], out aqq);
                    outer += " " + "<td>" + (aqq + Settings.top3NSeq - 1) + "</td></tr>";
                    fl.Write(outer);
                    result2 += outer;
                    index++;
                }

                result2 = "<h2>Нечетные</h2><table><tr><td>Ряд</td><td>Подряд (раз)</td><td>Тираж</td></tr>" + result2 + "</table>";
                result += result2;
                result  = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title> TOP 3</title></head><body>" + result + "</body></html>";

                fl.Write("</table></body></html>");

                Console.WriteLine("\t\t\rTOP 3 data saved in file!\t");

                if (Settings.emailOn == 1)
                {
                    _sender.SendMail(result, "TOP 3");
                }

                /*   if(lastFile != null)
                 * if(fl.NotEqualFile(lastFile, Settings.lastFile))
                 * Settings.soundLoop++;*/
                string tmpmd5 = "";
                if (Settings.top3MD5 != null)
                {
                    tmpmd5 = fl.GetMD5();
                    if (tmpmd5 != null)
                    {
                        if (Settings.top3MD5 != tmpmd5)
                        {
                            Settings.soundLoop++;
                            Console.WriteLine("***Top 3 NEW Combination***");
                            Console.WriteLine("{0} != {1}", Settings.top3MD5, tmpmd5);
                        }
                        else
                        {
                            Console.WriteLine("{0} = {1}", Settings.top3MD5, tmpmd5);
                        }
                    }
                }
                Settings.top3MD5 = fl.GetMD5();
                int timer = 0;
                while (true)
                {
                    if (!Settings.top3Thread)
                    {
                        Console.WriteLine("\t\t\rTop 3 stoped!");
                        return;
                    }

                    if (timer >= Settings.top3Time)
                    {
                        break;
                    }

                    timer++;
                    //Console.WriteLine("Next TOP 3 in {0} ", Settings.top3Time - timer);
                    Thread.Sleep(1000);
                }
            }
        }