コード例 #1
0
        public IActionResult JsonResult([FromBody] ObjectJson json)
        {
            var         url    = WebUtility.UrlDecode(json.url);
            MyWebClient client = new MyWebClient()
            {
                Encoding = Encoding.UTF8
            };

            client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36";
            if (json.isID)
            {
                client.DownloadData(url);
                var    mainUrl = client.ResponseUri.ToString();
                var    regex   = JsonConvert.DeserializeObject <JsonIDInput>(json.data);
                string item    = "";
                try
                {
                    var regexMatch = Regex.Match(mainUrl, regex._xpath);
                    item = regexMatch.Groups[regex.group_number].Value;
                }
                catch (Exception) { }
                return(Json(JsonConvert.SerializeObject(new JsonIDresult {
                    url = mainUrl, id = item
                }, Formatting.Indented)));
            }
            else
            {
                var          baseUri  = new Uri(url);
                var          isScript = json.javascript;
                var          config   = StructuredDataConfig.ParseJsonString(json.data);
                var          html     = client.DownloadString(!isScript ? url : this.configuration.GetAppSetting("UrlSeleniumGetHtmlExcuteJavascript") + "?url=" + WebUtility.UrlEncode(url));
                HtmlDocument docc     = new HtmlDocument();
                docc.LoadHtml(html);
                var urltmp = "";
                HtmlNodeCollection nodes = docc.DocumentNode.SelectNodes("//a");
                if (nodes != null)
                {
                    foreach (HtmlNode node in nodes)
                    {
                        if ((node.Attributes["href"] != null) && (node.Attributes["href"].Value != ""))
                        {
                            try
                            {
                                urltmp = node.Attributes["href"].Value.Trim();
                                node.Attributes["href"].Value = new Uri(baseUri, urltmp).AbsoluteUri;
                            }
                            catch (Exception) { }
                        }
                    }
                }
                ;
                html = docc.DocumentNode.InnerHtml;
                var openScraping    = new StructuredDataExtractor(config);
                var scrapingResults = openScraping.Extract(html);
                var result          = JsonConvert.SerializeObject(scrapingResults, Formatting.Indented);
                return(Json(result));
            }
        }
コード例 #2
0
    public static string ToJson <T>(T[] data)
    {
        ObjectJson <T> obj = new ObjectJson <T>()
        {
            data = data
        };
        string str = JsonUtility.ToJson(obj);

        str = str.Remove(0, 8);
        str = str.Remove(str.Length - 1, 1);
        return(str);
    }
