Пример #1
0
        /// <summary>
        /// Add an html sample to the tree and to all samples collection
        /// </summary>
        private void AddTreeNode(TreeNode root, HtmlSample sample)
        {
            var node = new TreeNode(sample.Name);

            node.Tag = new HtmlSample(sample.Name, sample.FullName, sample.Html);
            root.Nodes.Add(node);
        }
Пример #2
0
        public void Run(string city)
        {
            WeatherManager mgr;

            try
            {
                mgr = new WeatherManager(city);
            }
            catch (System.Net.WebException)
            {
                label2.Text       = "Nie znalaziono takiego miasta.";
                pictureBox1.Image = null;
                return;
            }
            WeatherInfo weatherInfo = mgr.weatherInfo;

            label2.Text = $"Temperatura w {weatherInfo.Name} wynosi teraz {weatherInfo.Main.Temp - 273} st. Celcjusza. Prędkość wiatru wynosi {weatherInfo.Wind.Speed} m/s, a ciśnienie {weatherInfo.Main.Pressure} hPa.";
            string    IconUrl    = "http://openweathermap.org/img/w/" + weatherInfo.Weather[0].Icon + ".png";
            string    IconPath   = weatherInfo.Weather[0].Icon + ".png";
            var       hs         = new HtmlSample(IconUrl);
            WebClient IconClient = new WebClient();

            IconClient.DownloadFile(IconUrl, IconPath);
            pictureBox1.ImageLocation = IconPath;
        }
Пример #3
0
        public void UpdateImagePath()
        {
            string wantedJpgPath = TaskName + Id.ToString() + ".jpg";
            var    hs            = new HtmlSample(Url);

            JpgPath = hs.FindByWord(Word, wantedJpgPath, Url);
        }
Пример #4
0
        /// <summary>
        /// Sets up a sample with anchor elements for a specific route.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="routename">The route name.</param>
        /// <param name="controller">The name of the controller.</param>
        /// <param name="action">The action method.</param>
        /// <param name="label">The label to use for the anchor element.</param>
        /// <param name="querystring">An optional querystring to append to the link's url.</param>
        /// <param name="parameters">The parameters of the action method.</param>
        /// <returns>
        /// Returns an instance of <see cref="T:Geocrest.Web.Mvc.Documentation.HtmlSample">HtmlSample</see>.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">configuration or routename or controller or action or label</exception>
        protected virtual HtmlSample SetLinkSample(HttpConfiguration configuration, string routename, string controller, string action,
                                                   string label, string querystring = "", params IDictionary <string, object>[] parameters)
        {
            Throw.IfArgumentNull(configuration, "configuration");
            Throw.IfArgumentNullOrEmpty(routename, "routename");
            Throw.IfArgumentNullOrEmpty(controller, "controller");
            Throw.IfArgumentNullOrEmpty(action, "action");
            Throw.IfArgumentNullOrEmpty(label, "label");

            RouteValueDictionary baseroute = new RouteValueDictionary(new
            {
                area       = AreaName.ToLower(),
                controller = controller,
                routename  = routename,
                action     = action
            });

            if (parameters == null || parameters.Length == 0)
            {
                return(SetLinkSample(configuration, baseroute, label, querystring, null));
            }

            HtmlSample sample = null;

            foreach (var paramDict in parameters)
            {
                sample = SetLinkSample(configuration, baseroute, label, querystring, paramDict);
            }
            return(sample);
        }
Пример #5
0
        /// <summary>
        /// Sets the HTML sample.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="route">The route.</param>
        /// <param name="html">The HTML.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="ispartial"><b>true</b>, if partial; otherwise, <b>false</b>.</param>
        /// <returns></returns>
        private HtmlSample SetHtmlSample(HttpConfiguration configuration, RouteValueDictionary route,
                                         string html, string[] parameters = null, bool ispartial = false)
        {
            string action = route["action"].ToString();

            route.Remove("action");

            // finish route
            if (parameters != null)
            {
                foreach (var param in parameters)
                {
                    route.Add(param, null);
                }
            }
            HtmlSample sample = new HtmlSample(html, ispartial);

            if (parameters != null)
            {
                configuration.SetHtmlSample(sample, route["controller"].ToString(), action, parameters);
            }
            else
            {
                configuration.SetHtmlSample(sample, route["controller"].ToString(), action);
            }

            return(sample);
        }
