Esempio n. 1
0
        static void Main(string[] args)
        {
            SPOService       spoM     = new SPOService();
            var              image    = spoM.GetPhotoInfo("Noticias", "1");
            CelebrityService cService = new CelebrityService();
            var              celebriy = cService.MakeAnalysisCelebrity(image);

            Console.WriteLine(cService.GetCelebrity(celebriy));
        }
Esempio n. 2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            string url = "https://encamina.sharepoint.com/sites/shernandez/SPOIntelligence";

            log.Info("C# HTTP trigger function processed a request.");
            string validationToken = req.GetQueryNameValuePairs()
                                     .FirstOrDefault(q => string.Compare(q.Key, "validationtoken", true) == 0)
                                     .Value;


            if (validationToken != null)
            {
                log.Info($"Validation token {validationToken} received");
                var response = req.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(validationToken);
                return(response);
            }

            log.Info($"SharePoint triggered our webhook...great :-)");
            var content = await req.Content.ReadAsStringAsync();

            log.Info($"Received following payload: {content}");

            var notifications = JsonConvert.DeserializeObject <ResponseModel <NotificationModel> >(content).Value;

            log.Info($"Found {notifications.Count} notifications");

            if (notifications.Count > 0)
            {
                var notification = notifications[0];

                log.Info($"Found {notification.SiteUrl} notifications");
                SPOService spService = new SPOService(url);
                var        eventData = spService.GetEvent(notification.Resource, url);

                HttpClient client = new HttpClient();

                log.Info("JSON:" + JsonConvert.SerializeObject(eventData));
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://spointelligence.azurewebsites.net/api/News?code=1OFts7dd2OaMT2z/bKr7KDHKL/q3Yf0OiN9iRSfemeWPaJIM14e8nQ==");
                request.Content = new StringContent(JsonConvert.SerializeObject(eventData), Encoding.UTF8, "application/json");
                HttpResponseMessage response = client.SendAsync(request).Result;
                if (response.IsSuccessStatusCode)
                {
                    string requestResult = response.Content.ReadAsStringAsync().Result;
                    if (JsonConvert.DeserializeObject <bool>(requestResult))
                    {
                        return(req.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }

            return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body"));
        }
Esempio n. 3
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            // parse query parameter
            dynamic data = await req.Content.ReadAsAsync <object>();

            log.Info("Data:" + data.Lista + data.Id + data.site);
            // Set name to query string or body data
            string lista = data?.Lista;
            string id    = data?.Id;
            string site  = data?.site;



            if (lista != null && id != null)
            {
                log.Info("Lista " + lista + " id " + id + " site " + site);

                SPOService       spoM          = new SPOService(site);
                var              image         = spoM.GetPhotoInfo(lista, id);
                CelebrityService cService      = new CelebrityService();
                var              content       = cService.MakeAnalysisCelebrity(image);
                var              celebrityName = cService.GetCelebrity(content.celebrity);

                log.Info("Obteniendo el celebrity");

                var azureSearch  = new AzureSearchService();
                var indexCreate  = azureSearch.CreateIndexAsync <AzureSearchModel>("newsindex", false, null).Result;
                var contentIndex = new AzureSearchModel()
                {
                    IdSharepoint = id, Name = celebrityName, Tags = content.tags, Id = id
                };
                var uploadDocument = azureSearch.UploadDocuments <AzureSearchModel>("newsindex", new List <AzureSearchModel>()
                {
                    contentIndex
                }.ToArray());

                log.Info("Creado el search");
                spoM.SetResultNews(lista, id, JsonConvert.SerializeObject(content.tags));
                return(req.CreateResponse(HttpStatusCode.OK, "Noticia categorizada"));
            }

            else
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Faltan parametros"));
            }
        }