コード例 #3
0
        internal void SendNotifcations()
        {
            RecipientsType.ForEach(item =>
            {
                item.FilttersRecipient.ForEach(r =>
                {
                    QueryReturn = "";
                    ParamsDynamicTableDataEvent.ForEach(d => {
                        QueryReturn = r.Filtter.Replace(d.IdParam, d.ValueParam);
                    });


                    using (Connection = new SqlConnection(ConectionString))
                    {
                        Connection.Open();
#pragma warning disable S3649 // User-provided values should be sanitized before use in SQL statements
                        using (Command = new SqlCommand(QueryReturn, Connection))
#pragma warning restore S3649 // User-provided values should be sanitized before use in SQL statements
                        {
                            MessageBase  = item.Message.Message;
                            TitleMessage = item.Message.TitleMessage;
                            DataAdapter  = new SqlDataAdapter(Command);
                            DataTable    = new DataTable();
                            DataAdapter.Fill(DataTable);
                            String table = QueryReturn.ToUpper();
                            if (table.Contains("FROM"))
                            {
                                table = table.Substring(table.LastIndexOf("FROM"));
                            }
                            if (table.Contains("WHERE"))
                            {
                                table = table.Substring(0, table.LastIndexOf("WHERE"));
                            }

                            table = table.Replace("FROM", "").Replace("WHERE", "");
                            String[] items;
                            if (table.Contains(","))
                            {
                                items = table.Split(',');
                                table = items[0].Trim();
                            }
                            else
                            {
                                table = table.Trim();
                            }



                            if (table.Contains(" "))
                            {
                                int index = QueryReturn.IndexOf(" ");
                                table     = table.Substring(0, index + 1);
                            }

                            String valueReplace = "";
                            foreach (DataRow dtRow in DataTable.Rows)
                            {
                                IdTables   = SchemaTables.GetColumKeys(ConectionString, Connection.Database, table);
                                JsonRow    = JsonConvert.SerializeObject(dtRow.Table).Replace("[", "").Replace("]", "");
                                ObjectJson = (JObject)JsonConvert.DeserializeObject(JsonRow);
                                IdTables.ForEach(i => { ObjectJson.Property(i)?.Remove(); });
                                JsonRow = ObjectJson.ToString();

                                item.Message.ConfigMessage.ForEach(c =>
                                {
                                    valueReplace = "";
                                    if (String.IsNullOrEmpty(c.DefinitiveValue))
                                    {
                                        c.NameColum.ForEach(d =>
                                        {
                                            foreach (var prop in ObjectJson)
                                            {
                                                if (prop.Key.ToUpper().Contains(d.ToUpper()))
                                                {
                                                    valueReplace = prop.Value?.ToString();
                                                    break;
                                                }
                                            }
                                        });
                                        if (String.IsNullOrEmpty(valueReplace))
                                        {
                                            c.ExpressionRegular.ForEach(f =>
                                            {
                                                Regex           = new Regex(f);
                                                MachtExpression = Regex.Match(JsonRow);
                                                if (MachtExpression.Groups.Count > 0)
                                                {
                                                    valueReplace = MachtExpression.Groups[0].Value;
                                                }
                                                Regex           = null;
                                                MachtExpression = null;
                                            });
                                        }
                                    }
                                    else
                                    {
                                        valueReplace = c.DefinitiveValue;
                                    }

                                    if (!String.IsNullOrEmpty(valueReplace))
                                    {
                                        MessageBase = MessageBase.Replace(c.DinamycParam, valueReplace);
                                    }
                                });
                                r.TypeNotification.ForEach(t => {
                                    string errorMessage   = "Type Notification not support";
                                    bool sendNotification = false;
                                    Regex           = new Regex(t.ExpressionRegularMach);
                                    MachtExpression = Regex.Match(JsonRow);



                                    if (Enum.TryParse(t.TypeNotification, out TypeNotification typeNotification) && !String.IsNullOrEmpty(MachtExpression.Value))
                                    {
                                        sendNotification = Notification.Send(MachtExpression.Value, TitleMessage, MessageBase, t.JsonNotificationConfig, typeNotification, t.Provaider, out errorMessage);
                                    }

                                    if (sendNotification)
                                    {
                                        errorMessage = "message send";
                                    }
                                    else if (String.IsNullOrEmpty(MachtExpression.Value))
                                    {
                                        errorMessage = "no se encontro en la consulta un destinatario";
                                    }



                                    Connection.Insert(new NotificationLog()
                                    {
                                        Destination           = MachtExpression.Groups[0].Value,
                                        MessageErrorProvaider = errorMessage,
                                        CreatedById           = "NotifyDll",
                                        MessageSend           = MessageBase,
                                        NotificationName      = NotficationName,
                                        NameRecipientsType    = item.RecipientName,
                                        FillterRecipenttype   = QueryReturn,
                                        Provaider             = t.Provaider,
                                        TypeNotification      = t.TypeNotification,
                                        TitleMessage          = TitleMessage,
                                        CreatedAt             = DateTime.Now,
                                        IsSend = sendNotification
                                    });
                                    //debe enviarse a grabar a la base de datos esta informacion
                                });
                            }
                            MessageBase  = null;
                            TitleMessage = null;
                        }
                    }
                });
            });
        }
コード例 #4
0
    public static T[] FromJson <T>(string str)
    {
        ObjectJson <T> obj = JsonUtility.FromJson <ObjectJson <T> >("{\"data\":" + str + "}");

        return(obj.data);
    }