Пример #6
0
        /// <summary>
        /// Add an html sample to the tree and to all samples collection
        /// </summary>
        private void AddTreeItem(TreeViewItem root, HtmlSample sample)
        {
            var html = sample.Html.Replace("$$Release$$", _htmlPanel.GetType().Assembly.GetName().Version.ToString());

            var node = new TreeViewItem();

            node.Header = sample.Name;
            node.Tag    = new HtmlSample(sample.Name, sample.FullName, html);
            root.Items.Add(node);
        }
Пример #7
0
        /// <summary>
        /// Sets the link sample.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="route">The route.</param>
        /// <param name="label">The label.</param>
        /// <param name="querystring">The querystring.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        private HtmlSample SetLinkSample(HttpConfiguration configuration, RouteValueDictionary route,
                                         string label, string querystring = "", IDictionary <string, object> parameters = null)
        {
            var    baseroute = new RouteValueDictionary(route);
            string action    = route["action"].ToString();

            baseroute.Remove("action");

            // finish route
            if (parameters != null)
            {
                foreach (var kvp in parameters)
                {
                    baseroute.Add(kvp.Key, kvp.Value);
                }
            }
            if (!string.IsNullOrEmpty(querystring))
            {
                var query = HttpUtility.ParseQueryString(querystring);
                foreach (var q in query.AllKeys)
                {
                    baseroute.Add(q, query[q]);
                }
            }

            // get the existing link sample
            HtmlSample link = configuration.GetHtmlSamples(baseroute["controller"].ToString(), action,
                                                           parameters != null ? parameters.Select(x => x.Key).ToArray() : new string[] { })
                              .FirstOrDefault(x => x is LinkSample);

            // add if sample exists
            if (link != null && link is LinkSample)
            {
                (link as LinkSample).Routes.Add(new KeyValuePair <RouteValueDictionary, string>(baseroute, label));
            }
            else // create new sample
            {
                link = new LinkSample(new List <KeyValuePair <RouteValueDictionary, string> >
                {
                    { new KeyValuePair <RouteValueDictionary, string>(baseroute, label) }
                });
                if (parameters != null)
                {
                    configuration.SetHtmlSample(link, baseroute["controller"].ToString(), action, parameters.Keys.ToArray());
                }
                else
                {
                    configuration.SetHtmlSample(link, baseroute["controller"].ToString(), action);
                }
            }
            return(link);
        }
Пример #8
0
        public Json(string city)
        {
            var site   = new HtmlSample("http://api.openweathermap.org/data/2.5/weather?q=" + city + ",pl&APPID=5a2583f8a76134addaffb0299912a39a");
            var api    = site.GetPageHtml();
            var output = JsonConvert.DeserializeObject(api);

            WeatherForecast deserializedWeather = JsonConvert.DeserializeObject <WeatherForecast>(output.ToString());

            temperature = Math.Round((deserializedWeather.Main.temp - 273), 1);
            description = "Dzisiaj jest " + temperature + " stopni Celcjusza. Ciśnienie " + deserializedWeather.Main.pressure + " hPa. " +
                          "A co na niebie? " + deserializedWeather.Weather[0].description;
            image = "http://openweathermap.org/img/w/" + deserializedWeather.Weather[0].icon + ".png";
        }
Пример #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Pobieranie z okien wartosc
            string url   = textBox1.Text.ToString();
            string tekst = textBox2.Text.ToString();
            string emial = textBox3.Text.ToString();

            //Sprawdzenie czy string jest pusty
            if (String.IsNullOrEmpty(url))
            {
                MessageBox.Show("Uzupelnij pole URL!");
            }
            else if (String.IsNullOrEmpty(tekst))
            {
                MessageBox.Show("Uzupelnij pole Tekst!");
            }
            else if (String.IsNullOrEmpty(emial))
            {
                MessageBox.Show("Uzupelnij pole E-mail!");
            }
            //Jezeli podano wszystkie wartosc
            else
            {
                var        doc     = new HtmlAgilityPack.HtmlDocument();
                HtmlSample docHtml = new HtmlSample(url);

                //Pobieranie zawartosci strony
                var pageHtml = docHtml.GetPageHtml();

                //Zaladowanie zawartosci strony do obiektu HtmlAgilityPack
                doc.LoadHtml(pageHtml);

                // Metoda Descendants pozwala wybrać zestaw node'ów o określonej nazwie
                var nodes = doc.DocumentNode.Descendants("img");

                //Przeszukuje wszystkie node
                foreach (var node in nodes)
                {
                    //Jeżeli znalazł obrazek z nazwą podaną w polu Tekst
                    if (node.GetAttributeValue("alt", "").Contains(tekst))
                    {
                        string scr = node.GetAttributeValue("src", "");
                        string filename;
                        New_Log(", zrodlo: " + scr + ", emial: " + emial);
                        MessageBox.Show(scr);
                        filename = docHtml.Save(scr, "hehe.jpg");
                        docHtml.CreatEmail(filename, "*****@*****.**", "dupadupa", emial);
                    }
                }
            }
        }
Пример #10
0
        //Dodawanie do listy
        private void button_dodajDoListy_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "Slowo" && (textBox_url.Text == "" ||
                                                            textBox_slowo.Text == "" || comboBox_akcja.Text == "" || textBox_nazwaZadania.Text == "" ||
                                                            comboBox_akcja.Text == "Wyślij e-mailem" && textBox_email.Text == "")

                || tabControl1.SelectedTab.Text == "Pogoda" && comboBox_akcja.Text == "Wyślij e-mailem" &&
                (textBox1.Text == "" || comboBox1.Text == "" || comboBox_akcja.Text == "" || textBox_email.Text == "" || textBox_nazwaZadania.Text == "")

                || tabControl1.SelectedTab.Text == "Pogoda" && comboBox_akcja.Text == "Wyświetl obraz" &&
                (textBox1.Text == "" || textBox_nazwaZadania.Text == "")
                )
            {
                label_komunikat.Text = "Brakuje parametrów.";
                logger.Log("Dodanie do listy nie powiodło się. Stan pól TextBox: URL = " + textBox_url.Text + "; Słowo = " + textBox_slowo.Text + "; Akcja = " + comboBox_akcja.Text + "; Nazwa = " + textBox_nazwaZadania.Text + "; Mail = " + textBox_email.Text);
            }
            else
            {
                Task quest = new Task();
                if (tabControl1.SelectedTab.Text == "Slowo")
                {
                    var    hs       = new HtmlSample(textBox_url.Text);
                    string testPage = hs.GetPageHtml();
                    if (testPage == "")
                    {
                        label_komunikat.Text = "Popraw url i spróbuj ponownie.";
                        logger.Log($"Niepoprawny url: {testPage}");
                        return;
                    }
                }

                try
                {
                    quest.Create(textBox_url.Text, textBox_slowo.Text, textBox_email.Text, comboBox_akcja.Text, textBox_nazwaZadania.Text, textBox1.Text, comboBox1.Text, numericUpDown1.Value, tabControl1.SelectedTab.Text);
                }
                catch (System.Net.WebException)
                {
                    label_komunikat.Text = "Upewnij się że podajesz poprawną nazwę miejscowości";
                    logger.Log("quest.Create -> System.Net.WebException");
                    return;
                }
                quest.JpgPath = "";
                list.Add(quest);
                dbmgr.AddTask(quest);
                label_komunikat.Text = "Dodano zadanie.";
                logger.Log($"Dodano zadanie: {quest}");
            }
        }